Changeset 373
- Timestamp:
- 05/25/15 07:31:57 (10 years ago)
- Location:
- trunk/nv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/common.hh
r372 r373 230 230 }; 231 231 232 template <typename TYPE> 233 void construct_object( void* object ) 234 { 235 new (object)TYPE; 236 } 237 template <typename TYPE> 238 void destroy_object( void* object ) 239 { 240 ( (TYPE*)object )->TYPE::~TYPE(); 241 } 232 242 233 243 } // namespace nv -
trunk/nv/core/types.hh
r372 r373 10 10 #include <nv/stl/cstring_store.hh> 11 11 #include <nv/stl/type_traits.hh> 12 #include <nv/stl/type_info.hh> 12 13 #include <unordered_map> 13 14 #include <vector> … … 85 86 86 87 template< typename TOBJECT, typename TFIELD > 87 type_creator field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< is_container<TFIELD>::value, void* >::type = nullptr );88 type_creator field( const char* aname, TFIELD TOBJECT::*field, typename enable_if< is_container<TFIELD>::value, void* >::type = nullptr ); 88 89 89 90 template< typename TOBJECT, typename TFIELD > 90 type_creator field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< !is_container<TFIELD>::value, void* >::type = nullptr );91 type_creator field( const char* aname, TFIELD TOBJECT::*field, typename enable_if< !is_container<TFIELD>::value, void* >::type = nullptr ); 91 92 92 93 type_creator value( const char* name, sint32 value ); … … 161 162 162 163 template< typename TOBJECT, typename TFIELD > 163 type_creator type_creator::field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< is_container<TFIELD>::value, void* >::type )164 type_creator type_creator::field( const char* aname, TFIELD TOBJECT::*field, typename enable_if< is_container<TFIELD>::value, void* >::type ) 164 165 { 165 166 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 166 167 type_field f; 167 168 f.name = m_entry->names.insert( name ); 168 f.raw_type = &typeid( typename std::remove_pointer<typename TFIELD::value_type>::type );169 f.raw_type = &typeid( typename remove_pointer<typename TFIELD::value_type>::type ); 169 170 f.type = type_db->get_type( *( f.raw_type ) ); 170 171 f.flags = TF_CONTAINER | 171 ( std::is_pointer<typename TFIELD::value_type>::value ? TF_POINTER : 0 ) |172 ( std::is_pod<typename TFIELD::value_type>::value ? TF_SIMPLETYPE : 0 );172 ( is_pointer<typename TFIELD::value_type>::value ? TF_POINTER : 0 ) | 173 ( is_pod<typename TFIELD::value_type>::value ? TF_SIMPLETYPE : 0 ); 173 174 f.offset = offset_of( field ); 174 175 m_entry->field_list.push_back( f ); … … 177 178 178 179 template< typename TOBJECT, typename TFIELD > 179 type_creator type_creator::field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< !is_container<TFIELD>::value, void* >::type )180 type_creator type_creator::field( const char* aname, TFIELD TOBJECT::*field, typename enable_if< !is_container<TFIELD>::value, void* >::type ) 180 181 { 181 182 NV_ASSERT( m_entry->enum_list.empty(), "Type cannot have both enums and fields!" ); 182 183 type_field f; 183 184 f.name = m_entry->names.insert( name ); 184 f.raw_type = &typeid( typename std::remove_pointer<TFIELD>::type );185 f.raw_type = &typeid( typename remove_pointer<TFIELD>::type ); 185 186 f.type = type_db->get_type( *( f.raw_type ) ); 186 187 f.flags = 187 ( std::is_pointer<TFIELD>::value ? TF_POINTER : 0 ) |188 ( std::is_pod<TFIELD>::value ? TF_SIMPLETYPE : 0 );188 ( is_pointer<TFIELD>::value ? TF_POINTER : 0 ) | 189 ( is_pod<TFIELD>::value ? TF_SIMPLETYPE : 0 ); 189 190 f.offset = offset_of( field ); 190 191 m_entry->field_list.push_back( f ); -
trunk/nv/lua/lua_values.hh
r368 r373 178 178 struct type_degrade 179 179 { 180 typedef typename std::remove_cv< typename std::remove_reference<T>::type >::type type;181 }; 182 183 template <typename T> 184 struct type_degrade< T, typename std::enable_if< std::is_floating_point< T >::value >::type >180 typedef typename remove_cv< typename remove_reference<T>::type >::type type; 181 }; 182 183 template <typename T> 184 struct type_degrade< T, typename enable_if< is_floating_point< T >::value >::type > 185 185 { 186 186 typedef lnumber type; … … 188 188 189 189 template <typename T> 190 struct type_degrade< T, typename std::enable_if< std::is_integral< T >::value && std::is_signed< T >::value >::type >190 struct type_degrade< T, typename enable_if< is_integral< T >::value && is_signed< T >::value >::type > 191 191 { 192 192 typedef linteger type; … … 194 194 195 195 template <typename T> 196 struct type_degrade< T, typename std::enable_if< std::is_integral< T >::value && std::is_unsigned< T >::value >::type >196 struct type_degrade< T, typename enable_if< is_integral< T >::value && is_unsigned< T >::value >::type > 197 197 { 198 198 typedef lunsigned type; … … 200 200 201 201 template <typename T> 202 struct type_degrade< T, typename std::enable_if< is_cstring< T >::value >::type >202 struct type_degrade< T, typename enable_if< is_cstring< T >::value >::type > 203 203 { 204 204 typedef const char* type; … … 206 206 207 207 template <typename T> 208 struct type_degrade< T, typename std::enable_if< is_stdstring< T >::value >::type >208 struct type_degrade< T, typename enable_if< is_stdstring< T >::value >::type > 209 209 { 210 210 typedef std::string type; -
trunk/nv/stl/string.hh
r372 r373 27 27 #include <fstream> 28 28 #include <nv/core/common.hh> 29 #include <nv/stl/type_traits.hh> 29 30 #include <nv/stl/memory.hh> 30 31 #include <nv/stl/exception.hh> … … 285 286 template< typename T > 286 287 struct string_length : public detail::string_length_impl < 287 typename std::remove_cv < typename std::remove_reference< T >::type >::type >288 typename remove_cv < typename remove_reference< T >::type >::type > 288 289 { 289 290 }; … … 291 292 template< typename T > 292 293 using string_length = detail::string_length_impl < 293 typename std::remove_cv < typename std::remove_reference< T >::type >::type >;294 typename remove_cv < typename remove_reference< T >::type >::type >; 294 295 #endif 295 296 … … 298 299 struct is_cstring 299 300 : public integral_constant < bool, 300 is_same< char *, typename std::decay< T >::type >::value ||301 is_same< const char *, typename std::decay< T >::type >::value >301 is_same< char *, typename decay< T >::type >::value || 302 is_same< const char *, typename decay< T >::type >::value > 302 303 { 303 304 }; … … 306 307 struct is_stdstring 307 308 : public integral_constant < bool, 308 is_same< std::string, typename std::decay< T >::type >::value309 is_same< std::string, typename remove_cvr< T >::type >::value 309 310 > 310 311 { … … 505 506 // Non-literal constructors 506 507 template< typename U > 507 inline string_ref( U str, typename std::enable_if<std::is_same<U, const char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {}508 inline string_ref( U str, typename enable_if<is_same<U, const char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {} 508 509 509 510 // Non-literal constructors 510 511 template< typename U > 511 inline string_ref( U str, typename std::enable_if<std::is_same<U, char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {}512 inline string_ref( U str, typename enable_if<is_same<U, char*>::value>::type* = nullptr ) : string_base( str, std::strlen( str ) ) {} 512 513 513 514 inline string_ref& operator=( const string_ref &rhs ) -
trunk/nv/stl/type_traits.hh
r372 r373 1 // Copyright (C) 2012-201 4ChaosForge Ltd1 // Copyright (C) 2012-2015 ChaosForge Ltd 2 2 // http://chaosforge.org/ 3 3 // … … 9 9 * @brief type traits 10 10 */ 11 // TODO: function_traits support only up to 4 parameters because:12 // -- if you have more than 4 params, you're doing something wrong13 // -- once the Variadic Templates cometh, for great justice we will win!14 15 #ifndef NV_ CORE_TYPE_TRAITS_HH16 #define NV_ CORE_TYPE_TRAITS_HH11 // TODO: "......" function match version? 12 // TODO: remove type_traits 13 // TODO: remove typeinfo? 14 15 #ifndef NV_STL_TYPE_TRAITS_HH 16 #define NV_STL_TYPE_TRAITS_HH 17 17 18 18 #include <nv/core/common.hh> 19 #include <type_traits>20 #include <typeinfo>21 19 22 20 namespace nv … … 29 27 typedef T value_type; 30 28 typedef integral_constant<T, VALUE> type; 31 operator value_type() const { return ( value ); }29 NV_CONSTEXPR operator value_type() const { return ( value ); } 32 30 }; 33 31 … … 60 58 61 59 template< typename T > 62 struct is_same < T, T > : true_type{}; 60 struct is_same < T, T > : true_type {}; 61 62 template< typename T > 63 struct is_array : false_type {}; 64 65 template< typename T, size_t N > 66 struct is_array < T[N] > : true_type {}; 67 68 template< typename T > 69 struct is_array < T[] > : true_type {}; 63 70 64 71 template< typename T > … … 76 83 template < typename T > 77 84 struct is_enum : integral_constant < bool, __is_enum( T ) > {}; 85 86 template < typename T > 87 struct is_pod : integral_constant < bool, __is_pod( T ) > {}; 78 88 79 89 template< typename T > … … 150 160 }; 151 161 162 template< typename T > 163 struct remove_cvr 164 { 165 typedef typename remove_cv< typename remove_reference<T>::type >::type 166 type; 167 }; 168 169 template< typename T > 170 struct remove_pointer 171 { 172 typedef T type; 173 }; 174 175 template< typename T > struct remove_pointer < T* > { typedef T type; }; 176 template< typename T > struct remove_pointer < T* const > { typedef T type; }; 177 template< typename T > struct remove_pointer < T* volatile > { typedef T type; }; 178 template< typename T > struct remove_pointer < T* const volatile > { typedef T type; }; 179 180 template< typename T > 181 struct remove_extent 182 { 183 typedef T type; 184 }; 185 186 template< typename T, unsigned int N > 187 struct remove_extent < T[N] > 188 { 189 typedef T type; 190 }; 191 192 template< typename T > 193 struct remove_extent < T[] > 194 { 195 typedef T type; 196 }; 197 198 template< typename T > 199 struct remove_all_extents 200 { 201 typedef T type; 202 }; 203 204 template< typename T, unsigned int N > 205 struct remove_all_extents < T[N] > 206 { 207 typedef typename remove_all_extents<T>::type type; 208 }; 209 210 template< typename T > 211 struct remove_all_extents < T[] > 212 { 213 typedef typename remove_all_extents<T>::type type; 214 }; 215 216 template< typename T > 217 struct add_pointer 218 { 219 typedef typename remove_reference<T>::type *type; 220 }; 221 152 222 namespace detail 153 223 { … … 155 225 // detail - research why it is so. 156 226 template < typename T > 157 struct is_const : publicfalse_type {};158 template < typename T > 159 struct is_const < T const > : publictrue_type {};227 struct is_const : false_type {}; 228 template < typename T > 229 struct is_const < T const > : true_type {}; 160 230 template < typename T > 161 struct is_volatile : publicfalse_type {};162 template < typename T > 163 struct is_volatile < T volatile > : publictrue_type {};231 struct is_volatile : false_type {}; 232 template < typename T > 233 struct is_volatile < T volatile > : true_type {}; 164 234 // TODO END 165 235 … … 186 256 typedef typename cv_selector< TARGET, CONST, VOLATILE >::type type; 187 257 }; 258 259 template < typename T > 260 struct is_void_impl : false_type{}; 261 262 template <> 263 struct is_void_impl< void > : true_type {}; 188 264 189 265 template< typename T > … … 287 363 } 288 364 365 template <typename T> struct is_signed : false_type {}; 366 367 template <> struct is_signed<signed char> : true_type {}; 368 template <> struct is_signed<const signed char> : true_type {}; 369 template <> struct is_signed<signed short> : true_type {}; 370 template <> struct is_signed<const signed short> : true_type {}; 371 template <> struct is_signed<signed int> : true_type {}; 372 template <> struct is_signed<const signed int> : true_type {}; 373 template <> struct is_signed<signed long> : true_type {}; 374 template <> struct is_signed<const signed long> : true_type {}; 375 template <> struct is_signed<sint64> : true_type {}; 376 template <> struct is_signed<const sint64> : true_type{}; 377 378 template <typename T> struct is_unsigned : false_type {}; 379 380 template <> struct is_unsigned<unsigned char> : true_type{}; 381 template <> struct is_unsigned<const unsigned char> : true_type{}; 382 template <> struct is_unsigned<unsigned short> : true_type{}; 383 template <> struct is_unsigned<const unsigned short> : true_type{}; 384 template <> struct is_unsigned<unsigned int> : true_type{}; 385 template <> struct is_unsigned<const unsigned int> : true_type{}; 386 template <> struct is_unsigned<unsigned long> : true_type{}; 387 template <> struct is_unsigned<const unsigned long> : true_type{}; 388 template <> struct is_unsigned<uint64> : true_type{}; 389 template <> struct is_unsigned<const uint64> : true_type{}; 390 391 template <> struct is_signed<char> : integral_constant<bool, ( char( 0 ) > char( -1 ) ) >{}; 392 template <> struct is_unsigned<char> : integral_constant<bool, ( char( 0 ) < char( -1 ) ) > {}; 393 394 289 395 template < typename T > 290 396 struct make_signed … … 303 409 template <> struct make_unsigned < bool > ; 304 410 411 template< typename T > 412 struct is_void : detail::is_void_impl < typename remove_cv<T>::type > 413 { 414 }; 305 415 306 416 template< typename T > … … 311 421 template< typename T > 312 422 struct is_floating_point : detail::is_floating_point_impl< typename remove_cv<T>::type > 423 { 424 }; 425 426 template < typename T > 427 struct is_arithmetic : integral_constant < bool, 428 is_integral<T>::value || is_floating_point<T>::value > 429 { 430 }; 431 432 template <typename T> 433 struct is_fundamental : integral_constant < bool, 434 is_void<T>::value || is_integral<T>::value || is_floating_point<T>::value > 313 435 { 314 436 }; … … 377 499 }; 378 500 501 template< typename T, typename IS_ENUM > 502 struct base_underlying_type_impl 503 { 504 typedef T type; 505 }; 506 507 template< typename T > 508 struct base_underlying_type_impl < T, true_type > 509 { 510 typedef typename underlying_type<T>::type type; 511 }; 512 513 template < typename T > struct is_pointer_impl : false_type {}; 514 515 template < typename T > struct is_pointer_impl< T* > : true_type{}; 516 template < typename T > struct is_pointer_impl< T* const > : true_type{}; 517 template < typename T > struct is_pointer_impl< T* volatile > : true_type{}; 518 template < typename T > struct is_pointer_impl< T* const volatile > : true_type{}; 519 379 520 } 380 521 381 522 template < typename F > 382 struct function_traits : publicdetail::function_traits_impl< F >523 struct function_traits : detail::function_traits_impl< F > 383 524 { 384 525 … … 397 538 }; 398 539 399 template <typename TYPE> 400 void construct_object(void* object) 401 { 402 new (object) TYPE; 403 } 404 template <typename TYPE> 405 void destroy_object(void* object) 406 { 407 ((TYPE*)object)->TYPE::~TYPE(); 408 } 409 410 template< typename T, typename IS_ENUM > 411 struct base_underlying_type_helper 412 { 413 typedef T type; 414 }; 415 416 template< typename T > 417 struct base_underlying_type_helper< T, true_type > 418 { 419 typedef typename underlying_type<T>::type type; 420 }; 421 422 423 template< typename T > 540 template < typename T > 424 541 struct base_underlying_type 425 542 { 426 typedef typename base_underlying_type_helper< T, typename is_enum<T>::type >::type type; 427 }; 428 429 class type_index 430 { 431 public: 432 inline type_index( const std::type_info& info ) : m_type_info( &info ) {} 433 inline size_t hash_code() const { return m_type_info->hash_code(); } 434 inline const char *name() const { return m_type_info->name(); } 435 436 inline bool operator==( const type_index& rhs ) const 437 { 438 return ( *m_type_info == *rhs.m_type_info ); 439 } 440 441 inline bool operator!=( const type_index& rhs ) const 442 { 443 return ( !( *this == rhs ) ); 444 } 445 446 inline bool operator<( const type_index& rhs ) const 447 { 448 return ( m_type_info->before( *rhs.m_type_info ) ); 449 } 450 451 inline bool operator>=( const type_index& rhs ) const 452 { 453 return ( !( *this < rhs ) ); 454 } 455 456 inline bool operator>( const type_index& rhs ) const 457 { 458 return ( rhs < *this ); 459 } 460 461 inline bool operator<=( const type_index& rhs ) const 462 { 463 return ( !( rhs < *this ) ); 464 } 465 466 private: 467 const std::type_info* m_type_info; 543 typedef typename detail::base_underlying_type_impl< T, typename is_enum<T>::type >::type type; 544 }; 545 546 template < typename F > struct is_function_pointer : false_type {}; 547 #if NV_COMPILER == NV_MSVC 548 template < typename R, typename... Args > struct is_function_pointer< R( __cdecl * )( Args... ) > : true_type{}; 549 template < typename R, typename... Args > struct is_function_pointer< R( __stdcall * )( Args... ) > : true_type{}; 550 template < typename R, typename... Args > struct is_function_pointer< R( __fastcall * )( Args... ) > : true_type{}; 551 template < typename R, typename... Args > struct is_function_pointer< R( __vectorcall * )( Args... ) > : true_type{}; 552 #else 553 template < typename R, typename... Args > struct is_function_pointer< R( *)( Args... ) > : true_type{}; 554 #endif 555 556 template < typename C > struct is_member_function_pointer : false_type {}; 557 #if NV_COMPILER == NV_MSVC 558 #define NV_IS_MEMFNPTR( call_conv ) \ 559 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( call_conv C::* )( Args... ) > : true_type{}; \ 560 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( call_conv C::* )( Args... ) const > : true_type{}; \ 561 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( call_conv C::* )( Args... ) volatile > : true_type{}; \ 562 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( call_conv C::* )( Args... ) const volatile > : true_type{}; 563 564 NV_IS_MEMFNPTR( __thiscall ) 565 NV_IS_MEMFNPTR( __cdecl ) 566 NV_IS_MEMFNPTR( __stdcall ) 567 NV_IS_MEMFNPTR( __fastcall ) 568 NV_IS_MEMFNPTR( __vectorcall ) 569 570 #undef NV_IS_MEMFNPTR 571 #else 572 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( C::* )( Args... ) > : true_type{}; 573 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( C::* )( Args... ) const > : true_type{}; 574 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( C::* )( Args... ) volatile > : true_type{}; 575 template < typename R, typename C, typename... Args > struct is_member_function_pointer< R( C::* )( Args... ) const volatile > : true_type{}; 576 #endif 577 578 template < typename F > struct is_member_pointer : integral_constant < bool, is_member_function_pointer<F>::value > {}; 579 template < typename C, typename R > struct is_member_pointer<R C::*> : true_type {}; 580 581 template < typename T > 582 struct is_pointer : integral_constant< bool, (detail::is_pointer_impl<T>::value) && !(is_member_pointer<T>::value) > {}; 583 584 template< typename T > 585 struct is_function : integral_constant< bool, is_function_pointer< typename remove_cv<T>::type *>::value > {}; 586 587 template< typename T > 588 struct is_function < T& > : false_type {}; 589 590 template< typename T > 591 struct is_function < T&& > : false_type {}; 592 593 template< typename T > 594 struct decay 595 { 596 typedef typename remove_reference<T>::type U; 597 typedef typename conditional < 598 is_array<U>::value, 599 typename remove_extent<U>::type*, 600 typename conditional < 601 is_function<U>::value, 602 typename add_pointer<U>::type, 603 typename remove_cv<U>::type 604 > ::type 605 > ::type type; 468 606 }; 469 607 470 608 } 471 609 472 #endif // NV_ CORE_TYPE_TRAITS_HH610 #endif // NV_STL_TYPE_TRAITS_HH -
trunk/nv/stl/utility.hh
r372 r373 15 15 16 16 #include <nv/core/common.hh> 17 #include <nv/stl/type_traits.hh> 17 18 18 19 namespace nv
Note: See TracChangeset
for help on using the changeset viewer.