Ignore:
Timestamp:
01/24/17 17:55:00 (8 years ago)
Author:
epyon
Message:
  • temporary_proxy implemented
  • table_guard now uses temporary_proxy as main read functionality
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/lua/lua_proxy.hh

    r538 r539  
    1010#include <nv/common.hh>
    1111#include <nv/stl/string.hh>
     12#include <nv/stl/string_table.hh>
    1213
    1314namespace nv
     
    2526                        stack_proxy( stack_proxy&& ) = default;
    2627                        stack_proxy& operator=( stack_proxy&& ) = default;
    27                         string64 get_string64() const;
    28                         string64 to_string64();
     28
     29                        uint32 get_uint32( uint32 def = 0 ) const;
     30                        sint32 get_sint32( sint32 def = 0 ) const;
     31                        char get_char( char def = ' ' ) const;
     32                        f64 get_f64( f64 def = 0.0 ) const;
     33                        f32 get_f32( f32 def = 0.0f ) const;
     34                        bool get_bool( bool def = false ) const;
     35
     36                        template< typename E >
     37                        E get_enum( E def = E() ) const
     38                        {
     39                                return static_cast<E>( get_uint32( static_cast<sint32>( def ) ) );
     40                        }
     41
     42                        template< typename T >
     43                        T as( const T& def ) const
     44                        {
     45                                return static_cast<T>( pass_traits< converted_type_t<T> >::to( *m_state, m_index, def ) );
     46                        }
     47
     48                        template< typename T >
     49                        T as() const
     50                        {
     51                                return static_cast<T>( pass_traits< converted_type_t<T> >::to( *m_state, m_index ) );
     52                        }
     53
     54                        bool is_table() const;
     55                        bool is_number() const;
     56                        bool is_bool() const;
     57                        bool is_string() const;
     58
     59                        const_string get_string() const { return const_string( get_string_view() ); }
     60                        const_string as_string()        { return const_string( as_string_view() ); }
     61                        string32 get_string32() const   { return string32( get_string_view() ); }
     62                        string32 as_string32()          { return string32( as_string_view() ); }
     63                        string64 get_string64() const   { return string64( get_string_view() ); }
     64                        string64 as_string64()          { return string64( as_string_view() ); }
     65                        string128 get_string128() const { return string128( get_string_view() ); }
     66                        string128 as_string128()        { return string128( as_string_view() ); }
     67                        shash64 get_shash64() const     { return is_string() ? shash64( get_string_view() ) : shash64(); }
     68                        shash64 as_shash64()            { return is_string() ? shash64( as_string_view() ) : shash64(); }
     69
     70                        shash64 get_string( string_table* table ) const
     71                        {
     72                                string_view result( get_string_view() );
     73                                return table ? table->insert( result ) : result;
     74                        }
     75
     76                        shash64 as_string( string_table* table )
     77                        {
     78                                string_view result( as_string_view() );
     79                                return table ? table->insert( result ) : result;
     80                        }
     81
    2982                        // TO FUCKING DO : non-copyable stringview
    3083//                      string_view get_string_view() const;
    3184//                      string_view to_string_view();
    3285                protected:
     86                        // Not public because not permanent
     87                        string_view get_string_view() const;
     88                        // Not public because not permanent
     89                        string_view as_string_view();
     90
    3391                        state* m_state;
    3492                        sint32 m_index;
    3593                };
     94
     95                class temporary_proxy : public stack_proxy
     96                {
     97                protected:
     98                        temporary_proxy( const temporary_proxy& ) = delete;
     99                        temporary_proxy& operator=( const temporary_proxy& ) = delete;
     100                        temporary_proxy( temporary_proxy&& ) = default;
     101                        temporary_proxy& operator=( temporary_proxy&& ) = default;
     102
     103                        temporary_proxy( state* state );
     104                public:
     105                        ~temporary_proxy();
     106                        friend class table_guard;
     107                };
     108
     109
    36110
    37111                class kv_proxy
Note: See TracChangeset for help on using the changeset viewer.