Changeset 378


Ignore:
Timestamp:
05/29/15 12:12:47 (10 years ago)
Author:
epyon
Message:
  • important fix in reverse_iterator operators
  • std::string functions removed or converted to string_ref in string.hh
  • capi.hh - more function forwards and usage of them instead of libc
  • more std removal
  • assert fix
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/logger.hh

    r368 r378  
    131131         * Console logger sink.
    132132         *
    133          * Logs to std::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!
    134134         */
    135135        class log_console_sink : public log_sink
  • trunk/nv/core/logging.hh

    r371 r378  
    8282                {
    8383                        log_append( t );
    84                         log_sequence( level, std::forward<Args>( args )... );
     84                        log_sequence( level, nv::forward<Args>( args )... );
    8585                }
    8686                virtual ~logger_base() {}
  • trunk/nv/lua/lua_path.hh

    r368 r378  
    1616#include <nv/core/common.hh>
    1717#include <nv/stl/string.hh>
    18 #include <cstring>
     18#include <nv/stl/utility.hh>
     19#include <nv/stl/capi.hh>
    1920
    2021struct lua_State;
     
    3233                        {
    3334                                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 )... );
    3536                        }
    3637
     
    4243                        void initialize( T&& arg )
    4344                        {
    44                                 push( std::forward<T>( arg ) );
     45                                push( nv::forward<T>( arg ) );
    4546                                if ( m_count == 1 && m_elements[0].length ) parse();
    4647                        }
     
    4950                        void initialize( T&& arg, Args&&... args )
    5051                        {
    51                                 push( std::forward<T>( arg ) );
    52                                 initialize( std::forward<Args>( args )... );
     52                                push( nv::forward<T>( arg ) );
     53                                initialize( nv::forward<Args>( args )... );
    5354                        }
    5455
  • trunk/nv/stl/capi.hh

    r376 r378  
    1818#include <nv/core/common.hh>
    1919
     20namespace nv
     21{
     22
     23        namespace detail
     24        {
     25
    2026#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                }
    2742#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)
    2944#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        }
    3660#endif
    3761
    38 namespace nv
    39 {
     62#if NV_COMPILER == NV_GNUC
     63#define NV_CAPI_CALL(name) __builtin_##name
     64#endif
     65        }
     66
    4067        inline void* nvmalloc( size_t size )
    4168        {
    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 );
    5070        }
    5171        inline void nvfree( void* p )
    5272        {
    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 );
    61114        }
    62115
    63116}
    64117
     118#undef NV_CAPI_CALL
     119
    65120#endif // NV_STL_CAPI_HH
  • trunk/nv/stl/cstring_store.hh

    r369 r378  
    1616#include <nv/core/common.hh>
    1717#include <nv/stl/array.hh>
     18#include <nv/stl/capi.hh>
    1819#include <unordered_map>
    19 #include <cstring>
    20 #include <cstdlib>
    2120
    2221namespace nv
     
    2827                inline char *cstring_duplicate( const char *s )
    2928                {
    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 );
    3231                        if ( result == nullptr ) return nullptr;
    33                         return (char *)std::memcpy( result, s, length );
     32                        return (char *)nvmemcpy( result, s, length );
    3433                }
    3534
     
    3837                        bool operator()( const char* lhs, const char* rhs ) const
    3938                        {
    40                                 return strcmp( lhs, rhs ) == 0;
     39                                return nvstrcmp( lhs, rhs ) == 0;
    4140                        }
    4241                };
  • trunk/nv/stl/iterator.hh

    r374 r378  
    145145        template < typename Iterator1, typename Iterator2 >
    146146        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(); }
    148148        template < typename Iterator > inline reverse_iterator<Iterator> operator+( typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& iter )
    149149        { return reverse_iterator<Iterator>( iter.base() - n ); }
  • trunk/nv/stl/singleton.hh

    r368 r378  
    1414#define NV_CORE_SINGLETON_HH
    1515
    16 #include <cassert>
     16#include <nv/core/common.hh>
    1717
    1818namespace nv
     
    3535        singleton()
    3636        {
    37             assert(!singleton_);
     37            NV_ASSERT(!singleton_,"Singleton already exists!");
    3838            singleton_ = static_cast<T*>(this);
    3939        }
     
    4444        ~singleton()
    4545        {
    46             assert(singleton_);
    47             singleton_ = 0;
     46                        NV_ASSERT( singleton_, "Singleton already destroyed!" );
     47                        singleton_ = nullptr;
    4848        }
    4949
     
    6666        static T *pointer()
    6767        {
    68             assert(singleton_);
     68                        NV_ASSERT( singleton_, "Singleton not valid!" );
    6969            return singleton_;
    7070        }
     
    7474        static T &reference()
    7575        {
    76             assert(singleton_);
    77             return *singleton_;
     76                        NV_ASSERT( singleton_, "Singleton not valid!" );
     77                        return *singleton_;
    7878        }
    7979    };
  • trunk/nv/stl/string.hh

    r377 r378  
    2222
    2323#include <string>
    24 #include <cstring>
    2524#include <sstream>
    26 #include <fstream>
    2725#include <nv/core/common.hh>
    2826#include <nv/stl/traits/primary.hh>
     
    6967
    7068        /**
    71         * Utility function for converting a string to the given type
    72         *
    73         * @param vin the string representing the value
    74         * @param vout the value to be read. Must be streamable with >>
    75         * @throw runtime_error Throws runtime_error on conversion fail
    76         */
    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 type
    91         *
    92         * @param vin the string representing the value
    93         * @throw runtime_error Throws runtime_error on conversion fail
    94         */
    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 the
    112         * 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 the
    121         * value passed.
    122         */
    123         template <>
    124         inline std::string string_cast( const string& vin )
    125         {
    126                 return vin;
    127         }
    128 
    129 
    130         /**
    13169        * Simple function for slurping a file into a string.
    13270        */
    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 );
    24572
    24673        namespace detail
     
    26491                struct string_length_impl < char* >
    26592                {
    266                         static size_t get( const char* s ) { return std::strlen( s ); }
     93                        static size_t get( const char* s ) { return nvstrlen( s ); }
    26794                };
    26895                template<>
    26996                struct string_length_impl < const char* >
    27097                {
    271                         static size_t get( const char* s ) { return std::strlen( s ); }
     98                        static size_t get( const char* s ) { return nvstrlen( s ); }
    27299                };
    273100                template<>
     
    359186                inline char at( size_type i ) const
    360187                {
    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" ) );
    362189                        return data()[i];
    363190                }
     
    370197                {
    371198                        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() ) );
    373200                        return cmp != 0 ? cmp : ( this_size == rhs.size() ? 0 : this_size < rhs.size() ? -1 : 1 );
    374201                }
     
    376203                bool starts_with( const string_base& s ) const
    377204                {
    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;
    379206                }
    380207                bool ends_with( char c ) const { return !empty() && c == back(); }
    381208                bool ends_with( const string_base& s ) const
    382209                {
    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;
    384211                }
    385212                size_type find( const string_base& s, size_type pos = 0 ) const
     
    399226                        if ( pos >= size() ) return npos;
    400227                        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 );
    402229                }
    403230                size_type rfind( char c, size_type pos = 0 ) const
     
    405232                        if ( pos >= size() ) return npos;
    406233                        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 );
    408235                }
    409236                size_type find_first_of( char c ) const { return find( c ); }
     
    417244                {
    418245                        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 );
    420247                }
    421248                size_type find_first_not_of( const string_base& s ) const
    422249                {
    423250                        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() ) )
    425252                                        return ( size_type )distance( this->cbegin(), it );
    426253                        return npos;
     
    436263                {
    437264                        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 );
    440267                        return npos;
    441268                }
     
    444271                        for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    445272                                if ( c != *it )
    446                                         return size() - 1 - ( size_type )distance( this->crbegin(), it );
     273                                        return reverse_distance( this->crbegin(), it );
    447274                        return npos;
    448275                }
     
    466293                }
    467294
     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
    468301        protected:
    469302                inline NV_CONSTEXPR string_base() : detail::data_base< const_storage_view< char > >() {}
    470303                inline NV_CONSTEXPR string_base( pointer a_data, size_type a_lenght )
    471304                        : 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                }
    472311        };
    473312
     
    503342                // Non-literal constructors
    504343                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 ) ) {}
    506345
    507346                // Non-literal constructors
    508347                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 ) ) {}
    510349
    511350                inline string_ref& operator=( const string_ref &rhs )
     
    546385                explicit const_string( const char* str )
    547386                {
    548                         initialize( str, std::strlen( str ) );
     387                        initialize( str, nvstrlen( str ) );
    549388                }
    550389
     
    582421                {
    583422                        char* data = new char[s + 1];
    584                         std::memcpy( data, p, s );
     423                        nvmemcpy( data, p, s );
    585424                        data[s] = 0;
    586425                        assign( data, s );
     
    590429        inline string_ref string_base::substr( size_type p, size_type n ) const
    591430        {
    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" ) );
    593432                if ( n == p || p + n > size() ) n = size() - p;
    594433                return string_ref( data() + p, n );
     
    664503size_t f64_to_buffer( f64 n, char* str );
    665504
     505inline 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
     519inline 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
     529inline 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
     540inline 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
    666548
    667549}
  • trunk/nv/stl/traits/properties.hh

    r377 r378  
    294294// TODO: non-standard, remove?
    295295        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 ) > {};
    296297        template < typename T > struct has_trivial_assign      : bool_constant < ( __has_trivial_assign( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_const<T>::value ) > {};
    297298        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  
    190190{
    191191        std::string id_name( filename );
    192         id_name.append( to_string( size ) );
     192        id_name.append( std::to_string( size ) );
    193193        auto i = m_font_names.find( id_name );
    194194        if ( i != m_font_names.end() )
  • trunk/src/lua/lua_area.cc

    r374 r378  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/stl/string.hh"
    1110#include "nv/core/random.hh"
    1211
     
    325324{
    326325        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 );
    337327        return 1;
    338328}
  • trunk/src/lua/lua_glm.cc

    r369 r378  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/stl/string.hh"
    1110#include "nv/core/random.hh"
     11#include "nv/stl/traits/common.hh"
    1212
    1313static size_t nlua_swizzel_lookup[256];
     
    292292{
    293293        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        }
    302304        return 1;
    303305}
  • trunk/src/lua/lua_map_tile.cc

    r374 r378  
    5555        nv::map_area* map_area = nv::lua::detail::to_map_area( L, 3 );
    5656        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() );
    5964
    6065        map_tile tile;
  • trunk/src/stl/assert.cc

    r376 r378  
    3434}
    3535#       else
    36 #include <assert.h>
     36extern "C" {
     37        extern void __assert_fail(const char *, const char *, unsigned int, const char *)
     38                throw() __attribute__ ((__noreturn__));
     39}
    3740#       endif
    3841void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function )
  • trunk/src/stl/string.cc

    r374 r378  
    1111#include <cstdio>
    1212#include <cstdlib>
     13#include <fstream> // for slurp only
    1314
    1415using namespace nv;
     
    1617static const double s_power_10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000,
    171810000000, 100000000, 1000000000 };
     19
     20std::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}
    1828
    1929static inline void string_reverse( char* begin, char* end )
Note: See TracChangeset for help on using the changeset viewer.