Changeset 437
- Timestamp:
- 07/23/15 08:30:41 (10 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/library.hh
r403 r437 16 16 #include <nv/common.hh> 17 17 #include <nv/stl/string.hh> 18 #include <string>19 18 20 19 namespace nv … … 83 82 * Exact implementation depends on platform/compiler. 84 83 */ 85 static st d::stringget_error();84 static string_view get_error(); 86 85 87 86 protected: … … 108 107 109 108 /// Library name 110 std::string m_name;109 const_string m_name; 111 110 112 111 }; // class Library -
trunk/nv/gfx/sliced_buffer.hh
r406 r437 13 13 #include <nv/common.hh> 14 14 #include <nv/stl/math.hh> 15 #include < vector> // TODO: remove15 #include <nv/stl/vector.hh> 16 16 17 17 namespace nv … … 25 25 public: 26 26 typedef sliced_buffer<T> cache_type; 27 typedef std::vector<T>vector_type;27 typedef vector<T> vector_type; 28 28 typedef size_t size_type; 29 29 … … 90 90 { 91 91 public: 92 typedef std::vector<T> vector_type;93 typedef T 92 typedef vector<T> vector_type; 93 typedef T value_type; 94 94 static const size_t value_type_size = sizeof(T); 95 95 … … 112 112 if ( !m_full_update && resized ) 113 113 { 114 m_data.erase( m_data.begin() + int( offset ), m_data.end() );114 m_data.erase( m_data.begin() + static_cast<int>( offset ), m_data.end() ); 115 115 m_min = nv::min<size_t>( m_min, offset ); 116 116 m_full_update = true; … … 119 119 { 120 120 offset = m_data.size(); 121 m_data. insert( m_data.end(),bv.cbegin(), bv.cend() );121 m_data.append( bv.cbegin(), bv.cend() ); 122 122 } 123 123 else if ( updated ) 124 124 { 125 125 // raw_copy( bv.cbegin(), bv.cend(), m_data.begin() + (int)offset ); 126 raw_copy( bv.data(), bv.data() + bv.size(), m_data.data() + int( offset ) );126 raw_copy( bv.data(), bv.data() + bv.size(), m_data.data() + static_cast<int>( offset ) ); 127 127 m_min = nv::min<size_t>( m_min, offset ); 128 128 m_max = nv::max<size_t>( m_max, offset + bv.size() ); … … 158 158 bool result = false; 159 159 size_t bsize = get_max_size(); 160 160 161 if ( m_data.size() > bsize ) 161 162 { -
trunk/nv/gfx/texture_atlas.hh
r395 r437 13 13 #include <nv/stl/math.hh> 14 14 #include <nv/gfx/image.hh> 15 //#include <nv/stl/vector.hh> 16 #include <vector> 15 #include <nv/stl/vector.hh> 17 16 18 17 namespace nv … … 32 31 size_t m_used; 33 32 size_t m_border; 34 std::vector<ivec3> m_nodes;33 vector<ivec3> m_nodes; 35 34 }; 36 35 -
trunk/nv/lua/lua_raw.hh
r395 r437 11 11 #include <nv/stl/vector.hh> 12 12 #include <nv/lib/lua.hh> 13 #include < string>13 #include <nv/stl/string.hh> 14 14 15 15 void nlua_toflags_set( lua_State *L, int index, nv::uint8* data, nv::uint32 count ); … … 17 17 void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count ); 18 18 19 std::string nlua_typecontent( lua_State* L, int idx ); 19 inline nv::string_view nlua_tostringview( lua_State* L, int idx ) 20 { 21 size_t len; 22 const char* str = lua_tolstring( L, idx, &len ); 23 return nv::string_view( str, len ); 24 } 25 26 inline void nlua_pushstringview( lua_State* L, const nv::string_view& str ) 27 { 28 lua_pushlstring( L, str.data(), str.size() ); 29 } 30 31 // TODO: this is not thread safe! 32 nv::string_view nlua_typecontent( lua_State* L, int idx ); 20 33 void nlua_shallowmerge( lua_State *L, int index ); 21 34 void nlua_shallowcopy( lua_State *L, int index ); … … 33 46 void nlua_register( lua_State *L, const char* lname, const luaL_Reg *l ); 34 47 48 49 35 50 #endif // NV_LUA_RAW_HH 36 51 -
trunk/nv/stl/container/growing_storage.hh
r435 r437 148 148 iterator erase( iterator position ) 149 149 { 150 if ( m_size == 0 ) return ;150 if ( m_size == 0 ) return iterator(); 151 151 iterator iend = Storage::data() + m_size; 152 152 InitializePolicy::destroy( position ); … … 162 162 InitializePolicy::destroy( first, last ); 163 163 iterator position = raw_alias_copy( last, iend, first ); 164 m_size -= ( last - first);164 m_size.size( m_size - ( last - first ) ); 165 165 return position; 166 166 } -
trunk/src/core/library.cc
r433 r437 6 6 7 7 #include "nv/core/library.hh" 8 #include <string> 8 9 9 10 #if NV_PLATFORM == NV_WINDOWS … … 40 41 void library::open( string_view name ) 41 42 { 42 m_name .assign( name.data(), name.size() );43 m_name = name; 43 44 if ( !open() ) 44 45 { … … 51 52 bool nv::library::try_open( string_view name ) 52 53 { 53 m_name .assign( name.data(), name.size() );54 m_name = name; 54 55 if ( !open() ) 55 56 { … … 62 63 string_view library::get_name() const 63 64 { 64 return string_view( m_name.c_str(), m_name.size() );65 return m_name; 65 66 } 66 67 … … 71 72 return true; 72 73 } 73 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loading..." );74 NV_LOG_NOTICE( "library \"", m_name, "\" : loading..." ); 74 75 75 std::string name = m_name;76 std::string name( m_name.data(), m_name.length() ); 76 77 std::string ext( NV_LIB_EXT ); 77 78 … … 85 86 if ( m_handle == NULL ) 86 87 { 87 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : failed to open!" );88 NV_LOG_NOTICE( "library \"", m_name, "\" : failed to open!" ); 88 89 return false; 89 90 } 90 NV_LOG_NOTICE( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : loaded." );91 91 return true; 92 92 } … … 97 97 if ( !result ) 98 98 { 99 NV_LOG_CRITICAL( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't find symbol \"", symbol, "\"" );99 NV_LOG_CRITICAL( "library \"", m_name, "\" : can't find symbol \"", symbol, "\"" ); 100 100 NV_ABORT( "Library symbol load failed!" ); 101 101 } … … 117 117 if ( ! NV_LIB_CLOSE( m_handle ) ) 118 118 { 119 NV_LOG_ERROR( "library \"", string_view( m_name.c_str(), m_name.size() ), "\" : can't close library!" );119 NV_LOG_ERROR( "library \"", m_name, "\" : can't close library!" ); 120 120 } 121 121 m_handle = nullptr; … … 130 130 } 131 131 132 std::stringlibrary::get_error()132 nv::string_view library::get_error() 133 133 { 134 134 #if NV_PLATFORM == NV_WINDOWS 135 135 // We do hate WinAPI for code like this, don't we? 136 LPTSTR buffer = nullptr; 137 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 138 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL ); 139 std::string msg( reinterpret_cast<char*>( buffer ) ); 140 LocalFree( buffer ); 141 return msg; 136 static TCHAR buffer[256]; 137 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 138 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 256, NULL ); 139 return string_view( reinterpret_cast<char*>( buffer ) ); 142 140 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 143 return std::string( dlerror() );141 return nv::string_view( dlerror() ); 144 142 #else 145 return std::string("");143 return nv::string_view(); 146 144 #endif 147 145 } -
trunk/src/gui/gui_gfx_renderer.cc
r435 r437 235 235 size_t size_before = er->buffer.data().size(); 236 236 237 std::vector< gui_quad >& qvec = er->buffer.lock();237 vector< gui_quad >& qvec = er->buffer.lock(); 238 238 239 239 qvec.clear(); -
trunk/src/lua/lua_map_area.cc
r431 r437 137 137 { 138 138 nv::map_area* ma = to_map_area( L, 1 ); 139 nv::string_view result( ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) ); 140 lua_pushlstring( L, result.data(), result.size() ); 139 nlua_pushstringview( L, ma->id_to_string( ma->get_cell( to_coord( L, 2 ) ) ) ); 141 140 return 1; 142 141 } -
trunk/src/lua/lua_nova.cc
r399 r437 817 817 // TODO: check if nova is loaded 818 818 lua_pushcfunction( L, nova_register_storage ); 819 lua_pushlstring( L, name.data(), name.size());819 nlua_pushstringview( L, name ); 820 820 lua_call( L, 1, 1 ); 821 821 lua_setglobal( L, constructor_name.data() ); -
trunk/src/lua/lua_raw.cc
r435 r437 7 7 #include "nv/lua/lua_raw.hh" 8 8 9 #include "nv/stl/string.hh" 10 11 std::string nlua_typecontent( lua_State* L, int idx ) 9 nv::string_view nlua_typecontent( lua_State* L, int idx ) 12 10 { 13 11 int type = lua_type( L, idx ); … … 19 17 //case LUA_TLIGHTUSERDATA : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) ); 20 18 //case LUA_TNUMBER : return std::to_string( lua_tonumber( L, idx ) ); 21 case LUA_TSTRING : return lua_tostring( L, idx ); 19 // TODO: copy to buffer? 20 case LUA_TSTRING : return nlua_tostringview( L, idx ); 22 21 case LUA_TTABLE : return "TABLE"; 23 22 case LUA_TFUNCTION : return "FUNCTION"; … … 26 25 default : break; 27 26 } 28 char buffer_data[64];27 static char buffer_data[64]; 29 28 nv::array_ref< char > buffer( buffer_data, 64 ); 30 29 if ( type == LUA_TLIGHTUSERDATA || type == LUA_TUSERDATA ) 31 30 { 32 31 size_t l = nv::uint64_to_buffer( buffer, nv::uint64( lua_touserdata( L, idx ) ) ); 33 return std::string( buffer_data, l);32 return nv::string_view( buffer.data(), buffer.size() ); 34 33 } 35 34 else if ( type == LUA_TNUMBER ) 36 35 { 37 36 size_t l = nv::f64_to_buffer( buffer, lua_tonumber( L, idx ) ); 38 return std::string( buffer_data, l);37 return nv::string_view( buffer.data(), buffer.size() ); 39 38 } 40 39 return "UNKNOWN!"; -
trunk/src/lua/lua_state.cc
r433 r437 134 134 if ( status != 0 ) 135 135 { 136 NV_LOG_ERROR( "Lua error : ", lua_tostring( m_state, -1 ) );136 NV_LOG_ERROR( "Lua error : ", nlua_tostringview( m_state, -1 ) ); 137 137 lua_pop( m_state, 1 ); 138 138 } … … 402 402 if (result) 403 403 { 404 NV_LOG_WARNING( "Failed to load string ", name, ": ", lua_tostring(m_state, -1));404 NV_LOG_WARNING( "Failed to load string ", name, ": ", nlua_tostringview(m_state, -1)); 405 405 return false; 406 406 } … … 414 414 if (result) 415 415 { 416 NV_LOG_WARNING( "Failed to open file ", filename, ": ", lua_tostring( m_state, -1 ) );416 NV_LOG_WARNING( "Failed to open file ", filename, ": ", nlua_tostringview( m_state, -1 ) ); 417 417 return false; 418 418 } … … 425 425 if (result) 426 426 { 427 NV_LOG_WARNING( "Failed to run script ", name, ": ", lua_tostring( m_state, -1 ) );427 NV_LOG_WARNING( "Failed to run script ", name, ": ", nlua_tostringview( m_state, -1 ) ); 428 428 lua_pop( m_state, 1 ); 429 429 } … … 442 442 for ( int i = 0; i < top; ++i ) 443 443 { 444 NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1) .c_str());444 NV_LOG_DEBUG( "#", i+1, " - ", lua_typename(m_state, lua_type(m_state, i+1) ), " = ", nlua_typecontent(m_state, i+1) ); 445 445 } 446 446 } … … 546 546 if ( !object_index.is_valid() ) return; 547 547 lua_rawgeti( m_state, LUA_REGISTRYINDEX, object_index.get() ); 548 lua_pushlstring( m_state, metaname.data(), metaname.size());548 nlua_pushstringview( m_state, metaname ); 549 549 lua_pushlightuserdata( m_state, pointer ); 550 550 lua_rawset( m_state, -3 ); … … 572 572 else 573 573 nlua_deepcopy( m_state, -2 ); 574 lua_pushlstring( m_state, id.data(), id.size());574 nlua_pushstringview( m_state, id ); 575 575 lua_pushvalue( m_state, -2 ); 576 576 lua_rawset( m_state, -4 ); … … 590 590 return; 591 591 } 592 lua_pushlstring( m_state, id.data(), id.size());592 nlua_pushstringview( m_state, id ); 593 593 lua_pushnil( m_state ); 594 594 lua_rawset( m_state, -3 );
Note: See TracChangeset
for help on using the changeset viewer.