- Timestamp:
- 05/26/15 17:35:06 (10 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/common.hh
r373 r374 137 137 #define NV_RESTRICT_VAR __restrict 138 138 #define NV_NOEXCEPT throw() 139 #define NV_ALIGN_OF(type) __alignof(type) 139 140 //#define NV_CONSTEXPR 140 141 #elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG … … 145 146 #define NV_RESTRICT_VAR __restrict__ 146 147 #define NV_NOEXCEPT noexcept 148 #define NV_ALIGN_OF(type) alignof(type) 147 149 //#define NV_CONSTEXPR constexpr 148 150 #else … … 153 155 #define NV_RESTRICT_VAR 154 156 #define NV_NOEXCEPT 157 #define NV_ALIGN_OF 155 158 //#define NV_CONSTEXPR 156 159 #endif … … 171 174 #endif 172 175 173 #define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / (( size_t)(!(sizeof(x) % sizeof(0[x])))))176 #define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((nv::size_t)(!(sizeof(x) % sizeof(0[x]))))) 174 177 #define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) ) 175 178 … … 180 183 class state; 181 184 } 185 186 using ::size_t; // typedef decltype( sizeof( int ) ) size_t; 187 using ::ptrdiff_t; 182 188 183 189 // Typedefs for fixed size types. … … 230 236 }; 231 237 232 template <typename TYPE> 233 void construct_object( void* object ) 234 { 235 new (object)TYPE; 238 template< typename T, T VALUE> 239 struct integral_constant 240 { 241 static const T value = VALUE; 242 typedef T value_type; 243 typedef integral_constant<T, VALUE> type; 244 NV_CONSTEXPR operator value_type() const { return ( value ); } 245 }; 246 247 typedef integral_constant<bool, true> true_type; 248 typedef integral_constant<bool, false> false_type; 249 250 template< bool TEST, typename T = void> 251 struct enable_if {}; 252 253 template< typename T > 254 struct enable_if < true, T > 255 { 256 typedef T type; 257 }; 258 259 template< bool TEST, typename T1, typename T2 > 260 struct conditional 261 { 262 typedef T2 type; 263 }; 264 265 template< typename T1, typename T2> 266 struct conditional < true, T1, T2 > 267 { 268 typedef T1 type; 269 }; 270 271 template <typename OBJ, typename T> 272 inline size_t offset_of( T OBJ::*ptr ) 273 { 274 return ( ( size_t )&( ( (OBJ*)0 )->*ptr ) ); 236 275 } 237 template <typename TYPE> 238 void destroy_object( void* object ) 239 { 240 ( (TYPE*)object )->TYPE::~TYPE(); 276 277 template <typename T, typename U> 278 inline T* down_cast( U* x ) 279 { 280 #if NV_DEBUG 281 T* p = dynamic_cast<T*>( x ); 282 if ( p == 0 ) 283 { 284 #ifdef NV_LOG 285 NV_THROW( std::bad_cast ); 286 #endif 287 } 288 return p; 289 #else 290 return static_cast<T*>( x ); 291 #endif 241 292 } 242 293 294 template <typename T, typename U> 295 T narrow_cast( const U& a ) 296 { 297 return static_cast<T>( a & T( -1 ) ); 298 } 299 243 300 } // namespace nv 244 245 template <typename OBJ, typename T>246 inline size_t offset_of(T OBJ::*ptr)247 {248 return ((size_t)&(((OBJ*)0)->*ptr));249 }250 251 template <typename T, typename U>252 inline T* down_cast(U* x)253 {254 #if NV_DEBUG255 T* p = dynamic_cast<T*>(x);256 if (p == 0)257 {258 #ifdef NV_LOG259 NV_THROW( std::bad_cast );260 #endif261 }262 263 return p;264 #else265 return static_cast<T*>(x);266 #endif267 }268 269 template <typename T, typename U>270 T narrow_cast(const U& a)271 {272 return static_cast<T>(a & T(-1) );273 }274 301 275 302 static_assert( sizeof( nv::sint8 ) == 1, "sint8 size isn't 1 bytes" ); -
trunk/nv/core/position.hh
r372 r374 17 17 #include <nv/stl/math.hh> 18 18 #include <nv/stl/range.hh> 19 #include <nv/stl/utility.hh> 19 20 20 21 namespace nv … … 26 27 { 27 28 typedef position::value_type value_type; 28 typedef s td::size_t size_type;29 typedef size_t size_type; 29 30 typedef rectangle type; 30 31 … … 278 279 { 279 280 if (r.contains(*this)) return false; 280 ul = nv::max( ul, r.ul );281 lr = nv::min( lr, r.lr );282 ul = nv::min( ul, lr );281 ul = glm::max( ul, r.ul ); 282 lr = glm::min( lr, r.lr ); 283 ul = glm::min( ul, lr ); 283 284 return true; 284 285 } … … 293 294 { 294 295 if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false; 295 ( *this) += nv::min( r.ul - ul, position() );296 ( *this) -= nv::min( lr - r.lr, position() );296 ( *this ) += glm::min( r.ul - ul, position() ); 297 ( *this ) -= glm::min( lr - r.lr, position() ); 297 298 return true; 298 299 } … … 303 304 void repair() 304 305 { 305 if (ul.x > lr.x) s td::swap( ul.x, lr.x );306 if (ul.y > lr.y) s td::swap( ul.y, lr.y );306 if (ul.x > lr.x) swap( ul.x, lr.x ); 307 if (ul.y > lr.y) swap( ul.y, lr.y ); 307 308 } 308 309 … … 314 315 void include_point( position p ) 315 316 { 316 lr = nv::max( lr, p );317 ul = nv::min( ul, p );317 lr = glm::max( lr, p ); 318 ul = glm::min( ul, p ); 318 319 } 319 320 -
trunk/nv/core/types.hh
r373 r374 110 110 i_type->size = sizeof( TYPE ); 111 111 112 i_type->constructor = construct_object < TYPE > ;113 i_type->destructor = destroy_object < TYPE > ;112 i_type->constructor = construct_object_raw < TYPE > ; 113 i_type->destructor = destroy_object_raw < TYPE > ; 114 114 m_idx_types[typeid( TYPE )] = i_type; 115 115 m_type_list.push_back( i_type ); -
trunk/nv/formats/md5_loader.hh
r368 r374 60 60 virtual mesh_data_pack* release_mesh_data_pack(); 61 61 virtual size_t get_mesh_count() const { return m_meshes.size(); } 62 protected:63 struct md5_joint_info64 {65 int flags;66 size_t start_index;67 };68 62 69 63 struct md5_weight … … 72 66 float bias; 73 67 glm::vec3 pos; 68 }; 69 70 protected: 71 struct md5_joint_info 72 { 73 int flags; 74 size_t start_index; 74 75 }; 75 76 -
trunk/nv/interface/image_data.hh
r368 r374 56 56 void initialize( const uint8* data ) 57 57 { 58 s td::size_t bsize = static_cast<std::size_t>(m_size.x * m_size.y) * get_depth();58 size_t bsize = static_cast<size_t>(m_size.x * m_size.y) * get_depth(); 59 59 m_data = new uint8[ bsize ]; 60 60 std::copy( data, data + bsize, m_data ); -
trunk/nv/interface/interpolation_template.hh
r368 r374 19 19 20 20 template < typename KEY, animation_slot SLOT > 21 void interpolate_slot( KEY& key, const KEY& k1, const KEY& k2, float factor, const std::true_type& )21 void interpolate_slot( KEY& key, const KEY& k1, const KEY& k2, float factor, const true_type& ) 22 22 { 23 23 key_slot_info< KEY, SLOT >::interpolate( key, k1, k2, factor ); … … 25 25 26 26 template < typename KEY, animation_slot SLOT > 27 void interpolate_slot( KEY&, const KEY&, const KEY&, float, const std::false_type& )27 void interpolate_slot( KEY&, const KEY&, const KEY&, float, const false_type& ) 28 28 { 29 29 } … … 32 32 void interpolate_key( KEY& key, const KEY& k1, const KEY& k2, float factor ) 33 33 { 34 interpolate_slot< KEY, animation_slot::POSITION >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >() );35 interpolate_slot< KEY, animation_slot::ROTATION >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() );36 interpolate_slot< KEY, animation_slot::SCALE >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >() );37 interpolate_slot< KEY, animation_slot::TFORM >( key, k1, k2, factor, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );34 interpolate_slot< KEY, animation_slot::POSITION >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >() ); 35 interpolate_slot< KEY, animation_slot::ROTATION >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() ); 36 interpolate_slot< KEY, animation_slot::SCALE >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >() ); 37 interpolate_slot< KEY, animation_slot::TFORM >( key, k1, k2, factor, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() ); 38 38 } 39 39 … … 85 85 86 86 template < typename KEY > 87 mat4 extract_matrix_prs( const KEY&, const std::false_type&, const std::false_type&, const std::false_type& )87 mat4 extract_matrix_prs( const KEY&, const false_type&, const false_type&, const false_type& ) 88 88 { return mat4(); } 89 89 template < typename KEY > 90 mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::false_type&, const std::false_type& )90 mat4 extract_matrix_prs( const KEY& k, const true_type&, const false_type&, const false_type& ) 91 91 { return extract_matrix_p_impl(k); } 92 92 template < typename KEY > 93 mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::true_type&, const std::false_type& )93 mat4 extract_matrix_prs( const KEY& k, const false_type&, const true_type&, const false_type& ) 94 94 { return extract_matrix_r_impl(k); } 95 95 template < typename KEY > 96 mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::false_type&, const std::true_type& )96 mat4 extract_matrix_prs( const KEY& k, const false_type&, const false_type&, const true_type& ) 97 97 { return extract_matrix_s_impl(k); } 98 98 template < typename KEY > 99 mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::true_type&, const std::false_type& )99 mat4 extract_matrix_prs( const KEY& k, const true_type&, const true_type&, const false_type& ) 100 100 { return extract_matrix_pr_impl(k); } 101 101 template < typename KEY > 102 mat4 extract_matrix_prs( const KEY& k, const std::false_type&, const std::true_type&, const std::true_type& )102 mat4 extract_matrix_prs( const KEY& k, const false_type&, const true_type&, const true_type& ) 103 103 { return extract_matrix_rs_impl(k); } 104 104 template < typename KEY > 105 mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::false_type&, const std::true_type& )105 mat4 extract_matrix_prs( const KEY& k, const true_type&, const false_type&, const true_type& ) 106 106 { return extract_matrix_ps_impl(k); } 107 107 template < typename KEY > 108 mat4 extract_matrix_prs( const KEY& k, const std::true_type&, const std::true_type&, const std::true_type& )108 mat4 extract_matrix_prs( const KEY& k, const true_type&, const true_type&, const true_type& ) 109 109 { return extract_matrix_prs_impl(k); } 110 110 111 111 112 112 template < typename KEY > 113 transform extract_transform_pr_impl( const KEY&, const std::false_type&, const std::false_type& ) { return transform(); }113 transform extract_transform_pr_impl( const KEY&, const false_type&, const false_type& ) { return transform(); } 114 114 template < typename KEY > 115 transform extract_transform_pr_impl( const KEY& k, const std::true_type&, const std::true_type& ) { return transform( k.position, k.rotation ); }115 transform extract_transform_pr_impl( const KEY& k, const true_type&, const true_type& ) { return transform( k.position, k.rotation ); } 116 116 template < typename KEY > 117 transform extract_transform_pr_impl( const KEY& k, const std::true_type&, const std::false_type& ) { return transform( k.position ); }117 transform extract_transform_pr_impl( const KEY& k, const true_type&, const false_type& ) { return transform( k.position ); } 118 118 template < typename KEY > 119 transform extract_transform_pr_impl( const KEY& k, const std::false_type&, const std::true_type& ) { return transform( k.rotation ); }119 transform extract_transform_pr_impl( const KEY& k, const false_type&, const true_type& ) { return transform( k.rotation ); } 120 120 121 121 122 122 123 123 template < typename KEY > 124 mat4 extract_matrix_impl( const KEY& k, const std::true_type& )124 mat4 extract_matrix_impl( const KEY& k, const true_type& ) 125 125 { 126 126 static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!"); … … 131 131 132 132 template < typename KEY > 133 mat4 extract_matrix_impl( const KEY& k, const std::false_type& )133 mat4 extract_matrix_impl( const KEY& k, const false_type& ) 134 134 { 135 135 static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!"); 136 136 return extract_matrix_prs( k, 137 std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),138 std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >(),139 std::integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >()137 integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(), 138 integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >(), 139 integral_constant< bool, key_has_slot< KEY, animation_slot::SCALE >::value >() 140 140 ); 141 141 } 142 142 143 143 template < typename KEY > 144 transform extract_transform_impl( const KEY& k, const std::true_type& )144 transform extract_transform_impl( const KEY& k, const true_type& ) 145 145 { 146 146 static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!"); … … 151 151 152 152 template < typename KEY > 153 transform extract_transform_impl( const KEY& k, const std::false_type& )153 transform extract_transform_impl( const KEY& k, const false_type& ) 154 154 { 155 155 static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!"); 156 156 static_assert( key_has_slot< KEY, animation_slot::SCALE >::value == false, "key!"); 157 157 return extract_transform_pr_impl( k, 158 std::integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(),159 std::integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >()158 integral_constant< bool, key_has_slot< KEY, animation_slot::POSITION >::value >(), 159 integral_constant< bool, key_has_slot< KEY, animation_slot::ROTATION >::value >() 160 160 ); 161 161 } … … 165 165 mat4 extract_matrix( const KEY& k ) 166 166 { 167 return detail::extract_matrix_impl( k, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );167 return detail::extract_matrix_impl( k, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() ); 168 168 } 169 169 … … 171 171 transform extract_transform( const KEY& k ) 172 172 { 173 return detail::extract_transform_impl( k, std::integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() );173 return detail::extract_transform_impl( k, integral_constant< bool, key_has_slot< KEY, animation_slot::TFORM >::value >() ); 174 174 } 175 175 -
trunk/nv/lib/curses.hh
r319 r374 29 29 #endif 30 30 31 #include <stdarg.h> 32 #include <stddef.h> 31 #ifdef CURSES_PDC_WIDE 33 32 #include <wchar.h> 33 #endif 34 34 35 35 #include <nv/lib/detail/curses_types.inc> … … 41 41 #endif 42 42 43 #define FILE void 43 44 #include <nv/lib/detail/curses_functions.inc> 44 45 #undef FILE 45 46 #undef NV_CURSES_FUN 46 47 } -
trunk/nv/lua/lua_glm.hh
r368 r374 7 7 #define NV_LUA_GLM_HH 8 8 9 #include <new>10 9 #include <nv/core/common.hh> 11 10 #include <nv/stl/math.hh> -
trunk/nv/stl/allocator.hh
r368 r374 20 20 21 21 #include <nv/core/common.hh> 22 #include <nv/ core/type_traits.hh>22 #include <nv/stl/type_traits.hh> 23 23 24 24 namespace nv … … 41 41 T *create( Args&&... args ) 42 42 { 43 return new ( allocate( sizeof( T ), alignof( T ) ) ) T( std::forward<Args>( args )... );43 return new ( allocate( sizeof( T ), alignof( T ) ) ) T( forward<Args>( args )... ); 44 44 } 45 45 -
trunk/nv/stl/any.hh
r368 r374 17 17 18 18 #include <nv/core/common.hh> 19 #include <nv/core/type_traits.hh> 19 #include <nv/stl/type_traits.hh> 20 #include <nv/stl/type_info.hh> 21 #include <nv/stl/utility.hh> 20 22 21 23 namespace nv … … 42 44 template< typename T > 43 45 any( T&& value ) 44 : m_content( new holder<T>( std::forward<T>(value) ) )46 : m_content( new holder<T>( forward<T>(value) ) ) 45 47 {} 46 48 … … 52 54 any& swap( any& rhs ) 53 55 { 54 std::swap( m_content, rhs.m_content );56 nv::swap( m_content, rhs.m_content ); 55 57 return *this; 56 58 } … … 71 73 any& operator= ( T&& rhs ) 72 74 { 73 any( std::forward<T>(rhs) ).swap(*this);75 any( forward<T>(rhs) ).swap(*this); 74 76 return *this; 75 77 } … … 123 125 { 124 126 } 125 holder( T&& value ) : held( std::forward<T>(value))127 holder( T&& value ) : held(forward<T>(value)) 126 128 { 127 129 } -
trunk/nv/stl/array.hh
r368 r374 16 16 #include <nv/core/common.hh> 17 17 #include <nv/stl/memory.hh> 18 #include <nv/stl/iterator.hh> 19 #include <nv/stl/utility.hh> 18 20 #include <vector> 19 21 #include <algorithm> … … 23 25 { 24 26 using std::vector; 25 using std::array; 26 27 template< class T, std::size_t N > 28 class static_array : public detail::data_base< T, false, N > 27 28 template< typename T, size_t N > 29 class array : public detail::pointer_iterators < array< T, N >, T, false > 29 30 { 30 31 public: 31 typedef T value_type; 32 typedef T* iterator; 33 typedef const T* const_iterator; 34 typedef T& reference; 35 typedef const T& const_reference; 36 typedef std::size_t size_type; 37 typedef std::ptrdiff_t difference_type; 38 39 typedef std::reverse_iterator<iterator> reverse_iterator; 40 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 41 42 // iterator begin() { return m_data; } 43 // const_iterator begin() const { return m_data; } 44 // const_iterator cbegin() const { return m_data; } 45 // 46 // iterator end() { return m_data+N; } 47 // const_iterator end() const { return m_data+N; } 48 // const_iterator cend() const { return m_data+N; } 49 // 50 // reverse_iterator rbegin() { return reverse_iterator( end() ); } 51 // const_reverse_iterator rbegin() const { return const_reverse_iterator( end() ); } 52 // const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); } 53 // 54 // reverse_iterator rend() { return reverse_iterator( begin() ); } 55 // const_reverse_iterator rend() const { return const_reverse_iterator( begin() ); } 56 // const_reverse_iterator crend() const { return const_reverse_iterator( begin() ); } 32 typedef T value_type; 33 typedef size_t size_type; 34 typedef ptrdiff_t difference_type; 35 typedef T* pointer; 36 typedef const T* const_pointer; 37 typedef T* iterator; 38 typedef const T* const_iterator; 39 typedef T& reference; 40 typedef const T& const_reference; 41 typedef nv::reverse_iterator<iterator> reverse_iterator; 42 typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 43 44 static const size_type SIZE = N; 45 static const size_type ELEMENT_SIZE = sizeof( value_type ); 46 47 inline const_pointer data() const { return m_data; } 48 inline pointer data() { return m_data; } 49 inline size_type size() const { return SIZE; } 50 inline bool empty() const { return false; } 51 inline size_type raw_size() const { return SIZE * sizeof( T ); } 52 inline const char* raw_data() const { return (const char*)m_data; } 53 inline char* raw_data() { return (char*)m_data; } 54 55 inline reference front() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; } 56 inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; } 57 inline reference back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[SIZE - 1]; } 58 inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[SIZE - 1]; } 57 59 58 60 reference operator[]( size_type i ) … … 68 70 } 69 71 70 // reference front() { return m_data[0]; } 71 // const_reference front() const { return m_data[0]; } 72 // reference back() { return m_data[N-1]; } 73 // const_reference back() const { return m_data[N-1]; } 74 // 75 // static size_type size() { return N; } 76 // static bool empty() { return false; } 77 // static size_type max_size() { return N; } 78 // 79 // const value_type* data() const { return m_data; } 80 // value_type* data() { return m_data; } 81 // 82 // size_type raw_size() const { return N * ELEMENT_SIZE; } 83 // const char* raw_data() const { return (const char*)m_data; } 84 // char* raw_data() { return (char*)m_data; } 85 86 void assign( const value_type& value ) { std::fill_n( this->begin(), this->size(), value ); } 87 88 static const size_type SIZE = N; 89 static const size_type ELEMENT_SIZE = sizeof(T); 72 reference at( size_type i ) 73 { 74 NV_ASSERT( i < N, "Out of range" ); 75 return this->m_data[i]; 76 } 77 78 const_reference at( size_type i ) const 79 { 80 NV_ASSERT( i < N, "Out of range" ); 81 return this->m_data[i]; 82 } 83 84 void swap( array<value_type, N>& y ) 85 { 86 for ( size_type i = 0; i < N; ++i ) 87 nv::swap( m_data[i], y.m_data[i] ); 88 } 89 90 void assign( const value_type& value ) { fill( value ); } 91 92 void fill( const value_type& value ) 93 { 94 std::fill_n( this->begin(), this->size(), value ); 95 } 96 97 private: 98 value_type m_data[SIZE]; 99 }; 100 101 template< typename T, size_t N > 102 inline void swap( array<T, N>& lhs, array<T, N>& rhs ) 103 { 104 lhs.swap( rhs ); 105 } 106 107 // template < typename T, typename ContainerAllocator > 108 // class vector_base 109 // { 110 // public: 111 // typedef T value_type; 112 // typedef size_t size_type; 113 // typedef ptrdiff_t difference_type; 114 // typedef T* pointer; 115 // typedef const T* const_pointer; 116 // typedef T* iterator; 117 // typedef const T* const_iterator; 118 // typedef T& reference; 119 // typedef const T& const_reference; 120 // 121 // protected: 122 // ContainerAllocator m_storage; 123 // }; 124 125 // template< typename T, size_t N > 126 // class static_vector : public detail::pointer_iterators < static_vector< T, N >, T, false > 127 // { 128 // public: 129 // typedef T value_type; 130 // typedef size_t size_type; 131 // typedef ptrdiff_t difference_type; 132 // typedef T* pointer; 133 // typedef const T* const_pointer; 134 // typedef T* iterator; 135 // typedef const T* const_iterator; 136 // typedef T& reference; 137 // typedef const T& const_reference; 138 // typedef nv::reverse_iterator<iterator> reverse_iterator; 139 // typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 140 // 141 // static_vector() : m_size(0) {} 142 // 143 // inline const_pointer data() const { return m_data; } 144 // inline pointer data() { return m_data; } 145 // inline size_type size() const { return m_size; } 146 // inline bool empty() const { return !m_size; } 147 // inline size_type raw_size() const { return N * sizeof( T ); } 148 // inline const char* raw_data() const { return (const char*)m_data; } 149 // inline char* raw_data() { return (char*)m_data; } 150 // 151 // inline reference front() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; } 152 // inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; } 153 // inline reference back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; } 154 // inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; } 155 // protected: 156 // value_type m_data[N]; 157 // size_type m_size; 158 // }; 159 160 template < typename T, typename ContainerAllocator > 161 class array_base : public detail:: pointer_iterators < array_base< T, ContainerAllocator >, T, false > 162 { 163 public: 164 typedef T value_type; 165 typedef size_t size_type; 166 typedef ptrdiff_t difference_type; 167 typedef T* pointer; 168 typedef const T* const_pointer; 169 typedef T* iterator; 170 typedef const T* const_iterator; 171 typedef T& reference; 172 typedef const T& const_reference; 173 typedef nv::reverse_iterator<iterator> reverse_iterator; 174 typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 175 176 inline array_base() : m_storage() {} 177 inline array_base( pointer a_data, size_t a_size ) 178 { 179 180 } 181 inline const_pointer data() const { return m_storage.data(); } 182 inline pointer data() { return m_storage.data(); } 183 inline size_t size() const { return m_storage.size(); } 184 inline bool empty() const { return m_storage.size() != 0; } 185 inline size_type raw_size() const { return sizeof( T ) * m_storage.size(); } 186 inline const char* raw_data() const { return (const char*)m_storage.data(); } 187 inline char* raw_data() { return (char*)m_storage.data(); } 188 189 inline reference front() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[0]; } 190 inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[0]; } 191 inline reference back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[size() - 1]; } 192 inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_storage.data()[size() - 1]; } 193 protected: 194 void push_values( size_type n, const value_type& value ) 195 { 196 197 } 198 ContainerAllocator m_storage; 90 199 }; 91 200 … … 94 203 { 95 204 public: 96 typedef T 97 typedef T* 98 typedef const T* 99 typedef T& 100 typedef const T& 101 typedef s td::size_t size_type;102 typedef std::ptrdiff_t difference_type;103 104 typedef std::reverse_iterator<iterator> reverse_iterator;105 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;205 typedef T value_type; 206 typedef T* iterator; 207 typedef const T* const_iterator; 208 typedef T& reference; 209 typedef const T& const_reference; 210 typedef size_t size_type; 211 typedef ptrdiff_t difference_type; 212 213 typedef nv::reverse_iterator<iterator> reverse_iterator; 214 typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 106 215 107 216 dynamic_array() : detail::data_base< T, false, 0 >() {} … … 166 275 // size_type size() const { return m_size; } 167 276 // bool empty() const { return m_size == 0; } 168 // static size_type max_size() { return std::numeric_limits< size_type >::max(); }277 // static size_type max_size() { return numeric_limits< size_type >::max(); } 169 278 // const value_type* data() const { return m_data; } 170 279 // value_type* data() { return m_data; } … … 191 300 }; 192 301 302 303 193 304 } 194 305 -
trunk/nv/stl/flags.hh
r368 r374 63 63 friend class flags<SIZE,T>; 64 64 public: 65 typedef T 66 typedef T 67 typedef T* 68 typedef const T* 69 typedef T& 70 typedef const T& 71 typedef s td::size_t size_type;72 typedef std::ptrdiff_t difference_type;65 typedef T index_type; 66 typedef T value_type; 67 typedef T* iterator; 68 typedef const T* const_iterator; 69 typedef T& reference; 70 typedef const T& const_reference; 71 typedef size_t size_type; 72 typedef ptrdiff_t difference_type; 73 73 74 74 T operator* () const { return m_index; } -
trunk/nv/stl/math.hh
r368 r374 84 84 static const size_t size = 4; 85 85 }; 86 87 using glm::max;88 using glm::min;89 86 90 87 enum datatype -
trunk/nv/stl/memory.hh
r372 r374 18 18 #include <nv/core/common.hh> 19 19 #include <nv/stl/type_traits.hh> 20 #include <iterator> 20 #include <nv/stl/utility.hh> 21 #include <nv/stl/iterator.hh> 22 23 #include <type_traits> 21 24 22 25 namespace nv … … 25 28 namespace detail 26 29 { 30 template < typename ForwardIterator, typename T > 31 void uninitialized_fill_impl( ForwardIterator first, ForwardIterator last, const T& value, true_type ) 32 { 33 fill( first, last, value ); 34 } 35 36 template < typename ForwardIterator, typename T > 37 void uninitialized_fill_impl( ForwardIterator first, ForwardIterator last, const T& value, false_type ) 38 { 39 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 40 ForwardIterator it( first ); 41 for ( ; it != last; ++it ) 42 ::new( (void*)&*it ) value_type( value ); 43 } 44 45 template < typename ForwardIterator, typename T > 46 ForwardIterator uninitialized_fill_n_impl( ForwardIterator first, size_t count, const T& value, true_type ) 47 { 48 return fill_n( first, count, value ); 49 } 50 51 template < typename ForwardIterator, typename T > 52 ForwardIterator uninitialized_fill_n_impl( ForwardIterator first, size_t count, const T& value, false_type ) 53 { 54 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 55 ForwardIterator it( first ); 56 for ( ; count > 0; --count, ++it ) 57 ::new ( (void*)&*it ) value_type( value ); 58 return it; 59 } 60 61 template < typename ForwardIterator > 62 inline void uninitialized_construct_impl( ForwardIterator first, ForwardIterator last, true_type ) 63 { 64 fill_default( first, last ); 65 } 66 67 template < typename ForwardIterator > 68 inline void uninitialized_construct_impl( ForwardIterator first, ForwardIterator last, false_type ) 69 { 70 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 71 ForwardIterator it( first ); 72 for ( ; it != last; ++it ) 73 ::new( (void*)&*it ) value_type; 74 } 75 76 template < typename ForwardIterator > 77 inline ForwardIterator uninitialized_construct_n_impl( ForwardIterator first, size_t count, true_type ) 78 { 79 return fill_default_n( first, count ); 80 } 81 82 template < typename ForwardIterator > 83 inline ForwardIterator uninitialized_construct_n_impl( ForwardIterator first, size_t count, false_type ) 84 { 85 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 86 ForwardIterator it( first ); 87 for ( ; count > 0; --count, ++it ) 88 ::new( (void*)&*it ) value_type; 89 } 90 91 template < typename ForwardIterator > 92 inline void uninitialized_destroy_impl( ForwardIterator, ForwardIterator, true_type ) 93 { 94 // no-op 95 } 96 97 template < typename ForwardIterator > 98 inline void uninitialized_destroy_impl( ForwardIterator first, ForwardIterator last, false_type ) 99 { 100 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 101 ForwardIterator it( first ); 102 for ( ; it != last; ++it ) 103 ( *it ).~value_type(); 104 } 105 106 template < typename ForwardIterator > 107 inline ForwardIterator uninitialized_destroy_n_impl( ForwardIterator first, size_t count, true_type ) 108 { 109 return first + count; 110 } 111 112 template < typename ForwardIterator > 113 inline ForwardIterator uninitialized_destroy_n_impl( ForwardIterator first, size_t count, false_type ) 114 { 115 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 116 ForwardIterator it( first ); 117 for ( ; count > 0; --count, ++it ) 118 ( *it ).~value_type(); 119 return it; 120 } 121 122 } 123 124 template < typename ForwardIterator, typename T > 125 inline void uninitialized_fill( ForwardIterator first, ForwardIterator last, const T& value ) 126 { 127 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 128 uninitialized_fill_impl( first, last, value, has_trivial_assign<value_type>() ); 129 } 130 131 template < typename ForwardIterator, typename T > 132 inline void uninitialized_fill_n( ForwardIterator first, size_t count, const T& value ) 133 { 134 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 135 return uninitialized_fill_n_impl( first, count, value, has_trivial_assign<value_type>() ); 136 } 137 138 template < typename T > 139 inline void raw_construct_object( void* object ) 140 { 141 new (object)T; 142 } 143 144 template < typename T, typename ...Args > 145 inline void raw_construct_object( void* object, Args&&... params ) 146 { 147 new (object)T( forward<Args>( params )... ); 148 } 149 150 template < typename T, typename ...Args > 151 inline void construct_object( T* object, Args&&... params ) 152 { 153 new (object)T( forward<Args>( params )... ); 154 } 155 156 template < typename T > 157 inline void destroy_object( T* object ) 158 { 159 object->~T(); 160 } 161 162 template <typename TYPE> 163 void raw_destroy_object( void* object ) 164 { 165 ( (TYPE*)object )->TYPE::~TYPE(); 166 } 167 168 169 template < typename ForwardIterator, typename ...Args > 170 inline void uninitialized_construct( ForwardIterator first, ForwardIterator last, Args&&... params ) 171 { 172 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 173 ForwardIterator it( first ); 174 for ( ; it != last; ++it ) 175 ::new( (void*)&*it ) value_type( forward<Args>( params )... ); 176 } 177 178 template < typename ForwardIterator > 179 inline void uninitialized_construct( ForwardIterator first, ForwardIterator last ) 180 { 181 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 182 uninitialized_construct_impl( first, last, has_trivial_constructor<value_type>() ); 183 } 184 185 template < typename ForwardIterator > 186 inline ForwardIterator uninitialized_construct_n( ForwardIterator first, size_t count ) 187 { 188 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 189 return uninitialized_construct_n_impl( first, count, has_trivial_constructor<value_type>() ); 190 } 191 192 template < typename ForwardIterator > 193 inline void uninitialized_destroy( ForwardIterator first, ForwardIterator last ) 194 { 195 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 196 uninitialized_destroy_impl( first, last, has_trivial_destructor<value_type>() ); 197 } 198 199 template < typename ForwardIterator > 200 inline ForwardIterator uninitialized_destroy_n( ForwardIterator first, size_t count ) 201 { 202 typedef typename iterator_traits< ForwardIterator >::value_type value_type; 203 return uninitialized_destroy_n_impl( first, count, has_trivial_destructor<value_type>() ); 204 } 205 206 namespace detail 207 { 27 208 template < typename PARENT, typename T, bool CONST, typename BASE = empty_base_class<PARENT> > 28 209 class pointer_iterators {}; … … 33 214 public: 34 215 typedef const T* const_iterator; 35 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;216 typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 36 217 37 218 inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); } … … 52 233 typedef T* iterator; 53 234 typedef const T* const_iterator; 54 typedef std::reverse_iterator<iterator> reverse_iterator;55 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;235 typedef nv::reverse_iterator<iterator> reverse_iterator; 236 typedef nv::reverse_iterator<const_iterator> const_reverse_iterator; 56 237 57 238 inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); } … … 226 407 }; 227 408 409 template < typename T, size_t N > 410 class static_container_allocator 411 { 412 public: 413 typedef T value_type; 414 typedef typename aligned_array<T, N, NV_ALIGN_OF( T ) >::type storage; 415 416 static const bool is_static = true; 417 static const size_t type_align = NV_ALIGN_OF( T ); 418 static const size_t type_size = sizeof( T ); 419 420 static_container_allocator() 421 { 422 } 423 bool resize( size_t new_size ) 424 { 425 return true; 426 } 427 static NV_CONSTEXPR size_t capacity() { return N; } 428 static NV_CONSTEXPR size_t size() { return N; } 429 NV_CONSTEXPR T* data() { return static_cast<T*>( m_data ); } 430 NV_CONSTEXPR const T* data() const { return static_cast<const T*>( m_data ); } 431 432 storage m_data; 433 }; 434 435 template < typename T > 436 class dynamic_container_allocator 437 { 438 public: 439 static const bool is_static = false; 440 static const size_t type_size = sizeof( T ); 441 static const size_t type_align = NV_ALIGN_OF( T ); 442 443 dynamic_container_allocator() 444 : m_data(nullptr), m_size(0) 445 { 446 447 } 448 449 static NV_CONSTEXPR size_t capacity() { return 0x80000000; } 450 size_t size() const { return m_size; } 451 T* data() { return static_cast<T*>( m_data ); } 452 const T* data() const { return static_cast<const T*>( m_data ); } 453 454 ~dynamic_container_allocator() 455 { 456 delete m_data; 457 } 458 459 uint8* m_data; 460 size_t m_size; 461 }; 228 462 229 463 } -
trunk/nv/stl/string.hh
r373 r374 22 22 23 23 #include <string> 24 #include <algorithm>25 24 #include <cstring> 26 25 #include <sstream> … … 30 29 #include <nv/stl/memory.hh> 31 30 #include <nv/stl/exception.hh> 31 #include <nv/stl/algorithm.hh> 32 32 33 33 namespace nv … … 222 222 inline std::string& remove_chars( std::string& s, const std::string& chars ) 223 223 { 224 s.erase( remove_if(s.begin(), s.end(),224 s.erase(nv::remove_if(s.begin(), s.end(), 225 225 [&chars](const char& c) { 226 226 return chars.find(c) != std::string::npos; … … 235 235 if ( std::string::npos != lastdot ) 236 236 ext = filename.substr( lastdot + 1 ); 237 std::transform( ext.begin(), ext.end(), ext.begin(), ::tolower);237 transform_seq( ext.begin(), ext.end(), ext.begin(), [=] ( char val ) { return char( ::tolower( val ) ); } ); 238 238 return ext; 239 239 } … … 346 346 typedef pointer const_iterator; 347 347 typedef const_iterator iterator; 348 typedef s td::size_tsize_type;349 typedef std::ptrdiff_tdifference_type;348 typedef size_t size_type; 349 typedef ptrdiff_t difference_type; 350 350 351 351 static NV_CONSTEXPR_CONST size_type npos = size_type( -1 ); … … 373 373 int compare( const string_base& rhs ) const 374 374 { 375 int cmp = std::memcmp( m_data, rhs.m_data, ( std::min )( m_size, rhs.m_size ) );375 int cmp = std::memcmp( m_data, rhs.m_data, ( nv::min )( m_size, rhs.m_size ) ); 376 376 return cmp != 0 ? cmp : ( m_size == rhs.m_size ? 0 : m_size < rhs.m_size ? -1 : 1 ); 377 377 } … … 389 389 { 390 390 if ( pos >= m_size ) return npos; 391 const_iterator it = s td::search( this->cbegin() + ( difference_type ) pos, this->cend(), s.cbegin(), s.cend() );392 return it == this->cend() ? npos : ( size_type ) std::distance( this->cbegin(), it );391 const_iterator it = search( this->cbegin() + ( difference_type ) pos, this->cend(), s.cbegin(), s.cend() ); 392 return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it ); 393 393 } 394 394 size_type find( char c, size_type pos = 0 ) const 395 395 { 396 396 if ( pos >= m_size ) return npos; 397 const_iterator it = std::find_if( this->cbegin() + ( difference_type ) pos, this->cend(), [=] ( char val ) { return val == c; } );398 return it == this->cend() ? npos : ( size_type ) std::distance( this->cbegin(), it );397 const_iterator it = find_if( this->cbegin() + ( difference_type ) pos, this->cend(), [=] ( char val ) { return val == c; } ); 398 return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it ); 399 399 } 400 400 size_type rfind( const string_base& s, size_type pos = 0 ) const 401 401 { 402 402 if ( pos >= m_size ) return npos; 403 const_reverse_iterator it = s td::search( this->crbegin() + ( difference_type ) pos, this->crend(), s.crbegin(), s.crend() );404 return it == this->crend() ? npos : m_size - 1 - ( size_type ) std::distance( this->crbegin(), it );403 const_reverse_iterator it = search( this->crbegin() + ( difference_type ) pos, this->crend(), s.crbegin(), s.crend() ); 404 return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it ); 405 405 } 406 406 size_type rfind( char c, size_type pos = 0 ) const 407 407 { 408 408 if ( pos >= m_size ) return npos; 409 const_reverse_iterator it = std::find_if( this->crbegin() + ( difference_type ) pos, this->crend(), [=] ( char val ) { return val == c; } );410 return it == this->crend() ? npos : m_size - 1 - ( size_type ) std::distance( this->crbegin(), it );409 const_reverse_iterator it = find_if( this->crbegin() + ( difference_type ) pos, this->crend(), [=] ( char val ) { return val == c; } ); 410 return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it ); 411 411 } 412 412 size_type find_first_of( char c ) const { return find( c ); } 413 413 size_type find_first_of( const string_base& s ) const 414 414 { 415 const_iterator it = std::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() );416 return it == this->cend() ? npos : ( size_type ) std::distance( this->cbegin(), it );415 const_iterator it = nv::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() ); 416 return it == this->cend() ? npos : ( size_type )distance( this->cbegin(), it ); 417 417 } 418 418 size_type find_last_of( char c ) const { return rfind( c ); } 419 419 size_type find_last_of( const string_base& s ) const 420 420 { 421 const_reverse_iterator it = std::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() );422 return it == this->crend() ? npos : m_size - 1 - ( size_type ) std::distance( this->crbegin(), it );421 const_reverse_iterator it = nv::find_first_of( this->crbegin(), this->crend(), s.cbegin(), s.cend() ); 422 return it == this->crend() ? npos : m_size - 1 - ( size_type )distance( this->crbegin(), it ); 423 423 } 424 424 size_type find_first_not_of( const string_base& s ) const … … 426 426 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it ) 427 427 if ( 0 == std::memchr( s.m_data, *it, s.m_size ) ) 428 return ( size_type ) std::distance( this->cbegin(), it );428 return ( size_type )distance( this->cbegin(), it ); 429 429 return npos; 430 430 } … … 433 433 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it ) 434 434 if ( c != *it ) 435 return ( size_type ) std::distance( this->cbegin(), it );435 return ( size_type )distance( this->cbegin(), it ); 436 436 return npos; 437 437 } … … 440 440 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it ) 441 441 if ( 0 == std::memchr( s.m_data, *it, s.m_size ) ) 442 return m_size - 1 - ( size_type ) std::distance( this->crbegin(), it );;442 return m_size - 1 - ( size_type )distance( this->crbegin(), it );; 443 443 return npos; 444 444 } … … 447 447 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it ) 448 448 if ( c != *it ) 449 return m_size - 1 - ( size_type ) std::distance( this->crbegin(), it );449 return m_size - 1 - ( size_type )distance( this->crbegin(), it ); 450 450 return npos; 451 451 } … … 454 454 string_ref substr( size_type p, size_type n = npos ) const; 455 455 456 inline s td::size_t hash() const456 inline size_t hash() const 457 457 { 458 458 const char* str = m_data; -
trunk/nv/stl/type_traits.hh
r373 r374 10 10 */ 11 11 // TODO: "......" function match version? 12 // TODO: remove type_traits13 12 // TODO: remove typeinfo? 14 13 … … 18 17 #include <nv/core/common.hh> 19 18 19 #include <type_traits> 20 20 namespace nv 21 21 { 22 22 23 template< typename T, T VALUE> 24 struct integral_constant 25 { 26 static const T value = VALUE; 27 typedef T value_type; 28 typedef integral_constant<T, VALUE> type; 29 NV_CONSTEXPR operator value_type() const { return ( value ); } 30 }; 31 32 typedef integral_constant<bool, true> true_type; 33 typedef integral_constant<bool, false> false_type; 34 35 template< bool TEST, typename T = void> 36 struct enable_if {}; 37 38 template< typename T > 39 struct enable_if< true, T > 40 { 41 typedef T type; 42 }; 43 44 template< bool TEST, typename T1, typename T2 > 45 struct conditional 46 { 47 typedef T2 type; 48 }; 49 50 template< typename T1, typename T2> 51 struct conditional < true, T1, T2 > 52 { 53 typedef T1 type; 54 }; 55 56 template< typename T1, typename T2 > 23 template < typename T1, typename T2 > 57 24 struct is_same : false_type {}; 58 25 59 template < typename T >26 template < typename T > 60 27 struct is_same < T, T > : true_type {}; 61 28 62 template < typename T >29 template < typename T > 63 30 struct is_array : false_type {}; 64 31 65 template < typename T, size_t N >32 template < typename T, size_t N > 66 33 struct is_array < T[N] > : true_type {}; 67 34 68 template < typename T >35 template < typename T > 69 36 struct is_array < T[] > : true_type {}; 70 37 71 template < typename T >38 template < typename T > 72 39 struct is_lvalue_reference : false_type {}; 73 40 74 template < typename T >41 template < typename T > 75 42 struct is_lvalue_reference < T& > : true_type{}; 76 43 77 template < typename T >44 template < typename T > 78 45 struct is_rvalue_reference : false_type {}; 79 46 80 template < typename T >47 template < typename T > 81 48 struct is_rvalue_reference < T&& > : true_type{}; 82 49 50 template < typename _Ty> 51 struct is_reference : integral_constant < bool, is_lvalue_reference<_Ty>::value || is_rvalue_reference<_Ty>::value > {}; 52 83 53 template < typename T > 84 54 struct is_enum : integral_constant < bool, __is_enum( T ) > {}; 85 55 86 template < typename T > 87 struct is_pod : integral_constant < bool, __is_pod( T ) > {}; 56 // TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in 57 // detail - research why it is so. 58 template < typename T > 59 struct is_const : false_type {}; 60 template < typename T > 61 struct is_const < T const > : true_type{}; 62 template < typename T > 63 struct is_volatile : false_type {}; 64 template < typename T > 65 struct is_volatile < T volatile > : true_type{}; 66 // TODO END 88 67 89 68 template< typename T > … … 222 201 namespace detail 223 202 { 224 // TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in225 // detail - research why it is so.226 template < typename T >227 struct is_const : false_type {};228 template < typename T >229 struct is_const < T const > : true_type {};230 template < typename T >231 struct is_volatile : false_type {};232 template < typename T >233 struct is_volatile < T volatile > : true_type {};234 // TODO END235 236 203 template< typename T, bool CONST, bool VOLATILE> 237 204 struct cv_selector; … … 454 421 #endif 455 422 423 template <typename T> 424 struct is_empty : integral_constant < bool, __is_empty( T ) > {}; 425 426 template < typename T > 427 struct is_pod : integral_constant < bool, __is_pod( T ) > {}; 428 429 template < typename T > 430 struct has_trivial_constructor : integral_constant < bool, __has_trivial_constructor( T ) || __is_pod( T ) > {}; 431 432 #if NV_COMPILER == NV_MSVC 433 template < typename T > 434 struct has_trivial_copy : integral_constant < bool, ( __has_trivial_copy( T ) || __is_pod( T ) ) && !is_volatile<T>::value > {}; 435 #else 436 template < typename T > 437 struct has_trivial_copy : integral_constant < bool, ( __has_trivial_copy( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_reference<T>::value ) > {}; 438 #endif 439 440 template < typename T > 441 struct has_trivial_assign : integral_constant < bool, ( __has_trivial_assign( T ) || __is_pod( T ) ) && ( !is_volatile<T>::value && !is_const<T>::value ) > {}; 442 443 template < typename T > 444 struct has_trivial_destructor : integral_constant < bool, __has_trivial_destructor( T ) || __is_pod( T ) > {}; 445 446 template < typename T > 447 struct has_virtual_destructor : integral_constant < bool, __has_virtual_destructor( T ) > {}; 448 449 456 450 namespace detail 457 451 { … … 606 600 }; 607 601 602 #if NV_COMPILER == NV_MSVC 603 typedef double max_align_t; 604 #elif NV_PLATFORM == NV_APPLE 605 typedef long double max_align_t; 606 #else 607 namespace detail 608 { 609 class aligned_dummy; 610 typedef void( *aligned_fptr )( ); 611 typedef int( aligned_dummy::*aligned_memptr ); 612 typedef int ( aligned_dummy::*aligned_memfptr )( ); 613 } 614 615 union max_align_t 616 { 617 double dummy0; 618 long double dummy1; 619 void* dummy2; 620 sint64 dummy3; 621 detail::aligned_fptr dummy4; 622 detail::aligned_memptr dummy5; 623 detail::aligned_memfptr dummy6; 624 }; 625 #endif 626 627 #if NV_COMPILER == NV_CLANG 628 template< typename T, size_t Size, size_t Align > 629 struct aligned_array 630 { 631 typedef T alignas( Align ) type[Size]; 632 }; 633 #elif NV_COMPILER == NV_GNUC 634 template< typename T, size_t Size, size_t Align > 635 struct aligned_array 636 { 637 typedef T __attribute__((aligned( Align ))) type[Size]; 638 }; 639 #else 640 // TODO: remove this shit after moving to MSVC 2015 641 template< typename T, size_t Size, size_t Align > 642 struct aligned_array; 643 644 // According to LLVM ( https://llvm.org/svn/llvm-project/llvm/trunk/include/llvm/Support/AlignOf.h ) 645 // MSVC has problems with align below 16... 646 #define NV_ALIGNED_ARRAY(N) \ 647 template< typename T, size_t Size > \ 648 struct aligned_array< T, Size, N > \ 649 { \ 650 typedef __declspec( align(N) ) T type[Size]; \ 651 }; 652 653 NV_ALIGNED_ARRAY( 1 ) 654 NV_ALIGNED_ARRAY( 2 ) 655 NV_ALIGNED_ARRAY( 4 ) 656 NV_ALIGNED_ARRAY( 8 ) 657 NV_ALIGNED_ARRAY( 16 ) 658 NV_ALIGNED_ARRAY( 32 ) 659 NV_ALIGNED_ARRAY( 64 ) 660 NV_ALIGNED_ARRAY( 128 ) 661 662 #undef NV_ALIGNED_ARRAY 663 #endif 664 665 template< size_t Size, size_t Align = NV_ALIGN_OF( max_align_t ) > 666 struct aligned_storage 667 { 668 struct type 669 { 670 typename aligned_array< unsigned char, Size, Align >::type data; 671 }; 672 }; 673 608 674 } 609 675 -
trunk/nv/stl/utility.hh
r373 r374 1 // Copyright (C) 201 4ChaosForge Ltd1 // Copyright (C) 2015 ChaosForge Ltd 2 2 // http://chaosforge.org/ 3 3 // … … 39 39 } 40 40 41 // TODO: change to swap once you get rid of STL 41 42 template< typename T > 42 43 void swap( T& x, T& y ) … … 47 48 } 48 49 50 template < typename T > 51 inline const T& max( const T& a, const T& b ) 52 { 53 return a < b ? b : a; 54 } 55 56 template < typename T > 57 inline const T& min( const T& a, const T& b ) 58 { 59 return a > b ? b : a; 60 } 61 49 62 } 50 63 51 #endif NV_STL_UTILITY_HH64 #endif // NV_STL_UTILITY_HH -
trunk/src/curses/curses_terminal.cc
r369 r374 65 65 } 66 66 mvaddch( p.y-1, p.x-1, ch ); 67 move( m_cursor.y-1, m_cursor.x-1 );67 ::move( m_cursor.y-1, m_cursor.x-1 ); 68 68 } 69 69 … … 80 80 m_update_needed = true; 81 81 ::clear(); 82 move( m_cursor.y-1, m_cursor.x-1 );82 ::move( m_cursor.y-1, m_cursor.x-1 ); 83 83 } 84 84 … … 160 160 { 161 161 terminal::set_cursor( p ); 162 move( m_cursor.y-1, m_cursor.x-1 );162 ::move( m_cursor.y-1, m_cursor.x-1 ); 163 163 } 164 164 -
trunk/src/engine/particle_engine.cc
r365 r374 7 7 #include <nv/interface/device.hh> 8 8 #include <nv/core/random.hh> 9 #include <nv/stl/utility.hh> 9 10 #include <nv/lua/lua_glm.hh> 10 11 #include <nv/core/logging.hh> 11 #include <cmath>12 12 13 13 static const char *nv_particle_engine_vertex_shader_world = … … 203 203 if ( datap->average ) 204 204 { 205 float norm_factor = glm::min( factor, 1.0f );205 float norm_factor = nv::min( factor, 1.0f ); 206 206 for ( uint32 i = 0; i < count; ++i ) 207 207 p[i].velocity = datap->force_vector * norm_factor + p[i].velocity * ( 1.0f - norm_factor ); … … 696 696 { 697 697 info->count--; 698 s td::swap( info->particles[i], info->particles[info->count] );698 swap( info->particles[i], info->particles[info->count] ); 699 699 } 700 700 } -
trunk/src/formats/md2_loader.cc
r367 r374 238 238 } 239 239 240 size_t md2_loader::get_max_frames() const240 nv::size_t md2_loader::get_max_frames() const 241 241 { 242 242 return static_cast< size_t >( ((md2_t*)m_md2)->header.num_frames ); -
trunk/src/formats/md3_loader.cc
r367 r374 172 172 source.read( surface->vertices, sizeof( md3_vertex_t ), static_cast<size_t>( surface->header.num_verts * surface->header.num_frames ) ); 173 173 174 if ( source.tell() != static_cast<s td::size_t>( pos + surface->header.ofs_end ) ) return false;174 if ( source.tell() != static_cast<size_t>( pos + surface->header.ofs_end ) ) return false; 175 175 176 176 return true; -
trunk/src/formats/md5_loader.cc
r367 r374 344 344 vtc.tangent = glm::vec3(0); 345 345 346 std::sort( weights + start_weight, weights + start_weight + weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } ); 346 stable_sort( weights + start_weight, weights + start_weight + weight_count, [] ( const md5_weight& a, const md5_weight& b ) -> bool { return a.bias > b.bias; } ); 347 //std::sort( weights + start_weight, weights + start_weight + weight_count, [](const md5_weight& a, const md5_weight& b) -> bool { return a.bias > b.bias; } ); 347 348 348 349 if ( weight_count > 4 ) -
trunk/src/formats/obj_loader.cc
r319 r374 53 53 std::string next_name; 54 54 55 s td::size_t size;56 bool 55 size_t size; 56 bool eof; 57 57 58 58 obj_reader(); … … 172 172 { 173 173 mesh_data_reader( bool normals ) : m_normals( normals ) {} 174 virtual s td::size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count )174 virtual size_t add_face( uint32* vi, uint32* ti, uint32* ni, size_t count ) 175 175 { 176 176 if ( count < 3 ) return 0; // TODO : report error? … … 178 178 // TODO : support if normals not present; 179 179 vec3 nullvec; 180 s td::size_t result = 0;180 size_t result = 0; 181 181 // Simple triangulation - obj's shouldn't have more than quads anyway 182 182 … … 278 278 } 279 279 280 for (s td::size_t a = 0; a < count; ++a )280 for (size_t a = 0; a < count; ++a ) 281 281 { 282 282 const vec3& n = m_data[a].normal; -
trunk/src/gfx/image.cc
r323 r374 4 4 5 5 #include "nv/gfx/image.hh" 6 7 #include <algorithm>8 6 9 7 using namespace nv; -
trunk/src/io/c_stream.cc
r319 r374 6 6 #include <sys/stat.h> 7 7 #include "nv/io/c_stream.hh" 8 #include <limits>9 8 10 9 using namespace nv; -
trunk/src/io/std_stream.cc
r319 r374 8 8 9 9 #include "nv/io/std_stream.hh" 10 #include <algorithm> 10 #include "nv/stl/math.hh" 11 #include "nv/stl/utility.hh" 11 12 12 13 using namespace nv; … … 15 16 : m_stream( source ) 16 17 , m_owner( owner ) 17 , m_buffer( std::max(bsize, put_back) + put_back )18 , m_put_back( std::max( put_back, std::size_t( 1 ) ) )18 , m_buffer( nv::max(bsize, put_back) + put_back ) 19 , m_put_back( nv::max( put_back, std::size_t( 1 ) ) ) 19 20 { 20 21 char *end = &m_buffer.front() + m_buffer.size(); -
trunk/src/lib/curses.cc
r319 r374 11 11 #include "nv/core/library.hh" 12 12 13 #define FILE void 13 14 #define NV_CURSES_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr; 14 15 #include <nv/lib/detail/curses_functions.inc> … … 21 22 curses_library.open( path ); 22 23 23 # define NV_CURSES_FUN( rtype, fname, fparams ) *(void **) (& fname) = curses_library.get(#fname);24 # define NV_CURSES_FUN( rtype, fname, fparams ) *(void **) (&::fname) = curses_library.get(#fname); 24 25 # include <nv/lib/detail/curses_functions.inc> 25 26 # undef NV_CURSES_FUN -
trunk/src/lua/lua_area.cc
r368 r374 79 79 { 80 80 nv::rectangle* a = to_parea( L, 1 ); 81 std::size_t l;81 nv::size_t l; 82 82 const char* index = lua_tolstring( L, 2, &l ); 83 83 if ( l == 1 && index[0] == 'a' ) … … 101 101 { 102 102 nv::rectangle* a = to_parea( L, 1 ); 103 std::size_t l;103 nv::size_t l; 104 104 const char* index = lua_tolstring( L, 2, &l ); 105 105 nv::ivec2 value( to_coord( L, 3 ) ); -
trunk/src/lua/lua_map_tile.cc
r369 r374 7 7 #include "nv/lua/lua_map_tile.hh" 8 8 9 #include <numeric>10 9 #include "nv/lua/lua_map_area.hh" 11 10 #include "nv/stl/flags.hh" 11 #include "nv/stl/numeric.hh" 12 #include "nv/stl/algorithm.hh" 12 13 #include "nv/core/random.hh" 13 14 #include "nv/lua/lua_area.hh" … … 59 60 map_tile tile; 60 61 61 tile.size_y = (nv::uint16)( std::count( code.begin(), code.end(), '\n' ) + 1 );62 tile.size_y = (nv::uint16)( nv::count( code.begin(), code.end(), '\n' ) + 1 ); 62 63 tile.size_x = (nv::uint16)( code.find( '\n' ) ); 63 64 if ( tile.size_x == 0 ) … … 236 237 nv::uint16 org_x = tile->size_x; 237 238 nv::uint16 org_y = tile->size_y; 238 nv::uint16 new_x = ( nv::uint16)std::accumulate( sizes_x.begin(), sizes_x.end(), 0 );239 nv::uint16 new_y = ( nv::uint16)std::accumulate( sizes_y.begin(), sizes_y.end(), 0 );239 nv::uint16 new_x = ( nv::uint16 )nv::accumulate( sizes_x.begin(), sizes_x.end(), 0 ); 240 nv::uint16 new_y = ( nv::uint16 )nv::accumulate( sizes_y.begin(), sizes_y.end(), 0 ); 240 241 241 242 nv::uint8* data = new nv::uint8[ new_x * new_y ]; -
trunk/src/stl/string.cc
r368 r374 28 28 } 29 29 30 size_t nv::sint32_to_buffer( sint32 n, char* str )30 nv::size_t nv::sint32_to_buffer( sint32 n, char* str ) 31 31 { 32 32 char* s = str; … … 43 43 } 44 44 45 size_t nv::sint64_to_buffer( sint64 n, char* str )45 nv::size_t nv::sint64_to_buffer( sint64 n, char* str ) 46 46 { 47 47 char* s = str; … … 58 58 } 59 59 60 size_t nv::uint32_to_buffer( uint32 n, char* str )60 nv::size_t nv::uint32_to_buffer( uint32 n, char* str ) 61 61 { 62 62 char* s = str; … … 71 71 } 72 72 73 size_t nv::uint64_to_buffer( uint64 n, char* str )73 nv::size_t nv::uint64_to_buffer( uint64 n, char* str ) 74 74 { 75 75 char* s = str; … … 84 84 } 85 85 86 size_t nv::f32_to_buffer( f32 n, char* str )86 nv::size_t nv::f32_to_buffer( f32 n, char* str ) 87 87 { 88 88 #if NV_COMPILER == NV_MSVC … … 95 95 } 96 96 97 size_t nv::f64_to_buffer( f64 n, char* str )97 nv::size_t nv::f64_to_buffer( f64 n, char* str ) 98 98 { 99 99 #if NV_COMPILER == NV_MSVC
Note: See TracChangeset
for help on using the changeset viewer.