- Timestamp:
- 06/13/15 21:51:27 (10 years ago)
- Location:
- trunk
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/base/assert.hh
r396 r402 39 39 #endif 40 40 41 // TODO: assert levels 41 42 #if NV_DEBUG 42 43 #define NV_ASSERT(cond, msg) NV_ASSERT_IMPL( (cond) && "assertion failed:" msg ) 44 #define NV_DEBUG_ASSERT(cond, msg) NV_ASSERT_IMPL( (cond) && "assertion failed:" msg ) 43 45 #else 44 #define NV_ASSERT(cond, msg) ((void)0) 46 #define NV_ASSERT(cond, msg) ((void)0) 47 #define NV_DEBUG_ASSERT(cond, msg) ((void)0) 45 48 #endif 46 49 -
trunk/nv/base/capi.hh
r397 r402 12 12 * This header is temporary 13 13 */ 14 15 // TODO: sanity checking with NV_DEBUG_ASSERT 14 16 15 17 #ifndef NV_BASE_CAPI_HH … … 110 112 inline void* nvmemset( void *dest, unsigned char value, size_t count ) 111 113 { 112 return NV_CAPI_CALL( memset )( dest, (int)value, count );114 return NV_CAPI_CALL( memset )( dest, static_cast<int>( value ), count ); 113 115 } 114 116 115 117 inline void* nvmemchr( const void *src, unsigned char value, size_t max_count ) 116 118 { 117 return NV_CAPI_CALL( memchr )( src, (int)value, max_count );119 return NV_CAPI_CALL( memchr )( src, static_cast<int>( value ), max_count ); 118 120 } 119 121 -
trunk/nv/base/common.hh
r401 r402 7 7 #ifndef NV_BASE_COMMON_HH 8 8 #define NV_BASE_COMMON_HH 9 10 #define _ITERATOR_DEBUG_LEVEL 011 9 12 10 // NV Library version … … 199 197 using size_t = decltype( sizeof(0) ); 200 198 #endif 201 using ptrdiff_t = decltype( (int*)0 - (int*)0);199 using ptrdiff_t = decltype( static_cast<int*>(0) - static_cast<int*>(0) ); 202 200 using nullptr_t = decltype( nullptr ); 203 201 … … 256 254 inline size_t offset_of( T OBJ::*ptr ) 257 255 { 258 return ( ( size_t )&( ( (OBJ*)0)->*ptr ) );256 return static_cast<size_t>( &( ( static_cast<OBJ*>(0) )->*ptr ) ); 259 257 } 260 258 … … 262 260 constexpr T narrow_cast( const U& a ) 263 261 { 264 return static_cast<T>( a & T( -1 ) );262 return static_cast<T>( a & static_cast<T>( -1 ) ); 265 263 } 266 264 267 265 } // namespace nv 268 266 269 static_assert( nv::size_t( -1 ) > 0,"size_t is signed!" );267 static_assert( static_cast<nv::size_t>( -1 ) > 0, "size_t is signed!" ); 270 268 static_assert( sizeof( nv::size_t ) >= 4, "size_t is smaller than 4 bytes!" ); 271 269 static_assert( sizeof( nv::sint8 ) == 1, "sint8 size isn't 1 bytes" ); -
trunk/nv/base/rtti_support.hh
r396 r402 49 49 constexpr uint64 rtti_hash_impl( char c, const char* remain, uint64 value ) 50 50 { 51 return c == 0 ? value : rtti_hash_impl( remain[0], remain + 1, (uint64)(uint64)( value ^ (uint64)c) * rtti_hash_prime );51 return c == 0 ? value : rtti_hash_impl( remain[0], remain + 1, static_cast<uint64>( value ^ static_cast<uint64>(c) ) * rtti_hash_prime ); 52 52 } 53 53 … … 66 66 static uint64 hash() 67 67 { 68 static_assert( NV_TYPE_FAIL( T), "Type not registered!" );68 static_assert( NV_TYPE_FAIL( T ), "Type not registered!" ); 69 69 return 0; 70 70 } -
trunk/nv/core/library.hh
r399 r402 127 127 128 128 /** 129 * Destructor.130 *131 * It must not throw any exceptions because of the inheritance132 */133 ~library_error() throw() {}134 135 /**136 129 * Returns library name 137 130 */ -
trunk/nv/core/logging.hh
r399 r402 78 78 static bool can_log( log_level level ) 79 79 { 80 return logger_base::is_valid() && (unsigned int)reference().get_level() >= (unsigned int)level;80 return logger_base::is_valid() && static_cast<unsigned int>( reference().get_level() ) >= static_cast<unsigned int>( level ); 81 81 } 82 82 … … 84 84 { 85 85 *m_pos = '\0'; 86 log( level, string_view( m_message, (size_t)( m_pos - m_message ) ) );86 log( level, string_view( m_message, static_cast<size_t>( m_pos - m_message ) ) ); 87 87 m_pos = m_message; 88 88 } -
trunk/nv/stl/algorithm/fill.hh
r401 r402 35 35 void fill_impl( BlockAccessIterator first, BlockAccessIterator last, T value, true_type, block_access_iterator_tag ) 36 36 { 37 raw_fill( first, last, (unsigned char)value);37 raw_fill( first, last, narrow_cast<unsigned char>( value ) ); 38 38 } 39 39 … … 49 49 BlockAccessIterator fill_n_impl( BlockAccessIterator first, size_t count, T value, true_type, block_access_iterator_tag ) 50 50 { 51 return BlockAccessIterator( raw_fill_n( first, count, (unsigned char)value) );51 return BlockAccessIterator( raw_fill_n( first, count, narrow_cast<unsigned char>( value ) ) ); 52 52 } 53 53 -
trunk/nv/stl/algorithm/raw.hh
r396 r402 19 19 namespace nv 20 20 { 21 22 // TODO: better debug macros, both here as well as in nv*funcs 23 namespace detail 24 { 25 template< typename T > 26 constexpr size_t byte_distance( const T* first, const T* last ) 27 { 28 return static_cast<size_t>( reinterpret_cast<uintptr_t>( last ) - reinterpret_cast<uintptr_t>( first ) ); 29 } 30 31 } 21 32 22 33 template< typename T > 23 34 T* raw_copy( const T* first, const T* last, T* out ) 24 35 { 25 return (T*)nvmemcpy( out, first, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first ); 36 NV_DEBUG_ASSERT( last - first > 0, "raw_copy range fail!" ); 37 return static_cast<T*>( nvmemcpy( out, first, detail::byte_distance( first, last ) ) ) + ( last - first ); 26 38 } 27 39 … … 29 41 T* raw_copy_n( const T* ptr, size_t n, T* out ) 30 42 { 31 return (T*)nvmemcpy( out, ptr, n * sizeof( T) ) + n;43 return static_cast<T*>( nvmemcpy( out, ptr, n * sizeof( T ) ) ) + n; 32 44 } 33 45 … … 35 47 T* raw_alias_copy( const T* first, const T* last, T* out ) 36 48 { 37 return (T*)nvmemmove( out, first, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first ); 49 NV_DEBUG_ASSERT( last - first > 0, "raw_alias_copy range fail!" ); 50 return static_cast<T*>( nvmemmove( out, first, detail::byte_distance( first, last ) ) ) + ( last - first ); 38 51 } 39 52 … … 41 54 T* raw_alias_copy_n( const T* ptr, size_t n, T* out ) 42 55 { 43 return (T*)nvmemmove( out, ptr, n * sizeof( T) ) + n;56 return static_cast<T*>( nvmemmove( out, ptr, n * sizeof( T ) ) ) + n; 44 57 } 45 58 … … 47 60 T* raw_zero( T* first, T* last ) 48 61 { 49 return (T*)nvmemset( first, 0, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first ); 62 NV_DEBUG_ASSERT( last - first > 0, "raw_zero range fail!" ); 63 return static_cast<T*>( nvmemset( first, 0, detail::byte_distance( first, last ) ) ) + ( last - first ); 50 64 } 51 65 … … 53 67 T* raw_zero_n( T* ptr, size_t n ) 54 68 { 55 return (T*)nvmemset( ptr, 0, n * sizeof( T) ) + n;69 return static_cast<T*>( nvmemset( ptr, 0, n * sizeof( T ) ) ) + n; 56 70 } 57 71 … … 59 73 T* raw_fill( T* first, T* last, unsigned char value ) 60 74 { 61 return (T*)nvmemset( first, value, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first ); 75 NV_DEBUG_ASSERT( last - first > 0, "raw_fill range fail!" ); 76 return static_cast<T*>( nvmemset( first, value, detail::byte_distance( first, last ) ) ) + ( last - first ); 62 77 } 63 78 … … 65 80 T* raw_fill_n( T* ptr, size_t n, unsigned char value ) 66 81 { 67 return (T*)nvmemset( ptr, value, n * sizeof( T) ) + n;82 return static_cast<T*>( nvmemset( ptr, value, n * sizeof( T ) ) ) + n; 68 83 } 69 84 -
trunk/nv/stl/container/hash_table.hh
r401 r402 56 56 public: 57 57 constexpr iterator_base() : m_node( nullptr ) {} 58 constexpr iterator_base( const iterator_base& it ) : m_node( it.m_node ) {}59 58 const entry_type* entry() const { return m_node; } 60 59 reference operator*() const { return m_node->value; } … … 72 71 typedef iterator_base< IsConst > base_type; 73 72 74 constexpr node_iterator() : base_type( nullptr ) {} 75 constexpr node_iterator( const node_iterator& it ) : base_type( it.m_node ) {} 76 73 constexpr node_iterator() = default; 77 74 template < bool B, typename = enable_if_t< IsConst && !B > > 78 constexpr node_iterator( const node_iterator< B >& it ) 79 : base_type( it.m_node ) 80 { 81 } 75 constexpr node_iterator( const node_iterator< B >& it ) : base_type( it.m_node ) {} 82 76 83 77 node_iterator& operator++() { increment(); return *this; } … … 236 230 inline size_type max_size() const { return 2147483647; } 237 231 inline size_type max_bucket_count() const { return 2147483647; } 238 inline float load_factor() const { return (float)m_element_count / (float)m_bucket_count; }232 inline float load_factor() const { return static_cast<float>( m_element_count ) / static_cast<float>( m_bucket_count ); } 239 233 inline float max_load_factor() const { return m_max_load_factor; } 240 234 inline void max_load_factor( float ml ) { m_max_load_factor = ml; } … … 312 306 void zero() 313 307 { 314 m_buckets = (node_type**)&g_hash_table_empty[0];308 m_buckets = reinterpret_cast<node_type**>( &g_hash_table_empty[0] ); 315 309 m_bucket_count = 1; 316 310 m_element_count = 0; … … 343 337 { 344 338 NV_ASSERT( new_count > 1, "allocate_buckets fail!" ); 345 node_type** buckets = ( node_type** )nvmalloc( ( new_count + 1 ) * sizeof( node_type*) );339 node_type** buckets = reinterpret_cast<node_type**>( nvmalloc( ( new_count + 1 ) * sizeof( node_type* ) ) ); 346 340 nvmemset( buckets, 0, ( new_count + 1 ) * sizeof( node_type* ) ); 347 buckets[ new_count ] = reinterpret_cast<node_type*>( (uintptr_t)~0); // sentinel341 buckets[ new_count ] = reinterpret_cast<node_type*>( uintptr_t(~0) ); // sentinel 348 342 return buckets; 349 343 } … … 356 350 node_type* alloc_node() 357 351 { 358 return (node_type*)nvmalloc( sizeof( node_type) );352 return static_cast<node_type*>( nvmalloc( sizeof( node_type ) ) ); 359 353 } 360 354 -
trunk/nv/stl/container/hash_table_policy.hh
r401 r402 279 279 static uint32 get_bucket_count( uint32 element_count, float load_factor ) 280 280 { 281 uint32 min_count = (uint32)( element_count / load_factor );281 uint32 min_count = static_cast<uint32>( element_count / load_factor ); 282 282 return get_prime_larger_or_equal_to( min_count ); 283 283 } 284 284 static uint32 is_rehash_required( uint32 bucket_count, uint32 element_count, float load_factor ) 285 285 { 286 uint32 min_count = (uint32)( element_count / load_factor );286 uint32 min_count = static_cast<uint32>( element_count / load_factor ); 287 287 if ( bucket_count < 2 || min_count > bucket_count ) 288 288 { -
trunk/nv/stl/functional/hash.hh
r401 r402 61 61 static constexpr H str_hash_impl( char c, const char* remain, H value ) 62 62 { 63 return c == 0 ? value : str_hash_impl( remain[0], remain + 1, (H)(H)( value ^ (H)c) * hash_prime );63 return c == 0 ? value : str_hash_impl( remain[0], remain + 1, static_cast<H>( value ^ static_cast<H>( c ) ) * hash_prime ); 64 64 } 65 65 static constexpr H hash_impl( const char* current, size_t remain, H value ) 66 66 { 67 return remain == 0 ? value : hash_impl( current + 1, remain - 1, (H)(H)( value ^ (H)(current[0]) ) * hash_prime );67 return remain == 0 ? value : hash_impl( current + 1, remain - 1, static_cast<H>( value ^ static_cast<H>( current[0] ) ) * hash_prime ); 68 68 } 69 69 }; … … 119 119 { 120 120 return value == 0.0f ? detail::fnv_hash<H>( &value, 1 ) : 0; 121 } ;121 } 122 122 inline H operator()( float value ) const { return get( value ); } 123 123 }; … … 130 130 { 131 131 return value == 0.0f ? detail::fnv_hash<H>( &value, 1 ) : 0; 132 } ;132 } 133 133 inline H operator()( float value ) const { return get( value ); } 134 134 }; -
trunk/nv/stl/limits.hh
r395 r402 36 36 static constexpr int sc_bit = sizeof( signed char ) * 8; 37 37 static constexpr char c_min = ( char( 0 ) < char( -1 ) ? 0 : -128 ); 38 static constexpr char c_max = ( char( 0 ) < char( -1 ) ? 255: 127 );38 static constexpr char c_max = ( char( 0 ) < char( -1 ) ? narrow_cast<char>( 255 ) : 127 ); 39 39 static constexpr int c_bit = sizeof( char ) * 8; 40 40 static constexpr unsigned short us_min = 0; -
trunk/nv/stl/memory.hh
r401 r402 163 163 } 164 164 165 template < typename TYPE>165 template < typename T > 166 166 void raw_destroy_object( void* object ) 167 167 { 168 ( (TYPE*)object )->TYPE::~TYPE();168 static_cast<T*>( object )->T::~T(); 169 169 } 170 170 … … 183 183 ForwardIterator it( first ); 184 184 for ( ; it != last; ++it ) 185 ::new( (void*)&*it) value_type( value );185 ::new( static_cast<void*>( addressof( *it ) ) ) value_type( value ); 186 186 } 187 187 … … 198 198 ForwardIterator it( first ); 199 199 for ( ; count > 0; --count, ++it ) 200 ::new ( (void*)&*it) value_type( value );200 ::new ( static_cast<void*>( addressof( *it ) ) ) value_type( value ); 201 201 return it; 202 202 } … … 214 214 ForwardIterator it( first ); 215 215 for ( ; it != last; ++it ) 216 ::new( (void*)&*it) value_type;216 ::new( static_cast<void*>( addressof( *it ) ) ) value_type; 217 217 } 218 218 … … 229 229 ForwardIterator it( first ); 230 230 for ( ; count > 0; --count, ++it ) 231 ::new( (void*)&*it) value_type;231 ::new( static_cast<void*>( addressof( *it ) ) ) value_type; 232 232 } 233 233 … … 323 323 ForwardIterator it( first ); 324 324 for ( ; it != last; ++it ) 325 ::new( (void*)&*it) value_type( forward<Args>( params )... );325 ::new( static_cast<void*>( addressof( *it ) ) ) value_type( forward<Args>( params )... ); 326 326 } 327 327 -
trunk/nv/stl/string.hh
r401 r402 168 168 size_type reverse_distance( ReverseIterator first, ReverseIterator last ) const 169 169 { 170 return this->size() - 1 - (size_t)nv::distance( first, last);170 return this->size() - 1 - static_cast<size_t>( nv::distance( first, last ) ); 171 171 } 172 172 }; … … 252 252 { 253 253 size_type this_size = this->size(); 254 int cmp = nvmemcmp( this->data(), rhs.data(), ( nv::min )( this_size, rhs.size() ) );254 int cmp = nvmemcmp( this->data(), rhs.data(), nv::min( this_size, rhs.size() ) ); 255 255 return cmp != 0 ? cmp : ( this_size == rhs.size() ? 0 : this_size < rhs.size() ? -1 : 1 ); 256 256 } … … 282 282 { 283 283 if ( pos >= this->size() ) return npos; 284 const_iterator it = nv::find_if( this->cbegin() + (difference_type)pos, this->cend(), [=] ( value_type val ) { return val == c; } );285 return it == this->cend() ? npos : (size_type)nv::distance( this->cbegin(), it);284 const_iterator it = nv::find_if( this->cbegin() + static_cast<difference_type>( pos ), this->cend(), [=] ( value_type val ) { return val == c; } ); 285 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) ); 286 286 } 287 287 template < typename Storage > … … 289 289 { 290 290 if ( pos >= this->size() ) return npos; 291 const_iterator it = nv::search( this->cbegin() + (difference_type)pos, this->cend(), s.cbegin(), s.cend() );292 return it == this->cend() ? npos : (size_type)nv::distance( this->cbegin(), it);291 const_iterator it = nv::search( this->cbegin() + static_cast<difference_type>( pos ), this->cend(), s.cbegin(), s.cend() ); 292 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) ); 293 293 } 294 294 … … 297 297 { 298 298 if ( pos >= this->size() ) return npos; 299 const_reverse_iterator it = nv::find_if( this->crbegin() + (difference_type)pos, this->crend(), [=] ( value_type val ) { return val == c; } );299 const_reverse_iterator it = nv::find_if( this->crbegin() + static_cast<difference_type>( pos ), this->crend(), [=] ( value_type val ) { return val == c; } ); 300 300 return it == this->crend() ? npos : this->reverse_distance( this->crbegin(), it ); 301 301 } … … 304 304 { 305 305 if ( pos >= this->size() ) return npos; 306 const_reverse_iterator it = nv::search( this->crbegin() + (difference_type)pos, this->crend(), s.crbegin(), s.crend() );306 const_reverse_iterator it = nv::search( this->crbegin() + static_cast<difference_type>( pos ), this->crend(), s.crbegin(), s.crend() ); 307 307 return it == this->crend() ? npos : this->reverse_distance( this->crbegin(), it ); 308 308 } … … 317 317 { 318 318 const_iterator it = nv::find_first_of( this->cbegin(), this->cend(), s.cbegin(), s.cend() ); 319 return it == this->cend() ? npos : (size_type)nv::distance( this->cbegin(), it);319 return it == this->cend() ? npos : static_cast<size_type>( nv::distance( this->cbegin(), it ) ); 320 320 } 321 321 … … 337 337 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it ) 338 338 if ( c != *it ) 339 return (size_type)distance( this->cbegin(), it);339 return static_cast<size_type>( nv::distance( this->cbegin(), it ) ); 340 340 return npos; 341 341 } … … 344 344 { 345 345 for ( const_iterator it = this->cbegin(); it != this->cend(); ++it ) 346 if ( 0 == nvmemchr( s.data(), (uchar8)*it, s.size() ) )347 return (size_type)distance( this->cbegin(), it);346 if ( 0 == nvmemchr( s.data(), static_cast<uchar8>( *it ), s.size() ) ) 347 return static_cast<size_type>( nv::distance( this->cbegin(), it ) ); 348 348 return npos; 349 349 } … … 361 361 { 362 362 for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it ) 363 if ( 0 == nvmemchr( s.data(), (uchar8)*it, s.size() ) )363 if ( 0 == nvmemchr( s.data(), static_cast<uchar8>( *it ), s.size() ) ) 364 364 return this->reverse_distance( this->crbegin(), it ); 365 365 return npos; … … 434 434 #undef NV_STRING_REF_CAST_OPERATORS 435 435 436 size_t sint32_to_buffer( sint32 n, char* str ); 437 size_t sint64_to_buffer( sint64 n, char* str ); 438 size_t uint32_to_buffer( uint32 n, char* str ); 439 size_t uint64_to_buffer( uint64 n, char* str ); 440 size_t f32_to_buffer( f32 n, char* str ); 441 size_t f64_to_buffer( f64 n, char* str ); 436 size_t sint32_to_buffer( sint32 n, char* str ); 437 size_t sint64_to_buffer( sint64 n, char* str ); 438 size_t uint32_to_buffer( uint32 n, char* str ); 439 size_t uint64_to_buffer( uint64 n, char* str ); 440 size_t f32_to_buffer( f32 n, char* str ); 441 size_t f64_to_buffer( f64 n, char* str ); 442 sint32 buffer_to_sint32( const char* str, char** end ); 443 sint64 buffer_to_sint64( const char* s, char** end ); 444 uint32 buffer_to_uint32( const char* s, char** end ); 445 uint64 buffer_to_uint64( const char* s, char** end ); 446 float buffer_to_f32( const char* s, char** end ); 447 double buffer_to_f64( const char* s, char** end ); 442 448 443 449 // const string is movable but not copyable -
trunk/nv/stl/type_traits.hh
r395 r402 11 11 */ 12 12 13 // TODO : "... ..." function match version?13 // TODO : "..., ..." function match version? 14 14 // TODO : the following symbols are unimplemented: 15 15 // * is_constructible, is_trivially_constructible, is_nothrow_constructible -
trunk/nv/stl/type_traits/common.hh
r401 r402 182 182 constexpr typename remove_reference<T>::type&& move( T&& arg ) noexcept 183 183 { 184 return ( ( typename remove_reference<T>::type&& )arg );184 return static_cast<typename remove_reference<T>::type&&>( arg ); 185 185 } 186 186 -
trunk/nv/stl/type_traits/function.hh
r395 r402 10 10 * @brief type traits - function traits 11 11 */ 12 // TODO: remove_cv? call traits? support "......"?12 // TODO: remove_cv? call traits? 13 13 14 14 #ifndef NV_STL_TRAITS_FUNCTION_HH … … 114 114 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( CALLDECL C::* )( Args... ) const > { typedef R result_type; }; \ 115 115 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( CALLDECL C::* )( Args... ) volatile > { typedef R result_type; }; \ 116 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( CALLDECL C::* )( Args... ) const volatile > { typedef R result_type; }; 117 116 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( CALLDECL C::* )( Args... ) const volatile > { typedef R result_type; }; \ 117 118 //NV_EMIT_WEAK_RESULT_TYPE_CALLDECL() 118 119 NV_EMIT_WEAK_RESULT_TYPE_CALLDECL( __cdecl ) 119 120 NV_EMIT_WEAK_RESULT_TYPE_CALLDECL( __fastcall ) 120 121 NV_EMIT_WEAK_RESULT_TYPE_CALLDECL( __vectorcall ) 122 template < typename R, typename... Args > struct weak_result_type_impl< R __cdecl ( Args..., ... ) > { typedef R result_type; }; \ 123 template < typename R, typename... Args > struct weak_result_type_impl< R( __cdecl & )( Args..., ... ) > { typedef R result_type; }; \ 124 template < typename R, typename... Args > struct weak_result_type_impl< R( __cdecl * )( Args..., ... ) > { typedef R result_type; }; \ 125 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __cdecl C::* )( Args..., ... ) > { typedef R result_type; }; \ 126 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __cdecl C::* )( Args..., ... ) const > { typedef R result_type; }; \ 127 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __cdecl C::* )( Args..., ... ) volatile > { typedef R result_type; }; \ 128 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __cdecl C::* )( Args..., ... ) const volatile > { typedef R result_type; }; \ 129 121 130 # if NV_ARCHITECTURE == NV_32BIT 122 131 NV_EMIT_WEAK_RESULT_TYPE_CALLDECL( __stdcall ) 123 132 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) > { typedef R result_type; }; 124 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) const > { typedef R result_type; }; \125 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) volatile > { typedef R result_type; }; \133 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) const > { typedef R result_type; }; 134 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) volatile > { typedef R result_type; }; 126 135 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( __thiscall C::* )( Args... ) const volatile > { typedef R result_type; }; 127 136 # endif … … 129 138 #else 130 139 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ) > { typedef R result_type; }; 131 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ... ) > { typedef R result_type; };140 template < typename R, typename... Args > struct weak_result_type_impl< R( Args..., ... ) > { typedef R result_type; }; 132 141 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ) const > { typedef R result_type; }; 133 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ... ) const > { typedef R result_type; };142 template < typename R, typename... Args > struct weak_result_type_impl< R( Args..., ... ) const > { typedef R result_type; }; 134 143 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ) volatile > { typedef R result_type; }; 135 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ... ) volatile > { typedef R result_type; };144 template < typename R, typename... Args > struct weak_result_type_impl< R( Args..., ... ) volatile > { typedef R result_type; }; 136 145 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ) const volatile > { typedef R result_type; }; 137 template < typename R, typename... Args > struct weak_result_type_impl< R( Args... ... ) const volatile > { typedef R result_type; };146 template < typename R, typename... Args > struct weak_result_type_impl< R( Args..., ... ) const volatile > { typedef R result_type; }; 138 147 template < typename R, typename... Args > struct weak_result_type_impl< R( & )( Args... ) > { typedef R result_type; }; 139 template < typename R, typename... Args > struct weak_result_type_impl< R( & )( Args... ... ) > { typedef R result_type; };148 template < typename R, typename... Args > struct weak_result_type_impl< R( & )( Args..., ... ) > { typedef R result_type; }; 140 149 template < typename R, typename... Args > struct weak_result_type_impl< R( * )( Args... ) > { typedef R result_type; }; 141 template < typename R, typename... Args > struct weak_result_type_impl< R( * )( Args... ... ) > { typedef R result_type; };150 template < typename R, typename... Args > struct weak_result_type_impl< R( * )( Args..., ... ) > { typedef R result_type; }; 142 151 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ) > { typedef R result_type; }; 143 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ... ) > { typedef R result_type; };152 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args..., ... ) > { typedef R result_type; }; 144 153 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ) const > { typedef R result_type; }; 145 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ... ) const > { typedef R result_type; };154 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args..., ... ) const > { typedef R result_type; }; 146 155 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ) volatile > { typedef R result_type; }; 147 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ... ) volatile > { typedef R result_type; };156 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args..., ... ) volatile > { typedef R result_type; }; 148 157 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ) const volatile > { typedef R result_type; }; 149 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args... ... ) const volatile > { typedef R result_type; };158 template < typename R, typename C, typename... Args > struct weak_result_type_impl< R( C::* )( Args..., ... ) const volatile > { typedef R result_type; }; 150 159 #endif 151 160 } -
trunk/nv/stl/type_traits/primary.hh
r395 r402 60 60 // is_function_pointer / is_member_function pointer - extension 61 61 // TODO: sanity check - this is very different - http://en.cppreference.com/w/cpp/types/is_function 62 // TODO: "... ..." function match version?62 // TODO: "..., ..." function match version? 63 63 // TODO: call conventions really needed? 64 64 -
trunk/nv/stl/type_traits/properties.hh
r400 r402 160 160 template < typename R, typename... Args > 161 161 struct is_referenceable < R( Args... ) > : true_type {}; 162 #if NV_COMPILER != NV_MSVC163 162 template < typename R, typename... Args > 164 struct is_referenceable < R( Args...... ) > : true_type {}; 165 #endif 163 struct is_referenceable < R( Args..., ... ) > : true_type {}; 166 164 167 165 template < typename To, typename From > … … 293 291 static size_two test( ... ); 294 292 public: 295 static constexpr bool value = sizeof( test <T>( 0) ) == 1;293 static constexpr bool value = sizeof( test( static_cast<T*>( nullptr ) ) ) == 1; 296 294 }; 297 295 } -
trunk/src/core/library.cc
r399 r402 11 11 # include <windows.h> 12 12 # define NV_LIB_EXT ".dll" 13 # define NV_LIB_HANDLE HMODULE 14 # define NV_LIB_OPEN( name ) LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) 15 # define NV_LIB_GET( handle, name ) GetProcAddress( handle, name ) 16 # define NV_LIB_CLOSE( name ) !FreeLibrary( name ) 13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ) 14 # define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) ) 15 # define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 ) 17 16 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 18 17 # include <dlfcn.h> 19 18 # define NV_LIB_EXT ".so" 20 # define NV_LIB_HANDLE void*21 19 # define NV_LIB_OPEN( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL) 22 # define NV_LIB_GET( handle, name ) dlsym( handle, name )23 # define NV_LIB_CLOSE( name ) dlclose( name)20 # define NV_LIB_GET( handle, name ) dlsym( static_cast<void*>( handle ), name ) 21 # define NV_LIB_CLOSE( handle ) ( dlclose( static_cast<void*>( handle ) ) == 0 ) 24 22 #elif NV_PLATFORM == NV_APPLE 25 23 # include "macUtils.h" 26 24 # include <dlfcn.h> 27 25 # define NV_LIB_EXT ".dylib" 28 # define NV_LIB_HANDLE CFBundleRef29 26 # define NV_LIB_OPEN( name ) mac_loadExeBundle( name ) 30 27 # define NV_LIB_GET( handle, name ) mac_getBundleSym( handle, name ) 31 # define NV_LIB_CLOSE( name ) mac_unloadExeBundle( name)28 # define NV_LIB_CLOSE( handle ) ( mac_unloadExeBundle( handle ) == 0 ) 32 29 #endif 33 30 … … 83 80 } 84 81 85 m_handle = (void*)NV_LIB_OPEN( name.c_str() );82 m_handle = NV_LIB_OPEN( name.c_str() ); 86 83 87 84 if ( m_handle == NULL ) … … 96 93 void* library::get( string_view symbol ) 97 94 { 98 void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );95 void* result = NV_LIB_GET( m_handle, symbol.data() ); 99 96 if ( !result ) 100 97 { … … 106 103 void* nv::library::try_get( string_view symbol ) 107 104 { 108 return (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );105 return NV_LIB_GET( m_handle, symbol.data() ); 109 106 } 110 107 … … 116 113 void library::close() 117 114 { 118 if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )115 if ( ! NV_LIB_CLOSE( m_handle ) ) 119 116 { 120 117 NV_LOG_ERROR( "library : can't close library '", m_name, "'!" ); 121 118 } 122 m_handle = NULL;119 m_handle = nullptr; 123 120 } 124 121 125 122 library::~library() 126 123 { 127 if ( m_handle != NULL)124 if ( m_handle != nullptr ) 128 125 { 129 126 close(); … … 135 132 #if NV_PLATFORM == NV_WINDOWS 136 133 // We do hate WinAPI for code like this, don't we? 137 LPTSTR buffer = NULL;134 LPTSTR buffer = nullptr; 138 135 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 139 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );140 std::string msg( (char*)buffer);136 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL ); 137 std::string msg( reinterpret_cast<char*>( buffer ) ); 141 138 LocalFree( buffer ); 142 139 return msg; 143 140 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 144 return st ring(dlerror());141 return std::string( dlerror() ); 145 142 #else 146 return st ring("");143 return std::string(""); 147 144 #endif 148 145 } -
trunk/src/core/logger.cc
r399 r402 89 89 for ( auto& sink_info : m_log_sinks ) 90 90 { 91 if ( sink_info.sink && (sink_info.level >= (uint32)level) )91 if ( sink_info.sink && (sink_info.level >= static_cast<uint32>( level ) ) ) 92 92 { 93 93 // log and iterate … … 106 106 { 107 107 sink_info.sink = sink; 108 sink_info.level = (uint32)level;108 sink_info.level = static_cast<uint32>( level ); 109 109 return; 110 110 } … … 194 194 //if ( m_flush ) FlushFileBuffers( m_handle ); 195 195 #else 196 fwrite( stamp, ssize, 1, (FILE*)m_handle ); 197 fwrite( " [", 2, 1, (FILE*)m_handle ); 198 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, (FILE*)m_handle ); 199 fwrite( "] ", 2, 1, (FILE*)m_handle ); 200 fwrite( message.data(), message.size(), 1, (FILE*)m_handle ); 201 fwrite( "\n", 1, 1, (FILE*)m_handle ); 202 if ( m_flush ) fflush( (FILE*)m_handle ); 196 FILE* file = static_cast<FILE*>( m_handle ); 197 fwrite( stamp, ssize, 1, file ); 198 fwrite( " [", 2, 1, file ); 199 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, file ); 200 fwrite( "] ", 2, 1, file ); 201 fwrite( message.data(), message.size(), 1, file ); 202 fwrite( "\n", 1, 1, file ); 203 if ( m_flush ) fflush( file ); 203 204 #endif 204 205 } … … 226 227 CloseHandle( m_handle ); 227 228 #else 228 fclose( (FILE*) m_handle);229 fclose( static_cast<FILE*>( m_handle ) ); 229 230 #endif 230 231 } … … 244 245 { 245 246 uint32 ms = get_system_ms(); 246 unsigned int secs = (unsigned int)(ms / 1000);247 unsigned int mm = (unsigned int)( ms * 100 / 1000 ) % 100;248 unsigned int h = (unsigned int)(secs / (60*60));249 unsigned int m = (unsigned int)(secs / 60) % 60;247 unsigned int secs = static_cast<unsigned int>( ms / 1000 ); 248 unsigned int mm = static_cast<unsigned int>( ms * 100 / 1000 ) % 100; 249 unsigned int h = static_cast<unsigned int>( secs / (60*60) ); 250 unsigned int m = static_cast<unsigned int>( secs / 60 ) % 60; 250 251 unsigned int s = secs % 60; 251 252 #if NV_COMPILER == NV_MSVC -
trunk/src/core/profiler.cc
r399 r402 124 124 if ( c->m_calls > 0 ) 125 125 { 126 f64 pparent = ( (f64)c->m_total_time_us / (f64)c->m_parent->m_total_time_us ) * 100.f; 126 f64 ftotal_time_us = static_cast<f64>( c->m_total_time_us ); 127 f64 pparent = ( ftotal_time_us / static_cast<f64>( c->m_parent->m_total_time_us ) ) * 100.f; 127 128 uint32 calls = c->m_calls; 128 f64 total_ms = c->m_total_time_us / 1000.f;129 f64 avg_ms = ( (f64)c->m_total_time_us / (f64)c->m_calls) / 1000.f;129 f64 total_ms = ftotal_time_us / 1000.f; 130 f64 avg_ms = ( ftotal_time_us / static_cast<f64>( c->m_calls ) ) / 1000.f; 130 131 if ( indent > 0 ) nvmemset( buffer, '-', indent ); 131 132 snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent, -
trunk/src/core/random.cc
r395 r402 19 19 random::seed_type random::randomize() 20 20 { 21 std::mt19937& rng = *( ( std::mt19937* )m_data);21 std::mt19937& rng = *( reinterpret_cast< std::mt19937* >( m_data ) ); 22 22 seed_type seed = randomized_seed(); 23 23 rng.seed( seed ); … … 27 27 void random::set_seed( random::seed_type seed /*= 0 */ ) 28 28 { 29 std::mt19937& rng = *( ( std::mt19937* )m_data);29 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 30 30 rng.seed( seed == 0 ? randomized_seed() : seed ); 31 31 } … … 39 39 random::result_type random::rand() 40 40 { 41 std::mt19937& rng = *( ( std::mt19937* )m_data);41 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 42 42 return rng(); 43 43 } … … 45 45 sint32 random::srand( sint32 val ) 46 46 { 47 std::mt19937& rng = *( ( std::mt19937* )m_data);47 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 48 48 std::uniform_int_distribution<sint32> dist( 0, val - 1 ); 49 49 return dist( rng ); … … 52 52 uint32 random::urand( uint32 val ) 53 53 { 54 std::mt19937& rng = *( ( std::mt19937* )m_data);54 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 55 55 std::uniform_int_distribution<uint32> dist( 0, val - 1 ); 56 56 return dist( rng ); … … 59 59 f32 random::frand( f32 val ) 60 60 { 61 std::mt19937& rng = *( ( std::mt19937* )m_data);61 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 62 62 std::uniform_real_distribution<f32> dist( 0, val ); 63 63 return dist( rng ); … … 66 66 sint32 random::srange( sint32 min, sint32 max ) 67 67 { 68 std::mt19937& rng = *( ( std::mt19937* )m_data);68 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 69 69 std::uniform_int_distribution<sint32> dist( min, max ); 70 70 return dist( rng ); … … 73 73 uint32 random::urange( uint32 min, uint32 max ) 74 74 { 75 std::mt19937& rng = *( ( std::mt19937* )m_data);75 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 76 76 std::uniform_int_distribution<uint32> dist( min, max ); 77 77 return dist( rng ); … … 80 80 f32 random::frange( f32 min, f32 max ) 81 81 { 82 std::mt19937& rng = *( ( std::mt19937* )m_data);82 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 83 83 std::uniform_real_distribution<f32> dist( min, max ); 84 84 return dist( rng ); … … 87 87 uint32 random::dice( uint32 count, uint32 sides ) 88 88 { 89 std::mt19937& rng = *( ( std::mt19937* )m_data);89 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 90 90 std::uniform_int_distribution<uint32> dist( 1, sides ); 91 91 uint32 result = 0; … … 106 106 nv::vec2 nv::random::precise_unit_vec2() 107 107 { 108 std::mt19937& rng = *( ( std::mt19937* )m_data);108 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 109 109 std::uniform_real_distribution<f32> dist( 0, glm::pi<float>() * 2.f ); 110 110 float angle = dist( rng ); … … 114 114 nv::vec3 nv::random::precise_unit_vec3() 115 115 { 116 std::mt19937& rng = *( ( std::mt19937* )m_data);116 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 117 117 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); 118 118 std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() ); … … 129 129 nv::vec2 nv::random::fast_disk_point() 130 130 { 131 std::mt19937& rng = *( ( std::mt19937* )m_data);131 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 132 132 std::uniform_real_distribution<f32> dist( 0.0f, 1.0f ); 133 133 float r1 = dist( rng ); … … 140 140 nv::vec2 nv::random::precise_disk_point() 141 141 { 142 std::mt19937& rng = *( ( std::mt19937* )m_data);142 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 143 143 std::uniform_real_distribution<f32> unit( 0.0f, 1.0f ); 144 144 std::uniform_real_distribution<f32> angle( 0.0f, glm::pi<float>() ); … … 150 150 nv::vec3 nv::random::fast_sphere_point() 151 151 { 152 std::mt19937& rng = *( ( std::mt19937* )m_data);152 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 153 153 std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f ); 154 154 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); … … 168 168 nv::vec3 nv::random::precise_sphere_point() 169 169 { 170 std::mt19937& rng = *( ( std::mt19937* )m_data);170 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 171 171 std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f ); 172 172 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); … … 185 185 nv::vec2 nv::random::precise_ellipse_point( const vec2& radii ) 186 186 { 187 std::mt19937& rng = *( ( std::mt19937* )m_data);187 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 188 188 std::uniform_real_distribution<f32> distx( -radii.x, radii.x ); 189 189 std::uniform_real_distribution<f32> disty( -radii.y, radii.y ); … … 204 204 nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii ) 205 205 { 206 std::mt19937& rng = *( ( std::mt19937* )m_data);206 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 207 207 std::uniform_real_distribution<f32> distx( -radii.x, radii.x ); 208 208 std::uniform_real_distribution<f32> disty( -radii.y, radii.y ); … … 225 225 nv::vec2 nv::random::fast_hollow_disk_point( float iradius, float oradius ) 226 226 { 227 std::mt19937& rng = *( ( std::mt19937* )m_data);227 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 228 228 float idist2 = iradius * iradius; 229 229 float odist2 = oradius * oradius; … … 239 239 nv::vec3 nv::random::fast_hollow_sphere_point( float iradius, float oradius ) 240 240 { 241 std::mt19937& rng = *( ( std::mt19937* )m_data);241 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 242 242 float idist3 = iradius * iradius * iradius; 243 243 float odist3 = oradius * oradius * oradius; … … 254 254 nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii ) 255 255 { 256 std::mt19937& rng = *( ( std::mt19937* )m_data);256 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 257 257 vec2 iradii2 = iradii * iradii; 258 258 vec2 opoint = ellipse_edge( oradii ); … … 275 275 nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii ) 276 276 { 277 std::mt19937& rng = *( ( std::mt19937* )m_data);277 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 278 278 vec3 iradii2 = iradii * iradii; 279 279 vec3 opoint = ellipsoid_edge( oradii ); -
trunk/src/core/time.cc
r401 r402 85 85 nv::uint32 nv::get_cpu_ms() 86 86 { 87 return (uint32)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000.0) ) ;87 return static_cast<uint32>( static_cast<f32>( clock() - zero_timer.clock_zero ) / ( static_cast<f32>(CLOCKS_PER_SEC) / 1000.0f ) ) ; 88 88 } 89 89 90 90 nv::uint64 nv::get_cpu_us() 91 91 { 92 return (uint64)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0) ) ;92 return static_cast<uint64>( static_cast<f32>( clock() - zero_timer.clock_zero ) / ( static_cast<f32>(CLOCKS_PER_SEC) / 1000000.0f ) ) ; 93 93 } 94 94 … … 99 99 QueryPerformanceCounter(&now); 100 100 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 101 return (uint32) (1000.0 * result / (double) zero_timer.frequency.QuadPart);101 return static_cast<uint32>(1000.0 * result / static_cast<f64>( zero_timer.frequency.QuadPart ) ); 102 102 #else 103 103 struct timeval now; 104 104 gettimeofday(&now, NULL); 105 return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 );105 return static_cast<uint32>( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 ); 106 106 #endif 107 107 } … … 113 113 QueryPerformanceCounter(&now); 114 114 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 115 return (uint64) (1000000.0 * result / (double) zero_timer.frequency.QuadPart);115 return static_cast<uint64>(1000000.0 * result / static_cast<f64>( zero_timer.frequency.QuadPart ) ); 116 116 #else 117 117 struct timeval now; 118 118 gettimeofday(&now, NULL); 119 return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) );119 return static_cast<uint64>( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) ); 120 120 #endif 121 121 } -
trunk/src/stl/assert.cc
r396 r402 31 31 extern "C" { 32 32 extern void __assert(const char *, const char *, unsigned int, const char *) 33 throw()__attribute__ ((__noreturn__));33 __attribute__ ((__noreturn__)); 34 34 } 35 35 # else 36 36 extern "C" { 37 37 extern void __assert_fail(const char *, const char *, unsigned int, const char *) 38 throw()__attribute__ ((__noreturn__));38 __attribute__ ((__noreturn__)); 39 39 } 40 40 # endif 41 void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function )41 __attribute__( ( __noreturn__ ) ) void nv_internal_assert( const char * assertion, const char * file, unsigned int line, const char * function ) 42 42 { 43 43 # if NV_COMPILER == NV_CLANG -
trunk/src/stl/hash_table.cc
r395 r402 47 47 }; 48 48 49 static const nv::uint32 s_primes_size = ( sizeof( s_primes ) / sizeof( *s_primes ) );49 //static const nv::uint32 s_primes_size = ( sizeof( s_primes ) / sizeof( *s_primes ) ); 50 50 51 51 namespace nv 52 52 { 53 void* g_hash_table_empty[2] = { nullptr, (void*)uintptr_t( ~0) };53 void* g_hash_table_empty[2] = { nullptr, reinterpret_cast<void*>( uintptr_t( ~0 ) ) }; 54 54 } 55 55 -
trunk/src/stl/string.cc
r395 r402 15 15 using namespace nv; 16 16 17 static const double s_power_10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 18 10000000, 100000000, 1000000000 }; 17 //static const double s_power_10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; 19 18 20 19 std::string nv::slurp( const std::string& filename ) … … 41 40 { 42 41 char* s = str; 43 uint32 abs = ( n < 0 ) ? (uint32)( -n ) : (uint32)(n );42 uint32 abs = static_cast< uint32 >( n < 0 ? -n : n ); 44 43 do 45 44 { 46 *s++ = (char)( '0' + ( abs % 10 ) );45 *s++ = static_cast<char>( '0' + ( abs % 10 ) ); 47 46 abs /= 10; 48 47 } while ( abs > 0 ); … … 50 49 *s = '\0'; 51 50 string_reverse( str, s - 1 ); 52 return (nv::size_t)( s - str );51 return static_cast<nv::size_t>( s - str ); 53 52 } 54 53 … … 56 55 { 57 56 char* s = str; 58 uint64 abs = ( n < 0 ) ? (uint64)( -n ) : (uint64)(n );57 uint64 abs = static_cast< uint64 >( n < 0 ? -n : n ); 59 58 do 60 59 { 61 *s++ = (char)( '0' + ( abs % 10 ) );60 *s++ = static_cast<char>( '0' + ( abs % 10 ) ); 62 61 abs /= 10; 63 62 } while ( abs > 0 ); … … 65 64 *s = '\0'; 66 65 string_reverse( str, s - 1 ); 67 return (nv::size_t)( s - str );66 return static_cast<nv::size_t>( s - str ); 68 67 } 69 68 … … 73 72 do 74 73 { 75 *s++ = (char)( '0' + ( n % 10 ) );74 *s++ = static_cast<char>( '0' + ( n % 10 ) ); 76 75 n /= 10; 77 76 } while ( n > 0 ); 78 77 *s = '\0'; 79 78 string_reverse( str, s - 1 ); 80 return (nv::size_t)( s - str );79 return static_cast<nv::size_t>( s - str ); 81 80 } 82 81 … … 86 85 do 87 86 { 88 *s++ = (char)( '0' + ( n % 10 ) );87 *s++ = static_cast<char>( '0' + ( n % 10 ) ); 89 88 n /= 10; 90 89 } while ( n > 0 ); 91 90 *s = '\0'; 92 91 string_reverse( str, s - 1 ); 93 return (size_t)( s - str );92 return static_cast<nv::size_t>( s - str ); 94 93 } 95 94 … … 101 100 int result = snprintf( str, 64, "%.*g", 6, n ); 102 101 #endif 103 return result > 0 ? ( nv::size_t )result : 0;102 return static_cast<nv::size_t>( result > 0 ? result : 0 ); 104 103 } 105 104 … … 111 110 int result = snprintf( str, 64, "%.*g", 6, n ); 112 111 #endif 113 return result > 0 ? ( nv::size_t )result : 0;112 return static_cast<nv::size_t>( result > 0 ? result : 0 ); 114 113 } 115 114 116 sint32 buffer_to_sint32( const char* str, char** end )115 sint32 nv::buffer_to_sint32( const char* str, char** end ) 117 116 { 118 117 const char* s = str; … … 131 130 ++s; 132 131 } 133 if ( end != nullptr ) *end = (char*)s;132 if ( end != nullptr ) *end = const_cast<char*>( s ); 134 133 return positive ? result : -result; 135 134 } 136 135 137 sint64 buffer_to_sint64( const char* s, char** end )136 sint64 nv::buffer_to_sint64( const char* s, char** end ) 138 137 { 139 138 while ( *s == ' ' ) ++s; … … 151 150 ++s; 152 151 } 153 if ( end != nullptr ) *end = (char*)s;152 if ( end != nullptr ) *end = const_cast<char*>( s ); 154 153 return positive ? result : -result; 155 154 } 156 155 157 uint32 buffer_to_uint32( const char* s, char** end )156 uint32 nv::buffer_to_uint32( const char* s, char** end ) 158 157 { 159 158 while ( *s == ' ' ) ++s; … … 161 160 while ( *s >= '0' && *s <= '9' ) 162 161 { 163 result = ( result * 10 ) + (uint32)( *s - '0' );162 result = ( result * 10 ) + static_cast<uint32>( *s - '0' ); 164 163 ++s; 165 164 } 166 if ( end != nullptr ) *end = (char*)s;165 if ( end != nullptr ) *end = const_cast<char*>( s ); 167 166 return result; 168 167 } 169 168 170 uint64 buffer_to_uint64( const char* s, char** end )169 uint64 nv::buffer_to_uint64( const char* s, char** end ) 171 170 { 172 171 while ( *s == ' ' ) ++s; … … 174 173 while ( *s >= '0' && *s <= '9' ) 175 174 { 176 result = ( result * 10 ) + (uint32)( *s - '0' );175 result = ( result * 10 ) + static_cast<uint32>( *s - '0' ); 177 176 ++s; 178 177 } 179 if ( end != nullptr ) *end = (char*)s;178 if ( end != nullptr ) *end = const_cast<char*>( s ); 180 179 return result; 181 180 } 182 181 183 float buffer_to_f32( const char* s, char** end )182 float nv::buffer_to_f32( const char* s, char** end ) 184 183 { 185 184 return strtof( s, end ); 186 185 } 187 186 188 double buffer_to_f64( const char* s, char** end )187 double nv::buffer_to_f64( const char* s, char** end ) 189 188 { 190 189 return strtod( s, end );
Note: See TracChangeset
for help on using the changeset viewer.