Changeset 433


Ignore:
Timestamp:
07/21/15 19:40:00 (10 years ago)
Author:
epyon
Message:
  • string.hh split into separate files
  • string.hh - removed std::string conversions (header still stays though)
Location:
trunk
Files:
6 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/gui/gui_environment.hh

    r395 r433  
    3131                        environment( renderer* r );
    3232                        // temporary
    33                         void load_style( const std::string& filename );
     33                        void load_style( const string_view& filename );
    3434                        handle create_element( const rectangle& r );
    3535                        handle create_element( handle parent, const rectangle& r );
  • trunk/nv/gui/gui_gfx_renderer.hh

    r395 r433  
    5656                        const image_info* get_image( size_t name ) const;
    5757
    58                         size_t load_font( const std::string& filename, size_t size );
    59                         size_t load_image( const std::string& filename );
     58                        size_t load_font( const string_view& filename, size_t size );
     59                        size_t load_image( const string_view& filename );
    6060
    61                         typedef unordered_map< std::string, size_t > names;
     61                        typedef hash_store< shash64, size_t > names;
    6262                        typedef vector< texture_font* >              font_vector;
    6363                        typedef vector< image_info >                 image_vector;
  • trunk/nv/gui/gui_renderer.hh

    r406 r433  
    2828                public:
    2929                        renderer() {}
    30                         virtual void load_style( const std::string& filename );
     30                        virtual void load_style( const string_view& filename );
    3131                        virtual void redraw( element* e, uint32 ) = 0;
    3232                        virtual void draw( element* e ) = 0;
  • trunk/nv/gui/gui_style.hh

    r395 r433  
    2727                public:
    2828                        style();
    29                         void load_style( const std::string& filename );
     29                        void load_style( const string_view& filename );
    3030                        bool get( element* e, const char* centry, const char* cselector, std::string& s );
    3131                        bool get( element* e, const char* centry, const char* cselector, vec4& vec );
  • trunk/nv/stl/memory.hh

    r427 r433  
    161161                size_type         m_size;
    162162        };
    163 
    164163
    165164        template < typename T >
  • trunk/nv/stl/string.hh

    r431 r433  
    2323#define NV_STL_STRING_HH
    2424
    25 #include <nv/common.hh>
     25#include <nv/stl/string/common.hh>
     26#include <nv/stl/string/string_base.hh>
     27#include <nv/stl/string/literal_string.hh>
     28#include <nv/stl/string/const_string.hh>
     29#include <nv/stl/string/short_string.hh>
    2630#include <string>
    2731#include <sstream>
     
    3337namespace nv
    3438{
    35 
    36         template < typename Storage > class string_base;
    37         class string_view;
    38 
    39         //      short_string< size_t >
    40         //      string32
    41         //      string64
    42         //      string
    43 
     39       
    4440        template< typename H >
    4541        struct hash< std::string, H > : detail::hash_base< std::string, H >
     
    7066                };
    7167
    72                 template < typename T, typename Enable = void >
    73                 struct is_string_base_impl : false_type {};
    74                 template < typename T >
    75                 struct is_string_base_impl < T,
    76                         typename enable_if<
    77                         is_base_of< string_base< typename T::storage_type >, T >::value,
    78                         void >::type > : true_type{};
     68
    7969        }
    8070
    81         // Stronger version
    82         //      template < typename T >
    83         //      struct is_string_base : is_template_base_of< T, string_base > {};
    84 
    85         template < typename T >
    86         struct is_string_base : detail::is_string_base_impl< T > {};
    8771
    8872        template < typename T >
     
    9175
    9276        };
    93 
    94         // string base class - will become a base for a string class later
    95         template < typename Storage >
    96         class string_base : public Storage
    97         {
    98                 typedef Storage                                     base_type;
    99                 typedef string_base< base_type >                    this_type;
    100         public:
    101                 typedef Storage                                     storage_type;
    102                 typedef typename base_type::value_type              value_type;
    103                 typedef typename base_type::pointer                 pointer;
    104                 typedef typename base_type::const_pointer           const_pointer;
    105                 typedef typename base_type::reference               reference;
    106                 typedef typename base_type::const_reference         const_reference;
    107                 typedef typename base_type::iterator                iterator;
    108                 typedef typename base_type::const_iterator          const_iterator;
    109                 typedef typename base_type::reverse_iterator        reverse_iterator;
    110                 typedef typename base_type::const_reverse_iterator  const_reverse_iterator;
    111                 typedef typename base_type::size_type               size_type;
    112                 typedef typename base_type::difference_type         difference_type;
    113 
    114                 static constexpr size_type npos = size_type( -1 );
    115 
    116                 // conversion to std::string
    117                 inline std::string to_string() const
    118                 {
    119                         return std::string( this->data(), this->size() );
    120                 }
    121 
    122                 inline size_type length()   const { return this->size(); }
    123 
    124                 // string operations
    125                 int compare( const string_view& rhs ) const;
    126                 bool starts_with( value_type c ) const;
    127                 bool starts_with( const string_view& s ) const;
    128                 bool ends_with( value_type c ) const;
    129                 bool ends_with( const string_view& s ) const;
    130                 auto find( value_type c, size_type pos = 0 ) const->size_type;
    131                 auto find( const string_view& s, size_type pos = 0 ) const->size_type;
    132                 auto rfind( value_type c, size_type pos = 0 ) const->size_type;
    133                 auto rfind( const string_view& s, size_type pos = 0 ) const->size_type;
    134                 auto find_first_of( value_type c ) const->size_type;
    135                 auto find_first_of( const string_view& s ) const->size_type;
    136                 auto find_last_of( value_type c )  const->size_type;
    137                 auto find_last_of( const string_view& s ) const->size_type;
    138                 auto find_first_not_of( value_type c ) const->size_type;
    139                 auto find_first_not_of( const string_view& s ) const->size_type;
    140                 auto find_last_not_of( value_type c ) const->size_type;
    141                 auto find_last_not_of( const string_view& s ) const->size_type;
    142 
    143                 // string operations
    144                 string_view substr( size_type p, size_type n = npos ) const;
    145 
    146                 template < typename H = size_type >
    147                 inline H get_hash() const
    148                 {
    149                         return hash_string< H >( this->data(), this->size() );
    150                 }
    151 
    152         protected:
    153                 using base_type::base_type;
    154                 constexpr string_base() : base_type() {}
    155                 constexpr string_base( pointer str, size_type len ) : base_type( str, len ) {}
    156 
    157                 template < typename ReverseIterator >
    158                 size_type reverse_distance( ReverseIterator first, ReverseIterator last ) const
    159                 {
    160                         return this->size() - 1 - static_cast<size_t>( nv::distance( first, last ) );
    161                 }
    162         };
    163 
    164         template< typename T, typename H >
    165         struct hash< T, H, typename enable_if< is_string_base<T>::value, void >::type >
    166                 : detail::hash_base< T, H >
    167         {
    168                 static H get( const T& value )
    169                 {
    170                         return value.template get_hash< H >();
    171                 }
    172                 inline H operator()( const T& value ) const { return get( value ); }
    173         };
    174 
    175         class string_view : public string_base< array_view< char > >
    176         {
    177         public:
    178                 typedef string_base< array_view< char > > this_type;
    179 
    180                 constexpr string_view() : this_type() {}
    181                 inline string_view( const string_view& rhs ) : this_type( rhs.data(), rhs.size() ) {}
    182                 template < typename S >
    183                 inline string_view( const string_base<S>& rhs ) : this_type( rhs.data(), rhs.size() ) {}
    184                 inline string_view( const std::string& str ) : this_type( str.data(), str.size() ) {}
    185                 constexpr string_view( const char* str, size_type len ) : this_type( str, len ) {}
    186 
    187                 // Literal constructors
    188                 template< size_t N >
    189                 constexpr string_view( char( &s )[N] ) : this_type( s, N - 1 ) {}
    190                 template< size_t N >
    191                 constexpr string_view( const char( &s )[N] ) : this_type( s, N - 1 ) {}
    192 
    193                 // Non-literal constructors
    194                 template< typename U >
    195                 inline string_view( U str, typename enable_if<is_same<U, const char*>::value>::type* = nullptr ) : this_type( str, nvstrlen( str ) ) {}
    196 
    197                 // Non-literal constructors
    198                 template< typename U >
    199                 inline string_view( U str, typename enable_if<is_same<U, char*>::value>::type* = nullptr ) : this_type( str, nvstrlen( str ) ) {}
    200 
    201                 inline string_view& operator=( const string_view &rhs )
    202                 {
    203                         assign( rhs.data(), rhs.size() );
    204                         return *this;
    205                 }
    206 
    207                 // modifiers
    208                 inline void clear()
    209                 {
    210                         assign( nullptr, 0 );
    211                 }
    212                 inline void remove_prefix( size_type n )
    213                 {
    214                         size_type s = size();
    215                         if ( n > s ) n = s;
    216                         assign( data() + n, s - n );
    217                 }
    218                 inline void remove_suffix( size_type n )
    219                 {
    220                         size_type s = size();
    221                         if ( n > s ) n = s;
    222                         assign( data(), s - n );
    223                 }
    224 
    225         };
    226 
    227         template < typename Storage >
    228         inline int string_base< Storage >::compare( const string_view& rhs ) const
    229         {
    230                 size_type this_size = this->size();
    231                 int cmp = nvmemcmp( this->data(), rhs.data(), nv::min( this_size, rhs.size() ) );
    232                 return cmp != 0 ? cmp : ( this_size == rhs.size() ? 0 : this_size < rhs.size() ? -1 : 1 );
    233         }
    234 
    235         template < typename Storage >
    236         inline bool string_base< Storage >::starts_with( value_type c ) const
    237         {
    238                 return !this->empty() && c == this->front();
    239         }
    240         template < typename Storage >
    241         inline bool string_base< Storage >::starts_with( const string_view& s ) const
    242         {
    243                 return this->size() >= s.size() && nvmemcmp( this->data(), s.data(), s.size() ) == 0;
    244         }
    245 
    246         template < typename Storage >
    247         inline bool string_base< Storage >::ends_with( value_type c ) const
    248         {
    249                 return !this->empty() && c == this->back();
    250         }
    251         template < typename Storage >
    252         inline bool string_base< Storage >::ends_with( const string_view& s ) const
    253         {
    254                 return this->size() >= s.size() && nvmemcmp( this->data() + this->size() - s.size(), s.data(), s.size() ) == 0;
    255         }
    256 
    257         template < typename Storage >
    258         inline auto string_base< Storage >::find( value_type c, size_type pos /*= 0*/ ) const -> size_type
    259         {
    260                 if ( pos >= this->size() ) return npos;
    261                 const_iterator it = nv::find_if( this->cbegin() + static_cast<difference_type>( pos ), this->cend(), [=] ( value_type val ) { return val == c; } );
    262                 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) );
    263         }
    264         template < typename Storage >
    265         inline auto string_base< Storage >::find( const string_view& s, size_type pos /*= 0*/ ) const -> size_type
    266         {
    267                 if ( pos >= this->size() ) return npos;
    268                 const_iterator it = nv::search( this->cbegin() + static_cast<difference_type>( pos ), this->cend(), s.cbegin(), s.cend() );
    269                 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) );
    270         }
    271 
    272         template < typename Storage >
    273         inline auto string_base< Storage >::rfind( value_type c, size_type pos /*= 0*/ ) const -> size_type
    274         {
    275                 if ( pos >= this->size() ) return npos;
    276                 const_reverse_iterator it = nv::find_if( this->crbegin() + static_cast<difference_type>( pos ), this->crend(), [=] ( value_type val ) { return val == c; } );
    277                 return it == this->crend() ? npos : this->reverse_distance( this->crbegin(), it );
    278         }
    279         template < typename Storage >
    280         inline auto string_base< Storage >::rfind( const string_view& s, size_type pos /*= 0*/ ) const -> size_type
    281         {
    282                 if ( pos >= this->size() ) return npos;
    283                 const_reverse_iterator it = nv::search( this->crbegin() + static_cast<difference_type>( pos ), this->crend(), s.crbegin(), s.crend() );
    284                 return it == this->crend() ? npos : this->reverse_distance( this->crbegin(), it );
    285         }
    286 
    287         template < typename Storage >
    288         inline auto string_base< Storage >::find_first_of( value_type c ) const -> size_type
    289         {
    290                 return this->find( c );
    291         }
    292         template < typename Storage >
    293         inline auto string_base< Storage >::find_first_of( const string_view& s ) const -> size_type
    294         {
    295                 const_iterator it = nv::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() );
    296                 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) );
    297         }
    298 
    299         template < typename Storage >
    300         inline auto string_base< Storage >::find_last_of( value_type c ) const -> size_type
    301         {
    302                 return this->rfind( c );
    303         }
    304         template < typename Storage >
    305         inline auto string_base< Storage >::find_last_of( const string_view& s ) const -> size_type
    306         {
    307                 const_reverse_iterator it = nv::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() );
    308                 return it == this->crend() ? npos : this->reverse_distance( this->crbegin(), it );
    309         }
    310 
    311         template < typename Storage >
    312         inline auto string_base< Storage >::find_first_not_of( value_type c ) const -> size_type
    313         {
    314                 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
    315                         if ( c != *it )
    316                         return static_cast<size_type>( nv::distance( this->cbegin(), it ) );
    317                 return npos;
    318         }
    319         template < typename Storage >
    320         inline auto string_base< Storage >::find_first_not_of( const string_view& s ) const -> size_type
    321         {
    322                 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
    323                         if ( 0 == nvmemchr( s.data(), static_cast<uchar8>( *it ), s.size() ) )
    324                         return static_cast<size_type>( nv::distance( this->cbegin(), it ) );
    325                 return npos;
    326         }
    327 
    328         template < typename Storage >
    329         inline auto string_base< Storage >::find_last_not_of( value_type c ) const -> size_type
    330         {
    331                 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    332                         if ( c != *it )
    333                         return this->reverse_distance( this->crbegin(), it );
    334                 return npos;
    335         }
    336         template < typename Storage >
    337         inline auto string_base< Storage >::find_last_not_of( const string_view& s ) const -> size_type
    338         {
    339                 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    340                         if ( 0 == nvmemchr( s.data(), static_cast<uchar8>( *it ), s.size() ) )
    341                         return this->reverse_distance( this->crbegin(), it );
    342                 return npos;
    343         }
    344 
    345         template < typename Storage >
    346         inline string_view string_base< Storage >::substr( size_type p, size_type n ) const
    347         {
    348                 if ( p > this->size() ) return string_view(); // NV_THROW( out_of_range( "substr" ) );
    349                 if ( n == npos || n == p || p + n > this->size() ) n = this->size() - p;
    350                 return string_view( this->data() + p, n );
    351         }
    352 
    353 #define NV_STRING_BASE_CAST_OPERATORS( OPERATOR )\
    354 template < typename S > inline bool operator OPERATOR ( const string_base< S >& lhs, const std::string& rhs )\
    355 {\
    356         return lhs OPERATOR string_view( rhs );\
    357 }\
    358 template < typename S > inline bool operator OPERATOR ( const std::string& lhs, const string_base< S >& rhs )\
    359 {\
    360         return string_view( lhs ) OPERATOR rhs;\
    361 }\
    362 template < typename S > inline bool operator OPERATOR ( const string_base< S >& lhs, const char* rhs )\
    363 {\
    364         return lhs OPERATOR string_view( rhs );\
    365 }\
    366 template < typename S > inline bool operator OPERATOR ( const char* lhs, const string_base< S >& rhs )\
    367 {\
    368         return string_view( lhs ) OPERATOR rhs;\
    369 }\
    370 
    371         // Base operators
    372         template < typename S1, typename S2 >
    373         inline bool operator==( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    374         {
    375                 return lhs.size() != rhs.size() ? false : ( lhs.compare( rhs ) == 0 );
    376         }
    377         template < typename S1, typename S2 >
    378         inline bool operator!=( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    379         {
    380                 return lhs.size() != rhs.size() ? true : ( lhs.compare( rhs ) != 0 );
    381         }
    382         template < typename S1, typename S2 >
    383         inline bool operator<( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    384         {
    385                 return lhs.compare( rhs ) < 0;
    386         }
    387         template < typename S1, typename S2 >
    388         inline bool operator>( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    389         {
    390                 return lhs.compare( rhs ) > 0;
    391         }
    392         template < typename S1, typename S2 >
    393         inline bool operator<=( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    394         {
    395                 return lhs.compare( rhs ) <= 0;
    396         }
    397         template < typename S1, typename S2 >
    398         inline bool operator>=( const string_base< S1 >& lhs, const string_base< S2 >& rhs )
    399         {
    400                 return lhs.compare( rhs ) >= 0;
    401         }
    402 
    403         NV_STRING_BASE_CAST_OPERATORS( == )
    404                 NV_STRING_BASE_CAST_OPERATORS( != )
    405                 NV_STRING_BASE_CAST_OPERATORS( < )
    406                 NV_STRING_BASE_CAST_OPERATORS( > )
    407                 NV_STRING_BASE_CAST_OPERATORS( <= )
    408                 NV_STRING_BASE_CAST_OPERATORS( >= )
    409 
    410 
    411 #undef NV_STRING_REF_CAST_OPERATORS
    41277
    41378        size_t sint32_to_buffer( sint32 n, char* str );
     
    42388        float buffer_to_f32( const char* s, char** end );
    42489        double buffer_to_f64( const char* s, char** end );
    425 
    426         // const string is movable but not copyable
    427         class const_string : public string_base< array_view< char > >
    428         {
    429         public:
    430                 inline const_string() {}
    431                 inline const_string( const char* str, size_type len )
    432                 {
    433                         initialize( str, len );
    434                 }
    435                 inline explicit const_string( const char* str )
    436                 {
    437                         initialize( str, nvstrlen( str ) );
    438                 }
    439                 inline const_string( const string_view& rhs )
    440                 {
    441                         initialize( rhs.data(), rhs.size() );
    442                 }
    443                 template< size_t N >
    444                 inline const_string( char( &s )[N] )
    445                 {
    446                         initialize( s, N-1 );
    447                 }
    448                 template< size_t N >
    449                 inline const_string( const char( &s )[N] )
    450                 {
    451                         initialize( s, N - 1 );
    452                 }
    453                 ~const_string()
    454                 {
    455                         if ( data() )
    456                         {
    457                                 delete data();
    458                         }
    459                 }
    460 
    461                 inline const_string( const_string&& other )
    462                 {
    463                         assign( other.data(), other.size() );
    464                         other.assign( nullptr, 0 );
    465                 }
    466 
    467                 inline const_string& operator=( const_string&& other )
    468                 {
    469                         pointer   old_data = data();
    470                         size_type old_size = size();
    471                         assign( other.data(), other.size() );
    472                         other.assign( old_data, old_size );
    473                         return *this;
    474                 }
    475 
    476                 // blocked copy constructor
    477                 const_string( const const_string & ) = delete;
    478                 // blocked copy operator
    479                 const_string& operator=( const const_string& ) = delete;
    480 
    481         private:
    482 
    483                 void initialize( const char* p, size_type s )
    484                 {
    485                         char* new_data = new char[s + 1];
    486                         nvmemcpy( new_data, p, s );
    487                         new_data[s] = 0;
    488                         assign( new_data, s );
    489                 }
    490         };
    491 
    492         class literal_string : public string_base< array_view< char > >
    493         {
    494                 constexpr literal_string( const char* str, size_t len ) : this_type( str, len ) {}
    495         public:
    496                 typedef string_base< array_view< char > > this_type;
    497                 friend constexpr literal_string operator "" _ls( const char* str, size_t len );
    498 
    499                 template< size_t N >
    500                 constexpr literal_string( char( &s )[N] ) : this_type( s, N - 1 ) {}
    501                 template< size_t N >
    502                 constexpr literal_string( const char( &s )[N] ) : this_type( s, N - 1 ) {}
    503         };
    504 
    505         constexpr literal_string operator "" _ls( const char* str, size_t len )
    506         {
    507                 return literal_string( str, len );
    508         }
    509 
    510         template < typename H >
    511         class hashed_literal_string;
    512         using hashed_literal_string_32 = hashed_literal_string< uint32 >;
    513         using hashed_literal_string_64 = hashed_literal_string< uint64 >;
    514 
    515         template < typename H >
    516         class hashed_literal_string : public string_base< array_view< char > >
    517         {
    518                 constexpr hashed_literal_string( const char* str, size_t len, H hash_code )
    519                         : this_type( str, len ), m_hash( hash_code ) {}
    520         public:
    521                 typedef string_base< array_view< char > > this_type;
    522 
    523                 template< size_t N >
    524                 constexpr hashed_literal_string( char( &s )[N] )
    525                         : this_type( s, N - 1 ), m_hash( detail::fnv_hash<H>::hash( s, N - 1 ) ) {}
    526                 template< size_t N >
    527                 constexpr hashed_literal_string( const char( &s )[N] )
    528                         : this_type( s, N - 1 ), m_hash( detail::fnv_hash<H>::hash( s, N - 1 ) ) {}
    529 
    530                 template < typename H2 >
    531                 constexpr H get_hash() const
    532                 {
    533                         static_assert( is_same< H, H2 >::value, "32/64 bit hash mismatch on hash_literal_string!" );
    534                         return m_hash;
    535                 }
    536 
    537                 friend constexpr hashed_literal_string_32 operator "" _hls32( const char* str, size_t len );
    538                 friend constexpr hashed_literal_string_64 operator "" _hls64( const char* str, size_t len );
    539         protected:
    540                 H m_hash;
    541         };
    542 
    543         constexpr hashed_literal_string_32 operator "" _hls32( const char* str, size_t len )
    544         {
    545                 return hashed_literal_string_32( str, len, detail::fnv_hash< uint32 >::hash( str, len ) );
    546         }
    547 
    548         constexpr hashed_literal_string_64 operator "" _hls64( const char* str, size_t len )
    549         {
    550                 return hashed_literal_string_64( str, len, detail::fnv_hash< uint64 >::hash( str, len ) );
    551         }
    552 
    553         template< typename H >
    554         struct hash< hashed_literal_string_32, H >
    555         {
    556                 static_assert( is_same< uint32, H >::value, "hashed_literal_string_32 used with non-32 bit hash!" );
    557                 static constexpr H get( const hashed_literal_string_32& value )
    558                 {
    559                         return value.get_hash< H >();
    560                 }
    561                 constexpr H operator()( const hashed_literal_string_32& value ) const { return get( value ); }
    562         };
    563 
    564         template< typename H >
    565         struct hash< hashed_literal_string_64, H >
    566         {
    567                 static_assert( is_same< uint64, H >::value, "hashed_literal_string_64 used with non-64 bit hash!" );
    568                 static constexpr H get( const hashed_literal_string_64& value )
    569                 {
    570                         return value.get_hash< H >();
    571                 }
    572                 constexpr H operator()( const hashed_literal_string_64& value ) const { return get( value ); }
    573         };
    57490
    57591        inline string_view trimmed( const string_view& str )
     
    648164}
    649165
    650 using nv::operator "" _ls;
    651 using nv::operator "" _hls32;
    652 using nv::operator "" _hls64;
    653 
    654166#endif // NV_STL_STRING_HH
  • trunk/src/core/library.cc

    r403 r433  
    6262string_view library::get_name() const
    6363{
    64     return string_view( m_name );
     64    return string_view( m_name.c_str(), m_name.size() );
    6565}
    6666
     
    7171        return true;
    7272    }
    73     NV_LOG_NOTICE( "library \"", string_view( m_name ), "\" : loading..." );
     73    NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loading..." );
    7474
    7575        std::string name = m_name;
    76         string_view ext( NV_LIB_EXT );
     76        std::string ext( NV_LIB_EXT );
    7777
    7878        if ( name.length() < ext.length() || name.substr( name.length() - ext.length(), ext.length() ) != ext )
     
    8585    if ( m_handle == NULL )
    8686    {
    87                 NV_LOG_NOTICE( "library \"", string_view( name ), "\" : failed to open!" );
     87                NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : failed to open!" );
    8888                return false;
    8989    }
    90     NV_LOG_NOTICE( "library \"", string_view( name ), "\" : loaded." );
     90    NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loaded." );
    9191        return true;
    9292}
     
    9797    if ( !result )
    9898    {
    99                 NV_LOG_CRITICAL( "library \"", string_view( m_name ), "\" : can't find symbol \"", symbol, "\"" );
     99                NV_LOG_CRITICAL( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't find symbol \"", symbol, "\"" );
    100100                NV_ABORT( "Library symbol load failed!" );
    101101    }
     
    117117    if ( ! NV_LIB_CLOSE( m_handle ) )
    118118    {
    119         NV_LOG_ERROR( "library \"", string_view( m_name ), "\" : can't close library!" );
     119        NV_LOG_ERROR( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't close library!" );
    120120    }
    121121    m_handle = nullptr;
  • trunk/src/engine/particle_engine.cc

    r406 r433  
    435435                                        {
    436436                                                data.affector_count--;
    437                                                 NV_LOG_WARNING( "Bad data passed to ", sub_type, " affector in particle system!" );
     437                                                NV_LOG_WARNING( "Bad data passed to ", string_view( sub_type.c_str(), sub_type.size() ), " affector in particle system!" );
    438438                                        }
    439439                                }
     
    441441                                {
    442442                                        data.affector_count--;
    443                                         NV_LOG_WARNING( "Unknown affector type in particle system! (", sub_type, ")" );
     443                                        NV_LOG_WARNING( "Unknown affector type in particle system! (", string_view( sub_type.c_str(), sub_type.size() ), ")" );
    444444                                }
    445445                        }
  • trunk/src/engine/program_manager.cc

    r399 r433  
    3737        }
    3838
    39         nv::program program = m_context->get_device()->create_program( string_view( vsource ), string_view( fsource ) );
     39        nv::program program = m_context->get_device()->create_program( string_view( vsource.c_str(), vsource.size() ), string_view( fsource.c_str(), fsource.size() ) );
    4040        return add( program );
    4141}
  • trunk/src/engine/resource_system.cc

    r431 r433  
    1212{
    1313        m_lua = a_lua_state;
    14         lua::register_storage( m_lua, get_storage_name(), string_view( "register_" + get_resource_name().to_string() ) );
     14        std::string delete_me = "register_" + std::string( get_resource_name().data(), get_resource_name().size() );
     15        lua::register_storage( m_lua, get_storage_name(), string_view( delete_me.c_str(), delete_me.size() ) );
    1516}
    1617
  • trunk/src/formats/md5_loader.cc

    r428 r433  
    155155                                        sstream >> shader;
    156156                                        remove_quotes( shader );
    157                                         maccess.set_name( make_name( shader ) );
     157                                        maccess.set_name( make_name( shader.c_str() ) );
    158158                                        next_line( sstream );
    159159                                }
  • trunk/src/formats/obj_loader.cc

    r427 r433  
    328328                data_channel_set* result = data_channel_set_creator::create_set( 1 );
    329329                data_channel_set_creator raccess( result );
    330                 raccess.set_name( make_name( reader->name ) );
     330                raccess.set_name( make_name( reader->name.c_str() ) );
    331331                uint8* rdata = raccess.add_channel( m_descriptor, reader->size * 3 ).raw_data();
    332332
  • trunk/src/gl/gl_device.cc

    r406 r433  
    1919        m_shader_header  = "#version 120\n";
    2020        for ( auto& i : get_uniform_factory() )
    21                 m_shader_header += "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ i.first.to_string() +";\n";
     21                m_shader_header += "uniform "+datatype_to_glsl_type( i.second->get_datatype() )+" "+ std::string( i.first.data(), i.first.size() ) +";\n";
    2222        for ( auto& i : get_link_uniform_factory() )
    23                 m_shader_header += "uniform sampler2D "+i.first.to_string() +";\n";
     23                m_shader_header += "uniform sampler2D "+std::string( i.first.data(), i.first.size() ) +";\n";
    2424}
    2525
     
    212212                for ( auto& i : *info->m_uniform_map )
    213213                {
    214                         auto j = lmap.find( i.first );
     214                        auto j = lmap.find( i.first.c_str() );
    215215                        if ( j != lmap.end() )
    216216                        {
     
    218218                        }                       
    219219
    220                         auto k = map.find( i.first );
     220                        auto k = map.find( i.first.c_str() );
    221221                        if ( k != map.end() )
    222222                        {
     
    238238                if ( fatal )
    239239                {
    240                         NV_LOG_CRITICAL( "gl_device : uniform '", string_view( name ), "' not found in program!" );
     240                        NV_LOG_CRITICAL( "gl_device : uniform '", string_view( name.c_str(), name.size() ), "' not found in program!" );
    241241                        NV_ABORT( "gl_device : uniform not found!" );
    242242                }
     
    257257                if ( fatal )
    258258                {
    259                         NV_LOG_CRITICAL( "gl_device : attribute '", string_view( name ), "' not found in program!" );
     259                        NV_LOG_CRITICAL( "gl_device : attribute '", string_view( name.c_str(), name.size() ), "' not found in program!" );
    260260                        NV_ABORT( "gl_device : attribute not found!" );
    261261                }
  • trunk/src/gui/gui_environment.cc

    r401 r433  
    3030}
    3131
    32 void nv::gui::environment::load_style( const std::string& filename )
     32void nv::gui::environment::load_style( const string_view& filename )
    3333{
    3434        m_renderer->load_style( filename );
  • trunk/src/gui/gui_gfx_renderer.cc

    r406 r433  
    187187}
    188188
    189 nv::size_t gfx_renderer::load_font( const std::string& filename, nv::size_t size )
    190 {
    191         std::string id_name( filename );
     189nv::size_t gfx_renderer::load_font( const string_view& filename, nv::size_t size )
     190{
     191        std::string id_name( filename.data(), filename.size() );
    192192        char buffer[8]; size_t len = nv::sint32_to_buffer( sint32( size ), buffer );
    193193        id_name.append( std::string( buffer, len ) );
    194         auto i = m_font_names.find( id_name );
     194        string_view id( id_name.c_str(), id_name.size() );
     195        auto i = m_font_names.find( id );
    195196        if ( i != m_font_names.end() )
    196197        {
     
    198199        }
    199200        size_t result = m_fonts.size();
    200         texture_font* f = new texture_font( &m_atlas, filename.c_str(), static_cast<float>( size ) );
     201        texture_font* f = new texture_font( &m_atlas, filename.data(), static_cast<float>( size ) );
    201202        f->load_glyphs( "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ " );
    202203        m_fonts.push_back( f );
    203204        m_reupload = true;
    204         m_font_names[id_name] = result;
     205        m_font_names[ id ] = result;
    205206        return result;
    206207}
    207208
    208 nv::size_t gfx_renderer::load_image( const std::string& filename )
     209nv::size_t gfx_renderer::load_image( const string_view& filename )
    209210{
    210211        auto i = m_image_names.find( filename );
     
    253254                if ( m_style.get( e, "skin", selector, path ) )
    254255                {
    255                         size_t image_id = load_image( path );
     256                        size_t image_id = load_image( string_view( path.c_str(), path.size() ) );
    256257                        const image_info* image = get_image( image_id );
    257258                        if ( image )
     
    318319                        if ( m_style.get( e, "text_color", selector, color ) && m_style.get( e, "text_font", selector, path ) && m_style.get( e, "text_size", selector, border ) )
    319320                        {
    320                                 size_t font_id = load_font( path, size_t( border ) );
     321                                size_t font_id = load_font( string_view( path.c_str(), path.size() ), size_t( border ) );
    321322                                texture_font* font = get_font( font_id );
    322323                                position p = abs.ul + position( 0, border );
  • trunk/src/gui/gui_renderer.cc

    r395 r433  
    77#include "nv/gui/gui_renderer.hh"
    88
    9 void nv::gui::renderer::load_style( const std::string& filename )
     9void nv::gui::renderer::load_style( const string_view& filename )
    1010{
    1111        m_style.load_style( filename );
  • trunk/src/gui/gui_style.cc

    r406 r433  
    1616}
    1717
    18 void style::load_style( const std::string& filename )
     18void style::load_style( const string_view& filename )
    1919{
    2020        m_lua.do_file( filename );
  • trunk/src/lua/lua_function.cc

    r406 r433  
    2121        {
    2222                lua_pop( L, 1 );
    23                 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() );
     23                NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string().c_str() );
    2424        }
    2525
     
    2727        {
    2828                lua_pop( L, 1 );
    29                 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() );
     29                NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string().c_str() );
    3030        }
    3131        m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
  • trunk/src/lua/lua_map_tile.cc

    r406 r433  
    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 ) ).to_string();
     57        nv::string_view lts = nv::trimmed( lua_tostring( L, 1 ) );
     58        std::string code( lts.data(), lts.size() );
    5859        std::string chars( " \r\t" );
    5960        code.erase( nv::remove_if( code.begin(), code.end(),
  • trunk/src/lua/lua_state.cc

    r431 r433  
    116116        if ( !p.resolve( m_state, global ) )
    117117        {
    118                 NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string() );
     118                NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string().c_str() );
    119119                return false;
    120120        }
     
    123123        {
    124124                lua_pop( m_state, 1 );
    125                 NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string() );
     125                NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string().c_str() );
    126126                return false;
    127127        }
     
    442442        for ( int i = 0; i < top; ++i )
    443443        {
    444                 NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1) );
     444                NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1).c_str() );
    445445        }
    446446}
Note: See TracChangeset for help on using the changeset viewer.