- Timestamp:
- 05/29/15 17:23:04 (10 years ago)
- Location:
- trunk/nv
- Files:
-
- 1 deleted
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/common.hh
r377 r379 176 176 #define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) ) 177 177 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 178 181 namespace nv 179 182 { 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 }; 184 188 185 189 using size_t = decltype( sizeof(0) ); … … 240 244 241 245 template <typename T, typename U> 242 inline T* down_cast( U* x )243 {244 #if NV_DEBUG245 T* p = dynamic_cast<T*>( x );246 if ( p == 0 )247 {248 #ifdef NV_LOG249 NV_THROW( std::bad_cast );250 #endif251 }252 return p;253 #else254 return static_cast<T*>( x );255 #endif256 }257 258 template <typename T, typename U>259 246 T narrow_cast( const U& a ) 260 247 { … … 278 265 279 266 #include <nv/stl/assert.hh> 267 #include <nv/stl/rtti_support.hh> 280 268 281 269 #endif // NV_CORE_COMMON_HH -
trunk/nv/core/library.hh
r368 r379 16 16 #include <nv/stl/exception.hh> 17 17 #include <nv/stl/string.hh> 18 #include <string> 18 19 19 20 namespace nv … … 37 38 * Throws library_error on failure 38 39 */ 39 void open( const string&name );40 void open( string_ref name ); 40 41 41 42 /** … … 44 45 * returns true if succeeded, false otherwise 45 46 */ 46 bool try_open( const string&name );47 bool try_open( string_ref name ); 47 48 48 49 /** … … 54 55 * Returns library name 55 56 */ 56 const string&get_name() const;57 string_ref get_name() const; 57 58 58 59 /** … … 61 62 * Throws on symbol not found 62 63 */ 63 void* get( const string&symbol );64 void* get( string_ref symbol ); 64 65 65 66 /** … … 68 69 * Returns null if symbol not found 69 70 */ 70 void* try_get( const string&symbol );71 void* try_get( string_ref symbol ); 71 72 72 73 /** … … 82 83 * Exact implementation depends on platform/compiler. 83 84 */ 84 static st ring get_error();85 static std::string get_error(); 85 86 86 87 protected: … … 107 108 108 109 /// Library name 109 st ring m_name;110 std::string m_name; 110 111 111 112 }; // class Library … … 114 115 { 115 116 /// Library name 116 st ring m_name;117 std::string m_name; 117 118 public: 118 119 /** 119 120 * Constructor 120 121 */ 121 library_error( const st ring& message, conststring& name )122 library_error( const std::string& message, const std::string& name ) 122 123 : runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name ) 123 124 { … … 134 135 * Returns library name 135 136 */ 136 const st ring& get_name()137 const std::string& get_name() 137 138 { 138 139 return m_name; -
trunk/nv/core/logging.hh
r378 r379 15 15 16 16 #include <nv/core/common.hh> 17 #include <nv/stl/capi.hh> 17 18 #include <nv/stl/string.hh> 18 19 #include <nv/stl/singleton.hh> … … 52 53 void log_append( string_ref ref ) 53 54 { 54 memcpy( m_pos, ref.data(), ref.size() );55 nvmemcpy( m_pos, ref.data(), ref.size() ); 55 56 m_pos += ref.size(); 56 57 } … … 62 63 { 63 64 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 ); 64 73 } 65 74 void log_append( f32 f ) -
trunk/nv/core/types.hh
r377 r379 11 11 #include <nv/stl/cstring_store.hh> 12 12 #include <nv/stl/traits/properties.hh> 13 #include <nv/stl/type_info.hh>14 13 #include <unordered_map> 15 14 #include <vector> 16 15 17 namespace std18 {19 template<>20 struct hash < nv::type_index >21 {22 size_t operator()( nv::type_index key ) const23 {24 return ( key.hash_code() );25 }26 };27 }28 29 16 namespace nv 30 17 { 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 }; 31 37 32 38 struct type_entry; … … 47 53 struct type_field 48 54 { 49 uint32 50 const std::type_info* raw_type; //!< typeinfo for later retrieval of type51 type_entry* 52 uint32 53 uint32 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 54 60 }; 55 61 … … 128 134 } 129 135 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 ); 133 139 if ( it != m_idx_types.end() ) 134 140 { … … 148 154 } 149 155 private: 150 typedef std::vector<type_entry*> 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; 152 158 cstring_store m_names; 153 159 type_list m_type_list; … … 169 175 type_field f; 170 176 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 ); 173 179 f.flags = TF_CONTAINER | 174 180 ( is_pointer<field_type>::value ? TF_POINTER : 0 ) | … … 185 191 type_field f; 186 192 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 ); 189 195 f.flags = 190 196 ( is_pointer<TFIELD>::value ? TF_POINTER : 0 ) | -
trunk/nv/core/uid.hh
r323 r379 99 99 U* get_as( uid auid ) const 100 100 { 101 static_assert( NV_TYPE_FAIL( U ), "Currently unsupported due to lack of dynamic_cast!" ); 101 102 return dynamic_cast< U* >( get(auid) ); 102 103 } -
trunk/nv/engine/program_manager.hh
r364 r379 28 28 protected: 29 29 virtual resource_id load_resource( lua::table_guard& table ); 30 void load_source( lua::table_guard& table, st ring& out, conststring& append );30 void load_source( lua::table_guard& table, std::string& out, const std::string& append ); 31 31 virtual void release( program p ); 32 32 private: 33 33 context* m_context; 34 st ring m_vertex_head;35 st ring m_fragment_head;34 std::string m_vertex_head; 35 std::string m_fragment_head; 36 36 }; 37 37 -
trunk/nv/engine/resource_system.hh
r364 r379 42 42 43 43 lua::state* m_lua; 44 std::unordered_map< st ring, resource_id > m_names;44 std::unordered_map< std::string, resource_id > m_names; 45 45 }; 46 46 … … 54 54 return ( id < m_data.size() ? m_data[ id ] : T() ); 55 55 } 56 T get_resource( const st ring& id )56 T get_resource( const std::string& id ) 57 57 { 58 58 auto m = m_names.find( id ); … … 92 92 public: 93 93 explicit resource_system() : m_lua_state( nullptr ) { m_managers.push_back(nullptr); } 94 resource_type_id register_resource_type( const st ring& name, resource_manager_base* manager );95 resource_type_id get_resource_type_id( const st ring& 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; 96 96 void initialize( lua::state* a_lua_state ); 97 97 virtual ~resource_system(); 98 98 protected: 99 99 std::vector< resource_manager_base* > m_managers; 100 std::unordered_map< st ring, resource_id > m_manager_names;100 std::unordered_map< std::string, resource_id > m_manager_names; 101 101 lua::state* m_lua_state; 102 102 }; -
trunk/nv/formats/assimp_loader.hh
r319 r379 20 20 { 21 21 public: 22 explicit assimp_loader( const st ring& a_ext, uint32 a_assimp_flags = 0 );22 explicit assimp_loader( const std::string& a_ext, uint32 a_assimp_flags = 0 ); 23 23 virtual bool load( stream& source ); 24 24 virtual mesh_data* release_mesh_data( size_t index = 0 ); … … 38 38 39 39 string_table_creator m_strings; 40 st ring m_ext;40 std::string m_ext; 41 41 uint32 m_assimp_flags; 42 42 const void* m_scene; -
trunk/nv/gfx/texture_font.hh
r368 r379 45 45 texture_font( texture_atlas* atlas, const char * filename, float size ); 46 46 const texture_glyph* get_glyph( uint16 charcode ) const; 47 bool load_glyphs( const string&codes );47 bool load_glyphs( string_ref codes ); 48 48 float get_size() const { return m_size; } 49 49 ~texture_font(); … … 54 54 55 55 texture_atlas* m_atlas; //!< Atlas Image object for this font. 56 st ring m_filename; //!< Name of the file.56 std::string m_filename; //!< Name of the file. 57 57 float m_size; //!< Font size. 58 58 float m_height; //!< Height of the font. (x-height?) -
trunk/nv/gl/gl_device.hh
r361 r379 53 53 virtual const buffer_info* get_buffer_info( buffer t ) const; 54 54 55 virtual int get_attribute_location( program p, const st ring& name, bool fatal = true ) const;55 virtual int get_attribute_location( program p, const std::string& name, bool fatal = true ) const; 56 56 virtual void prepare_program( program p ); 57 virtual const st ring& get_shader_header() const { return m_shader_header; }57 virtual const std::string& get_shader_header() const { return m_shader_header; } 58 58 virtual ~gl_device(); 59 59 protected: 60 uniform_base* get_uniform( program p, const st ring& name, bool fatal = true ) const;60 uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const; 61 61 62 62 -
trunk/nv/gl/gl_window.hh
r364 r379 25 25 public: 26 26 gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc ); 27 virtual void set_title( const st ring& ) {}27 virtual void set_title( const std::string& ) {} 28 28 virtual context* get_context() { return m_context; } 29 29 virtual device* get_device() { return m_device; } 30 30 virtual uint16 get_width() const { return m_width; } 31 31 virtual uint16 get_height() const { return m_height; } 32 virtual st ring get_title() const{ return std::string(); }32 virtual std::string get_title() const { return std::string(); } 33 33 // TODO : implement? 34 34 virtual void set_swap_control( bool ) {} -
trunk/nv/gui/gui_element.hh
r368 r379 32 32 typedef std::list<handle> list; 33 33 34 st ring m_id; ///< id type of the object34 std::string m_id; ///< id type of the object 35 35 handle m_parent; ///< pointer to parent 36 36 flags m_flags; 37 37 list m_children; ///< children objects 38 38 size_t m_child_count; ///< number of children 39 st ring m_class; ///< Class name.40 st ring m_text; ///< Displayed label or text.39 std::string m_class; ///< Class name. 40 std::string m_text; ///< Displayed label or text. 41 41 rectangle m_relative; ///< Position relative to parent. 42 42 rectangle m_absolute; ///< Position relative to window/screen. -
trunk/nv/gui/gui_environment.hh
r368 r379 35 35 handle create_element( const rectangle& r ); 36 36 handle create_element( handle parent, const rectangle& r ); 37 void set_text( handle e, const st ring& text );38 void set_class( handle e, const st ring& text );37 void set_text( handle e, const std::string& text ); 38 void set_class( handle e, const std::string& text ); 39 39 void update(); 40 40 void draw(); -
trunk/nv/interface/device.hh
r368 r379 67 67 struct attribute 68 68 { 69 st ring name;69 std::string name; 70 70 int location; 71 71 datatype type; … … 73 73 }; 74 74 75 typedef std::unordered_map< st ring, attribute > attribute_map;75 typedef std::unordered_map< std::string, attribute > attribute_map; 76 76 77 77 struct texture_tag {}; … … 168 168 virtual const texture_info* get_texture_info( texture ) const = 0; 169 169 virtual const buffer_info* get_buffer_info( buffer ) const = 0; 170 virtual const st ring& get_shader_header() const = 0;170 virtual const std::string& get_shader_header() const = 0; 171 171 172 172 virtual texture create_texture( image_data* data, sampler asampler ) … … 175 175 } 176 176 177 int try_get_attribute_location( program p, const st ring& name ) const177 int try_get_attribute_location( program p, const std::string& name ) const 178 178 { 179 179 return get_attribute_location( p, name, false ); 180 180 } 181 181 182 virtual int get_attribute_location( program p, const st ring& name, bool fatal = true ) const = 0;183 184 template < typename T > 185 void set_uniform_array( program p, const st ring& 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 ) 186 186 { 187 187 uniform_base* base = get_uniform( p, name, fatal ); … … 198 198 199 199 template < typename T > 200 void set_opt_uniform_array( program p, const st ring& name, const T* value, uint32 count )200 void set_opt_uniform_array( program p, const std::string& name, const T* value, uint32 count ) 201 201 { 202 202 set_uniform_array( p, name, value, count, false ); … … 204 204 205 205 template < typename T > 206 void set_opt_uniform_array( program p, const st ring& name, const std::vector<T>& value )206 void set_opt_uniform_array( program p, const std::string& name, const std::vector<T>& value ) 207 207 { 208 208 set_uniform_array( p, name, (const T*)value.data(), value.size(), false ); … … 211 211 212 212 template < typename T > 213 void set_uniform( program p, const st ring& name, const T& value, bool fatal = true )213 void set_uniform( program p, const std::string& name, const T& value, bool fatal = true ) 214 214 { 215 215 uniform_base* base = get_uniform( p, name, fatal ); … … 224 224 225 225 template < typename T > 226 void set_opt_uniform( program p, const st ring& name, const T& value )226 void set_opt_uniform( program p, const std::string& name, const T& value ) 227 227 { 228 228 set_uniform( p, name, value, false ); … … 251 251 252 252 protected: 253 virtual uniform_base* get_uniform( program p, const st ring& name, bool fatal = true ) const = 0;253 virtual uniform_base* get_uniform( program p, const std::string& name, bool fatal = true ) const = 0; 254 254 255 255 void initialize_engine_uniforms() -
trunk/nv/interface/map_area.hh
r368 r379 17 17 #include <nv/stl/string.hh> 18 18 #include <nv/stl/array.hh> 19 #include <string> 19 20 20 21 namespace nv … … 27 28 virtual uint32 get_cell( const position& p ) const = 0; 28 29 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(); } 31 32 virtual dimension get_size() const = 0; 32 33 virtual position get_shift() const { return position(); } … … 48 49 virtual dimension get_size() const { return m_area.get_size(); } 49 50 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 ); } 52 53 private: 53 54 map_area* m_map_area; -
trunk/nv/interface/mesh_data.hh
r368 r379 221 221 struct mesh_node_data 222 222 { 223 st ring name;223 std::string name; 224 224 sint16 target_id; 225 225 sint16 parent_id; … … 233 233 friend class mesh_nodes_creator; 234 234 public: 235 explicit mesh_nodes_data( const st ring& name, uint32 count, mesh_node_data* nodes )235 explicit mesh_nodes_data( const std::string& name, uint32 count, mesh_node_data* nodes ) 236 236 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(0), m_duration(0.0f), m_flat( false ) 237 237 { 238 238 } 239 239 240 explicit mesh_nodes_data( const st ring& name, uint32 count, mesh_node_data* nodes,240 explicit mesh_nodes_data( const std::string& name, uint32 count, mesh_node_data* nodes, 241 241 uint16 a_fps, float a_frames, bool a_flat ) 242 242 : m_name( name ), m_count( count ), m_nodes( nodes ), m_frame_rate(a_fps), m_duration(a_frames), m_flat( a_flat ) … … 283 283 float get_duration() const { return m_duration; } 284 284 void set_name( const std::string& name ) { m_name = name; } 285 const st ring& get_name() const { return m_name; }285 const std::string& get_name() const { return m_name; } 286 286 287 287 ~mesh_nodes_data() … … 293 293 294 294 private: 295 st ring m_name;295 std::string m_name; 296 296 uint32 m_count; 297 297 mesh_node_data* m_nodes; -
trunk/nv/interface/uniform.hh
r368 r379 17 17 #include <nv/stl/string.hh> 18 18 #include <unordered_map> 19 #include <string> 19 20 20 21 namespace nv … … 25 26 { 26 27 public: 27 uniform_base( const st ring& name, datatype type, int location, int length )28 uniform_base( const std::string& name, datatype type, int location, int length ) 28 29 : m_name( name ), m_type( type ), m_location(location), m_length( length ), m_dirty( true ) {} 29 30 bool try_type_check( datatype ) … … 43 44 bool is_dirty() const { return m_dirty; } 44 45 void clean() { m_dirty = false; } 45 static uniform_base* create( datatype utype, const st ring& name, int location, int length );46 static uniform_base* create( datatype utype, const std::string& name, int location, int length ); 46 47 virtual ~uniform_base() {} 47 48 protected: 48 st ring m_name;49 std::string m_name; 49 50 datatype m_type; 50 51 int m_location; … … 59 60 typedef T value_type; 60 61 61 uniform( const st ring& name, int location, int length )62 uniform( const std::string& name, int location, int length ) 62 63 : uniform_base( name, type_to_enum< T >::type, location, length ), m_value( nullptr ) 63 64 { … … 148 149 }; 149 150 150 typedef std::unordered_map< st ring, uniform_base* > uniform_map;151 typedef std::unordered_map< std::string, uniform_base* > uniform_map; 151 152 typedef std::vector< engine_uniform_base* > engine_uniform_list; 152 typedef std::unordered_map< st ring, engine_uniform_factory_base* > engine_uniform_factory_map;153 typedef std::unordered_map< st ring, 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; 154 155 155 156 class engine_uniform_m_view : public engine_uniform< mat4 > … … 246 247 }; 247 248 248 inline uniform_base* uniform_base::create( datatype utype, const st ring& name, int location, int length )249 inline uniform_base* uniform_base::create( datatype utype, const std::string& name, int location, int length ) 249 250 { 250 251 switch( utype ) -
trunk/nv/interface/window.hh
r368 r379 27 27 virtual uint16 get_width() const = 0; 28 28 virtual uint16 get_height() const = 0; 29 virtual st ring get_title() const = 0;30 virtual void set_title( const st ring& title ) = 0;29 virtual std::string get_title() const = 0; 30 virtual void set_title( const std::string& title ) = 0; 31 31 virtual context* get_context() = 0; 32 32 virtual bool is_event_pending() = 0; -
trunk/nv/lua/lua_path.hh
r378 r379 55 55 56 56 void parse(); 57 void push( size_tvalue );57 void push( uint32 value ); 58 58 void push( string_ref p ); 59 59 … … 63 63 union 64 64 { 65 size_tvalue;65 uint32 value; 66 66 const char* str; 67 67 }; 68 size_tlength;68 uint32 length; 69 69 }; 70 70 71 71 element m_elements[8]; 72 sint32 m_count;72 uint32 m_count; 73 73 }; 74 74 -
trunk/nv/lua/lua_state.hh
r377 r379 33 33 namespace lua 34 34 { 35 class state; 35 36 36 37 const int ret_multi = -1; -
trunk/nv/lua/lua_values.hh
r377 r379 206 206 207 207 template <typename T> 208 struct type_degrade< T, enable_if_t< is_s tdstring< T>::value > >208 struct type_degrade< T, enable_if_t< is_same< std::string, remove_cvr_t< T > >::value > > 209 209 { 210 210 typedef std::string type; -
trunk/nv/sdl/sdl_window.hh
r343 r379 26 26 public: 27 27 window( device* dev, uint16 width, uint16 height, bool fullscreen = false ); 28 virtual void set_title( const st ring& title );28 virtual void set_title( const std::string& title ); 29 29 virtual void swap_buffers(); 30 30 … … 33 33 virtual uint16 get_width() const { return m_width; } 34 34 virtual uint16 get_height() const { return m_height; } 35 virtual st ring get_title() const{ return m_title; }35 virtual std::string get_title() const { return m_title; } 36 36 virtual void set_swap_control( bool enabled ); 37 37 virtual bool is_event_pending() { return m_input->is_event_pending(); } … … 44 44 uint16 m_width; 45 45 uint16 m_height; 46 st ring m_title;46 std::string m_title; 47 47 void* m_handle; 48 48 gl_context* m_context; -
trunk/nv/stl/any.hh
r377 r379 20 20 #include <nv/stl/type_traits.hh> 21 21 #include <nv/stl/type_info.hh> 22 23 #error "any type is currently unsupported!" 22 24 23 25 namespace nv -
trunk/nv/stl/string.hh
r378 r379 3 3 // For conditions of distribution and use, see copyright notice in nv.hh 4 4 // 5 // TODO: tests for string_length5 // TODO: 6 6 // * performance tests 7 7 // * matching tests … … 31 31 namespace nv 32 32 { 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 << operator41 * to stream42 * @throw runtime_error Throws runtime_error on conversion fail43 * @return value converted to string44 */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 the61 * value passed.62 */63 inline string to_string( const string& value)64 {65 return value;66 }67 68 33 /** 69 34 * Simple function for slurping a file into a string. … … 73 38 namespace detail 74 39 { 75 template< typename T >76 struct string_length_impl77 {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 111 40 // These could be done much better 112 41 template <typename T> … … 121 50 } 122 51 123 template< typename T >124 using string_length = detail::string_length_impl < remove_cvr_t < T > >;125 126 52 template < typename T > 127 53 struct is_cstring : detail::is_cstring_impl< remove_reference_t<T> >::type … … 129 55 130 56 }; 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 159 58 class string_ref; 160 59 … … 249 148 { 250 149 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() ) ) 252 151 return ( size_type )distance( this->cbegin(), it ); 253 152 return npos; … … 263 162 { 264 163 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() ) ) 266 165 return reverse_distance( this->crbegin(), it ); 267 166 return npos; … … 307 206 size_type reverse_distance( ReverseIterator first, ReverseIterator last ) const 308 207 { 309 return size() - 1 - distance( first, last );208 return size() - 1 - (size_t)distance( first, last ); 310 209 } 311 210 }; … … 508 407 size_t startpos = str.find_first_not_of( " \r\n\t" ); 509 408 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; 514 413 return str.substr( startpos, endpos ); 515 414 } … … 520 419 { 521 420 size_t endpos = str.find_last_not_of( " \r\n\t" ); 522 if ( string ::npos != endpos )421 if ( string_ref::npos != endpos ) 523 422 { 524 423 return str.substr( 0, endpos + 1 ); … … 530 429 { 531 430 size_t startpos = str.find_first_not_of( " \r\n\t" ); 532 if ( string ::npos != startpos )431 if ( string_ref::npos != startpos ) 533 432 { 534 433 return str.substr( startpos );
Note: See TracChangeset
for help on using the changeset viewer.