- Timestamp:
- 07/24/15 12:52:05 (10 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/base/capi.hh
r441 r442 102 102 inline void* nvmemcpy( void *dest, const void *src, size_t count ) 103 103 { 104 NV_ASSERT( dest && src, "Bad parameter to nvmemcpy!" ); 104 105 if ( dest == src ) return dest; 105 106 return NV_CAPI_CALL( memcpy )( dest, src, count ); … … 108 109 inline void* nvmemmove( void *dest, const void *src, size_t count ) 109 110 { 111 NV_ASSERT( dest && src, "Bad parameter to nvmemmove!" ); 110 112 if ( dest == src ) return dest; 111 113 return NV_CAPI_CALL( memmove )( dest, src, count ); … … 114 116 inline void* nvmemset( void *dest, unsigned char value, size_t count ) 115 117 { 118 NV_ASSERT( dest, "Bad parameter to nvmemset!" ); 116 119 return NV_CAPI_CALL( memset )( dest, static_cast<int>( value ), count ); 117 120 } … … 119 122 inline void* nvmemchr( const void *src, unsigned char value, size_t max_count ) 120 123 { 124 NV_ASSERT( src, "Bad parameter to nvmemchr!" ); 121 125 return NV_CAPI_CALL( memchr )( src, static_cast<int>( value ), max_count ); 122 126 } … … 124 128 inline int nvmemcmp( const void * m1, const void * m2, nv::size_t max_count ) 125 129 { 130 NV_ASSERT( m1 && m2, "Bad parameter to nvmemcmp!" ); 126 131 return NV_CAPI_CALL( memcmp )( m1, m2, max_count ); 127 132 } … … 129 134 inline int nvstrcmp( const char * s1, const char * s2 ) 130 135 { 136 NV_ASSERT( s1 && s2, "Bad parameter to nvstrcmp!" ); 131 137 return NV_CAPI_CALL( strcmp )( s1, s2 ); 132 138 } -
trunk/nv/gui/gui_element.hh
r440 r442 19 19 #include <nv/stl/string.hh> 20 20 #include <nv/gui/gui_common.hh> 21 #include <list>22 21 23 22 namespace nv -
trunk/nv/io/c_stream.hh
r438 r442 32 32 virtual size_t read( void* buffer, size_t size, size_t count ); 33 33 virtual size_t write( const void* buffer, size_t size, size_t count ); 34 virtual bool gets( char* buffer, size_t max_count ); 34 35 virtual bool seek( long offset, origin orig ); 35 36 virtual size_t tell(); -
trunk/nv/stl/algorithm.hh
r402 r442 63 63 for ( ForwardIterator it = first2; it != last2; ++it ) 64 64 if ( *first1 == *it ) 65 break;65 return ( first1 ); 66 66 return ( first1 ); 67 67 } … … 73 73 for ( ForwardIterator it = first2; it != last2; ++it ) 74 74 if ( comp_op( *first1, *it ) ) 75 break;75 return ( first1 ); 76 76 return ( first1 ); 77 77 } -
trunk/nv/stl/stream.hh
r422 r442 34 34 virtual size_t read( void* buffer, size_t size, size_t count ) = 0; 35 35 virtual size_t write( const void* buffer, size_t size, size_t count ) = 0; 36 virtual bool gets( char* buffer, size_t max_count ) = 0; 36 37 virtual bool seek( long offset, origin orig ) = 0; 37 38 virtual size_t tell() = 0; -
trunk/nv/stl/string/short_string.hh
r441 r442 59 59 size_t append( const char* data, size_t sz ) 60 60 { 61 if ( !data ) return 0; 61 62 size_t pos = size(); 62 63 size_t amount = expand_by( sz ); -
trunk/nv/stl/string/string_base.hh
r435 r442 74 74 // string operations 75 75 string_view substr( size_type p, size_type n = npos ) const; 76 string_view without_prefix( size_type p ) const; 77 string_view without_suffix( size_type p ) const; 76 78 77 79 template < typename H = size_type > … … 278 280 return string_view( this->data() + p, n ); 279 281 } 282 283 template < typename Storage > 284 inline string_view string_base< Storage >::without_prefix( size_type p ) const 285 { 286 string_view result( this->data(), this->size() ); 287 result.remove_prefix( p ); 288 return result; 289 } 290 291 template < typename Storage > 292 inline string_view string_base< Storage >::without_suffix( size_type p ) const 293 { 294 string_view result( this->data(), this->size() ); 295 result.remove_suffix( p ); 296 return result; 297 } 298 280 299 281 300 #define NV_STRING_BASE_CAST_OPERATORS( OPERATOR )\ -
trunk/src/formats/nmd_loader.cc
r431 r442 6 6 7 7 #include "nv/formats/nmd_loader.hh" 8 #include "nv/io/std_stream.hh"9 8 #include "nv/stl/string.hh" 10 9 #include "nv/interface/data_channel_access.hh" -
trunk/src/formats/obj_loader.cc
r433 r442 6 6 7 7 #include "nv/formats/obj_loader.hh" 8 #include "nv/io/std_stream.hh"9 8 #include "nv/interface/data_channel_access.hh" 10 9 11 #include < sstream>10 #include <cstdio> 12 11 13 12 using namespace nv; … … 50 49 vector< vec2 > t; 51 50 52 std::string line; 53 std::string cmd; 54 std::string name; 55 std::string next_name; 51 string32 name; 52 string32 next_name; 56 53 57 54 nv::size_t size; … … 59 56 60 57 obj_reader(); 61 bool read_stream( st d::istream& stream);58 bool read_stream( stream& str ); 62 59 virtual nv::size_t add_face( uint32* vi, uint32* ti, uint32* ni, nv::size_t count ) = 0; 63 60 virtual nv::size_t raw_size() const = 0; … … 79 76 } 80 77 81 bool obj_reader::read_stream( st d::istream& stream)82 { 83 name = next_name;78 bool obj_reader::read_stream( stream& str ) 79 { 80 name.assign( next_name ); 84 81 bool added_faces = false; 85 82 f32 x, y, z; 86 83 if ( eof ) return false; 87 88 while ( std::getline( stream, line ) ) 89 { 90 if ( line.length() < 3 || line[0] == '#' ) 91 { 92 continue; 93 } 94 95 std::istringstream ss(line); 96 ss >> cmd; 97 98 if ( cmd == "v" ) 99 { 100 ss >> x >> y >> z; 84 char buffer[256]; 85 while ( str.gets( buffer, 256 ) ) 86 { 87 string_view cline( static_cast<const char*>( buffer ) ); 88 cline = nv::trimmed( cline ); 89 90 if ( cline.length() < 3 || cline[0] == '#' ) 91 { 92 continue; 93 } 94 95 if ( cline.starts_with( "vn " ) ) 96 { 97 sscanf( cline.data(), "vn %f %f %f", &x, &y, &z ); 98 n.push_back( vec3( x, y, z ) ); 99 continue; 100 } 101 102 if ( cline.starts_with( "vt " ) ) 103 { 104 sscanf( cline.data(), "vt %f %f", &x, &y ); 105 t.push_back( vec2( x, 1.0f - y ) ); 106 continue; 107 } 108 109 if ( cline.starts_with( "v " ) ) 110 { 111 sscanf( cline.data(), "v %f %f %f", &x, &y, &z ); 101 112 v.push_back( vec3( x, y, z ) ); 102 113 continue; 103 114 } 104 115 105 if ( cmd == "vn" ) 106 { 107 ss >> x >> y >> z; 108 n.push_back( vec3( x, y, z ) ); 109 continue; 110 } 111 112 if ( cmd == "vt" ) 113 { 114 ss >> x >> y; 115 t.push_back( vec2( x, 1.0f - y ) ); 116 continue; 117 } 118 119 if ( cmd == "f" ) 116 if ( cline.starts_with( "f " ) ) 120 117 { 121 118 added_faces = true; 122 ss >> cmd;123 119 124 120 uint32 vis[8]; … … 128 124 uint32 count = 0; 129 125 130 while ( !ss.fail() ) 126 string_view scan( cline ); 127 scan.remove_prefix( 2 ); 128 size_t pos = 0; 129 while ( pos != string_view::npos ) 131 130 { 132 char ch; 133 134 std::istringstream ss2( cmd ); 135 ss2 >> vis[count] >> ch; 136 ss2 >> tis[count] >> ch; 137 if ( ch == '/') 131 scan.remove_prefix( pos ); 132 scan = nv::trimmed( scan ); 133 if ( sscanf( scan.data(), "%u/%u/%u", &vis[count], &tis[count], &nis[count] ) == 3 ) 138 134 { 139 135 normals = true; 140 ss2 >> nis[count];141 136 } 142 143 ss >> cmd; 137 else if ( !normals && sscanf( scan.data(), "%u/%u", &vis[count], &tis[count] ) == 2 ) 138 { 139 140 } 141 else 142 { 143 break; 144 } 144 145 count++; 146 pos = scan.find_first_of( "\t " ); 145 147 } 146 148 … … 149 151 } 150 152 151 if ( c md == "g")152 { 153 ss >> next_name;153 if ( cline.starts_with( "g " ) ) 154 { 155 next_name.assign( nv::trimmed( cline.without_prefix( 2 ) ) ); 154 156 if (added_faces) 155 157 return true; 156 name = next_name;157 continue; 158 } 159 160 if ( c md == "s")158 name.assign( next_name ); 159 continue; 160 } 161 162 if ( cline.starts_with( "s " ) ) 161 163 { 162 164 continue; … … 317 319 else 318 320 reader = new mesh_data_reader_vt(); 319 std_stream sstream( &source ); 320 321 while ( reader->read_stream( sstream ) ) 321 while ( reader->read_stream( source ) ) 322 322 { 323 323 if ( m_tangents ) … … 328 328 data_channel_set* result = data_channel_set_creator::create_set( 1 ); 329 329 data_channel_set_creator raccess( result ); 330 raccess.set_name( make_name( reader->name .c_str()) );330 raccess.set_name( make_name( reader->name ) ); 331 331 uint8* rdata = raccess.add_channel( m_descriptor, reader->size * 3 ).raw_data(); 332 332 -
trunk/src/io/c_stream.cc
r406 r442 47 47 } 48 48 49 bool c_stream::gets( char* buffer, size_t max_count ) 50 { 51 NV_ASSERT( buffer != nullptr && max_count != 0, "Bad parameter passed to write!" ); 52 char* result = ::fgets( buffer, max_count, reinterpret_cast<FILE*>( m_file ) ); 53 if ( !result ) return false; 54 return true; 55 } 56 49 57 bool c_stream::seek( long offset, origin orig ) 50 58 { -
trunk/src/stl/string.cc
r438 r442 11 11 #include <cstdio> 12 12 #include <cstdlib> 13 #include <fstream> // for slurp only14 #include <sstream> // for slurp only15 13 16 14 using namespace nv;
Note: See TracChangeset
for help on using the changeset viewer.