Changeset 378
- Timestamp:
- 05/29/15 12:12:47 (10 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/logger.hh
r368 r378 131 131 * Console logger sink. 132 132 * 133 * Logs to st d::out -- be sure a console window is open, or std::out redirected!133 * Logs to standard output -- be sure a console window is open, or output redirected! 134 134 */ 135 135 class log_console_sink : public log_sink -
trunk/nv/core/logging.hh
r371 r378 82 82 { 83 83 log_append( t ); 84 log_sequence( level, std::forward<Args>( args )... );84 log_sequence( level, nv::forward<Args>( args )... ); 85 85 } 86 86 virtual ~logger_base() {} -
trunk/nv/lua/lua_path.hh
r368 r378 16 16 #include <nv/core/common.hh> 17 17 #include <nv/stl/string.hh> 18 #include <cstring> 18 #include <nv/stl/utility.hh> 19 #include <nv/stl/capi.hh> 19 20 20 21 struct lua_State; … … 32 33 { 33 34 static_assert( sizeof...( Args ) < 8, "Path can only take up to 8 arguments!" ); 34 initialize( std::forward<Args>( args )... );35 initialize( nv::forward<Args>( args )... ); 35 36 } 36 37 … … 42 43 void initialize( T&& arg ) 43 44 { 44 push( std::forward<T>( arg ) );45 push( nv::forward<T>( arg ) ); 45 46 if ( m_count == 1 && m_elements[0].length ) parse(); 46 47 } … … 49 50 void initialize( T&& arg, Args&&... args ) 50 51 { 51 push( std::forward<T>( arg ) );52 initialize( std::forward<Args>( args )... );52 push( nv::forward<T>( arg ) ); 53 initialize( nv::forward<Args>( args )... ); 53 54 } 54 55 -
trunk/nv/stl/capi.hh
r376 r378 18 18 #include <nv/core/common.hh> 19 19 20 namespace nv 21 { 22 23 namespace detail 24 { 25 20 26 #if NV_COMPILER == NV_MSVC 21 extern "C" { 22 NV_NOALIAS NV_RESTRICT void * __cdecl calloc( size_t _Count, size_t _Size ); 23 NV_NOALIAS void __cdecl free( void * _Memory ); 24 NV_NOALIAS NV_RESTRICT void * __cdecl malloc( size_t ); 25 NV_NOALIAS NV_RESTRICT void * __cdecl realloc( void * _Memory, size_t _NewSize ); 26 } 27 #define NV_CAPI_CALL(name) detail::name 28 extern "C" { 29 NV_NOALIAS NV_RESTRICT void * __cdecl calloc( size_t _Count, size_t _Size ); 30 NV_NOALIAS void __cdecl free( void * _Memory ); 31 NV_NOALIAS NV_RESTRICT void * __cdecl malloc( size_t ); 32 NV_NOALIAS NV_RESTRICT void * __cdecl realloc( void * _Memory, size_t _NewSize ); 33 void * __cdecl memcpy( void * _Dst, const void * _Src, size_t _Size ); 34 void * __cdecl memmove( void * _Dst, const void * _Src, size_t _Size ); 35 void * __cdecl memset( void * _Dst, int _Val, size_t _Size ); 36 void * __cdecl memchr( const void * _Buf, int _Val, size_t _MaxCount ); 37 int __cdecl memcmp( const void * _Buf1, const void * _Buf2, size_t _Size ); 38 int __cdecl strcmp( const char * _Str1, const char * _Str2 ); 39 int __cdecl strncmp( const char * _Str1, const char * _Str2, size_t _MaxCount ); 40 size_t __cdecl strlen( const char * _Str ); 41 } 27 42 #endif 28 // TODO: remove when clang 3.5 will be used (with builtins)43 // TODO: remove when clang 3.5 will be used (with builtins) 29 44 #if NV_COMPILER == NV_CLANG 30 extern "C" { 31 extern void * calloc( nv::size_t, nv::size_t ); 32 extern void free( void * ); 33 extern void * malloc( nv::size_t ); 34 extern void * realloc( void * , nv::size_t ); 35 } 45 #define NV_CAPI_CALL(name) detail::name 46 extern "C" { 47 extern void * __cdecl calloc( nv::size_t, nv::size_t ); 48 extern void __cdecl free( void * ); 49 extern void * __cdecl malloc( nv::size_t ); 50 extern void * __cdecl realloc( void * , nv::size_t ); 51 extern void * __cdecl memcpy( void * , const void * , nv::size_t ); 52 extern void * __cdecl memmove( void * , const void * , nv::size_t ); 53 extern void * __cdecl memset( void * , int , nv::size_t ); 54 extern void * __cdecl memchr( const void * , int , nv::size_t ); 55 extern int __cdecl memcmp( const void * , const void * , nv::size_t ); 56 extern int __cdecl strcmp ( const char * , const char * ); 57 extern int __cdecl strncmp( const char * , const char * , size_t ); 58 extern nv::size_t __cdecl strlen ( const char * ); 59 } 36 60 #endif 37 61 38 namespace nv 39 { 62 #if NV_COMPILER == NV_GNUC 63 #define NV_CAPI_CALL(name) __builtin_##name 64 #endif 65 } 66 40 67 inline void* nvmalloc( size_t size ) 41 68 { 42 #if NV_COMPILER == NV_MSVC 43 return malloc( size ); 44 #elif NV_COMPILER == NV_CLANG 45 return malloc( size ); 46 // return __builtin_operator_new( size ); 47 #else 48 return __builtin_malloc( size ); 49 #endif 69 return NV_CAPI_CALL(malloc)( size ); 50 70 } 51 71 inline void nvfree( void* p ) 52 72 { 53 #if NV_COMPILER == NV_MSVC 54 free( p ); 55 #elif NV_COMPILER == NV_CLANG 56 free( p ); 57 // __builtin_operator_delete( p ); 58 #else 59 __builtin_free( p ); 60 #endif 73 NV_CAPI_CALL( free )( p ); 74 } 75 76 inline void* nvmemcpy( void *dest, const void *src, size_t count ) 77 { 78 return NV_CAPI_CALL( memcpy )( dest, src, count ); 79 } 80 81 inline void* nvmemmove( void *dest, const void *src, size_t count ) 82 { 83 return NV_CAPI_CALL( memmove )( dest, src, count ); 84 } 85 86 inline void* nvmemset( void *dest, unsigned char value, size_t count ) 87 { 88 return NV_CAPI_CALL( memset )( dest, (int)value, count ); 89 } 90 91 inline void* nvmemchr( const void *src, unsigned char value, size_t max_count ) 92 { 93 return NV_CAPI_CALL( memchr )( src, (int)value, max_count ); 94 } 95 96 inline int nvmemcmp( const void * m1, const void * m2, nv::size_t max_count ) 97 { 98 return NV_CAPI_CALL( memcmp )( m1, m2, max_count ); 99 } 100 101 inline int nvstrcmp( const char * s1, const char * s2 ) 102 { 103 return NV_CAPI_CALL( strcmp )( s1, s2 ); 104 } 105 106 inline int nvstrncmp( const char * s1, const char * s2, size_t max_count ) 107 { 108 return NV_CAPI_CALL( strncmp )( s1, s2, max_count ); 109 } 110 111 inline nv::size_t nvstrlen( const char * s ) 112 { 113 return NV_CAPI_CALL( strlen )( s ); 61 114 } 62 115 63 116 } 64 117 118 #undef NV_CAPI_CALL 119 65 120 #endif // NV_STL_CAPI_HH -
trunk/nv/stl/cstring_store.hh
r369 r378 16 16 #include <nv/core/common.hh> 17 17 #include <nv/stl/array.hh> 18 #include <nv/stl/capi.hh> 18 19 #include <unordered_map> 19 #include <cstring>20 #include <cstdlib>21 20 22 21 namespace nv … … 28 27 inline char *cstring_duplicate( const char *s ) 29 28 { 30 size_t length = std::strlen( s ) + 1;31 void *result = std::malloc( length );29 size_t length = nvstrlen( s ) + 1; 30 void *result = nvmalloc( length ); 32 31 if ( result == nullptr ) return nullptr; 33 return (char *) std::memcpy( result, s, length );32 return (char *)nvmemcpy( result, s, length ); 34 33 } 35 34 … … 38 37 bool operator()( const char* lhs, const char* rhs ) const 39 38 { 40 return strcmp( lhs, rhs ) == 0;39 return nvstrcmp( lhs, rhs ) == 0; 41 40 } 42 41 }; -
trunk/nv/stl/iterator.hh
r374 r378 145 145 template < typename Iterator1, typename Iterator2 > 146 146 inline typename reverse_iterator<Iterator1>::difference_type operator-( const reverse_iterator<Iterator1>& lhs, const reverse_iterator<Iterator2>& rhs ) 147 { return lhs.base() - rhs.base(); }147 { return rhs.base() - lhs.base(); } 148 148 template < typename Iterator > inline reverse_iterator<Iterator> operator+( typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& iter ) 149 149 { return reverse_iterator<Iterator>( iter.base() - n ); } -
trunk/nv/stl/singleton.hh
r368 r378 14 14 #define NV_CORE_SINGLETON_HH 15 15 16 #include < cassert>16 #include <nv/core/common.hh> 17 17 18 18 namespace nv … … 35 35 singleton() 36 36 { 37 assert(!singleton_);37 NV_ASSERT(!singleton_,"Singleton already exists!"); 38 38 singleton_ = static_cast<T*>(this); 39 39 } … … 44 44 ~singleton() 45 45 { 46 assert(singleton_);47 singleton_ = 0;46 NV_ASSERT( singleton_, "Singleton already destroyed!" ); 47 singleton_ = nullptr; 48 48 } 49 49 … … 66 66 static T *pointer() 67 67 { 68 assert(singleton_);68 NV_ASSERT( singleton_, "Singleton not valid!" ); 69 69 return singleton_; 70 70 } … … 74 74 static T &reference() 75 75 { 76 assert(singleton_);77 76 NV_ASSERT( singleton_, "Singleton not valid!" ); 77 return *singleton_; 78 78 } 79 79 }; -
trunk/nv/stl/string.hh
r377 r378 22 22 23 23 #include <string> 24 #include <cstring>25 24 #include <sstream> 26 #include <fstream>27 25 #include <nv/core/common.hh> 28 26 #include <nv/stl/traits/primary.hh> … … 69 67 70 68 /** 71 * Utility function for converting a string to the given type72 *73 * @param vin the string representing the value74 * @param vout the value to be read. Must be streamable with >>75 * @throw runtime_error Throws runtime_error on conversion fail76 */77 template < class T >78 void from_string( const string& vin, T& vout )79 {80 std::istringstream value( vin );81 value >> vout;82 83 if ( value.fail() )84 {85 // NV_THROW( runtime_error, "bad cast" );86 }87 }88 89 /**90 * Utility function for converting a string to the given type91 *92 * @param vin the string representing the value93 * @throw runtime_error Throws runtime_error on conversion fail94 */95 template < class T >96 T string_cast( const string& vin )97 {98 T vout;99 std::istringstream value( vin );100 value >> vout;101 102 if ( value.fail() )103 {104 // NV_THROW( runtime_error, "bad cast" );105 }106 return vout;107 }108 109 110 /**111 * Override function for special treatment of strings. Returns the112 * value passed.113 */114 inline void from_string( const string& vin, string& vout )115 {116 vout = vin;117 }118 119 /**120 * Override function for special treatment of strings. Returns the121 * value passed.122 */123 template <>124 inline std::string string_cast( const string& vin )125 {126 return vin;127 }128 129 130 /**131 69 * Simple function for slurping a file into a string. 132 70 */ 133 inline std::string slurp( const std::string& filename ) 134 { 135 std::ifstream input(filename); 136 // if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!"); 137 std::stringstream sstr; 138 while(input >> sstr.rdbuf()); 139 return sstr.str(); 140 } 141 142 inline bool trim( std::string& str ) 143 { 144 size_t endpos = str.find_last_not_of(" \r\n\t"); 145 size_t startpos = str.find_first_not_of(" \r\n\t"); 146 147 if ( string::npos != endpos || string::npos != startpos ) 148 { 149 if ( string::npos == startpos ) startpos = 0; 150 if ( string::npos != endpos ) endpos = endpos+1-startpos; 151 str = str.substr( startpos, endpos ); 152 return true; 153 } 154 return false; 155 } 156 157 inline bool rtrim( std::string& str ) 158 { 159 size_t endpos = str.find_last_not_of(" \r\n\t"); 160 if ( string::npos != endpos ) 161 { 162 str = str.substr( 0, endpos+1 ); 163 return true; 164 } 165 return false; 166 } 167 168 inline bool ltrim( std::string& str ) 169 { 170 size_t startpos = str.find_first_not_of(" \r\n\t"); 171 if( string::npos != startpos ) 172 { 173 str = str.substr( startpos ); 174 return true; 175 } 176 return false; 177 } 178 179 inline std::string trimmed( const std::string& str ) 180 { 181 size_t endpos = str.find_last_not_of(" \r\n\t"); 182 size_t startpos = str.find_first_not_of(" \r\n\t"); 183 184 if ( string::npos != endpos || string::npos != startpos ) 185 { 186 if ( string::npos == startpos ) startpos = 0; 187 if ( string::npos != endpos ) endpos = endpos+1-startpos; 188 return str.substr( startpos, endpos ); 189 } 190 return str; 191 } 192 193 inline std::string rtrimmed( const std::string& str ) 194 { 195 size_t endpos = str.find_last_not_of(" \r\n\t"); 196 if ( string::npos != endpos ) 197 { 198 return str.substr( 0, endpos+1 ); 199 } 200 return str; 201 } 202 203 inline std::string ltrimmed( const std::string& str ) 204 { 205 size_t startpos = str.find_first_not_of(" \r\n\t"); 206 if( string::npos != startpos ) 207 { 208 return str.substr( startpos ); 209 } 210 return str; 211 } 212 213 inline bool ends_with( const std::string& s, const std::string & ending ) 214 { 215 if ( s.length() >= ending.length() ) { 216 return ( 0 == s.compare (s.length() - ending.length(), ending.length(), ending) ); 217 } else { 218 return false; 219 } 220 } 221 222 inline std::string& remove_chars( std::string& s, const std::string& chars ) 223 { 224 s.erase(nv::remove_if(s.begin(), s.end(), 225 [&chars](const char& c) { 226 return chars.find(c) != std::string::npos; 227 }), s.end()); 228 return s; 229 } 230 231 inline std::string extract_extension( const std::string& filename ) 232 { 233 size_t lastdot = filename.find_last_of( "." ); 234 std::string ext; 235 if ( std::string::npos != lastdot ) 236 ext = filename.substr( lastdot + 1 ); 237 transform_seq( ext.begin(), ext.end(), ext.begin(), [=] ( char val ) { return char( ::tolower( val ) ); } ); 238 return ext; 239 } 240 241 inline std::string remove_chars_copy( std::string s, const std::string& chars ) 242 { 243 return remove_chars(s, chars); 244 } 71 std::string slurp( const std::string& filename ); 245 72 246 73 namespace detail … … 264 91 struct string_length_impl < char* > 265 92 { 266 static size_t get( const char* s ) { return std::strlen( s ); }93 static size_t get( const char* s ) { return nvstrlen( s ); } 267 94 }; 268 95 template<> 269 96 struct string_length_impl < const char* > 270 97 { 271 static size_t get( const char* s ) { return std::strlen( s ); }98 static size_t get( const char* s ) { return nvstrlen( s ); } 272 99 }; 273 100 template<> … … 359 186 inline char at( size_type i ) const 360 187 { 361 // if ( i >= m_data ) NV_THROW( std::out_of_range( "string_ref::at" ) );188 // if ( i >= m_data ) NV_THROW( out_of_range( "string_ref::at" ) ); 362 189 return data()[i]; 363 190 } … … 370 197 { 371 198 size_type this_size = size(); 372 int cmp = std::memcmp( data(), rhs.data(), ( nv::min )( this_size, rhs.size() ) );199 int cmp = nvmemcmp( data(), rhs.data(), ( nv::min )( this_size, rhs.size() ) ); 373 200 return cmp != 0 ? cmp : ( this_size == rhs.size() ? 0 : this_size < rhs.size() ? -1 : 1 ); 374 201 } … … 376 203 bool starts_with( const string_base& s ) const 377 204 { 378 return size() >= s.size() && std::memcmp( data(), s.data(), s.size() ) == 0;205 return size() >= s.size() && nvmemcmp( data(), s.data(), s.size() ) == 0; 379 206 } 380 207 bool ends_with( char c ) const { return !empty() && c == back(); } 381 208 bool ends_with( const string_base& s ) const 382 209 { 383 return size() >= s.size() && std::memcmp( data() + size() - s.size(), s.data(), s.size() ) == 0;210 return size() >= s.size() && nvmemcmp( data() + size() - s.size(), s.data(), s.size() ) == 0; 384 211 } 385 212 size_type find( const string_base& s, size_type pos = 0 ) const … … 399 226 if ( pos >= size() ) return npos; 400 227 const_reverse_iterator it = search( this->crbegin() + (difference_type)pos, this->crend(), s.crbegin(), s.crend() ); 401 return it == this->crend() ? npos : size() - 1 - ( size_type )distance( this->crbegin(), it );228 return it == this->crend() ? npos : reverse_distance( this->crbegin(), it ); 402 229 } 403 230 size_type rfind( char c, size_type pos = 0 ) const … … 405 232 if ( pos >= size() ) return npos; 406 233 const_reverse_iterator it = find_if( this->crbegin() + (difference_type)pos, this->crend(), [=] ( char val ) { return val == c; } ); 407 return it == this->crend() ? npos : size() - 1 - ( size_type )distance( this->crbegin(), it );234 return it == this->crend() ? npos : reverse_distance( this->crbegin(), it ); 408 235 } 409 236 size_type find_first_of( char c ) const { return find( c ); } … … 417 244 { 418 245 const_reverse_iterator it = nv::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() ); 419 return it == this->crend() ? npos : size() - 1 - ( size_type )distance( this->crbegin(), it );246 return it == this->crend() ? npos : reverse_distance( this->crbegin(), it ); 420 247 } 421 248 size_type find_first_not_of( const string_base& s ) const 422 249 { 423 250 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it ) 424 if ( 0 == std::memchr( s.data(), *it, s.size() ) )251 if ( 0 == nvmemchr( s.data(), *it, s.size() ) ) 425 252 return ( size_type )distance( this->cbegin(), it ); 426 253 return npos; … … 436 263 { 437 264 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it ) 438 if ( 0 == std::memchr( s.data(), *it, s.size() ) )439 return size() - 1 - (size_type)distance( this->crbegin(), it );265 if ( 0 == nvmemchr( s.data(), *it, s.size() ) ) 266 return reverse_distance( this->crbegin(), it ); 440 267 return npos; 441 268 } … … 444 271 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it ) 445 272 if ( c != *it ) 446 return size() - 1 - ( size_type )distance( this->crbegin(), it );273 return reverse_distance( this->crbegin(), it ); 447 274 return npos; 448 275 } … … 466 293 } 467 294 295 // Literal constructors 296 template< size_t N > 297 inline string_base( char( &s )[N] ) : detail::data_base< const_storage_view< char > >( s, N - 1 ) {} 298 template< size_t N > 299 inline string_base( const char( &s )[N] ) : detail::data_base< const_storage_view< char > >( s, N - 1 ) {} 300 468 301 protected: 469 302 inline NV_CONSTEXPR string_base() : detail::data_base< const_storage_view< char > >() {} 470 303 inline NV_CONSTEXPR string_base( pointer a_data, size_type a_lenght ) 471 304 : detail::data_base< const_storage_view< char > >( a_data, a_lenght ) {} 305 306 template < typename ReverseIterator > 307 size_type reverse_distance( ReverseIterator first, ReverseIterator last ) const 308 { 309 return size() - 1 - distance( first, last ); 310 } 472 311 }; 473 312 … … 503 342 // Non-literal constructors 504 343 template< typename U > 505 inline string_ref( U str, typename enable_if<is_same<U, const char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {}344 inline string_ref( U str, typename enable_if<is_same<U, const char*>::value>::type* = nullptr ) : string_base( str, nvstrlen( str ) ) {} 506 345 507 346 // Non-literal constructors 508 347 template< typename U > 509 inline string_ref( U str, typename enable_if<is_same<U, char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {}348 inline string_ref( U str, typename enable_if<is_same<U, char*>::value>::type* = nullptr ) : string_base( str, nvstrlen( str ) ) {} 510 349 511 350 inline string_ref& operator=( const string_ref &rhs ) … … 546 385 explicit const_string( const char* str ) 547 386 { 548 initialize( str, std::strlen( str ) );387 initialize( str, nvstrlen( str ) ); 549 388 } 550 389 … … 582 421 { 583 422 char* data = new char[s + 1]; 584 std::memcpy( data, p, s );423 nvmemcpy( data, p, s ); 585 424 data[s] = 0; 586 425 assign( data, s ); … … 590 429 inline string_ref string_base::substr( size_type p, size_type n ) const 591 430 { 592 if ( p > size() ) return string_ref(); // NV_THROW( std::out_of_range( "substr" ) );431 if ( p > size() ) return string_ref(); // NV_THROW( out_of_range( "substr" ) ); 593 432 if ( n == p || p + n > size() ) n = size() - p; 594 433 return string_ref( data() + p, n ); … … 664 503 size_t f64_to_buffer( f64 n, char* str ); 665 504 505 inline string_ref trimmed( const string_ref& str ) 506 { 507 size_t endpos = str.find_last_not_of( " \r\n\t" ); 508 size_t startpos = str.find_first_not_of( " \r\n\t" ); 509 510 if ( string::npos != endpos || string::npos != startpos ) 511 { 512 if ( string::npos == startpos ) startpos = 0; 513 if ( string::npos != endpos ) endpos = endpos + 1 - startpos; 514 return str.substr( startpos, endpos ); 515 } 516 return str; 517 } 518 519 inline string_ref rtrimmed( const string_ref& str ) 520 { 521 size_t endpos = str.find_last_not_of( " \r\n\t" ); 522 if ( string::npos != endpos ) 523 { 524 return str.substr( 0, endpos + 1 ); 525 } 526 return str; 527 } 528 529 inline string_ref ltrimmed( const string_ref& str ) 530 { 531 size_t startpos = str.find_first_not_of( " \r\n\t" ); 532 if ( string::npos != startpos ) 533 { 534 return str.substr( startpos ); 535 } 536 return str; 537 } 538 539 540 inline string_ref extract_extension( string_ref filename ) 541 { 542 size_t lastdot = filename.find_last_of( '.' ); 543 if ( string_ref::npos != lastdot ) 544 return filename.substr( lastdot + 1 ); 545 return filename; 546 } 547 666 548 667 549 } -
trunk/nv/stl/traits/properties.hh
r377 r378 294 294 // TODO: non-standard, remove? 295 295 template < typename T > struct has_trivial_constructor : bool_constant < __has_trivial_constructor( T ) || __is_pod( T ) > {}; 296 template < typename T > struct has_trivial_copy : bool_constant < ( __has_trivial_copy( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value ) > {}; 296 297 template < typename T > struct has_trivial_assign : bool_constant < ( __has_trivial_assign( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_const<T>::value ) > {}; 297 298 template < typename T > struct has_trivial_destructor : bool_constant < __has_trivial_destructor( T ) || __is_pod( T ) > {}; -
trunk/src/gui/gui_gfx_renderer.cc
r376 r378 190 190 { 191 191 std::string id_name( filename ); 192 id_name.append( to_string( size ) );192 id_name.append( std::to_string( size ) ); 193 193 auto i = m_font_names.find( id_name ); 194 194 if ( i != m_font_names.end() ) -
trunk/src/lua/lua_area.cc
r374 r378 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/stl/string.hh"11 10 #include "nv/core/random.hh" 12 11 … … 325 324 { 326 325 nv::rectangle a = to_area( L, 1 ); 327 std::string s = "("; 328 s += nv::to_string(a.ul.x); 329 s += ","; 330 s += nv::to_string(a.ul.y); 331 s += "x"; 332 s += nv::to_string(a.lr.x); 333 s += ","; 334 s += nv::to_string(a.lr.y); 335 s += ")"; 336 lua_pushstring( L, s.c_str() ); 326 lua_pushfstring( L, "(%d,%dx%d,%d)", a.ul.x, a.ul.y, a.lr.x, a.lr.y ); 337 327 return 1; 338 328 } -
trunk/src/lua/lua_glm.cc
r369 r378 8 8 9 9 #include "nv/lua/lua_raw.hh" 10 #include "nv/stl/string.hh"11 10 #include "nv/core/random.hh" 11 #include "nv/stl/traits/common.hh" 12 12 13 13 static size_t nlua_swizzel_lookup[256]; … … 292 292 { 293 293 T v = to_vec<T>( L, 1 ); 294 std::string s = "("; 295 for ( size_t i = 0; i < v.length(); ++i ) 296 { 297 if (i > 0) s += ","; 298 s += nv::to_string(v[i]); 299 } 300 s+=")"; 301 lua_pushstring( L, s.c_str() ); 294 bool fl = nv::is_floating_point<typename T::value_type>::value; 295 switch ( v.length() ) 296 { 297 case 1: lua_pushfstring( L, ( fl ? "(%f)" : "(%d)" ), v[0] ); 298 case 2: lua_pushfstring( L, ( fl ? "(%f,%f)" : "(%d,%d)" ), v[0], v[1] ); 299 case 3: lua_pushfstring( L, ( fl ? "(%f,%f,%f)" : "(%d,%d,%d)" ), v[0], v[1], v[2] ); 300 case 4: lua_pushfstring( L, ( fl ? "(%f,%f,%f,%f)" : "(%d,%d,%d,%d)" ), v[0], v[1], v[2], v[3] ); 301 default: 302 lua_pushliteral( L, "(vector?)" ); break; 303 } 302 304 return 1; 303 305 } -
trunk/src/lua/lua_map_tile.cc
r374 r378 55 55 nv::map_area* map_area = nv::lua::detail::to_map_area( L, 3 ); 56 56 lua_settop( L, 2 ); 57 std::string code = nv::trimmed( lua_tostring( L, 1 ) ); 58 nv::remove_chars( code, " \r\t" ); 57 std::string code = nv::trimmed( lua_tostring( L, 1 ) ).to_string(); 58 std::string chars( " \r\t" ); 59 code.erase( nv::remove_if( code.begin(), code.end(), 60 [&chars] ( const char& c ) 61 { 62 return chars.find( c ) != std::string::npos; 63 } ), code.end() ); 59 64 60 65 map_tile tile; -
trunk/src/stl/assert.cc
r376 r378 34 34 } 35 35 # else 36 #include <assert.h> 36 extern "C" { 37 extern void __assert_fail(const char *, const char *, unsigned int, const char *) 38 throw() __attribute__ ((__noreturn__)); 39 } 37 40 # endif 38 41 void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function ) -
trunk/src/stl/string.cc
r374 r378 11 11 #include <cstdio> 12 12 #include <cstdlib> 13 #include <fstream> // for slurp only 13 14 14 15 using namespace nv; … … 16 17 static const double s_power_10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 17 18 10000000, 100000000, 1000000000 }; 19 20 std::string nv::slurp( const std::string& filename ) 21 { 22 std::ifstream input( filename ); 23 // if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!"); 24 std::stringstream sstr; 25 while ( input >> sstr.rdbuf() ); 26 return sstr.str(); 27 } 18 28 19 29 static inline void string_reverse( char* begin, char* end )
Note: See TracChangeset
for help on using the changeset viewer.