Changeset 374 for trunk


Ignore:
Timestamp:
05/26/15 17:35:06 (10 years ago)
Author:
epyon
Message:
  • MASSIVE commit
  • common.hh - size_t, ptrdiff_t, nv:: namespace, NV_ALIGN_OF and basic template tools
  • STL - algorithm.hh, iterator.hh, limits.hh, numeric.hh and type_info.hh
  • STL - updates to memory, array and string
Location:
trunk
Files:
5 added
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/common.hh

    r373 r374  
    137137#define NV_RESTRICT_VAR __restrict
    138138#define NV_NOEXCEPT throw()
     139#define NV_ALIGN_OF(type) __alignof(type)
    139140//#define NV_CONSTEXPR
    140141#elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG
     
    145146#define NV_RESTRICT_VAR __restrict__
    146147#define NV_NOEXCEPT noexcept
     148#define NV_ALIGN_OF(type) alignof(type)
    147149//#define NV_CONSTEXPR constexpr
    148150#else
     
    153155#define NV_RESTRICT_VAR
    154156#define NV_NOEXCEPT
     157#define NV_ALIGN_OF
    155158//#define NV_CONSTEXPR
    156159#endif
     
    171174#endif
    172175
    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])))))
    174177#define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) )
    175178
     
    180183                class state;
    181184        }
     185
     186        using ::size_t; // typedef decltype( sizeof( int ) ) size_t;
     187        using ::ptrdiff_t;
    182188
    183189        // Typedefs for fixed size types.
     
    230236        };
    231237
    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 ) );
    236275        }
    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
    241292        }
    242293
     294        template <typename T, typename U>
     295        T narrow_cast( const U& a )
     296        {
     297                return static_cast<T>( a & T( -1 ) );
     298        }
     299
    243300} // 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_DEBUG
    255         T* p = dynamic_cast<T*>(x);
    256         if (p == 0)
    257         {
    258 #ifdef NV_LOG
    259                 NV_THROW( std::bad_cast );
    260 #endif
    261         }
    262 
    263         return p;
    264 #else
    265         return static_cast<T*>(x);
    266 #endif
    267 }
    268 
    269 template <typename T, typename U>
    270 T narrow_cast(const U& a)
    271 {
    272         return static_cast<T>(a & T(-1) );
    273 }
    274301
    275302static_assert( sizeof( nv::sint8 ) == 1, "sint8 size isn't 1 bytes" );
  • trunk/nv/core/position.hh

    r372 r374  
    1717#include <nv/stl/math.hh>
    1818#include <nv/stl/range.hh>
     19#include <nv/stl/utility.hh>
    1920
    2021namespace nv
     
    2627        {
    2728                typedef position::value_type value_type;
    28                 typedef std::size_t size_type;
     29                typedef size_t size_type;
    2930                typedef rectangle type;
    3031               
     
    278279                {
    279280                        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 );
    283284                        return true;
    284285                }
     
    293294                {
    294295                        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() );
    297298                        return true;
    298299                }
     
    303304                void repair()
    304305                {
    305                         if (ul.x > lr.x) std::swap( ul.x, lr.x );
    306                         if (ul.y > lr.y) std::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 );
    307308                }
    308309
     
    314315                void include_point( position p )
    315316                {
    316                         lr = nv::max( lr, p );
    317                         ul = nv::min( ul, p );
     317                        lr = glm::max( lr, p );
     318                        ul = glm::min( ul, p );
    318319                }
    319320
  • trunk/nv/core/types.hh

    r373 r374  
    110110                        i_type->size = sizeof( TYPE );
    111111
    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 > ;
    114114                        m_idx_types[typeid( TYPE )] = i_type;
    115115                        m_type_list.push_back( i_type );
  • trunk/nv/formats/md5_loader.hh

    r368 r374  
    6060                virtual mesh_data_pack* release_mesh_data_pack();
    6161                virtual size_t get_mesh_count() const { return m_meshes.size(); }
    62         protected:
    63                 struct md5_joint_info
    64                 {
    65                         int         flags;
    66                         size_t      start_index;
    67                 };
    6862
    6963                struct md5_weight
     
    7266                        float     bias;
    7367                        glm::vec3 pos;
     68                };
     69
     70        protected:
     71                struct md5_joint_info
     72                {
     73                        int         flags;
     74                        size_t      start_index;
    7475                };
    7576
  • trunk/nv/interface/image_data.hh

    r368 r374  
    5656                void initialize( const uint8* data )
    5757                {
    58                         std::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();
    5959                        m_data = new uint8[ bsize ];
    6060                        std::copy( data, data + bsize, m_data );
  • trunk/nv/interface/interpolation_template.hh

    r368 r374  
    1919
    2020        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& )
    2222        {
    2323                key_slot_info< KEY, SLOT >::interpolate( key, k1, k2, factor );
     
    2525
    2626        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& )
    2828        {
    2929        }
     
    3232        void interpolate_key( KEY& key, const KEY& k1, const KEY& k2, float factor )
    3333        {
    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 >() );
    3838        }
    3939
     
    8585
    8686                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& )
    8888                { return mat4(); }
    8989                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& )
    9191                { return extract_matrix_p_impl(k); }
    9292                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& )
    9494                { return extract_matrix_r_impl(k); }
    9595                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& )
    9797                { return extract_matrix_s_impl(k); }
    9898                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& )
    100100                { return extract_matrix_pr_impl(k); }
    101101                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& )
    103103                { return extract_matrix_rs_impl(k); }
    104104                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& )
    106106                { return extract_matrix_ps_impl(k); }
    107107                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& )
    109109                { return extract_matrix_prs_impl(k); }
    110110
    111111
    112112                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(); }
    114114                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 ); }
    116116                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 ); }
    118118                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 ); }
    120120
    121121
    122122
    123123                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& )
    125125                {
    126126                        static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!");
     
    131131
    132132                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& )
    134134                {
    135135                        static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!");
    136136                        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 >()
    140140                                );
    141141                }
    142142
    143143                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& )
    145145                {
    146146                        static_assert( key_has_slot< KEY, animation_slot::POSITION >::value == false, "key!");
     
    151151
    152152                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& )
    154154                {
    155155                        static_assert( key_has_slot< KEY, animation_slot::TFORM >::value == false, "key!");
    156156                        static_assert( key_has_slot< KEY, animation_slot::SCALE >::value == false, "key!");
    157157                        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 >()
    160160                                );
    161161                }
     
    165165        mat4 extract_matrix( const KEY& k )
    166166        {
    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 >() );
    168168        }
    169169
     
    171171        transform extract_transform( const KEY& k )
    172172        {
    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 >() );
    174174        }
    175175
  • trunk/nv/lib/curses.hh

    r319 r374  
    2929#endif
    3030
    31 #include <stdarg.h>
    32 #include <stddef.h>
     31#ifdef CURSES_PDC_WIDE
    3332#include <wchar.h>
     33#endif
    3434
    3535#include <nv/lib/detail/curses_types.inc>
     
    4141#endif
    4242
     43#define FILE void
    4344#include <nv/lib/detail/curses_functions.inc>
    44 
     45#undef FILE
    4546#undef NV_CURSES_FUN
    4647}
  • trunk/nv/lua/lua_glm.hh

    r368 r374  
    77#define NV_LUA_GLM_HH
    88
    9 #include <new>
    109#include <nv/core/common.hh>
    1110#include <nv/stl/math.hh>
  • trunk/nv/stl/allocator.hh

    r368 r374  
    2020
    2121#include <nv/core/common.hh>
    22 #include <nv/core/type_traits.hh>
     22#include <nv/stl/type_traits.hh>
    2323
    2424namespace nv
     
    4141                T *create( Args&&... args )
    4242                {
    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 )... );
    4444                }
    4545
  • trunk/nv/stl/any.hh

    r368 r374  
    1717
    1818#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>
    2022
    2123namespace nv
     
    4244                template< typename T >
    4345                any( T&& value )
    44                         : m_content( new holder<T>( std::forward<T>(value) ) )
     46                        : m_content( new holder<T>( forward<T>(value) ) )
    4547                {}
    4648
     
    5254                any& swap( any& rhs )
    5355                {
    54                         std::swap( m_content, rhs.m_content );
     56                        nv::swap( m_content, rhs.m_content );
    5557                        return *this;
    5658                }
     
    7173                any& operator= ( T&& rhs )
    7274                {
    73                         any( std::forward<T>(rhs) ).swap(*this);
     75                        any( forward<T>(rhs) ).swap(*this);
    7476                        return *this;
    7577                }
     
    123125                        {
    124126                        }
    125                         holder( T&& value ) : held(std::forward<T>(value))
     127                        holder( T&& value ) : held(forward<T>(value))
    126128                        {
    127129                        }
  • trunk/nv/stl/array.hh

    r368 r374  
    1616#include <nv/core/common.hh>
    1717#include <nv/stl/memory.hh>
     18#include <nv/stl/iterator.hh>
     19#include <nv/stl/utility.hh>
    1820#include <vector>
    1921#include <algorithm>
     
    2325{
    2426        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 >
    2930        {
    3031        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]; }
    5759
    5860                reference operator[]( size_type i )
     
    6870                }
    6971
    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;
    90199        };
    91200
     
    94203        {
    95204        public:
    96                 typedef T              value_type;
    97                 typedef T*             iterator;
    98                 typedef const T*       const_iterator;
    99                 typedef T&             reference;
    100                 typedef const T&       const_reference;
    101                 typedef std::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;
    106215
    107216                dynamic_array() : detail::data_base< T, false, 0 >() {}
     
    166275//              size_type        size() const     { return m_size; }
    167276//              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(); }
    169278//              const value_type* data() const { return m_data; }
    170279//              value_type*       data()       { return m_data; }
     
    191300        };
    192301
     302
     303
    193304}
    194305
  • trunk/nv/stl/flags.hh

    r368 r374  
    6363                        friend class flags<SIZE,T>;
    6464                public:
    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 std::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;
    7373
    7474                        T operator* () const { return m_index; }
  • trunk/nv/stl/math.hh

    r368 r374  
    8484                static const size_t size = 4;
    8585        };
    86 
    87         using glm::max;
    88         using glm::min;
    8986
    9087        enum datatype
  • trunk/nv/stl/memory.hh

    r372 r374  
    1818#include <nv/core/common.hh>
    1919#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>
    2124
    2225namespace nv
     
    2528        namespace detail
    2629        {
     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        {
    27208                template < typename PARENT, typename T, bool CONST, typename BASE = empty_base_class<PARENT> >
    28209                class pointer_iterators {};
     
    33214                public:
    34215                        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;
    36217
    37218                        inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); }
     
    52233                        typedef T*       iterator;
    53234                        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;
    56237
    57238                        inline const_iterator begin() const { return const_iterator( static_cast<const PARENT&>( *this ).data() ); }
     
    226407        };
    227408
     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        };
    228462
    229463}
  • trunk/nv/stl/string.hh

    r373 r374  
    2222
    2323#include <string>
    24 #include <algorithm>
    2524#include <cstring>
    2625#include <sstream>
     
    3029#include <nv/stl/memory.hh>
    3130#include <nv/stl/exception.hh>
     31#include <nv/stl/algorithm.hh>
    3232
    3333namespace nv
     
    222222        inline std::string& remove_chars( std::string& s, const std::string& chars )
    223223        {
    224                 s.erase(remove_if(s.begin(), s.end(),
     224                s.erase(nv::remove_if(s.begin(), s.end(),
    225225                        [&chars](const char& c) {
    226226                                return chars.find(c) != std::string::npos;
     
    235235                if ( std::string::npos != lastdot )
    236236                        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 ) ); } );
    238238                return ext;
    239239        }
     
    346346                typedef pointer        const_iterator;
    347347                typedef const_iterator iterator;
    348                 typedef std::size_t    size_type;
    349                 typedef std::ptrdiff_t difference_type;
     348                typedef size_t         size_type;
     349                typedef ptrdiff_t      difference_type;
    350350
    351351                static NV_CONSTEXPR_CONST size_type npos = size_type( -1 );
     
    373373                int compare( const string_base& rhs ) const
    374374                {
    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 ) );
    376376                        return cmp != 0 ? cmp : ( m_size == rhs.m_size ? 0 : m_size < rhs.m_size ? -1 : 1 );
    377377                }
     
    389389                {
    390390                        if ( pos >= m_size ) return npos;
    391                         const_iterator it = std::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 );
    393393                }
    394394                size_type find( char c, size_type pos = 0 ) const
    395395                {
    396396                        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 );
    399399                }
    400400                size_type rfind( const string_base& s, size_type pos = 0 ) const
    401401                {
    402402                        if ( pos >= m_size ) return npos;
    403                         const_reverse_iterator it = std::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 );
    405405                }
    406406                size_type rfind( char c, size_type pos = 0 ) const
    407407                {
    408408                        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 );
    411411                }
    412412                size_type find_first_of( char c ) const { return find( c ); }
    413413                size_type find_first_of( const string_base& s ) const
    414414                {
    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 );
    417417                }
    418418                size_type find_last_of( char c )  const { return rfind( c ); }
    419419                size_type find_last_of( const string_base& s ) const
    420420                {
    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 );
    423423                }
    424424                size_type find_first_not_of( const string_base& s ) const
     
    426426                        for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
    427427                                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 );
    429429                        return npos;
    430430                }
     
    433433                        for ( const_iterator it = this->cbegin(); it != this->cend(); ++it )
    434434                                if ( c != *it )
    435                                         return ( size_type )std::distance( this->cbegin(), it );
     435                                        return ( size_type )distance( this->cbegin(), it );
    436436                        return npos;
    437437                }
     
    440440                        for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    441441                                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 );;
    443443                        return npos;
    444444                }
     
    447447                        for ( const_reverse_iterator it = this->crbegin(); it != this->crend(); ++it )
    448448                                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 );
    450450                        return npos;
    451451                }
     
    454454                string_ref substr( size_type p, size_type n = npos ) const;
    455455
    456                 inline std::size_t hash() const
     456                inline size_t hash() const
    457457                {
    458458                        const char* str = m_data;
  • trunk/nv/stl/type_traits.hh

    r373 r374  
    1010 */
    1111// TODO: "......" function match version?
    12 // TODO: remove type_traits
    1312// TODO: remove typeinfo?
    1413
     
    1817#include <nv/core/common.hh>
    1918
     19#include <type_traits>
    2020namespace nv
    2121{
    2222
    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 >
    5724        struct is_same : false_type {};
    5825
    59         template< typename T >
     26        template < typename T >
    6027        struct is_same < T, T > : true_type {};
    6128
    62         template< typename T >
     29        template < typename T >
    6330        struct is_array : false_type {};
    6431
    65         template< typename T, size_t N >
     32        template < typename T, size_t N >
    6633        struct is_array < T[N] > : true_type {};
    6734
    68         template< typename T >
     35        template < typename T >
    6936        struct is_array < T[] > : true_type {};
    7037
    71         template< typename T >
     38        template < typename T >
    7239        struct is_lvalue_reference : false_type {};
    7340
    74         template< typename T >
     41        template < typename T >
    7542        struct is_lvalue_reference < T& > : true_type{};
    7643
    77         template< typename T >
     44        template < typename T >
    7845        struct is_rvalue_reference : false_type {};
    7946
    80         template< typename T >
     47        template < typename T >
    8148        struct is_rvalue_reference < T&& > : true_type{};
    8249
     50        template < typename _Ty>
     51        struct is_reference : integral_constant < bool, is_lvalue_reference<_Ty>::value || is_rvalue_reference<_Ty>::value > {};
     52
    8353        template < typename T >
    8454        struct is_enum : integral_constant < bool, __is_enum( T ) > {};
    8555
    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
    8867
    8968        template< typename T >
     
    222201        namespace detail
    223202        {
    224                 // TODO: these seem to simple compared to MSVC/GCC - so we'll leave them in
    225                 // 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 END
    235 
    236203                template< typename T, bool CONST, bool VOLATILE>
    237204                struct cv_selector;
     
    454421#endif
    455422
     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
    456450        namespace detail
    457451        {
     
    606600        };
    607601
     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
     653NV_ALIGNED_ARRAY( 1 )
     654NV_ALIGNED_ARRAY( 2 )
     655NV_ALIGNED_ARRAY( 4 )
     656NV_ALIGNED_ARRAY( 8 )
     657NV_ALIGNED_ARRAY( 16 )
     658NV_ALIGNED_ARRAY( 32 )
     659NV_ALIGNED_ARRAY( 64 )
     660NV_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
    608674}
    609675
  • trunk/nv/stl/utility.hh

    r373 r374  
    1 // Copyright (C) 2014 ChaosForge Ltd
     1// Copyright (C) 2015 ChaosForge Ltd
    22// http://chaosforge.org/
    33//
     
    3939        }
    4040
     41        // TODO: change to swap once you get rid of STL
    4142        template< typename T >
    4243        void swap( T& x, T& y )
     
    4748        }
    4849
     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
    4962}
    5063
    51 #endif NV_STL_UTILITY_HH
     64#endif // NV_STL_UTILITY_HH
  • trunk/src/curses/curses_terminal.cc

    r369 r374  
    6565        }
    6666        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 );
    6868}
    6969
     
    8080        m_update_needed = true;
    8181        ::clear();
    82         move( m_cursor.y-1, m_cursor.x-1 );
     82        ::move( m_cursor.y-1, m_cursor.x-1 );
    8383}
    8484
     
    160160{
    161161        terminal::set_cursor( p );
    162         move( m_cursor.y-1, m_cursor.x-1 );
     162        ::move( m_cursor.y-1, m_cursor.x-1 );
    163163}
    164164
  • trunk/src/engine/particle_engine.cc

    r365 r374  
    77#include <nv/interface/device.hh>
    88#include <nv/core/random.hh>
     9#include <nv/stl/utility.hh>
    910#include <nv/lua/lua_glm.hh>
    1011#include <nv/core/logging.hh>
    11 #include <cmath>
    1212
    1313static const char *nv_particle_engine_vertex_shader_world =
     
    203203        if ( datap->average )
    204204        {
    205                 float norm_factor = glm::min( factor, 1.0f );
     205                float norm_factor = nv::min( factor, 1.0f );
    206206                for ( uint32 i = 0; i < count; ++i )
    207207                        p[i].velocity = datap->force_vector * norm_factor + p[i].velocity * ( 1.0f - norm_factor );
     
    696696                        {
    697697                                info->count--;
    698                                 std::swap( info->particles[i], info->particles[info->count] );
     698                                swap( info->particles[i], info->particles[info->count] );
    699699                        }
    700700                }
  • trunk/src/formats/md2_loader.cc

    r367 r374  
    238238}
    239239
    240 size_t md2_loader::get_max_frames() const
     240nv::size_t md2_loader::get_max_frames() const
    241241{
    242242        return static_cast< size_t >( ((md2_t*)m_md2)->header.num_frames );
  • trunk/src/formats/md3_loader.cc

    r367 r374  
    172172        source.read( surface->vertices, sizeof( md3_vertex_t ), static_cast<size_t>( surface->header.num_verts * surface->header.num_frames ) );
    173173
    174         if ( source.tell() != static_cast<std::size_t>( pos + surface->header.ofs_end ) ) return false;
     174        if ( source.tell() != static_cast<size_t>( pos + surface->header.ofs_end ) ) return false;
    175175
    176176        return true;
  • trunk/src/formats/md5_loader.cc

    r367 r374  
    344344                vtc.tangent  = glm::vec3(0);
    345345
    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; } );
    347348
    348349                if ( weight_count > 4 )
  • trunk/src/formats/obj_loader.cc

    r319 r374  
    5353        std::string next_name;
    5454
    55         std::size_t size;
    56         bool        eof;
     55        size_t size;
     56        bool   eof;
    5757
    5858        obj_reader();
     
    172172{
    173173        mesh_data_reader( bool normals ) : m_normals( normals ) {}
    174         virtual std::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 )
    175175        {
    176176                if ( count < 3 ) return 0; // TODO : report error?
     
    178178                // TODO : support if normals not present;
    179179                vec3 nullvec;
    180                 std::size_t result = 0;
     180                size_t result = 0;
    181181                // Simple triangulation - obj's shouldn't have more than quads anyway
    182182
     
    278278                }
    279279
    280                 for (std::size_t a = 0; a < count; ++a )
     280                for (size_t a = 0; a < count; ++a )
    281281                {
    282282                        const vec3& n = m_data[a].normal;
  • trunk/src/gfx/image.cc

    r323 r374  
    44
    55#include "nv/gfx/image.hh"
    6 
    7 #include <algorithm>
    86
    97using namespace nv;
  • trunk/src/io/c_stream.cc

    r319 r374  
    66#include <sys/stat.h>
    77#include "nv/io/c_stream.hh"
    8 #include <limits>
    98
    109using namespace nv;
  • trunk/src/io/std_stream.cc

    r319 r374  
    88
    99#include "nv/io/std_stream.hh"
    10 #include <algorithm>
     10#include "nv/stl/math.hh"
     11#include "nv/stl/utility.hh"
    1112
    1213using namespace nv;
     
    1516        : m_stream( source )
    1617        , 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 ) ) )
    1920{
    2021        char *end = &m_buffer.front() + m_buffer.size();
  • trunk/src/lib/curses.cc

    r319 r374  
    1111#include "nv/core/library.hh"
    1212
     13#define FILE void
    1314#define NV_CURSES_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
    1415#include <nv/lib/detail/curses_functions.inc>
     
    2122        curses_library.open( path );
    2223
    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);
    2425#       include <nv/lib/detail/curses_functions.inc>
    2526#       undef NV_CURSES_FUN
  • trunk/src/lua/lua_area.cc

    r368 r374  
    7979{
    8080        nv::rectangle* a = to_parea( L, 1 );
    81         std::size_t l;
     81        nv::size_t l;
    8282        const char* index = lua_tolstring( L, 2, &l );
    8383        if ( l == 1 && index[0] == 'a' )
     
    101101{
    102102        nv::rectangle* a = to_parea( L, 1 );
    103         std::size_t l;
     103        nv::size_t l;
    104104        const char* index = lua_tolstring( L, 2, &l );
    105105        nv::ivec2 value( to_coord( L, 3 ) );
  • trunk/src/lua/lua_map_tile.cc

    r369 r374  
    77#include "nv/lua/lua_map_tile.hh"
    88
    9 #include <numeric>
    109#include "nv/lua/lua_map_area.hh"
    1110#include "nv/stl/flags.hh"
     11#include "nv/stl/numeric.hh"
     12#include "nv/stl/algorithm.hh"
    1213#include "nv/core/random.hh"
    1314#include "nv/lua/lua_area.hh"
     
    5960        map_tile tile;
    6061
    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 );
    6263        tile.size_x = (nv::uint16)( code.find( '\n' ) );
    6364        if ( tile.size_x == 0 )
     
    236237        nv::uint16 org_x = tile->size_x;
    237238        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 );
    240241
    241242        nv::uint8* data = new nv::uint8[ new_x * new_y ];
  • trunk/src/stl/string.cc

    r368 r374  
    2828}
    2929
    30 size_t nv::sint32_to_buffer( sint32 n, char* str )
     30nv::size_t nv::sint32_to_buffer( sint32 n, char* str )
    3131{
    3232        char* s = str;
     
    4343}
    4444
    45 size_t nv::sint64_to_buffer( sint64 n, char* str )
     45nv::size_t nv::sint64_to_buffer( sint64 n, char* str )
    4646{
    4747        char* s = str;
     
    5858}
    5959
    60 size_t nv::uint32_to_buffer( uint32 n, char* str )
     60nv::size_t nv::uint32_to_buffer( uint32 n, char* str )
    6161{
    6262        char* s = str;
     
    7171}
    7272
    73 size_t nv::uint64_to_buffer( uint64 n, char* str )
     73nv::size_t nv::uint64_to_buffer( uint64 n, char* str )
    7474{
    7575        char* s = str;
     
    8484}
    8585
    86 size_t nv::f32_to_buffer( f32 n, char* str )
     86nv::size_t nv::f32_to_buffer( f32 n, char* str )
    8787{
    8888#if NV_COMPILER == NV_MSVC
     
    9595}
    9696
    97 size_t nv::f64_to_buffer( f64 n, char* str )
     97nv::size_t nv::f64_to_buffer( f64 n, char* str )
    9898{
    9999#if NV_COMPILER == NV_MSVC
Note: See TracChangeset for help on using the changeset viewer.