Changeset 380 for trunk/src


Ignore:
Timestamp:
05/29/15 17:28:16 (10 years ago)
Author:
epyon
Message:
  • oops, missed src : got rid of to_string and other std::string utilities (except slurp) string no longer in nv namespace
Location:
trunk/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/library.cc

    r365 r380  
    3939}
    4040
    41 void library::open( const string& name )
     41void library::open( string_ref name )
    4242{
    43         m_name = name;
     43        m_name.assign( name.data(), name.size() );
    4444        if ( !open() )
    4545        {
    4646                m_handle = nullptr;
    47                 NV_THROW( library_error, "Can't load library!", name );
     47                NV_THROW( library_error, "Can't load library!", name.data() );
    4848        }
    4949}
    5050
    51 bool nv::library::try_open( const string& name )
     51bool nv::library::try_open( string_ref name )
    5252{
    53         m_name = name;
     53        m_name.assign( name.data(), name.size() );
    5454        if ( !open() )
    5555        {
     
    6060}
    6161
    62 const string& library::get_name() const
     62string_ref library::get_name() const
    6363{
    64     return m_name;
     64    return string_ref( m_name );
    6565}
    6666
     
    7373    NV_LOG_NOTICE( "library : loading '", m_name, "'..." );
    7474
    75     string name = m_name;
    76     string ext  = NV_LIB_EXT;
    77     size_t ext_len   = ext.length();
     75        std::string name = m_name;
     76        string_ref ext( NV_LIB_EXT );
    7877
    79     if ( name.length() < ext_len || name.substr( name.length() - ext_len, ext_len ) != ext )
     78        if ( name.length() < ext.length() || name.substr( name.length() - ext.length(), ext.length() ) != ext )
    8079    {
    81         name += ext;
     80        name.append( ext.data(), ext.length() );
    8281    }
    8382
     
    9392}
    9493
    95 void* library::get( const string& symbol )
     94void* library::get( string_ref symbol )
    9695{
    97         void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
     96        void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() );
    9897    if ( !result )
    9998    {
    100         NV_THROW( library_error, "Can't find symbol " + symbol + "!", m_name );
     99        NV_THROW( library_error, "Can't find symbol " + std::string(symbol.data(),symbol.size()) + "!", m_name );
    101100    }
    102101        return result;
    103102}
    104103
    105 void* nv::library::try_get( const string& symbol )
     104void* nv::library::try_get( string_ref symbol )
    106105{
    107         return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
     106        return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.data() );
    108107}
    109108
     
    130129}
    131130
    132 string library::get_error()
     131std::string library::get_error()
    133132{
    134133#if NV_PLATFORM == NV_WINDOWS
     
    137136    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    138137        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );
    139     string msg( (char*)buffer );
     138    std::string msg( (char*)buffer );
    140139    LocalFree( buffer );
    141140    return msg;
  • trunk/src/core/logger.cc

    r376 r380  
    163163        {
    164164                const char* lcolor = log_color[( level ) / 10];
    165                 fwrite( lcolor, strlen(lcolor), 1, stdout );
     165                fwrite( lcolor, nvstrlen(lcolor), 1, stdout );
    166166        }
    167167        fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, stdout );
  • trunk/src/core/profiler.cc

    r376 r380  
    108108        char buffer[128];
    109109        snprintf( buffer, 128, "%-23s %6s %6s %9s %6s", "TAG", "%PARNT", "CALLS", "TOTAL(ms)", "AVG(ms)" );
    110         NV_LOG_INFO( string_ref( buffer, strlen(buffer) ) );
     110        NV_LOG_INFO( string_ref( buffer, nvstrlen( buffer ) ) );
    111111        log_node_children( 0, m_root );
    112112        NV_LOG_INFO( "-- PROFILER REPORT END ---------------------------------" );
     
    122122                if ( c->m_calls > 0 )
    123123                {
    124                         double pparent  = ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.f;
    125                         int calls       = c->m_calls;
    126                         double total_ms = c->m_total_time_us / 1000.f;
    127                         double avg_ms   = ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f;
    128                         if ( indent > 0 ) memset( buffer, '-', indent );
     124                        f64 pparent = ( (f64)c->m_total_time_us / (f64)c->m_parent->m_total_time_us ) * 100.f;
     125                        uint32 calls       = c->m_calls;
     126                        f64 total_ms = c->m_total_time_us / 1000.f;
     127                        f64 avg_ms = ( (f64)c->m_total_time_us / (f64)c->m_calls ) / 1000.f;
     128                        if ( indent > 0 ) nvmemset( buffer, '-', indent );
    129129                        snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent,
    130130                                c->m_tag.c_str(), pparent, calls, total_ms, avg_ms );
    131                         NV_LOG_INFO( string_ref( buffer, strlen( buffer ) ) );
     131                        NV_LOG_INFO( string_ref( buffer, nvstrlen( buffer ) ) );
    132132                        if ( c->m_children.size() > 0 )
    133133                        {
  • trunk/src/core/time.cc

    r376 r380  
    7474        struct timespec ts;
    7575        ts.tv_sec = 0;
    76         ts.tv_nsec = ms * 1000000;
     76        ts.tv_nsec = (long)ms * 1000000;
    7777        nanosleep(&ts, NULL);
    7878//      usleep( ms * 1000 );
  • trunk/src/engine/program_manager.cc

    r368 r380  
    4646}
    4747
    48 void nv::program_manager::load_source( lua::table_guard& table, string& out, const string& append )
     48void nv::program_manager::load_source( lua::table_guard& table, std::string& out, const std::string& append )
    4949{
    5050        out = append;
  • trunk/src/engine/resource_system.cc

    r368 r380  
    3636}
    3737
    38 nv::resource_type_id nv::resource_system::register_resource_type( const string& /*name*/, resource_manager_base* /*manager*/ )
     38nv::resource_type_id nv::resource_system::register_resource_type( const std::string& /*name*/, resource_manager_base* /*manager*/ )
    3939{
    4040        return 0;
    4141}
    4242
    43 nv::resource_type_id nv::resource_system::get_resource_type_id( const string& /*name*/ ) const
     43nv::resource_type_id nv::resource_system::get_resource_type_id( const std::string& /*name*/ ) const
    4444{
    4545        return 0;
  • trunk/src/formats/assimp_loader.cc

    r376 r380  
    5757
    5858
    59 nv::assimp_loader::assimp_loader( const string& a_ext, uint32 a_assimp_flags /*= 0 */ )
     59nv::assimp_loader::assimp_loader( const std::string& a_ext, uint32 a_assimp_flags /*= 0 */ )
    6060        : m_scene( nullptr ), m_mesh_count(0)
    6161{
     
    374374        const aiScene* scene = (const aiScene*)m_scene;
    375375        const aiNode*  node  = (const aiNode*)vnode;
    376         string name( node->mName.data );
     376        std::string name( node->mName.data );
    377377        const aiAnimation* anim  = scene->mAnimations[anim_id];
    378378        const aiNodeAnim*  anode = nullptr;
  • trunk/src/gfx/texture_font.cc

    r367 r380  
    9191}
    9292
    93 bool texture_font::load_glyphs( const string& codes )
     93bool texture_font::load_glyphs( string_ref codes )
    9494{
    9595        FT_Face face     = (FT_Face)(m_rface);
  • trunk/src/gl/gl_device.cc

    r365 r380  
    217217}
    218218
    219 uniform_base* nv::gl_device::get_uniform( program p, const string& name, bool fatal /*= true */ ) const
     219uniform_base* nv::gl_device::get_uniform( program p, const std::string& name, bool fatal /*= true */ ) const
    220220{
    221221        const gl_program_info* info = m_programs.get( p );
     
    235235}
    236236
    237 int nv::gl_device::get_attribute_location( program p, const string& name, bool fatal /*= true */ ) const
     237int nv::gl_device::get_attribute_location( program p, const std::string& name, bool fatal /*= true */ ) const
    238238{
    239239        const gl_program_info* info = m_programs.get( p );
     
    347347                glGetActiveAttrib( p->glid, i, 128, &attr_nlen, &attr_len, &attr_type, name_buffer );
    348348
    349                 string name( name_buffer, size_t(attr_nlen) );
     349                std::string name( name_buffer, size_t( attr_nlen ) );
    350350
    351351                // skip built-ins
     
    376376                glGetActiveUniform( p->glid, i, 128, &uni_nlen, &uni_len, &uni_type, name_buffer );
    377377
    378                 string name( name_buffer, size_t(uni_nlen) );
     378                std::string name( name_buffer, size_t( uni_nlen ) );
    379379
    380380                // skip built-ins
     
    385385
    386386                // check for array
    387                 string::size_type arrchar = name.find('[');
    388                 if ( arrchar != string::npos )
     387                std::string::size_type arrchar = name.find( '[' );
     388                if ( arrchar != std::string::npos )
    389389                {
    390390                        name = name.substr( 0, arrchar );
  • trunk/src/gui/gui_environment.cc

    r356 r380  
    311311}
    312312
    313 void nv::gui::environment::set_class( handle e, const string& text )
     313void nv::gui::environment::set_class( handle e, const std::string& text )
    314314{
    315315        element* ep = m_elements.get(e);
     
    321321}
    322322
    323 void nv::gui::environment::set_text( handle e, const string& text )
     323void nv::gui::environment::set_text( handle e, const std::string& text )
    324324{
    325325        element* ep = m_elements.get(e);
  • trunk/src/gui/gui_gfx_renderer.cc

    r378 r380  
    190190{
    191191        std::string id_name( filename );
    192         id_name.append( std::to_string( size ) );
     192        char buffer[8]; size_t len = nv::sint32_to_buffer( (sint32)size, buffer );
     193        id_name.append( std::string( buffer, len ) );
    193194        auto i = m_font_names.find( id_name );
    194195        if ( i != m_font_names.end() )
  • trunk/src/lua/lua_glm.cc

    r378 r380  
    295295        switch ( v.length() )
    296296        {
    297         case 1: lua_pushfstring( L, ( fl ? "(%f)"          : "(%d)" ),          v[0] );
    298         case 2: lua_pushfstring( L, ( fl ? "(%f,%f)"       : "(%d,%d)" ),       v[0], v[1] );
    299         case 3: lua_pushfstring( L, ( fl ? "(%f,%f,%f)"    : "(%d,%d,%d)" ),    v[0], v[1], v[2] );
    300         case 4: lua_pushfstring( L, ( fl ? "(%f,%f,%f,%f)" : "(%d,%d,%d,%d)" ), v[0], v[1], v[2], v[3] );
     297        case 1: lua_pushfstring( L, ( fl ? "(%f)"          : "(%d)" ),          v[0] ); break;
     298        case 2: lua_pushfstring( L, ( fl ? "(%f,%f)"       : "(%d,%d)" ),       v[0], v[1] ); break;
     299        case 3: lua_pushfstring( L, ( fl ? "(%f,%f,%f)"    : "(%d,%d,%d)" ),    v[0], v[1], v[2] ); break;
     300        case 4: lua_pushfstring( L, ( fl ? "(%f,%f,%f,%f)" : "(%d,%d,%d,%d)" ), v[0], v[1], v[2], v[3] ); break;
    301301        default:
    302302                lua_pushliteral( L, "(vector?)" ); break;
  • trunk/src/lua/lua_path.cc

    r376 r380  
    3232}
    3333
    34 void lua::path::push( nv::size_t value )
     34void lua::path::push( nv::uint32 value )
    3535{
    3636        m_elements[ m_count ].value  = value;
     
    5050        if (m_count == 0) return false;
    5151        if (global) lua_pushglobaltable( L );
    52         for (int i = 0; i < m_count; ++i )
     52        for ( uint32 i = 0; i < m_count; ++i )
    5353        {
    5454                if ( lua_istable( L, -1 ) )
     
    7676std::string nv::lua::path::to_string() const
    7777{
    78         std::string result;
    79         result.reserve( 64 );
     78        char buffer[64];
     79        char* start   = buffer;
     80        char* current = buffer;
    8081        bool dot = false;
     82        bool oos = false;
    8183        for ( const element& e : m_elements )
    8284        {
    83                 if ( dot ) result.append(".");
     85                if ( current - start > 48 ) { oos = true; break; }
     86                if ( dot ) *current++ = '.';
    8487                if ( e.length == 0 )
    8588                {
    86                         result.append("[" + nv::to_string( e.value ) + "]" );
     89                        *current++ = '[';
     90                        current += uint32_to_buffer( e.value, current );
     91                        *current++ = ']';
    8792                        dot = false;
    8893                }
    8994                else
    9095                {
    91                         result.append( e.str, e.length );
     96                        if ( size_t(current - start) + e.length > 60 ) { oos = true; break; }
     97                        nvmemcpy( current, e.str, e.length );
     98                        current += e.length;
    9299                        dot = true;
    93100                }
    94101        }
    95         return result;
     102        if (oos)
     103        {
     104                *current++ = '.';
     105                *current++ = '.';
     106                *current++ = '.';
     107        }
     108        *current++ = '\0';
     109        return std::string( buffer, size_t(current - start - 1) );
    96110}
  • trunk/src/lua/lua_raw.cc

    r368 r380  
    1111std::string nlua_typecontent( lua_State* L, int idx )
    1212{
    13         switch ( lua_type( L, idx ) )
     13        int type = lua_type( L, idx );
     14        switch ( type )
    1415        {
    1516        case LUA_TNONE          : return "NONE";
    1617        case LUA_TNIL               : return "NIL";
    1718        case LUA_TBOOLEAN               : return lua_toboolean( L, idx ) == 0 ? "false" : "true";
    18         case LUA_TLIGHTUSERDATA : return nv::to_string( nv::uint64( lua_touserdata( L, idx ) ) );
    19         case LUA_TNUMBER                : return nv::to_string( lua_tonumber( L, idx ) );
     19        //case LUA_TLIGHTUSERDATA       : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) );
     20        //case LUA_TNUMBER              : return std::to_string( lua_tonumber( L, idx ) );
    2021        case LUA_TSTRING                : return lua_tostring( L, idx );
    2122        case LUA_TTABLE             : return "TABLE";
    2223        case LUA_TFUNCTION              : return "FUNCTION";
    23         case LUA_TUSERDATA              : return nv::to_string( nv::uint64( lua_touserdata( L, idx ) ) );
     24//      case LUA_TUSERDATA              : return std::to_string( nv::uint64( lua_touserdata( L, idx ) ) );
    2425        case LUA_TTHREAD                : return "THREAD";
    25         default : return "UNKNOWN!";
    26         }
     26        default : break;
     27        }
     28        char buffer[64];
     29        if ( type == LUA_TLIGHTUSERDATA || type == LUA_TUSERDATA )
     30        {
     31                size_t l = nv::uint64_to_buffer( nv::uint64( lua_touserdata( L, idx ) ), buffer );
     32                return std::string( buffer, l );
     33        }
     34        else if ( type == LUA_TNUMBER )
     35        {
     36                size_t l = nv::f64_to_buffer( lua_tonumber( L, idx ), buffer );
     37                return std::string( buffer, l );
     38        }
     39        return "UNKNOWN!";
    2740}
    2841
  • trunk/src/lua/lua_state.cc

    r376 r380  
    179179}
    180180
    181 string lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ )
     181std::string lua::table_guard::get_std_string( string_ref element, string_ref defval /*= string_ref() */ )
    182182{
    183183        lua_getfield( m_state, -1, element.data() );
  • trunk/src/sdl/sdl_window.cc

    r367 r380  
    7575}
    7676
    77 void sdl::window::set_title( const string& title )
     77void sdl::window::set_title( const std::string& title )
    7878{
    7979        SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
  • trunk/src/stl/string.cc

    r378 r380  
    9797{
    9898#if NV_COMPILER == NV_MSVC
    99         sprintf_s( str, 64, "%.*g", 6, n );
     99        int result = sprintf_s( str, 64, "%.*g", 6, n );
    100100#else
    101         snprintf( str, 64, "%.*g", 6, n );
     101        int result = snprintf( str, 64, "%.*g", 6, n );
    102102#endif
    103         sprintf( str, "%g", n );
    104         return strlen( str );
     103        return result > 0 ? ( nv::size_t )result : 0;
    105104}
    106105
     
    108107{
    109108#if NV_COMPILER == NV_MSVC
    110         sprintf_s( str, 64, "%.*g", 6, n );
     109        int result = sprintf_s( str, 64, "%.*g", 6, n );
    111110#else
    112         snprintf( str, 64, "%.*g", 6, n );
     111        int result = snprintf( str, 64, "%.*g", 6, n );
    113112#endif
    114         return strlen( str );
     113        return result > 0 ? ( nv::size_t )result : 0;
    115114}
    116115
     
    162161        while ( *s >= '0' && *s <= '9' )
    163162        {
    164                 result = ( result * 10 ) + ( *s - '0' );
     163                result = ( result * 10 ) + (uint32)( *s - '0' );
    165164                ++s;
    166165        }
     
    175174        while ( *s >= '0' && *s <= '9' )
    176175        {
    177                 result = ( result * 10 ) + ( *s - '0' );
     176                result = ( result * 10 ) + (uint32)( *s - '0' );
    178177                ++s;
    179178        }
Note: See TracChangeset for help on using the changeset viewer.