Changeset 440 for trunk


Ignore:
Timestamp:
07/23/15 21:16:01 (10 years ago)
Author:
epyon
Message:
  • massive std::string removal
  • no header depends on std::string anymore (or any other STL header)
  • still some code files do (WIP)
  • massive refactoring where std::string was used
  • lua still messy (grep for string128 - used everywhere)
  • string_twine added
Location:
trunk
Files:
2 added
30 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/nv/gl/gl_window.hh

    r395 r440  
    2626        public:
    2727                gl_window( device* dev, window_manager* wm, input* a_input, void* handle, void* dc );
    28                 virtual void set_title( const std::string& ) {}
     28                virtual void set_title( const string_view& ) {}
    2929                virtual context* get_context()    { return m_context; }
    3030                virtual device* get_device()      { return m_device; }
    3131                virtual uint16 get_width() const  { return m_width; }
    3232                virtual uint16 get_height() const { return m_height; }
    33                 virtual std::string get_title() const { return std::string(); }
     33                virtual string_view get_title() const { return string_view(); }
    3434                // TODO : implement?
    3535                virtual void set_swap_control( bool ) {}
  • trunk/nv/gui/gui_element.hh

    r395 r440  
    3030                public:
    3131                        /// List type
    32                         typedef std::list<handle> list;
    33 
    34                         std::string    m_id;              ///< id type of the object
     32                        // TODO: change to small_vector once implemented!
     33                        typedef vector< handle > child_list;
     34                        shash64 m_id;              ///< id type of the object
    3535                        handle    m_parent;          ///< pointer to parent
    3636                        flags     m_flags;
    37                         list      m_children;        ///< children objects
     37                        child_list m_children;        ///< children objects
    3838                        size_t    m_child_count;     ///< number of children
    39                         std::string    m_class; ///< Class name.
    40                         std::string    m_text; ///< Displayed label or text.
     39                        shash64    m_class; ///< Class name.
     40                        string_buffer 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

    r433 r440  
    3434                        handle create_element( const rectangle& r );
    3535                        handle create_element( handle parent, const rectangle& r );
    36                         void set_text( handle e, const std::string& text );
    37                         void set_class( handle  e, const std::string& text );
     36                        void set_text( handle e, const string_twine& text );
     37                        void set_class( handle e, const string_view& text );
    3838                        void update();
    3939                        void draw();
    4040                        void destroy_element( handle e );
    4141                        bool process_io_event( const io_event& ev );
     42                        string_view get_string( shash64 h );
    4243                        virtual ~environment();
    4344                protected:
     
    5354                        handle get_deepest_child( handle e, const position& p );
    5455                        void move_to_top( handle child );
    55                         void move_to_bottom( handle child );
    5656                        void set_relative( handle e, const rectangle& r );
    5757                        void set_relative( handle e, const position& p );
     
    5959
    6060                        handle_store< element, handle > m_elements;
     61                        string_table  m_strings;
    6162                        renderer*     m_renderer;
    6263                        handle        m_screen;
  • trunk/nv/gui/gui_renderer.hh

    r433 r440  
    2828                public:
    2929                        renderer() {}
     30                        virtual void set_environment( environment* env ) { m_style.set_environment( env ); }
    3031                        virtual void load_style( const string_view& filename );
    3132                        virtual void redraw( element* e, uint32 ) = 0;
  • trunk/nv/gui/gui_style.hh

    r433 r440  
    2626                {
    2727                public:
    28                         style();
     28                        style() : m_env( nullptr ) {}
     29                        void set_environment( environment* env ) { m_env = env;  }
    2930                        void load_style( const string_view& filename );
    30                         bool get( element* e, const char* centry, const char* cselector, std::string& s );
    31                         bool get( element* e, const char* centry, const char* cselector, vec4& vec );
    32                         bool get( element* e, const char* centry, const char* cselector, int& i );
    33                         bool get( element* e, const char* centry, const char* cselector, double& d );
     31                        bool get( element* e, const string_view& centry, const string_view& cselector, string128& s );
     32                        bool get( element* e, const string_view& centry, const string_view& cselector, vec4& vec );
     33                        bool get( element* e, const string_view& centry, const string_view& cselector, int& i );
     34                        bool get( element* e, const string_view& centry, const string_view& cselector, double& d );
    3435                        ~style();
    3536                protected:
    36                         bool find_entry( const char* cselector, const char* centry, int type );
    37                         bool resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type );
     37                        bool find_entry( const string_view& cselector, const string_view& centry, int type );
     38                        bool resolve( shash64 cid, shash64 cclass, const string_view& cselector, const string_view& centry, int type );
    3839                protected:
     40                        environment* m_env;
    3941                        lua::state m_lua; //!< separate lua state for style calculation
    4042                };
  • trunk/nv/interface/image_data.hh

    r395 r440  
    1616#include <nv/common.hh>
    1717#include <nv/stl/math.hh>
    18 #include <algorithm>
     18#include <nv/stl/algorithm/raw.hh>
    1919
    2020namespace nv
     
    5858                        size_t bsize = static_cast<size_t>(m_size.x * m_size.y) * get_depth();
    5959                        m_data = new uint8[ bsize ];
    60                         std::copy( data, data + bsize, m_data );
     60                        raw_copy( data, data + bsize, m_data );
    6161                }
    6262
  • trunk/nv/interface/uniform.hh

    r439 r440  
    7979                {
    8080                        // TODO: memcmp?
    81                         std::copy( value, value + count, m_value );
     81                        raw_copy( value, value + count, m_value );
    8282                        m_dirty = true;
    8383                }
  • trunk/nv/interface/window.hh

    r395 r440  
    2828                virtual uint16 get_width() const = 0;
    2929                virtual uint16 get_height() const = 0;
    30                 virtual std::string get_title() const = 0;
    31                 virtual void set_title( const std::string& title ) = 0;
     30                virtual string_view get_title() const = 0;
     31                virtual void set_title( const string_view& title ) = 0;
    3232                virtual context* get_context() = 0;
    3333                virtual bool is_event_pending() = 0;
  • trunk/nv/lua/lua_function.hh

    r406 r440  
    5454                        {
    5555                                retrieve();
    56                                 detail::push_values(L, std::forward<Args>(args)...);
     56                                detail::push_values(L, forward<Args>(args)...);
    5757                                return call_result<R>(sizeof...(Args));
    5858                        }
  • trunk/nv/lua/lua_path.hh

    r399 r440  
    3535                        }
    3636
    37                         std::string to_string() const;
     37                        string128 to_string() const;
    3838                        bool resolve( lua_State* L, bool global = true ) const;
    3939               
  • trunk/nv/lua/lua_state.hh

    r431 r440  
    6161                                if (push_function(p, m_global))
    6262                                {
    63                                         detail::push_values(m_state, std::forward<Args>(args)...);
     63                                        detail::push_values(m_state, forward<Args>(args)...);
    6464                                        if (call_function(sizeof...(Args), detail::return_count< R >::value) == 0)
    6565                                        {
     
    268268                                if ( push_function( p, false ) )
    269269                                {
    270                                         detail::push_values( m_state, std::forward<Args>(args)... );
     270                                        detail::push_values( m_state, forward<Args>(args)... );
    271271                                        if (call_function(sizeof...(Args), detail::return_count< R >::value) == 0)
    272272                                        {
     
    297297                        shash64 get_string_hash_64( string_view element, uint64 defval = 0 );
    298298                        shash64 get_string( string_view element, string_table& table, uint64 defval = 0 );
    299                         std::string get_std_string( string_view element, string_view defval = string_view() );
    300299                        const_string get_string( string_view element, string_view defval = string_view() );
     300                        string128 get_string128( string_view element, string_view defval = string_view() );
    301301                        char get_char( string_view element, char defval = ' ' );
    302302                        int get_integer( string_view element, int defval = 0 );
  • trunk/nv/lua/lua_values.hh

    r438 r440  
    7373                        void push_number     ( lua_State *L, lnumber v );
    7474                        void push_bool       ( lua_State *L, bool v );
    75                         void push_string     ( lua_State *L, const std::string& s );
    7675                        void push_string_view( lua_State *L, string_view s );
    7776                        void push_cstring    ( lua_State *L, const char* s );
     
    8382                        lnumber     to_number     ( lua_State *L, int index );
    8483                        bool        to_bool       ( lua_State *L, int index );
    85                         std::string to_string     ( lua_State *L, int index );
    8684                        const char* to_cstring    ( lua_State *L, int index );
    8785                        string_view to_string_view( lua_State *L, int index );
     
    9391                        lnumber     to_number     ( lua_State *L, int index, lnumber def );
    9492                        bool        to_bool       ( lua_State *L, int index, bool def );
    95                         std::string to_string     ( lua_State *L, int index, const std::string& def );
    9693                        const char* to_cstring    ( lua_State *L, int index, const char* def );
    9794                        string_view to_string_view( lua_State *L, int index, string_view def );
     
    151148
    152149                template <>
    153                 struct pass_traits<std::string>
    154                 {
    155                         static void push( lua_State *L, const std::string& s ) { detail::push_string( L, s ); }
    156                         static std::string to( lua_State *L, int index ) { return detail::to_string( L, index ); }
    157                         static std::string to( lua_State *L, int index, const std::string& def ) { return detail::to_string( L, index, def ); }
    158                 };
    159 
    160                 template <>
    161150                struct pass_traits < string_view >
    162151                {
     
    171160                        static void push( lua_State *L, const const_string& s ) { detail::push_string_view( L, s ); }
    172161                        static const_string to( lua_State *L, int index ) { return const_string( detail::to_string_view( L, index ) ); }
    173                         static const_string to( lua_State *L, int index, const_string def ) { return const_string( detail::to_string_view( L, index, def ) ); }
     162                        static const_string to( lua_State *L, int index, const string_view& def ) { return const_string( detail::to_string_view( L, index, def ) ); }
     163                };
     164
     165                template <>
     166                struct pass_traits < string128 >
     167                {
     168                        static void push( lua_State *L, const string128& s ) { detail::push_string_view( L, s ); }
     169                        static string128 to( lua_State *L, int index ) { return string128( detail::to_string_view( L, index ) ); }
     170                        static string128 to( lua_State *L, int index, const string_view& def ) { return string128( detail::to_string_view( L, index, def ) ); }
    174171                };
    175172
     
    211208                        {
    212209                                typedef const char* type;
    213                         };
    214 
    215                         template <typename T>
    216                         struct type_degrade< T, enable_if_t< is_same< std::string, remove_cvr_t< T > >::value > >
    217                         {
    218                                 typedef std::string type;
    219210                        };
    220211
  • trunk/nv/sdl/sdl_window.hh

    r395 r440  
    2727                public:
    2828                        window( device* dev, uint16 width, uint16 height, bool fullscreen = false );
    29                         virtual void set_title( const std::string& title );
     29                        virtual void set_title( const string_view& title );
    3030                        virtual void swap_buffers();
    3131
     
    3434                        virtual uint16 get_width() const  { return m_width; }
    3535                        virtual uint16 get_height() const { return m_height; }
    36                         virtual std::string get_title() const { return m_title; }
     36                        virtual string_view get_title() const { return m_title; }
    3737                        virtual void set_swap_control( bool enabled );
    3838                        virtual bool is_event_pending()            { return m_input->is_event_pending(); }
     
    4545                        uint16      m_width;
    4646                        uint16      m_height;
    47                         std::string      m_title;
     47                        string128   m_title;
    4848                        void*       m_handle;
    4949                        gl_context* m_context;
  • trunk/nv/stl/handle.hh

    r406 r440  
    4343                bool is_valid() const { return !is_nil(); }
    4444                T index() const { return m_index; }
    45                 //size_t hash() const { return std::hash<T>()( T( m_counter << IBITS | m_index ) ); }
     45                //size_t hash() const { return hash<T>()( T( m_counter << IBITS | m_index ) ); }
    4646                size_t hash() const { NV_ASSERT( false, "UNIMPLEMENTED!" ); return 0; }
    4747        protected:
     
    200200                        if ( dead_eindex != static_cast<index_type>( m_data.size()-1 ) )
    201201                        {
    202                                 m_data[ unsigned( dead_eindex ) ]    = m_data.back();
     202                                m_data[ unsigned( dead_eindex ) ]   = move( m_data.back() );
    203203                                m_handles[unsigned( dead_eindex ) ] = swap_handle;
    204                                 m_indexes[ swap_handle.index() ]       = dead_eindex;
     204                                m_indexes[ swap_handle.index() ]    = dead_eindex;
    205205                        }
    206206                        m_data.pop_back();
  • trunk/nv/stl/string.hh

    r438 r440  
    2828#include <nv/stl/string/const_string.hh>
    2929#include <nv/stl/string/short_string.hh>
    30 #include <string>
    3130#include <nv/stl/type_traits/primary.hh>
    3231#include <nv/stl/memory.hh>
     
    3736{
    3837       
    39         template< typename H >
    40         struct hash< std::string, H > : detail::hash_base< std::string, H >
    41         {
    42                 static H get( const std::string& value )
    43                 {
    44                         return hash_string< H >( value.c_str(), value.length() );
    45                 }
    46                 inline H operator()( const std::string& value ) const { return get( value ); }
    47         };
    48 
    4938        namespace detail
    5039        {
     
    5847                                is_same< const char *, decayed_type >::value > type;
    5948                };
    60 
    6149
    6250        }
  • trunk/nv/stl/string/short_string.hh

    r438 r440  
    3333                }
    3434
    35 
    3635                template < typename Base >
    3736                inline explicit string_buffer_base( const string_base< Base >& s ) : this_type( s.data(), s.size() ) {}
     
    4443                inline string_buffer_base( string_buffer_base&& copy ) = default;
    4544                inline string_buffer_base& operator=( string_buffer_base&& other ) = default;
     45
     46                void assign( const char* data, size_t sz )
     47                {
     48                        clear();
     49                        append( data, sz );
     50                }
     51
     52                template < typename T >
     53                void assign( const T& value )
     54                {
     55                        clear();
     56                        append( value );
     57                }
    4658
    4759                size_t append( const char* data, size_t sz )
  • trunk/src/engine/resource_system.cc

    r433 r440  
    1212{
    1313        m_lua = a_lua_state;
    14         std::string delete_me = "register_" + std::string( get_resource_name().data(), get_resource_name().size() );
    15         lua::register_storage( m_lua, get_storage_name(), string_view( delete_me.c_str(), delete_me.size() ) );
     14        string128 storage_name = "register_" + get_resource_name();
     15        lua::register_storage( m_lua, get_storage_name(), storage_name );
    1616}
    1717
  • trunk/src/formats/md5_loader.cc

    r433 r440  
    1414#include <stdio.h>  // sscanf
    1515#include <stdlib.h> // atof
     16
     17#include <string> // TODO: remove
    1618
    1719using namespace nv;
  • trunk/src/gui/gui_ascii_renderer.cc

    r406 r440  
    4949                er->clear = true;
    5050                int color = 0;
    51                 std::string path;
    52                 std::string text;
     51                string128 path;
    5352                const char* stext[] = { nullptr, "selected", "hover" };
    5453                const char* selector = stext[0];
  • trunk/src/gui/gui_environment.cc

    r433 r440  
    99#include "nv/gui/gui_renderer.hh"
    1010
    11 #include <algorithm> // std::find on std::list
    12 
    1311        /*
    1412
     
    2725        : m_renderer( r )
    2826{
     27        r->set_environment( this );
    2928        m_screen   = create_element( handle(), m_renderer->get_area() );
    3029}
     
    161160                while ( !parent->m_children.empty() )
    162161                {
    163                         destroy_element( parent->m_children.front() );
     162                        destroy_element( parent->m_children.back() );
    164163                }
    165164        }
     
    196195}
    197196
     197nv::string_view nv::gui::environment::get_string( shash64 h )
     198{
     199        return m_strings[h];
     200}
     201
    198202bool nv::gui::environment::set_selected( handle e )
    199203{
     
    235239
    236240        handle result;
    237         element::list::reverse_iterator it = el->m_children.rbegin();
     241        auto it = el->m_children.rbegin();
    238242
    239243        while ( it != el->m_children.rend() )
     
    254258        if ( e && parent )
    255259        {
    256                 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
     260                auto it = find( parent->m_children.begin(), parent->m_children.end(), child );
    257261                if ( it != parent->m_children.end() )
    258262                {
     
    264268}
    265269
    266 void nv::gui::environment::move_to_bottom( handle child )
    267 {
    268         element* e      = m_elements.get( child );
    269         element* parent = m_elements.get( e->m_parent );
    270         if ( e && parent )
    271         {
    272                 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
    273                 if ( it != parent->m_children.end() )
    274                 {
    275                         parent->m_children.erase( it );
    276                         parent->m_children.push_front( child );
    277                         parent->m_flags[DIRTY] = true;
    278                 }
    279         }
    280 }
    281 
    282270void nv::gui::environment::set_relative( handle e, const rectangle& r )
    283271{
     
    312300}
    313301
    314 void nv::gui::environment::set_class( handle e, const std::string& text )
     302void nv::gui::environment::set_class( handle e, const string_view& text )
    315303{
    316304        element* ep = m_elements.get(e);
    317305        if ( ep != nullptr )
    318306        {
    319                 ep->m_class        = text;
     307                ep->m_class        = m_strings.insert( text );
    320308                ep->m_flags[DIRTY] = true;
    321309        }
    322310}
    323311
    324 void nv::gui::environment::set_text( handle e, const std::string& text )
     312void nv::gui::environment::set_text( handle e, const string_twine& text )
    325313{
    326314        element* ep = m_elements.get(e);
    327315        if ( ep != nullptr )
    328316        {
    329                 ep->m_text         = text;
     317                ep->m_text.assign( text );
    330318                ep->m_flags[DIRTY] = true;
    331319        }
     
    337325        if ( p )
    338326        {
    339                 auto it = std::find( p->m_children.begin(), p->m_children.end(), child );
     327                auto it = find( p->m_children.begin(), p->m_children.end(), child );
    340328                if ( it != p->m_children.end() )
    341329                {
    342330                        element* e = m_elements.get( *it );
    343331                        e->m_parent = handle();
    344                         p->m_children.erase(it);
    345                 }       
    346         }
    347 }
    348 
     332                        p->m_children.erase( it );
     333                }
     334        }
     335}
     336
  • trunk/src/gui/gui_gfx_renderer.cc

    r437 r440  
    243243                int border = 0;
    244244                vec4 color;
    245                 std::string path;
    246                 std::string text;
    247                 const char* stext[] = { nullptr, "selected", "hover" };
     245                string128 path;
     246                const char* stext[] = { "", "selected", "hover" };
    248247                const char* selector = stext[border];
    249248                if ( e->m_flags[HOVER] )    selector = stext[2];
     
    252251                if ( m_style.get( e, "skin", selector, path ) )
    253252                {
    254                         size_t image_id = load_image( string_view( path.c_str(), path.size() ) );
     253                        size_t image_id = load_image( path );
    255254                        const image_info* image = get_image( image_id );
    256255                        if ( image )
     
    312311                }
    313312
    314                 text = e->m_text;
    315                 if ( !text.empty() )
     313                e->m_text;
     314                if ( !e->m_text.empty() )
    316315                {
    317316                        if ( m_style.get( e, "text_color", selector, color ) && m_style.get( e, "text_font", selector, path ) && m_style.get( e, "text_size", selector, border ) )
    318317                        {
    319                                 size_t font_id = load_font( string_view( path.c_str(), path.size() ), size_t( border ) );
     318                                size_t font_id = load_font( path, size_t( border ) );
    320319                                texture_font* font = get_font( font_id );
    321320                                position p = abs.ul + position( 0, border );
    322                                 for ( char c : text )
     321                                for ( char c : e->m_text )
    323322                                {
    324323                                        const texture_glyph* g = font->get_glyph( static_cast<uint16>( c ) );
  • trunk/src/gui/gui_style.cc

    r433 r440  
    77#include "nv/gui/gui_style.hh"
    88
     9#include "nv/gui/gui_environment.hh"
    910#include <nv/lua/lua_raw.hh>
    1011
     
    1213using namespace nv::gui;
    1314
    14 style::style()
    15 {
    16 }
    17 
    1815void style::load_style( const string_view& filename )
    1916{
     17        NV_ASSERT_ALWAYS( m_env, "Environment not set in style!" );
    2018        m_lua.do_file( filename );
    2119}
    2220
    23 bool style::get( element* e, const char* centry, const char* cselector, std::string& s )
     21bool style::get( element* e, const string_view& centry, const string_view& cselector, string128& s )
    2422{
    2523        lua::stack_guard guard( m_lua );
    26         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false;
    27         s = lua_tostring( m_lua, -1 );
     24        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TSTRING ) ) return false;
     25        // TODO: create lua_tostringbuffer< size >
     26        s.assign( lua_tostring( m_lua, -1 ) );
    2827        return true;
    2928}
    3029
    31 bool style::get( element* e, const char* centry, const char* cselector, vec4& vec )
     30bool style::get( element* e, const string_view& centry, const string_view& cselector, vec4& vec )
    3231{
    3332        lua::stack_guard guard( m_lua );
    34         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false;
     33        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TTABLE ) ) return false;
    3534        vec = vec4();
    3635        for ( int i = 0; i < 4; ++i )
     
    4443}
    4544
    46 bool style::get( element* e, const char* centry, const char* cselector, int& i )
     45bool style::get( element* e, const string_view& centry, const string_view& cselector, int& i )
    4746{
    4847        lua::stack_guard guard( m_lua );
    49         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
     48        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false;
    5049        i = static_cast< int >( lua_tointeger( m_lua, -1 ) );
    5150        return true;
    5251}
    5352
    54 bool style::get( element* e, const char* centry, const char* cselector, double& d )
     53bool style::get( element* e, const string_view& centry, const string_view& cselector, double& d )
    5554{
    5655        lua::stack_guard guard( m_lua );
    57         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
     56        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false;
    5857        d = lua_tonumber( m_lua, -1 );
    5958        return true;
     
    6463}
    6564
    66 bool style::find_entry( const char* cselector, const char* centry, int type )
     65bool style::find_entry( const string_view& cselector, const string_view& centry, int type )
    6766{
    6867        if ( lua_istable( m_lua, -1 ) )
    6968        {
    70                 if ( cselector )
     69                if ( !cselector.empty() )
    7170                {
    72                         lua_getfield( m_lua, -1, cselector );
     71                        lua_getfield( m_lua, -1, cselector.data() );
    7372                        if ( lua_istable( m_lua, -1 ) )
    7473                        {
    75                                 lua_getfield( m_lua, -1, centry );
     74                                lua_getfield( m_lua, -1, centry.data() );
    7675                                if ( lua_type( m_lua, -1 ) == type )
    7776                                {
     
    8382                }
    8483
    85                 lua_getfield( m_lua, -1, centry );
     84                lua_getfield( m_lua, -1, centry.data() );
    8685                if ( lua_type( m_lua, -1 ) == type ) return true;
    8786        }
     
    8988}
    9089
    91 bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type )
     90bool style::resolve( shash64 cid, shash64 cclass, const string_view& cselector, const string_view& centry, int type )
    9291{
    9392        lua_getglobal( m_lua, "default" );
     
    9594
    9695        // check id
    97         lua_getfield( m_lua, -1, cid );
    98         if ( find_entry( cselector, centry, type ) ) return true;
    99         lua_settop( m_lua, global );
    100 
     96        string_view id( m_env->get_string( cid ) );
     97        if ( !id.empty() )
     98        {
     99                lua_getfield( m_lua, -1, id.data() );
     100                if ( find_entry( cselector, centry, type ) ) return true;
     101                lua_settop( m_lua, global );
     102        }
    101103        // check class
    102         lua_getfield( m_lua, -1, cclass );
    103         if ( find_entry( cselector, centry, type ) ) return true;
    104         lua_settop( m_lua, global );
     104        string_view klass( m_env->get_string( cclass ) );
     105        if ( !klass.empty() )
     106        {
     107                lua_getfield( m_lua, -1, klass.data() );
     108                if ( find_entry( cselector, centry, type ) ) return true;
     109                lua_settop( m_lua, global );
     110        }
    105111
    106112        // check entry
  • trunk/src/lib/gl.cc

    r406 r440  
    5656
    5757
    58 static void* load_gl_ext_symbol_impl( const char* name, nv::log_level fail_level = nv::LOG_DEBUG )
    59 {
    60         void* result = gl_ext_loader( name );
     58static void* load_gl_ext_symbol_impl( const nv::string_view& name, nv::log_level fail_level = nv::LOG_DEBUG )
     59{
     60        void* result = gl_ext_loader( name.data() );
    6161        NV_LOG( ( result ? nv::LOG_DEBUG : fail_level ), "load_gl_ext_symbol : ", name, ( result ? " succeded." : "failed." ) );
    6262        return result;
    6363}
    6464
    65 static void* load_gl_ext_symbol( const char* name, bool iterate, const char* ext )
     65static void* load_gl_ext_symbol( const nv::string_view& name, bool iterate, const nv::string_view& ext )
    6666{
    6767        void * result        = nullptr;
    68         result = load_gl_ext_symbol_impl( ext ? ( std::string(name) + ext ).c_str() : name );
     68        nv::string128 test_name = name + ext;
     69        result = load_gl_ext_symbol_impl( !ext.empty() ? test_name : name );
    6970        if ( result ) return result;
    7071        if ( iterate )
    7172        {
    72                 result = gl_ext_loader( (std::string(name) + "ARB").c_str() );
     73                test_name = name + "ARB"_ls;
     74                result = gl_ext_loader( test_name.data() );
    7375                if ( result ) return result;
    74                 result = gl_ext_loader( (std::string(name) + "EXT").c_str() );
     76                test_name = name + "EXT"_ls;
     77                result = gl_ext_loader( test_name.data() );
    7578                if ( result ) return result;
    7679        }
     
    255258
    256259#       define NV_GL_FUN_EXT( rtype, symbol, fparams ) \
    257         void_assign( symbol, load_gl_ext_symbol(#symbol, true, nullptr) ); \
     260        void_assign( symbol, load_gl_ext_symbol(#symbol, true, string_view()) ); \
    258261        count++; if ( !symbol ) fail_count++;
    259262
  • trunk/src/lua/lua_function.cc

    r433 r440  
    2121        {
    2222                lua_pop( L, 1 );
    23                 NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string().c_str() );
     23                NV_LUA_ABORT( "function_base::function_base", "not a valid path - ", a_path.to_string() );
    2424        }
    2525
     
    2727        {
    2828                lua_pop( L, 1 );
    29                 NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string().c_str() );
     29                NV_LUA_ABORT( "function_base::function_base", "not a valid function - ", a_path.to_string() );
    3030        }
    3131        m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
     
    6464        if ( status != 0 )
    6565        {
    66                 std::string error = lua_tostring( L, -1 );
     66                string128 error( nlua_tostringview( L, -1 ) );
    6767                lua_pop( L, 1 );
    68                 NV_LUA_ABORT( "function_base::call", "call failed - ", error.c_str() );
     68                NV_LUA_ABORT( "function_base::call", "call failed - ", error );
    6969        }
    7070}
  • trunk/src/lua/lua_map_tile.cc

    r433 r440  
    1616#include "nv/lua/lua_values.hh"
    1717#include "nv/lua/lua_raw.hh"
     18
     19// TODO: REMOVE
     20#include <string>
    1821
    1922static const char* NLUA_MAP_TILE_METATABLE = "map_tile";
  • trunk/src/lua/lua_path.cc

    r435 r440  
    7474}
    7575
    76 std::string nv::lua::path::to_string() const
     76string128 nv::lua::path::to_string() const
    7777{
    78         char buffer[64];
    79         char* start   = buffer;
    80         char* current = buffer;
     78        string128 buffer;
    8179        bool dot = false;
    82         bool oos = false;
    8380        for ( const element& e : m_elements )
    8481        {
    85                 if ( current - start > 48 ) { oos = true; break; }
    86                 if ( dot ) *current++ = '.';
     82                if ( dot ) buffer.append( "." );
    8783                if ( e.length == 0 )
    8884                {
    89                         *current++ = '[';
    90                         current += uint32_to_buffer( array_ref< char >( current, current - start ), e.value );
    91                         *current++ = ']';
     85                        buffer.append( "["_ls + e.value + "]"_ls );
    9286                        dot = false;
    9387                }
    9488                else
    9589                {
    96                         if ( size_t(current - start) + e.length > 60 ) { oos = true; break; }
    97                         nvmemcpy( current, e.str, e.length );
    98                         current += e.length;
     90                        buffer.append( e.str, e.length );
    9991                        dot = true;
    10092                }
    10193        }
    102         if (oos)
    103         {
    104                 *current++ = '.';
    105                 *current++ = '.';
    106                 *current++ = '.';
    107         }
    108         *current++ = '\0';
    109         return std::string( buffer, size_t(current - start - 1) );
     94        return buffer;
    11095}
  • trunk/src/lua/lua_state.cc

    r437 r440  
    116116        if ( !p.resolve( m_state, global ) )
    117117        {
    118                 NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string().c_str() );
     118                NV_LOG_ERROR( "Lua error : not a valid path - ", p.to_string() );
    119119                return false;
    120120        }
     
    123123        {
    124124                lua_pop( m_state, 1 );
    125                 NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string().c_str() );
     125                NV_LOG_ERROR( "Lua error : not a valid function - ", p.to_string() );
    126126                return false;
    127127        }
     
    212212        lua_pop( m_state, 1 );
    213213        return shash64( result );
    214 }
    215 
    216 std::string lua::table_guard::get_std_string( string_view element, string_view defval /*= string_view() */ )
    217 {
    218         lua_getfield( m_state, -1, element.data() );
    219         size_t l = 0;
    220         const char* str = nullptr;
    221         if ( lua_type( m_state, -1 ) == LUA_TSTRING )
    222         {
    223                 str = lua_tolstring( m_state, -1, &l );
    224         }
    225         else
    226         {
    227                 l = defval.size();
    228                 str = defval.data();
    229         }
    230         std::string result( str, l );
    231         lua_pop( m_state, 1 );
    232         return result;
    233214}
    234215
     
    250231        lua_pop( m_state, 1 );
    251232        return result;
     233}
     234
     235string128 lua::table_guard::get_string128( string_view element, string_view defval )
     236{
     237        lua_getfield( m_state, -1, element.data() );
     238        size_t l = 0;
     239        const char* str = nullptr;
     240        if ( lua_type( m_state, -1 ) == LUA_TSTRING )
     241        {
     242                str = lua_tolstring( m_state, -1, &l );
     243        }
     244        else
     245        {
     246                l = defval.size();
     247                str = defval.data();
     248        }
     249        string128 result( str, l );
     250        lua_pop( m_state, 1 );
     251        return result;
    252252}
    253253
  • trunk/src/lua/lua_values.cc

    r399 r440  
    6565}
    6666
    67 void nv::lua::detail::push_string  ( lua_State *L, const std::string& s )
    68 {
    69         lua_pushlstring( L, s.c_str(), s.size() );
    70 }
    71 
    7267void nv::lua::detail::push_cstring ( lua_State *L, const char* s )
    7368{
     
    109104{
    110105        return lua_toboolean( L, index ) != 0;
    111 }
    112 
    113 std::string nv::lua::detail::to_string  ( lua_State *L, int index )
    114 {
    115         size_t length = 0;
    116         const char* result = lua_tolstring( L, index, &length );
    117         return std::string( result, length );
    118106}
    119107
     
    171159}
    172160
    173 std::string nv::lua::detail::to_string  ( lua_State *L, int index, const std::string& def )
     161nv::string_view nv::lua::detail::to_string_view( lua_State *L, int index, string_view def )
    174162{
    175         return ( lua_type( L, index ) == LUA_TSTRING ? lua_tostring( L, index ) : def );
     163        return ( lua_type( L, index ) == LUA_TSTRING ? nlua_tostringview( L, index ) : def );
    176164}
    177165
  • trunk/src/sdl/sdl_window.cc

    r406 r440  
    3636        uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
    3737        if (fullscreen) flags |= SDL_WINDOW_FULLSCREEN;
    38         m_title  = "Nova Engine";
    39         m_handle = SDL_CreateWindow( m_title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
     38        m_title.assign( "Nova Engine" );
     39        m_handle = SDL_CreateWindow( m_title.data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
    4040                width, height, flags );
    4141        if ( m_handle == 0 )
     
    7777}
    7878
    79 void sdl::window::set_title( const std::string& title )
     79void sdl::window::set_title( const string_view& title )
    8080{
    81         SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
    82         m_title = title;
     81        SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.data() );
     82        m_title.assign( title );
    8383}
    8484
  • trunk/src/stl/assert.cc

    r410 r440  
    1010extern "C" {
    1111#if NV_COMPILER == NV_MSVC
    12         _ACRTIMP NV_NORETURN void __cdecl exit( _In_ int _Code );
     12        NV_NORETURN void __cdecl exit( int _Code );
    1313#else
    1414        void exit( int status_code ) NV_NORETURN;
Note: See TracChangeset for help on using the changeset viewer.