Changeset 450
- Timestamp:
- 07/30/15 14:43:02 (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/base/common.hh
r406 r450 253 253 254 254 template <typename OBJ, typename T> 255 inline size_t offset_of( T OBJ::*ptr )256 { 257 return static_cast<size_t>( &( ( static_cast<OBJ*>(0) )->*ptr ) );255 inline ptrdiff_t offset_of( T OBJ::*ptr ) 256 { 257 return reinterpret_cast<ptrdiff_t>( &reinterpret_cast<const volatile char&>( ( static_cast<OBJ*>(0) )->*ptr ) ); 258 258 } 259 259 -
trunk/nv/core/types.hh
r447 r450 33 33 // TODO: enforce exact type? 34 34 constexpr thash64() : inherited_type() {} 35 template < typename T >36 constexpr thash64() : inherited_type( rtti_type_hash< T >::hash() ) {}37 35 constexpr explicit thash64( hash_type value ) : inherited_type( value ) {} 38 36 constexpr thash64( const thash64& value ) = default; 37 38 template < typename T > 39 static thash64 create() { return thash64( rtti_type_hash< T >::hash() ); } 39 40 }; 40 41 … … 78 79 uint32 flags; //!< flags 79 80 uint32 offset; //!< offset into parent 81 type_field* control; //!< pointer to field control (in unions) 82 sint32 enumidx; //!< field index (in unions) 80 83 }; 81 84 … … 115 118 type_creator field( const string_view& aname, TFIELD TOBJECT::*field, typename enable_if< !is_container<TFIELD>::value, void* >::type = nullptr ); 116 119 120 template< typename TOBJECT, typename TFIELD, typename ENUM_VALUE > 121 type_creator union_field( const string_view& aname, TFIELD TOBJECT::*field, const string_view& control_name, ENUM_VALUE control_value, typename enable_if< is_container<TFIELD>::value, void* >::type = nullptr ); 122 123 template< typename TOBJECT, typename TFIELD, typename ENUM_VALUE > 124 type_creator union_field( const string_view& aname, TFIELD TOBJECT::*field, const string_view& control_name, ENUM_VALUE control_value, typename enable_if< !is_container<TFIELD>::value, void* >::type = nullptr ); 125 117 126 type_creator value( const string_view& aname, sint32 value ); 118 127 private: … … 129 138 type_creator create_type() 130 139 { 131 return create_type<TYPE>( rtti_type_hash< TYPE > .name() );140 return create_type<TYPE>( rtti_type_hash< TYPE >::name() ); 132 141 } 133 142 … … 143 152 i_type->constructor = raw_construct_object < TYPE >; 144 153 i_type->destructor = raw_destroy_object < TYPE >; 145 m_index_by_type[ thash64 < TYPE >() ] = i_type;154 m_index_by_type[ thash64::create< TYPE >() ] = i_type; 146 155 m_index_by_name[ i_type->name ] = i_type; 147 156 m_type_list.push_back( i_type ); … … 164 173 type_entry* get_type() 165 174 { 166 auto it = m_index_by_type.find( thash64 < T >() );175 auto it = m_index_by_type.find( thash64::create< T >() ); 167 176 return it != m_index_by_type.end() ? it->second : nullptr; 168 177 } … … 197 206 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 198 207 type_field f; 199 f.name = m_database->m_names.insert( name );200 f.type = type_db->get_type< remove_pointer_t<TFIELD> >();208 f.name = m_database->m_names.insert( aname ); 209 f.type = m_database->get_type< remove_pointer_t<TFIELD> >(); 201 210 f.flags = TF_CONTAINER | 202 211 ( is_pointer<field_type>::value ? TF_POINTER : 0 ) | 203 212 ( is_pod<field_type>::value ? TF_SIMPLETYPE : 0 ); 204 213 f.offset = offset_of( field ); 205 m_entry->field_list.push_back( f ); 214 f.control = nullptr; 215 f.enumidx = 0; 216 m_entry->field_list.push_back( f ); 217 m_entry->field_names[f.name] = &m_entry->field_list.back(); 206 218 return *this; 207 219 } … … 212 224 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 213 225 type_field f; 214 f.name = m_database->m_names.insert( name );215 f.type = type_db->get_type< remove_pointer_t<TFIELD> >();226 f.name = m_database->m_names.insert( aname ); 227 f.type = m_database->get_type< remove_pointer_t<TFIELD> >(); 216 228 f.flags = 217 229 ( is_pointer<TFIELD>::value ? TF_POINTER : 0 ) | 218 230 ( is_pod<TFIELD>::value ? TF_SIMPLETYPE : 0 ); 219 231 f.offset = offset_of( field ); 220 m_entry->field_list.push_back( f ); 232 f.control = nullptr; 233 f.enumidx = 0; 234 m_entry->field_list.push_back( f ); 235 m_entry->field_names[f.name] = &m_entry->field_list.back(); 236 return *this; 237 } 238 239 template< typename TOBJECT, typename TFIELD, typename ENUM_VALUE > 240 type_creator type_creator::union_field( const string_view& aname, TFIELD TOBJECT::*field, const string_view& control_name, ENUM_VALUE control_value, typename enable_if< is_container<TFIELD>::value, void* >::type ) 241 { 242 typedef typename TFIELD::value_type field_type; 243 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 244 type_field f; 245 f.name = m_database->m_names.insert( aname ); 246 f.type = m_database->get_type< remove_pointer_t<TFIELD> >(); 247 f.flags = TF_CONTAINER | 248 ( is_pointer<field_type>::value ? TF_POINTER : 0 ) | 249 ( is_pod<field_type>::value ? TF_SIMPLETYPE : 0 ); 250 f.offset = offset_of( field ); 251 f.control = m_entry->field_names[ control_name ]; 252 f.enumidx = static_cast< sint32 >( control_value ); 253 m_entry->field_list.push_back( f ); 254 m_entry->field_names[f.name] = &m_entry->field_list.back(); 255 return *this; 256 } 257 258 template< typename TOBJECT, typename TFIELD, typename ENUM_VALUE > 259 type_creator type_creator::union_field( const string_view& aname, TFIELD TOBJECT::*field, const string_view& control_name, ENUM_VALUE control_value, typename enable_if< !is_container<TFIELD>::value, void* >::type ) 260 { 261 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 262 type_field f; 263 f.name = m_database->m_names.insert( aname ); 264 f.type = m_database->get_type< remove_pointer_t<TFIELD> >(); 265 f.flags = 266 ( is_pointer<TFIELD>::value ? TF_POINTER : 0 ) | 267 ( is_pod<TFIELD>::value ? TF_SIMPLETYPE : 0 ); 268 f.offset = offset_of( field ); 269 f.control = m_entry->field_names[control_name]; 270 f.enumidx = static_cast<sint32>( control_value ); 271 m_entry->field_list.push_back( f ); 272 m_entry->field_names[f.name] = &m_entry->field_list.back(); 221 273 return *this; 222 274 } … … 229 281 e.value = value; 230 282 m_entry->enum_list.push_back( e ); 283 m_entry->enum_names[e.name] = &m_entry->enum_list.back(); 231 284 return *this; 232 285 } -
trunk/src/core/io_event.cc
r447 r450 141 141 .field( "param2", &system_event::param2 ); 142 142 143 // TODO: io_event 143 db->create_type<io_event>() 144 .field( "type", &io_event::type ) 145 .union_field( "key", &io_event::key, "type", EV_KEY ) 146 .union_field( "mbutton", &io_event::mbutton,"type", EV_MOUSE_BUTTON ) 147 .union_field( "mmove", &io_event::mmove, "type", EV_MOUSE_MOVE ) 148 .union_field( "mwheel", &io_event::mwheel, "type", EV_MOUSE_WHEEL ) 149 .union_field( "pbutton", &io_event::pbutton,"type", EV_PAD_BUTTON ) 150 .union_field( "paxis", &io_event::paxis, "type", EV_PAD_AXIS ) 151 .union_field( "jbutton", &io_event::jbutton,"type", EV_JOY_BUTTON ) 152 .union_field( "jaxis", &io_event::jaxis, "type", EV_JOY_AXIS ) 153 .union_field( "jhat", &io_event::jhat, "type", EV_JOY_HAT ) 154 .union_field( "jball", &io_event::jball, "type", EV_JOY_BALL ) 155 .union_field( "resize", &io_event::resize, "type", EV_ACTIVE ) 156 .union_field( "active", &io_event::active, "type", EV_RESIZE ) 157 .union_field( "system", &io_event::system, "type", EV_SYSTEM ); 158 144 159 }
Note: See TracChangeset
for help on using the changeset viewer.