Changeset 64


Ignore:
Timestamp:
05/30/13 20:13:08 (12 years ago)
Author:
epyon
Message:
  • root class for object trees
  • revised exception throwing - now using NV_THROW macro
  • exceptions thrown are logged
  • formatting fixes
Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/common.hh

    r60 r64  
    1010#include <typeinfo>
    1111#include <cstddef>
     12#include <cassert>
     13#include <nv/logging.hh>
    1214
    1315// NV Library version
     
    112114#endif
    113115
    114 #include <cassert>
     116#define NV_STRINGIZE_DETAIL(x) #x
     117#define NV_STRINGIZE(x) NV_STRINGIZE_DETAIL(x)
     118
    115119#define NV_ASSERT(cond, msg) assert( (cond) && msg )
     120#define NV_THROW(eobj, ...) { \
     121        NV_LOG( LOG_ERROR, __FILE__ " line " NV_STRINGIZE(__LINE__) " - exception thrown - " #eobj ); \
     122  throw eobj( __VA_ARGS__ ); \
     123}
    116124
    117125#if NV_COMPILER == NV_MSVC
     
    122130{
    123131        class object;
     132        class root;
     133        class type_database;
     134        class uid_store;
     135
     136        namespace lua
     137        {
     138                class state;
     139        }
    124140
    125141        // Typedefs for fixed size types.
     
    164180#if NV_DEBUG
    165181        T* p = dynamic_cast<T*>(x);
    166         if (p == 0) throw std::bad_cast();
     182        if (p == 0) THROW( std::bad_cast, () );
    167183        return p;
    168184#else
  • trunk/nv/interface/program.hh

    r62 r64  
    127127                        }
    128128                        NV_LOG( LOG_ERROR, "Attribute '" << name << "' not found in program!" );
    129                         throw runtime_error( "Attribute '"+name+"' not found!" );
     129                        NV_THROW( runtime_error, ( "Attribute '"+name+"' not found!" ) );
    130130                }
    131131
     
    148148                        }
    149149                        NV_LOG( LOG_ERROR, "Uniform '" << name << "' not found in program!" );
    150                         throw runtime_error( "Uniform '"+name+"' not found!" );
     150                        NV_THROW( runtime_error, ( "Uniform '"+name+"' not found!" ) );
    151151                }
    152152
  • trunk/nv/logging.hh

    r4 r64  
    1414#define NV_LOGGING_HH
    1515
    16 #include <nv/common.hh>
    1716#include <nv/singleton.hh>
    1817#include <sstream>
  • trunk/nv/object.hh

    r61 r64  
    1212namespace nv
    1313{
    14         class type_database;
    15 
    1614        /**
    1715         * Implements a object tree-like structure.
     
    3634                 * Object constructor
    3735                 */
    38                 object( string aid, uid auid );
     36                object( root* aroot, const string& aid, uid auid );
    3937
    4038                /**
     
    154152
    155153        protected:
     154                root*   m_root;        ///< pointer to root
    156155                string  m_id;          ///< id type of the object
    157156                string  m_name;        ///< name of the object
  • trunk/nv/string.hh

    r8 r64  
    1616        using std::string;
    1717
    18     /**
    19      * Utility function for converting any value to string.
    20      *
    21      * @param value value to be converted, needs to have << operator
    22      *        to stream
    23      * @throw ore::runtime_error Throws ore::runtime_error on conversion fail
    24      * @return value converted to string
    25      */
    26     template < class T >
    27     string to_string( const T& value )
    28     {
    29       std::stringstream stream;
    30       stream << value;
     18        /**
     19        * Utility function for converting any value to string.
     20        *
     21        * @param value value to be converted, needs to have << operator
     22        *        to stream
     23        * @throw runtime_error Throws runtime_error on conversion fail
     24        * @return value converted to string
     25        */
     26        template < class T >
     27        string to_string( const T& value )
     28        {
     29                std::stringstream stream;
     30                stream << value;
    3131
    32       if ( stream.fail() )
    33       {
    34         throw runtime_error( "bad cast" );
    35       }
     32                if ( stream.fail() )
     33                {
     34                        NV_THROW( runtime_error, "bad cast" );
     35                }
    3636
    37       return stream.str();
    38     }
     37                return stream.str();
     38        }
    3939
    40     /**
    41      * Override function for special treatment of strings. Returns the
    42      * value passed.
    43      */
    44     inline string to_string( const string& value)
    45     {
    46         return value;
    47     }
     40        /**
     41        * Override function for special treatment of strings. Returns the
     42        * value passed.
     43        */
     44        inline string to_string( const string& value)
     45        {
     46                return value;
     47        }
    4848
    49     /**
    50      * Utility function for converting a string to the given type
    51      *
    52      * @param vin the string representing the value
    53      * @param vout the value to be read. Must be streamable with >>
    54      * @throw ore::runtime_error Throws ore::runtime_error on conversion fail
    55      */
    56     template < class T >
    57     void from_string( const string& vin, T& vout )
    58     {
    59       std::istringstream value( vin );
    60       value >> vout;
     49        /**
     50        * Utility function for converting a string to the given type
     51        *
     52        * @param vin the string representing the value
     53        * @param vout the value to be read. Must be streamable with >>
     54        * @throw runtime_error Throws runtime_error on conversion fail
     55        */
     56        template < class T >
     57        void from_string( const string& vin, T& vout )
     58        {
     59                std::istringstream value( vin );
     60                value >> vout;
    6161
    62       if ( value.fail() )
    63       {
    64         throw runtime_error( "bad cast" );
    65       }
    66     }
     62                if ( value.fail() )
     63                {
     64                        NV_THROW( runtime_error, "bad cast" );
     65                }
     66        }
    6767
    68     /**
    69      * Utility function for converting a string to the given type
    70      *
    71      * @param vin the string representing the value
    72      * @throw ore::runtime_error Throws ore::runtime_error on conversion fail
    73      */
     68        /**
     69        * Utility function for converting a string to the given type
     70        *
     71        * @param vin the string representing the value
     72        * @throw runtime_error Throws runtime_error on conversion fail
     73        */
    7474        template < class T >
    7575        T string_cast( const string& vin )
     
    8181                if ( value.fail() )
    8282                {
    83                         throw runtime_error( "bad cast" );
     83                        NV_THROW( runtime_error, "bad cast" );
    8484                }
    8585                return vout;
     
    8787
    8888
    89     /**
    90      * Override function for special treatment of strings. Returns the
    91      * value passed.
    92      */
    93     inline void from_string( const string& vin, string& vout )
     89        /**
     90        * Override function for special treatment of strings. Returns the
     91        * value passed.
     92        */
     93        inline void from_string( const string& vin, string& vout )
    9494        {
    95       vout = vin;
    96     }
     95                vout = vin;
     96        }
    9797
    9898        /**
    99      * Override function for special treatment of strings. Returns the
    100      * value passed.
    101      */
     99        * Override function for special treatment of strings. Returns the
     100        * value passed.
     101        */
    102102        template <>
    103     inline std::string string_cast( const string& vin )
     103        inline std::string string_cast( const string& vin )
    104104        {
    105105                return vin;
    106     }
     106        }
    107107
    108108
    109109        /**
    110          * Simple function for slurping a file into a string.
    111          */
     110        * Simple function for slurping a file into a string.
     111        */
    112112        inline std::string slurp( const std::string& filename )
    113113        {
    114114                std::ifstream input(filename);
    115                 if ( !input.is_open() ) throw std::runtime_error("File "+filename+" not found!");
     115                if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!");
    116116                std::stringstream sstr;
    117117                while(input >> sstr.rdbuf());
  • trunk/src/gl/gl_context.cc

    r45 r64  
    4949        if ( viewport.z < 0 || viewport.w < 0 )
    5050        {
    51                 throw new logic_error("viewport width and height must be greater than zero!");
     51                NV_THROW( logic_error, "viewport width and height must be greater than zero!");
    5252        }
    5353
     
    126126        if ( scissor.dim.x < 0 || scissor.dim.y < 0 )
    127127        {
    128                 throw new logic_error("scissor_test.rect width and height must be greater than zero!");
     128                NV_THROW( logic_error, "scissor_test.rect width and height must be greater than zero!" );
    129129        }
    130130
     
    174174        if ( range.near < 0.0 || range.near > 1.0 )
    175175        {
    176                 throw new logic_error("render_state.depth_range.near must be between zero and one!");
     176                NV_THROW( logic_error, "render_state.depth_range.near must be between zero and one!");
    177177        }
    178178        if ( range.far < 0.0 || range.far > 1.0 )
    179179        {
    180                 throw new logic_error("render_state.depth_range.far must be between zero and one!");
     180                NV_THROW( logic_error, "render_state.depth_range.far must be between zero and one!");
    181181        }
    182182
  • trunk/src/gl/texture_font.cc

    r45 r64  
    4444         
    4545        error = FT_Init_FreeType( (FT_Library*)(&m_rlibrary) );
    46         if ( error ) throw std::runtime_error( "FT_Error" );
     46        if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
    4747
    4848        error = FT_New_Face( (FT_Library)(m_rlibrary), filename, 0, (FT_Face*)(&m_rface) );
    49         if ( error ) throw std::runtime_error( "FT_Error" );
     49        if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
    5050
    5151        error = FT_Set_Char_Size( (FT_Face)(m_rface), (int)(size*64), 0, 72*64, 72 );
    52         if ( error ) throw std::runtime_error( "FT_Error" );
     52        if ( error ) NV_THROW( std::runtime_error, "FT_Error" );
    5353
    5454    FT_Set_Transform( (FT_Face)(m_rface), &matrix, NULL );
     
    106106                        error_msg << "FT_Error while loading glyphs, error: "
    107107                                << error << " code: " << c;
    108                         throw std::runtime_error( error_msg.str().c_str() );
     108                        NV_THROW( std::runtime_error, error_msg.str().c_str() );
    109109                }
    110110
     
    124124                                << "r.pos.x: " << r.pos.x << " code: "
    125125                                << c;
    126                         throw std::runtime_error( error_msg.str().c_str() );
     126                        NV_THROW( std::runtime_error, error_msg.str().c_str() );
    127127                }
    128128                r.size.x -= 1;
  • trunk/src/library.cc

    r14 r64  
    7575    if ( m_handle == NULL )
    7676    {
    77         throw library_error( "Can't load library!", name );
     77        NV_THROW( library_error, "Can't load library!", name );
    7878    }
    7979    NV_LOG( LOG_NOTICE, "library : '" + name + "' loaded." );
     
    8585    if ( !result )
    8686    {
    87         throw library_error( "Can't find symbol " + symbol + "!", m_name );
     87        NV_THROW( library_error, "Can't find symbol " + symbol + "!", m_name );
    8888    }
    8989        return result;
  • trunk/src/logger.cc

    r48 r64  
    55#include "nv/logger.hh"
    66
     7#include "nv/common.hh"
    78#include <iostream>
    89#include <utility>
     
    208209        {
    209210                // throw if not open
    210                 throw runtime_error( "Could not open file \""+file_name+"\" for logging!" );
     211                NV_THROW( runtime_error, "Could not open file \""+file_name+"\" for logging!" );
    211212        }
    212213
  • trunk/src/object.cc

    r57 r64  
    77#include "nv/object.hh"
    88
     9#include "nv/root.hh"
    910#include "nv/types.hh"
    1011
     
    1213
    1314object::object()
    14         : m_id(), m_name(), m_uid(0), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
     15        : m_root( nullptr ), m_id(), m_name(), m_uid(0), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
    1516{
    1617//      m_uid = uid_store::get_free_uid();
     
    1819}
    1920
    20 object::object( string aid, uid auid )
    21         : m_id(aid), m_name(), m_uid( auid ), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
     21object::object( root* aroot, const string& aid, uid auid )
     22        : m_root( aroot ), m_id(aid), m_name(), m_uid( auid ), m_lua_index(-2), m_parent( nullptr ), m_children(), m_child_count(0)
    2223{
    2324        //      uid_store::register_object( this, auid );
Note: See TracChangeset for help on using the changeset viewer.