Changeset 379 for trunk


Ignore:
Timestamp:
05/29/15 17:23:04 (10 years ago)
Author:
epyon
Message:
  • got rid of to_string and other std::string utilities (except slurp)
  • string no longer in nv namespace
Location:
trunk/nv
Files:
1 deleted
24 edited

Legend:

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

    r377 r379  
    176176#define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) )
    177177
     178#define NV_TYPE_FAIL(T) (nv::static_assert_fail<T>::value)
     179#define NV_TEMPLATE_FAIL(T,message) static_assert( NV_TYPE_FAIL(T), message );
     180
    178181namespace nv
    179182{
    180         namespace lua
    181         {
    182                 class state;
    183         }
     183        template < typename T >
     184        struct static_assert_fail
     185        {
     186                static const bool value = false;
     187        };
    184188
    185189        using size_t    = decltype( sizeof(0) );
     
    240244
    241245        template <typename T, typename U>
    242         inline T* down_cast( U* x )
    243         {
    244 #if NV_DEBUG
    245                 T* p = dynamic_cast<T*>( x );
    246                 if ( p == 0 )
    247                 {
    248 #ifdef NV_LOG
    249                         NV_THROW( std::bad_cast );
    250 #endif
    251                 }
    252                 return p;
    253 #else
    254                 return static_cast<T*>( x );
    255 #endif
    256         }
    257 
    258         template <typename T, typename U>
    259246        T narrow_cast( const U& a )
    260247        {
     
    278265
    279266#include <nv/stl/assert.hh>
     267#include <nv/stl/rtti_support.hh>
    280268
    281269#endif // NV_CORE_COMMON_HH
  • trunk/nv/core/library.hh

    r368 r379  
    1616#include <nv/stl/exception.hh>
    1717#include <nv/stl/string.hh>
     18#include <string>
    1819
    1920namespace nv
     
    3738                 * Throws library_error on failure
    3839                 */
    39                 void open( const string& name );
     40                void open( string_ref name );
    4041
    4142                /**
     
    4445                 * returns true if succeeded, false otherwise
    4546                 */
    46                 bool try_open( const string& name );
     47                bool try_open( string_ref name );
    4748
    4849                /**
     
    5455                 * Returns library name
    5556                 */
    56                 const string& get_name() const;
     57                string_ref get_name() const;
    5758
    5859                /**
     
    6162                 * Throws on symbol not found
    6263                 */
    63                 void* get( const string& symbol );
     64                void* get( string_ref symbol );
    6465
    6566                /**
     
    6869                 * Returns null if symbol not found
    6970                 */
    70                 void* try_get( const string& symbol );
     71                void* try_get( string_ref symbol );
    7172
    7273                /**
     
    8283                 * Exact implementation depends on platform/compiler.
    8384                 */
    84                 static string get_error();
     85                static std::string get_error();
    8586
    8687        protected:
     
    107108
    108109                /// Library name
    109                 string m_name;
     110                std::string m_name;
    110111
    111112        };  // class Library
     
    114115        {
    115116                /// Library name
    116                 string m_name;
     117                std::string m_name;
    117118        public:
    118119                /**
    119120                 * Constructor
    120121                 */
    121                 library_error( const string& message, const string& name )
     122                library_error( const std::string& message, const std::string& name )
    122123                        : runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name )
    123124                {
     
    134135                 * Returns library name
    135136                 */
    136                 const string& get_name()
     137                const std::string& get_name()
    137138                {
    138139                        return m_name;
  • trunk/nv/core/logging.hh

    r378 r379  
    1515
    1616#include <nv/core/common.hh>
     17#include <nv/stl/capi.hh>
    1718#include <nv/stl/string.hh>
    1819#include <nv/stl/singleton.hh>
     
    5253                void log_append( string_ref ref )
    5354                {
    54                         memcpy( m_pos, ref.data(), ref.size() );
     55                        nvmemcpy( m_pos, ref.data(), ref.size() );
    5556                        m_pos += ref.size();
    5657                }
     
    6263                {
    6364                        m_pos += sint32_to_buffer( s, m_pos );
     65                }
     66                void log_append( uint64 u )
     67                {
     68                        m_pos += uint64_to_buffer( u, m_pos );
     69                }
     70                void log_append( sint64 s )
     71                {
     72                        m_pos += sint64_to_buffer( s, m_pos );
    6473                }
    6574                void log_append( f32 f )
  • trunk/nv/core/types.hh

    r377 r379  
    1111#include <nv/stl/cstring_store.hh>
    1212#include <nv/stl/traits/properties.hh>
    13 #include <nv/stl/type_info.hh>
    1413#include <unordered_map>
    1514#include <vector>
    1615
    17 namespace std
    18 {
    19         template<>
    20         struct hash < nv::type_index >
    21         {
    22                 size_t operator()( nv::type_index key ) const
    23                 {
    24                         return ( key.hash_code() );
    25                 }
    26         };
    27 }
    28 
    2916namespace nv
    3017{
     18        typedef nv::uint64 type_hash;
     19
     20        template< typename T >
     21        struct is_container
     22        {
     23        private:
     24                typedef char                      yes;
     25                typedef struct { char array[2]; } no;
     26                template<typename C> static yes test( typename C::iterator* );
     27                template<typename C> static no  test( ... );
     28        public:
     29                static const bool value = sizeof( test<T>( 0 ) ) == sizeof( yes );
     30        };
     31
     32        template<>
     33        struct is_container < std::string >
     34        {
     35                static const bool value = false;
     36        };
    3137
    3238        struct type_entry;
     
    4753        struct type_field
    4854        {
    49                 uint32                name;     //!< name of the field
    50                 const std::type_info* raw_type; //!< typeinfo for later retrieval of type
    51                 type_entry*           type;     //!< pointer to field type
    52                 uint32                flags;    //!< flags
    53                 uint32                offset;   //!< offset into parent
     55                uint32      name;     //!< name of the field
     56                type_hash   hash; //!< typeinfo for later retrieval of type
     57                type_entry* type;     //!< pointer to field type
     58                uint32      flags;    //!< flags
     59                uint32      offset;   //!< offset into parent
    5460        };
    5561
     
    128134                }
    129135
    130                 type_entry* get_type( const std::type_info& t )
    131                 {
    132                         type_info_map::iterator it = m_idx_types.find( type_index( t ) );
     136                type_entry* get_type( type_hash hash )
     137                {
     138                        type_info_map::iterator it = m_idx_types.find( hash );
    133139                        if ( it != m_idx_types.end() )
    134140                        {
     
    148154                }
    149155        private:
    150                 typedef std::vector<type_entry*>                         type_list;
    151                 typedef std::unordered_map<type_index, type_entry*> type_info_map;
     156                typedef std::vector<type_entry*>                   type_list;
     157                typedef std::unordered_map<type_hash, type_entry*> type_info_map;
    152158                cstring_store m_names;
    153159                type_list     m_type_list;
     
    169175                type_field f;
    170176                f.name = m_entry->names.insert( name );
    171                 f.raw_type = &typeid( remove_pointer_t<field_type> );
    172                 f.type = type_db->get_type( *( f.raw_type ) );
     177                f.hash = rtti_type_hash< remove_pointer_t<field_type> >::hash();
     178                f.type = type_db->get_type( f.hash );
    173179                f.flags = TF_CONTAINER |
    174180                        ( is_pointer<field_type>::value ? TF_POINTER : 0 ) |
     
    185191                type_field f;
    186192                f.name = m_entry->names.insert( name );
    187                 f.raw_type = &typeid( remove_pointer_t<TFIELD> );
    188                 f.type = type_db->get_type( *( f.raw_type ) );
     193                f.hash = rtti_type_hash< remove_pointer_t<TFIELD> >::hash();
     194                f.type = type_db->get_type( f.hash );
    189195                f.flags =
    190196                        ( is_pointer<TFIELD>::value ? TF_POINTER : 0 ) |
  • trunk/nv/core/uid.hh

    r323 r379  
    9999                U* get_as( uid auid ) const
    100100                {
     101                        static_assert( NV_TYPE_FAIL( U ), "Currently unsupported due to lack of dynamic_cast!" );
    101102                        return dynamic_cast< U* >( get(auid) );
    102103                }
  • trunk/nv/engine/program_manager.hh

    r364 r379  
    2828        protected:
    2929                virtual resource_id load_resource( lua::table_guard& table );
    30                 void load_source( lua::table_guard& table, string& out, const string& append );
     30                void load_source( lua::table_guard& table, std::string& out, const std::string& append );
    3131                virtual void release( program p );
    3232        private:
    3333                context* m_context;
    34                 string   m_vertex_head;
    35                 string   m_fragment_head;
     34                std::string   m_vertex_head;
     35                std::string   m_fragment_head;
    3636        };
    3737
  • trunk/nv/engine/resource_system.hh

    r364 r379  
    4242
    4343                lua::state* m_lua;
    44                 std::unordered_map< string, resource_id > m_names;
     44                std::unordered_map< std::string, resource_id > m_names;
    4545        };
    4646
     
    5454                        return ( id < m_data.size() ? m_data[ id ] : T() );
    5555                }
    56                 T get_resource( const string& id )
     56                T get_resource( const std::string& id )
    5757                {
    5858                        auto m = m_names.find( id );
     
    9292        public:
    9393                explicit resource_system() : m_lua_state( nullptr ) { m_managers.push_back(nullptr); }
    94                 resource_type_id register_resource_type( const string& name, resource_manager_base* manager );
    95                 resource_type_id get_resource_type_id( const string& name ) const;
     94                resource_type_id register_resource_type( const std::string& name, resource_manager_base* manager );
     95                resource_type_id get_resource_type_id( const std::string& name ) const;
    9696                void initialize( lua::state* a_lua_state );
    9797                virtual ~resource_system();
    9898        protected:
    9999                std::vector< resource_manager_base* >     m_managers;
    100                 std::unordered_map< string, resource_id > m_manager_names;
     100                std::unordered_map< std::string, resource_id > m_manager_names;
    101101                lua::state* m_lua_state;
    102102        };
  • trunk/nv/formats/assimp_loader.hh

    r319 r379  
    2020        {
    2121        public:
    22                 explicit assimp_loader( const string& a_ext, uint32 a_assimp_flags = 0 );
     22                explicit assimp_loader( const std::string& a_ext, uint32 a_assimp_flags = 0 );
    2323                virtual bool load( stream& source );
    2424                virtual mesh_data* release_mesh_data( size_t index = 0 );
     
    3838
    3939                string_table_creator m_strings;
    40                 string m_ext;
     40                std::string m_ext;
    4141                uint32 m_assimp_flags;
    4242                const void* m_scene;
  • trunk/nv/gfx/texture_font.hh

    r368 r379  
    4545                        texture_font( texture_atlas* atlas, const char * filename, float size );
    4646                        const texture_glyph* get_glyph( uint16 charcode ) const;
    47                         bool load_glyphs( const string& codes );
     47                        bool load_glyphs( string_ref codes );
    4848                        float get_size() const { return m_size; }
    4949                        ~texture_font();
     
    5454
    5555                        texture_atlas* m_atlas; //!< Atlas Image object for this font.
    56                         string m_filename; //!< Name of the file.
     56                        std::string m_filename; //!< Name of the file.
    5757                        float m_size;           //!< Font size.
    5858                        float m_height;         //!< Height of the font. (x-height?)
  • trunk/nv/gl/gl_device.hh

    r361 r379  
    5353                virtual const buffer_info* get_buffer_info( buffer t ) const;
    5454
    55                 virtual int get_attribute_location( program p, const string& name, bool fatal = true ) const;
     55                virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const;
    5656                virtual void prepare_program( program p );
    57                 virtual const string& get_shader_header() const { return m_shader_header; }
     57                virtual const std::string& get_shader_header() const { return m_shader_header; }
    5858                virtual ~gl_device();
    5959        protected:
    60                 uniform_base* get_uniform( program p, const string& name, bool fatal = true ) const;
     60                uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const;
    6161
    6262       
  • trunk/nv/gl/gl_window.hh

    r364 r379  
    2525        public:
    2626                gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc );
    27                 virtual void set_title( const string& ) {}
     27                virtual void set_title( const std::string& ) {}
    2828                virtual context* get_context()    { return m_context; }
    2929                virtual device* get_device()      { return m_device; }
    3030                virtual uint16 get_width() const  { return m_width; }
    3131                virtual uint16 get_height() const { return m_height; }
    32                 virtual string get_title() const { return std::string(); }
     32                virtual std::string get_title() const { return std::string(); }
    3333                // TODO : implement?
    3434                virtual void set_swap_control( bool ) {}
  • trunk/nv/gui/gui_element.hh

    r368 r379  
    3232                        typedef std::list<handle> list;
    3333
    34                         string    m_id;              ///< id type of the object
     34                        std::string    m_id;              ///< id type of the object
    3535                        handle    m_parent;          ///< pointer to parent
    3636                        flags     m_flags;
    3737                        list      m_children;        ///< children objects
    3838                        size_t    m_child_count;     ///< number of children
    39                         string    m_class; ///< Class name.
    40                         string    m_text; ///< Displayed label or text.
     39                        std::string    m_class; ///< Class name.
     40                        std::string    m_text; ///< Displayed label or text.
    4141                        rectangle m_relative; ///< Position relative to parent.
    4242                        rectangle m_absolute; ///< Position relative to window/screen.
  • trunk/nv/gui/gui_environment.hh

    r368 r379  
    3535                        handle create_element( const rectangle& r );
    3636                        handle create_element( handle parent, const rectangle& r );
    37                         void set_text( handle e, const string& text );
    38                         void set_class( handle  e, const string& text );
     37                        void set_text( handle e, const std::string& text );
     38                        void set_class( handle  e, const std::string& text );
    3939                        void update();
    4040                        void draw();
  • trunk/nv/interface/device.hh

    r368 r379  
    6767        struct attribute
    6868        {
    69                 string   name;
     69                std::string   name;
    7070                int      location;
    7171                datatype type;
     
    7373        };
    7474
    75         typedef std::unordered_map< string, attribute >    attribute_map;
     75        typedef std::unordered_map< std::string, attribute >    attribute_map;
    7676
    7777        struct texture_tag {};
     
    168168                virtual const texture_info* get_texture_info( texture ) const = 0;
    169169                virtual const buffer_info* get_buffer_info( buffer ) const = 0;
    170                 virtual const string& get_shader_header() const = 0;
     170                virtual const std::string& get_shader_header() const = 0;
    171171
    172172                virtual texture create_texture( image_data* data, sampler asampler )
     
    175175                }
    176176
    177                 int try_get_attribute_location( program p, const string& name ) const
     177                int try_get_attribute_location( program p, const std::string& name ) const
    178178                {
    179179                        return get_attribute_location( p, name, false );
    180180                }
    181181
    182                 virtual int get_attribute_location( program p, const string& name, bool fatal = true ) const = 0;
    183 
    184                 template < typename T >
    185                 void set_uniform_array( program p, const string& name, const T* value, uint32 count, bool fatal = true )
     182                virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const = 0;
     183
     184                template < typename T >
     185                void set_uniform_array( program p, const std::string& name, const T* value, uint32 count, bool fatal = true )
    186186                {
    187187                        uniform_base* base = get_uniform( p, name, fatal );
     
    198198
    199199                template < typename T >
    200                 void set_opt_uniform_array( program p, const string& name, const T* value, uint32 count )
     200                void set_opt_uniform_array( program p, const std::string& name, const T* value, uint32 count )
    201201                {
    202202                        set_uniform_array( p, name, value, count, false );
     
    204204
    205205                template < typename T >
    206                 void set_opt_uniform_array( program p, const string& name, const std::vector<T>& value )
     206                void set_opt_uniform_array( program p, const std::string& name, const std::vector<T>& value )
    207207                {
    208208                        set_uniform_array( p, name, (const T*)value.data(), value.size(), false );
     
    211211
    212212                template < typename T >
    213                 void set_uniform( program p, const string& name, const T& value, bool fatal = true )
     213                void set_uniform( program p, const std::string& name, const T& value, bool fatal = true )
    214214                {
    215215                        uniform_base* base = get_uniform( p, name, fatal );
     
    224224
    225225                template < typename T >
    226                 void set_opt_uniform( program p, const string& name, const T& value )
     226                void set_opt_uniform( program p, const std::string& name, const T& value )
    227227                {
    228228                        set_uniform( p, name, value, false );
     
    251251
    252252        protected:
    253                 virtual uniform_base* get_uniform( program p, const string& name, bool fatal = true ) const = 0;
     253                virtual uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const = 0;
    254254
    255255                void initialize_engine_uniforms()
  • trunk/nv/interface/map_area.hh

    r368 r379  
    1717#include <nv/stl/string.hh>
    1818#include <nv/stl/array.hh>
     19#include <string>
    1920
    2021namespace nv
     
    2728                virtual uint32 get_cell( const position& p ) const = 0;
    2829                virtual void set_cell( const position& p, uint32 value ) = 0;
    29                 virtual uint32 string_to_id( const nv::string& ) const { return 0; }
    30                 virtual nv::string id_to_string( uint32 ) const { return nv::string(); }
     30                virtual uint32 string_to_id( const std::string& ) const { return 0; }
     31                virtual std::string id_to_string( uint32 ) const { return std::string(); }
    3132                virtual dimension get_size() const = 0;
    3233                virtual position get_shift() const { return position(); }
     
    4849                virtual dimension get_size() const { return m_area.get_size(); }
    4950                virtual position get_shift() const { return m_area.ul + m_map_area->get_shift(); }
    50                 virtual uint32 string_to_id( const nv::string& s ) const { return m_map_area->string_to_id( s ); }
    51                 virtual nv::string id_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); }
     51                virtual uint32 string_to_id( const std::string& s ) const { return m_map_area->string_to_id( s ); }
     52                virtual std::string id_to_string( uint32 id ) const { return m_map_area->id_to_string( id ); }
    5253        private:
    5354                map_area* m_map_area;
  • trunk/nv/interface/mesh_data.hh

    r368 r379  
    221221        struct mesh_node_data
    222222        {
    223                 string    name;
     223                std::string    name;
    224224                sint16    target_id;
    225225                sint16    parent_id;
     
    233233                friend class mesh_nodes_creator;
    234234        public:
    235                 explicit mesh_nodes_data( const string& name, uint32 count, mesh_node_data* nodes )
     235                explicit mesh_nodes_data( const std::string& name, uint32 count, mesh_node_data* nodes )
    236236                        : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false )
    237237                {
    238238                }
    239239
    240                 explicit mesh_nodes_data( const string& name, uint32 count, mesh_node_data* nodes,
     240                explicit mesh_nodes_data( const std::string& name, uint32 count, mesh_node_data* nodes,
    241241                        uint16 a_fps, float a_frames, bool a_flat )
    242242                        : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat )
     
    283283                float get_duration() const { return m_duration; }
    284284                void set_name( const std::string& name ) { m_name = name; }
    285                 const string& get_name() const { return m_name; }
     285                const std::string& get_name() const { return m_name; }
    286286
    287287                ~mesh_nodes_data()
     
    293293
    294294        private:
    295                 string m_name;
     295                std::string m_name;
    296296                uint32 m_count;
    297297                mesh_node_data* m_nodes;
  • trunk/nv/interface/uniform.hh

    r368 r379  
    1717#include <nv/stl/string.hh>
    1818#include <unordered_map>
     19#include <string>
    1920
    2021namespace nv
     
    2526        {
    2627        public:
    27                 uniform_base( const string& name, datatype type, int location, int length )
     28                uniform_base( const std::string& name, datatype type, int location, int length )
    2829                        : m_name( name ), m_type( type ), m_location(location), m_length( length ), m_dirty( true ) {}
    2930                bool try_type_check( datatype )
     
    4344                bool is_dirty() const { return m_dirty; }
    4445                void clean() { m_dirty = false; }
    45                 static uniform_base* create( datatype utype, const string& name, int location, int length );
     46                static uniform_base* create( datatype utype, const std::string& name, int location, int length );
    4647                virtual ~uniform_base() {}
    4748        protected:
    48                 string   m_name;
     49                std::string   m_name;
    4950                datatype m_type;
    5051                int      m_location;
     
    5960                typedef T value_type;
    6061
    61                 uniform( const string& name, int location, int length )
     62                uniform( const std::string& name, int location, int length )
    6263                        : uniform_base( name, type_to_enum< T >::type, location, length ), m_value( nullptr )
    6364                {
     
    148149        };
    149150
    150         typedef std::unordered_map< string, uniform_base* >                uniform_map;
     151        typedef std::unordered_map< std::string, uniform_base* >                uniform_map;
    151152        typedef std::vector< engine_uniform_base* >                        engine_uniform_list;
    152         typedef std::unordered_map< string, engine_uniform_factory_base* > engine_uniform_factory_map;
    153         typedef std::unordered_map< string, engine_link_uniform_base* >    engine_link_uniform_factory_map;
     153        typedef std::unordered_map< std::string, engine_uniform_factory_base* > engine_uniform_factory_map;
     154        typedef std::unordered_map< std::string, engine_link_uniform_base* >    engine_link_uniform_factory_map;
    154155
    155156        class engine_uniform_m_view : public engine_uniform< mat4 >
     
    246247        };
    247248
    248         inline uniform_base* uniform_base::create( datatype utype, const string& name, int location, int length )
     249        inline uniform_base* uniform_base::create( datatype utype, const std::string& name, int location, int length )
    249250        {
    250251                switch( utype )
  • trunk/nv/interface/window.hh

    r368 r379  
    2727                virtual uint16 get_width() const = 0;
    2828                virtual uint16 get_height() const = 0;
    29                 virtual string get_title() const = 0;
    30                 virtual void set_title( const string& title ) = 0;
     29                virtual std::string get_title() const = 0;
     30                virtual void set_title( const std::string& title ) = 0;
    3131                virtual context* get_context() = 0;
    3232                virtual bool is_event_pending() = 0;
  • trunk/nv/lua/lua_path.hh

    r378 r379  
    5555
    5656                        void parse();
    57                         void push( size_t value );
     57                        void push( uint32 value );
    5858                        void push( string_ref p );
    5959
     
    6363                                union
    6464                                {
    65                                         size_t      value;
     65                                        uint32      value;
    6666                                        const char* str;
    6767                                };
    68                                 size_t      length;
     68                                uint32      length;
    6969                        };
    7070
    7171                        element m_elements[8];
    72                         sint32  m_count;
     72                        uint32  m_count;
    7373                };
    7474
  • trunk/nv/lua/lua_state.hh

    r377 r379  
    3333        namespace lua
    3434        {
     35                class state;
    3536
    3637                const int ret_multi = -1;
  • trunk/nv/lua/lua_values.hh

    r377 r379  
    206206
    207207                        template <typename T>
    208                         struct type_degrade< T, enable_if_t< is_stdstring< T >::value > >
     208                        struct type_degrade< T, enable_if_t< is_same< std::string, remove_cvr_t< T > >::value > >
    209209                        {
    210210                                typedef std::string type;
  • trunk/nv/sdl/sdl_window.hh

    r343 r379  
    2626                public:
    2727                        window( device* dev, uint16 width, uint16 height, bool fullscreen = false );
    28                         virtual void set_title( const string& title );
     28                        virtual void set_title( const std::string& title );
    2929                        virtual void swap_buffers();
    3030
     
    3333                        virtual uint16 get_width() const  { return m_width; }
    3434                        virtual uint16 get_height() const { return m_height; }
    35                         virtual string get_title() const { return m_title; }
     35                        virtual std::string get_title() const { return m_title; }
    3636                        virtual void set_swap_control( bool enabled );
    3737                        virtual bool is_event_pending()            { return m_input->is_event_pending(); }
     
    4444                        uint16      m_width;
    4545                        uint16      m_height;
    46                         string      m_title;
     46                        std::string      m_title;
    4747                        void*       m_handle;
    4848                        gl_context* m_context;
  • trunk/nv/stl/any.hh

    r377 r379  
    2020#include <nv/stl/type_traits.hh>
    2121#include <nv/stl/type_info.hh>
     22
     23#error "any type is currently unsupported!"
    2224
    2325namespace nv
  • trunk/nv/stl/string.hh

    r378 r379  
    33// For conditions of distribution and use, see copyright notice in nv.hh
    44//
    5 // TODO: tests for string_length
     5// TODO:
    66//  * performance tests
    77//  * matching tests
     
    3131namespace nv
    3232{
    33         using std::string;
    34 
    35 
    36 
    37         /**
    38         * Utility function for converting any value to string.
    39         *
    40         * @param value value to be converted, needs to have << operator
    41         *        to stream
    42         * @throw runtime_error Throws runtime_error on conversion fail
    43         * @return value converted to string
    44         */
    45         template < class T >
    46         string to_string( const T& value )
    47         {
    48                 std::stringstream stream;
    49                 stream << value;
    50 
    51                 if ( stream.fail() )
    52                 {
    53 //                      NV_THROW( runtime_error, "bad cast" );
    54                 }
    55 
    56                 return stream.str();
    57         }
    58 
    59         /**
    60         * Override function for special treatment of strings. Returns the
    61         * value passed.
    62         */
    63         inline string to_string( const string& value)
    64         {
    65                 return value;
    66         }
    67 
    6833        /**
    6934        * Simple function for slurping a file into a string.
     
    7338        namespace detail
    7439        {
    75                 template< typename T >
    76                 struct string_length_impl
    77                 {
    78                         static size_t get( T ) { return 0; }
    79                 };
    80                 template< size_t S >
    81                 struct string_length_impl < char[S] >
    82                 {
    83                         static size_t get( const char[S] ) { return S - 1; }
    84                 };
    85                 template< size_t S >
    86                 struct string_length_impl < const char[S] >
    87                 {
    88                         static size_t get( const char[S] ) { return S - 1; }
    89                 };
    90                 template<>
    91                 struct string_length_impl < char* >
    92                 {
    93                         static size_t get( const char* s ) { return nvstrlen( s ); }
    94                 };
    95                 template<>
    96                 struct string_length_impl < const char* >
    97                 {
    98                         static size_t get( const char* s ) { return nvstrlen( s ); }
    99                 };
    100                 template<>
    101                 struct string_length_impl < std::string >
    102                 {
    103                         static size_t get( const std::string& s ) { return s.length(); }
    104                 };
    105                 template<>
    106                 struct string_length_impl < const std::string >
    107                 {
    108                         static size_t get( const std::string& s ) { return s.length(); }
    109                 };
    110 
    11140                // These could be done much better
    11241                template <typename T>
     
    12150        }
    12251
    123         template< typename T >
    124         using string_length = detail::string_length_impl < remove_cvr_t < T > >;
    125 
    12652        template < typename T >
    12753        struct is_cstring : detail::is_cstring_impl< remove_reference_t<T> >::type
     
    12955
    13056        };
    131 
    132         template <typename T>
    133         struct is_stdstring     : is_same< std::string, remove_cvr_t< T > >
    134         {
    135         };
    136 
    137         template < typename T > struct is_string : bool_constant < is_stdstring<T>::value || is_cstring<T>::value > {};
    138 
    139         template<typename T>
    140         struct is_container
    141         {
    142         private:
    143                 typedef char                      yes;
    144                 typedef struct { char array[2]; } no;
    145                 template<typename C> static yes test( typename C::iterator* );
    146                 template<typename C> static no  test( ... );
    147         public:
    148                 static const bool value = sizeof( test<T>( 0 ) ) == sizeof( yes );
    149         };
    150 
    151         template<>
    152         struct is_container < std::string >
    153         {
    154                 static const bool value = false;
    155         };
    156 
    157 
    158 
     57       
    15958        class string_ref;
    16059
     
    249148                {
    250149                        for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
    251                                 if ( 0 == nvmemchr( s.data(), *it, s.size() ) )
     150                                if ( 0 == nvmemchr( s.data(), (uchar8)*it, s.size() ) )
    252151                                        return ( size_type )distance( this->cbegin(), it );
    253152                        return npos;
     
    263162                {
    264163                        for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    265                                 if ( 0 == nvmemchr( s.data(), *it, s.size() ) )
     164                                if ( 0 == nvmemchr( s.data(), (uchar8)*it, s.size() ) )
    266165                                        return reverse_distance( this->crbegin(), it );
    267166                        return npos;
     
    307206                size_type reverse_distance( ReverseIterator first, ReverseIterator last ) const
    308207                {
    309                         return size() - 1 - distance( first, last );
     208                        return size() - 1 - (size_t)distance( first, last );
    310209                }
    311210        };
     
    508407        size_t startpos = str.find_first_not_of( " \r\n\t" );
    509408
    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;
     409        if ( string_ref::npos != endpos || string_ref::npos != startpos )
     410        {
     411                if ( string_ref::npos == startpos ) startpos = 0;
     412                if ( string_ref::npos != endpos )   endpos = endpos + 1 - startpos;
    514413                return str.substr( startpos, endpos );
    515414        }
     
    520419{
    521420        size_t endpos = str.find_last_not_of( " \r\n\t" );
    522         if ( string::npos != endpos )
     421        if ( string_ref::npos != endpos )
    523422        {
    524423                return str.substr( 0, endpos + 1 );
     
    530429{
    531430        size_t startpos = str.find_first_not_of( " \r\n\t" );
    532         if ( string::npos != startpos )
     431        if ( string_ref::npos != startpos )
    533432        {
    534433                return str.substr( startpos );
Note: See TracChangeset for help on using the changeset viewer.