Changeset 256


Ignore:
Timestamp:
06/14/14 21:06:00 (11 years ago)
Author:
epyon
Message:
  • various minor fixes
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/exception.hh

    r3 r256  
    1414#define NV_EXCEPTION_HH
    1515
     16#include <nv/common.hh>
     17#include <string>
    1618#include <exception>
    1719#include <stdexcept>
    18 #include <string>
    1920
    2021namespace nv
     
    2829        {
    2930        public:
    30                 explicit logic_error(const std::string&  __arg) : std::logic_error( __arg ) {}
     31                explicit logic_error( const std::string& msg ) : std::logic_error( msg ) {}
    3132        };
    3233
     
    3940        {
    4041        public:
    41                 explicit runtime_error(const std::string&  __arg) : std::runtime_error( __arg ) {}
     42                explicit runtime_error( const std::string& msg ) : std::runtime_error( msg ) {}
    4243        };
    4344}
  • trunk/nv/gfx/texture_font.hh

    r132 r256  
    99
    1010#include <nv/common.hh>
    11 #include <string>
     11#include <nv/string.hh>
    1212#include <unordered_map>
    1313#include <nv/math.hh>
     
    4545                        texture_font( texture_atlas* atlas, const char * filename, float size );
    4646                        const texture_glyph* get_glyph( uint16 charcode ) const;
    47                         bool load_glyphs( const std::string& codes );
     47                        bool load_glyphs( const string& codes );
    4848                        float get_size() const { return m_size; }
    4949                        ~texture_font();
     
    5454
    5555                        texture_atlas* m_atlas; //!< Atlas Image object for this font.
    56                         std::string m_filename; //!< Name of the file.
     56                        string m_filename; //!< Name of the file.
    5757                        float m_size;           //!< Font size.
    5858                        float m_height;         //!< Height of the font. (x-height?)
  • trunk/nv/interface/vertex_buffer.hh

    r239 r256  
    1818#include <nv/interface/mesh_data.hh>
    1919#include <unordered_map>
    20 #include <string>
    2120
    2221namespace nv
  • trunk/nv/library.hh

    r166 r256  
    1515
    1616#include <nv/exception.hh>
    17 #include <string>
     17#include <nv/string.hh>
    1818
    1919namespace nv
     
    3737                 * Throws library_error on failure
    3838                 */
    39                 void open( const std::string& name );
     39                void open( const string& name );
    4040
    4141                /**
     
    4444                 * returns true if succeeded, false otherwise
    4545                 */
    46                 bool try_open( const std::string& name );
     46                bool try_open( const string& name );
    4747
    4848                /**
     
    5454                 * Returns library name
    5555                 */
    56                 const std::string& get_name() const;
     56                const string& get_name() const;
    5757
    5858                /**
     
    6161                 * Throws on symbol not found
    6262                 */
    63                 void* get( const std::string& symbol );
     63                void* get( const string& symbol );
    6464
    6565                /**
     
    6868                 * Returns null if symbol not found
    6969                 */
    70                 void* try_get( const std::string& symbol );
     70                void* try_get( const string& symbol );
    7171
    7272                /**
     
    8282                 * Exact implementation depends on platform/compiler.
    8383                 */
    84                 static std::string get_error();
     84                static string get_error();
    8585
    8686        protected:
     
    107107
    108108                /// Library name
    109                 std::string m_name;
     109                string m_name;
    110110
    111111        };  // class Library
     
    114114        {
    115115                /// Library name
    116                 std::string m_name;
     116                string m_name;
    117117        public:
    118118                /**
    119119                 * Constructor
    120120                 */
    121                 library_error( const std::string& message, const std::string& name )
     121                library_error( const string& message, const string& name )
    122122                        : runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name )
    123123                {
     
    134134                 * Returns library name
    135135                 */
    136                 const std::string& get_name()
     136                const string& get_name()
    137137                {
    138138                        return m_name;
  • trunk/nv/logger.hh

    r121 r256  
    1414#define NV_LOGGER_HH
    1515
    16 #include <string>
     16#include <nv/string.hh>
     17#include <nv/logging.hh>
    1718#include <iosfwd>
    1819#include <list>
    19 #include <nv/logging.hh>
    2020
    2121namespace nv
  • trunk/nv/logging.hh

    r121 r256  
    1616#include <nv/common.hh>
    1717#include <nv/singleton.hh>
     18#include <string>
    1819#include <sstream>
    19 #include <string>
    2020
    2121namespace nv
  • trunk/nv/lua/lua_state.hh

    r253 r256  
    142142                                register_native_function( detail::function_wrapper< F, f >, name );
    143143                        }
     144
     145                        template < typename C, typename F, F f >
     146                        struct register_member
     147                        {
     148                                register_member( const char* ) { }
     149                        };
    144150
    145151                        template < typename C, typename F, F f >
     
    211217
    212218                        void store_metadata( object* o, const std::string& metaname, void* pointer );
    213                         void unregister_object( object * o );
     219                        void unregister_object( object * o ); // DELETE ME
     220                        void unregister_object( int index );
    214221                        void register_native_object_method( const char* lua_name, const char* name, lfunction f );
    215222                        template < typename F, F f >
  • trunk/nv/object.hh

    r217 r256  
    1212namespace nv
    1313{
     14
    1415        /**
    1516         * Implements a object tree-like structure.
     
    1819        {
    1920        public:
     21                friend class root;
     22
    2023                /**
    2124                 * Register the object type in the type database.
    2225                 */
    23                 static void register_type( type_database* db );
     26                //static void register_type( type_database* db );
    2427
    2528                /// List type
  • trunk/nv/root.hh

    r215 r256  
    2222                virtual void child_added( object* ) {}
    2323                virtual void child_removed( object* ) {}
     24                virtual void object_created( object* o );
     25                virtual void object_destroyed( object* o );
    2426                lua::state*    get_lua_state()     const { return m_lua_state; }
    2527                uid_store*     get_uid_store()     const { return m_uid_store; }
    26                 virtual ~root() { destroy_children(); }
     28                virtual ~root()
     29                {
     30                        object_destroyed( this );
     31                        destroy_children();
     32                        m_root = nullptr;
     33                }
    2734        protected:
    2835                lua::state*    m_lua_state;
  • trunk/src/gfx/texture_font.cc

    r121 r256  
    9292}
    9393
    94 bool texture_font::load_glyphs( const std::string& codes )
     94bool texture_font::load_glyphs( const string& codes )
    9595{
    9696        FT_Face face     = (FT_Face)(m_rface);
  • trunk/src/library.cc

    r166 r256  
    44#include "nv/common.hh"
    55#include "nv/library.hh"
    6 
    7 #include <string.h>
    86
    97#if NV_PLATFORM == NV_WINDOWS
     
    4139}
    4240
    43 void library::open( const std::string& name )
     41void library::open( const string& name )
    4442{
    4543        m_name = name;
     
    5149}
    5250
    53 bool nv::library::try_open( const std::string& name )
     51bool nv::library::try_open( const string& name )
    5452{
    5553        m_name = name;
     
    6260}
    6361
    64 const std::string& library::get_name() const
     62const string& library::get_name() const
    6563{
    6664    return m_name;
     
    7573    NV_LOG( LOG_NOTICE, "library : loading '" + m_name + "'..." );
    7674
    77     std::string name = m_name;
    78     std::string ext  = NV_LIB_EXT;
     75    string name = m_name;
     76    string ext  = NV_LIB_EXT;
    7977    size_t ext_len   = ext.length();
    8078
     
    9593}
    9694
    97 void* library::get( const std::string& symbol )
     95void* library::get( const string& symbol )
    9896{
    9997        void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
     
    105103}
    106104
    107 void* nv::library::try_get( const std::string& symbol )
     105void* nv::library::try_get( const string& symbol )
    108106{
    109107        return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
     
    133131}
    134132
    135 std::string library::get_error()
     133string library::get_error()
    136134{
    137135#if NV_PLATFORM == NV_WINDOWS
     
    140138    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    141139        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );
    142     std::string msg( (char*)buffer );
     140    string msg( (char*)buffer );
    143141    LocalFree( buffer );
    144142    return msg;
    145143#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
    146     return std::string(dlerror());
     144    return string(dlerror());
    147145#else
    148     return std::string("");
     146    return string("");
    149147#endif
    150148}
  • trunk/src/lua/lua_state.cc

    r228 r256  
    383383{
    384384        if (!o) return;
     385        unregister_object( o->get_lua_index() );
     386}
     387
     388void lua::state::unregister_object( int index )
     389{
    385390        stack_guard guard( this );
    386         lua_rawgeti( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
     391        lua_rawgeti( m_state, LUA_REGISTRYINDEX, index );
    387392        lua_pushstring( m_state, "__ptr" );
    388393        lua_pushboolean( m_state, false );
    389394        lua_rawset( m_state, -3 );
    390395        lua_pop( m_state, 1 );
    391         luaL_unref( m_state, LUA_REGISTRYINDEX, o->get_lua_index() );
    392 }
     396        luaL_unref( m_state, LUA_REGISTRYINDEX, index );
     397}
     398
    393399
    394400void lua::state::deep_pointer_copy( int index, void* obj )
  • trunk/src/object.cc

    r217 r256  
    4141        if ( m_root )
    4242        {
    43                 uid_store*  store = get_root()->get_uid_store();
    44                 if (store)
    45                 {
    46                         m_uid = store->insert( this );
    47                 }
    48         }
    49 
     43                m_root->object_created( this );
     44        }
    5045}
    5146
     
    10499object::~object()
    105100{
    106         if ( m_lua_index != lua::ref_none )
    107         {
    108                 lua::state* state = get_root()->get_lua_state();
    109                 state->unregister_object( this );
    110         }
    111         if ( m_uid != 0 && m_root )
    112         {
    113                 uid_store* store = get_root()->get_uid_store();
    114                 if (store) store->remove( m_uid );
     101        if ( m_root )
     102        {
     103                m_root->object_destroyed( this );
    115104        }
    116105        detach();
     
    194183}
    195184
    196 void object::register_type( type_database* db )
    197 {
    198         type_field fields[] = {
    199                 type_field("id",          &object::m_id),
    200                 type_field("uid",         &object::m_uid).flag( TF_READONLY ),
    201                 type_field("lua_index",   &object::m_lua_index).flag( TF_READONLY | TF_NOSERIALIZE ),
    202                 type_field("parent",      &object::m_parent).flag( TF_READONLY | TF_NOSERIALIZE ),
    203                 type_field("child_count", &object::m_child_count).flag( TF_READONLY ),
    204                 type_field("children"   , &object::m_children).flag( TF_READONLY ),
    205         };
    206         db->create_type<object>("object").fields(fields);
    207 }
     185// void object::register_type( type_database* db )
     186// {
     187//      type_field fields[] = {
     188//              type_field("id",          &object::m_id),
     189//              type_field("uid",         &object::m_uid).flag( TF_READONLY ),
     190//              type_field("lua_index",   &object::m_lua_index).flag( TF_READONLY | TF_NOSERIALIZE ),
     191//              type_field("parent",      &object::m_parent).flag( TF_READONLY | TF_NOSERIALIZE ),
     192//              type_field("child_count", &object::m_child_count).flag( TF_READONLY ),
     193//              type_field("children"   , &object::m_children).flag( TF_READONLY ),
     194//      };
     195//      db->create_type<object>("object").fields(fields);
     196// }
    208197
    209198void nv::object::register_with_lua( const char* lua_name, const char* storage )
  • trunk/src/root.cc

    r64 r256  
     1// Copyright (C) 2012-2014 ChaosForge Ltd
     2// http://chaosforge.org/
     3//
     4// This file is part of NV Libraries.
     5// For conditions of distribution and use, see copyright notice in nv.hh
     6
     7#include "nv/root.hh"
     8
     9#include "nv/uid.hh"
     10#include "nv/lua/lua_state.hh"
     11
     12void nv::root::object_created( object* o )
     13{
     14        if ( m_uid_store )
     15        {
     16                o->m_uid = m_uid_store->insert( o );
     17        }
     18}
     19
     20void nv::root::object_destroyed( object* o )
     21{
     22        if ( m_lua_state && o->m_lua_index != lua::ref_none )
     23        {
     24                m_lua_state->unregister_object( o );
     25        }
     26        if ( m_uid_store && o->m_uid != 0 )
     27        {
     28                m_uid_store->remove( o->m_uid );
     29        }
     30}
Note: See TracChangeset for help on using the changeset viewer.