Changeset 383 for trunk


Ignore:
Timestamp:
06/02/15 20:56:15 (10 years ago)
Author:
epyon
Message:
  • more work on stl
  • fully working vectors!
  • copy & copy_n
  • removal of a lot of std code!
Location:
trunk
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv.lua

    r368 r383  
    147147
    148148        configuration "vs*"
    149                 defines { "_SECURE_SCL=0", "_CRT_SECURE_NO_WARNINGS=1" }
     149                defines { "_SECURE_SCL=0", "_CRT_SECURE_NO_WARNINGS=1", "_ITERATOR_DEBUG_LEVEL=0", "_HAS_ITERATOR_DEBUGGING=0" }
    150150
    151151if _ACTION == "gmake-clang" then
  • trunk/nv/core/common.hh

    r382 r383  
    66#ifndef NV_CORE_COMMON_HH
    77#define NV_CORE_COMMON_HH
     8
     9#define _ITERATOR_DEBUG_LEVEL 0
    810
    911// NV Library version
  • trunk/nv/core/profiler.hh

    r371 r383  
    2121#if NV_PROFILER
    2222#define NV_PROFILE( tag ) nv::profiler_guard __profile( tag )
     23#define NV_PROFILE_IF( tag, condition ) nv::profiler_condition_guard __profile( tag, condition )
    2324#else
    2425#define NV_PROFILE( tag )
     26#define NV_PROFILE_IF( tag, condition )
    2527#endif
     28
    2629
    2730namespace nv
     
    6871                friend class auto_singleton< profiler >;
    6972                friend class profiler_guard;
     73                friend class profiler_condition_guard;
    7074                void log_report();
    7175        private:
     
    8993        };
    9094
     95        class profiler_condition_guard
     96        {
     97        public:
     98                profiler_condition_guard( string_ref tag, bool condition )
     99                        : m_active( condition )
     100                {
     101                        if ( m_active ) profiler::pointer()->start_profile( tag );
     102                }
     103
     104                ~profiler_condition_guard()
     105                {
     106                        if ( m_active ) profiler::pointer()->stop_profile();
     107                }
     108        private:
     109                bool m_active;
     110        };
     111
    91112} // namespace nv
    92113
  • trunk/nv/formats/assimp_loader.hh

    r379 r383  
    3131        private:
    3232                mesh_nodes_data* release_merged_bones( mesh_data* meshes );
    33                 bool load_bones( size_t index, std::vector< mesh_node_data >& bones );
     33                bool load_bones( size_t index, array_ref< mesh_node_data > bones );
    3434                void load_mesh_data( mesh_data* data, size_t index );
    3535                sint16 load_node( uint32 anim_id, mesh_node_data* nodes, const void* vnode, sint16 this_id, sint16 parent_id );
  • trunk/nv/formats/md2_loader.hh

    r368 r383  
    1515
    1616#include <nv/core/common.hh>
    17 #include <unordered_map>
    1817#include <nv/stl/array.hh>
    1918#include <nv/interface/mesh_loader.hh>
     
    3736        private:
    3837                void* m_md2;
    39                 std::vector< uint16 > m_new_indexes;
    40                 std::vector< uint16 > m_new_vindexes;
    41                 std::vector< uint16 > m_new_tindexes;
     38                vector< uint16 > m_new_indexes;
     39                vector< uint16 > m_new_vindexes;
     40                vector< uint16 > m_new_tindexes;
    4241        };
    4342
  • trunk/nv/formats/md3_loader.hh

    r368 r383  
    4343        private:
    4444                void release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface );
    45                 key_raw_channel* load_tags( const std::string& tag );
     45                key_raw_channel* load_tags( const string_ref& tag );
    4646                bool m_merge_all;
    4747                void* m_md3;
  • trunk/nv/formats/md5_loader.hh

    r374 r383  
    8383        protected:
    8484                void reset();
    85                 void build_frame_skeleton( mesh_node_data* nodes, uint32 index, const std::vector<md5_joint_info>& joint_info, const std::vector<transform>& base_frames, const std::vector<float>& frame_data );
     85                void build_frame_skeleton( mesh_node_data* nodes, uint32 index, const const_array_ref<md5_joint_info>& joint_info, const const_array_ref<transform>& base_frames, const const_array_ref<float>& frame_data );
    8686                bool prepare_mesh( mesh_node_data* nodes, uint32 vtx_count, mesh_data* mdata, md5_weight* weights, md5_weight_info* weight_info );
    8787        protected:
  • trunk/nv/formats/obj_loader.hh

    r319 r383  
    3131                ~obj_loader();
    3232        private:
    33                 vertex_descriptor         m_descriptor;
    34                 bool                      m_normals;
    35                 bool                      m_tangents;
    36                 std::vector< mesh_data* > m_meshes;
     33                vertex_descriptor    m_descriptor;
     34                bool                 m_normals;
     35                bool                 m_tangents;
     36                vector< mesh_data* > m_meshes;
    3737        };
    3838
  • trunk/nv/interface/context.hh

    r350 r383  
    297297                {
    298298                        vertex_array  va = create_vertex_array();
    299                         const std::vector< mesh_raw_channel* >& channels = data->get_raw_channels();
     299                        const_array_ref< mesh_raw_channel* > channels = data->get_raw_channels();
    300300                        for ( uint32 ch = 0; ch < channels.size(); ++ch )
    301301                        {
  • trunk/nv/interface/mesh_data.hh

    r379 r383  
    107107                }
    108108
    109                 const std::vector< mesh_raw_channel* >& get_raw_channels() const { return m_channels; }
    110                 const mesh_raw_channel*           get_index_channel() const { return m_index_channel; }
     109                const_array_ref< mesh_raw_channel* > get_raw_channels() const { return m_channels; }
     110                const mesh_raw_channel*              get_index_channel() const { return m_index_channel; }
    111111                size_t get_channel_count() const { return m_channels.size(); }
    112112                const mesh_raw_channel* get_channel( size_t index ) const
     
    214214                }
    215215        private:
    216                 std::string                      m_name;
    217                 std::vector< mesh_raw_channel* > m_channels;
    218                 mesh_raw_channel*                m_index_channel;
     216                std::string                 m_name;
     217                vector< mesh_raw_channel* > m_channels;
     218                mesh_raw_channel*           m_index_channel;
    219219        };
    220220
  • trunk/nv/lua/lua_dispatch.hh

    r368 r383  
    44// This file is part of NV Libraries.
    55// For conditions of distribution and use, see copyright notice in nv.hh
    6 //
    7 // TODO: the calls are supported only up to 4 parameters because:
    8 //    -- if you have more than 4 params, you're doing something wrong
    9 //    -- once the Variadic Templates cometh, for great justice we will win!
    10 //
    11 // TODO: this is a job for std::forward, but I'll take care of it later
    126
    137#ifndef NV_LUA_DISPATCH_HH
     
    3832                                static void do_call(lua_State* L, R(*func)(Args...), Vs&&... vs)
    3933                                {
    40                                         push_value(L, func(std::forward<Vs>(vs)...));
     34                                        push_value(L, func( nv::forward<Vs>(vs)...));
    4135                                }
    4236                                template <class C, typename... Args, typename... Vs>
    4337                                static void do_call(lua_State* L, C* c, R(C::*func)(Args...), Vs&&... vs)
    4438                                {
    45                                         push_value(L, (*c.*func)(std::forward<Vs>(vs)...));
     39                                        push_value(L, (*c.*func)( nv::forward<Vs>(vs)...));
    4640                                }
    4741                                template <class C, typename... Args, typename... Vs>
    4842                                static void do_call( lua_State* L, C const * c, R( C::*func )( Args... ) const, Vs&&... vs )
    4943                                {
    50                                         push_value( L, ( *c.*func )( std::forward<Vs>( vs )... ) );
     44                                        push_value( L, ( *c.*func )( nv::forward<Vs>( vs )... ) );
    5145                                }
    5246                        };
     
    5852                                static void do_call(lua_State*, void(*func)(Args...), Vs&&... vs)
    5953                                {
    60                                         func(std::forward<Vs>(vs)...);
     54                                        func( nv::forward<Vs>(vs)...);
    6155                                }
    6256                                template <class C, typename... Args, typename... Vs>
    6357                                static void do_call(lua_State*, C* c, void(C::*func)(Args...), Vs&&... vs)
    6458                                {
    65                                         (*c.*func)(std::forward<Vs>(vs)...);
     59                                        (*c.*func)( nv::forward<Vs>(vs)...);
    6660                                }
    6761                                template <class C, typename... Args, typename... Vs>
    6862                                static void do_call( lua_State*, C const * c, void( C::*func )( Args... ) const, Vs&&... vs )
    6963                                {
    70                                         ( *c.*func )( std::forward<Vs>( vs )... );
     64                                        ( *c.*func )( nv::forward<Vs>( vs )... );
    7165                                }
    7266                        };
     
    7569                        int do_call(lua_State* L, int index, R(*func)(Args...), types<Head, Tail...>, Vs&&... vs)
    7670                        {
    77                                 do_call(L, index + 1, func, types < Tail... > {}, std::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
     71                                do_call(L, index + 1, func, types < Tail... > {}, nv::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
    7872                        }
    7973
     
    8175                        int do_call(lua_State* L, int index, C* c, R(C::*func)(Args...), types<Head, Tail...>, Vs&&... vs)
    8276                        {
    83                                 do_call(L, index + 1, c, func, types < Tail... > {}, std::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
     77                                do_call(L, index + 1, c, func, types < Tail... > {}, nv::forward<Vs>(vs)..., get_value<Head>(L, index)); return 1;
    8478                        }
    8579
     
    8781                        int do_call( lua_State* L, int index, C const * c, R( C::*func )( Args... ) const, types<Head, Tail...>, Vs&&... vs )
    8882                        {
    89                                 do_call( L, index + 1, c, func, types < Tail... > {}, std::forward<Vs>( vs )..., get_value<Head>( L, index ) ); return 1;
     83                                do_call( L, index + 1, c, func, types < Tail... > {}, nv::forward<Vs>( vs )..., get_value<Head>( L, index ) ); return 1;
    9084                        }
    9185
     
    9387                        int do_call(lua_State* L, int, R(*func)(Args...), types<>, Vs&&... vs)
    9488                        {
    95                                 call_and_push<R>::do_call(L, func, std::forward<Vs>(vs)...);
     89                                call_and_push<R>::do_call(L, func, nv::forward<Vs>(vs)...);
    9690                                return 1;
    9791                        }
     
    10094                        int do_call(lua_State* L, int, C* c, R(C::*func)(Args...), types<>, Vs&&... vs)
    10195                        {
    102                                 call_and_push<R>::do_call(L, c, func, std::forward<Vs>(vs)...);
     96                                call_and_push<R>::do_call(L, c, func, nv::forward<Vs>(vs)...);
    10397                                return 1;
    10498                        }
     
    107101                        int do_call( lua_State* L, int, C const * c, R( C::*func )( Args... ) const, types<>, Vs&&... vs )
    108102                        {
    109                                 call_and_push<R>::do_call( L, c, func, std::forward<Vs>( vs )... );
     103                                call_and_push<R>::do_call( L, c, func, nv::forward<Vs>( vs )... );
    110104                                return 1;
    111105                        }
  • trunk/nv/lua/lua_raw.hh

    r368 r383  
    2424void nlua_tokeyset( lua_State *L, int index );
    2525
    26 std::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index );
     26nv::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index );
    2727
    2828void nlua_register( lua_State *L, const char* fname, lua_CFunction func, int index );
  • trunk/nv/stl/algorithm.hh

    r376 r383  
    1818#include <nv/stl/utility.hh>
    1919#include <nv/stl/iterator.hh>
     20#include <nv/stl/capi.hh>
    2021
    2122namespace nv
     
    185186        }
    186187
     188        template< typename T >
     189        T* raw_copy( const T* first, const T* last, T* out )
     190        {
     191                return (T*)nvmemcpy( out, first, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first );
     192        }
     193
     194        template< typename T >
     195        T* raw_copy_n( const T* ptr, size_t n, T* out )
     196        {
     197                return (T*)nvmemcpy( out, ptr, n * sizeof(T) ) + n;
     198        }
     199
     200        template< typename T >
     201        T* raw_alias_copy( const T* first, const T* last, T* out )
     202        {
     203                return (T*)nvmemmove( out, first, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first );
     204        }
     205
     206        template< typename T >
     207        T* raw_alias_copy_n( const T* ptr, size_t n, T* out )
     208        {
     209                return (T*)nvmemmove( out, ptr, n * sizeof( T ) ) + n;
     210        }
     211
     212        template< typename T >
     213        T* raw_zero( T* first, T* last )
     214        {
     215                return (T*)nvmemset( first, 0, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first );
     216        }
     217
     218        template< typename T >
     219        T* raw_zero_n( T* ptr, size_t n )
     220        {
     221                return (T*)nvmemset( ptr, 0, n * sizeof( T ) ) + n;
     222        }
     223
     224        template< typename T >
     225        T* raw_fill( T* first, T* last, unsigned char value )
     226        {
     227                return (T*)nvmemset( first, value, (size_t)( (uintptr_t)last - (uintptr_t)first ) ) + ( last - first );
     228        }
     229
     230        template< typename T >
     231        T* raw_fill_n( T* ptr, size_t n, unsigned char value )
     232        {
     233                return (T*)nvmemset( ptr, value, n * sizeof( T ) ) + n;
     234        }
     235
    187236        namespace detail
    188237        {
    189                 template < typename ForwardIterator, typename T >
    190                 void fill_impl( ForwardIterator first, ForwardIterator last, const T& value, false_type )
    191                 {
     238                template < typename ForwardIterator, typename T, typename AnyType >
     239                void fill_impl( ForwardIterator first, ForwardIterator last, const T& value, AnyType, forward_iterator_tag )
     240                {
     241                        // TODO: version with T temp = value for scalars
    192242                        for (; first != last; ++first )
    193243                                *first = value;
    194244                }
    195245
    196                 template < typename ForwardIterator, typename T >
    197                 void fill_impl( ForwardIterator first, ForwardIterator last, const T& value, true_type )
    198                 {
    199                         memset( first, value, last - first );
    200                 }
    201 
    202                 template < typename ForwardIterator, typename T >
    203                 ForwardIterator fill_n_impl( ForwardIterator first, size_t count, const T& value, false_type )
    204                 {
     246                template < typename BlockAccessIterator, typename T >
     247                void fill_impl( BlockAccessIterator first, BlockAccessIterator last, T value, true_type, block_access_iterator_tag )
     248                {
     249                        raw_fill( first, last, (unsigned char)value ); 
     250                }
     251
     252                template < typename ForwardIterator, typename T, typename AnyType >
     253                ForwardIterator fill_n_impl( ForwardIterator first, size_t count, const T& value, AnyType, forward_iterator_tag )
     254                {
     255                        // TODO: version with T temp = T() for scalars
    205256                        for ( ; count-- > 0; ++first ) *first = value;
    206257                        return first;
    207258                }
    208259
    209                 template < typename ForwardIterator, typename T >
    210                 ForwardIterator fill_n_impl( ForwardIterator first, size_t count, const T& value, true_type )
    211                 {
    212                         return ForwardIterator( memset( first, value, count ) + count );
     260                template < typename BlockAccessIterator, typename T >
     261                BlockAccessIterator fill_n_impl( BlockAccessIterator first, size_t count, T value, true_type, block_access_iterator_tag )
     262                {
     263                        return BlockAccessIterator( raw_fill_n( first, count, (unsigned char)value ) );
     264                }
     265
     266                template < typename ForwardIterator, typename T, typename AnyType >
     267                void fill_default_impl( ForwardIterator first, ForwardIterator last, AnyType, forward_iterator_tag )
     268                {
     269                        // TODO: version with T temp = T() for scalars
     270                        for ( ; first != last; ++first )
     271                                *first = T();
     272                }
     273
     274                template < typename BlockAccessIterator, typename T >
     275                void fill_default_impl( BlockAccessIterator first, BlockAccessIterator last, true_type, block_access_iterator_tag )
     276                {
     277                        raw_zero( first, last );
     278                }
     279
     280                template < typename ForwardIterator, typename T, typename AnyType >
     281                ForwardIterator fill_default_n_impl( ForwardIterator first, size_t n, AnyType, forward_iterator_tag )
     282                {
     283                        // TODO: version with T temp = T() for scalars
     284                        for ( ; n-- > 0; ++first ) *first = value;
     285                        return first;
     286                }
     287
     288                template < typename BlockAccessIterator, typename T >
     289                BlockAccessIterator fill_default_n_impl( BlockAccessIterator first, size_t count, true_type, block_access_iterator_tag )
     290                {
     291                        return BlockAccessIterator( raw_zero_n( first, count, (unsigned char)value ) );
    213292                }
    214293        }
     
    218297        inline void fill( ForwardIterator first, ForwardIterator last, const T& value )
    219298        {
    220                 detail::fill_impl( first, last, value,
    221                         bool_constant< sizeof( T ) == 1 && has_trivial_assign<T>::value >() );
     299                typedef typename iterator_traits< ForwardIterator >::value_type        value_type;
     300                typedef typename iterator_traits< ForwardIterator >::iterator_category iterator_category;
     301                detail::fill_impl( first, last, static_cast<value_type>( value ),
     302                        bool_constant< sizeof( value_type ) == 1 &&
     303                        has_trivial_assign<value_type>::value >(), iterator_category() );
    222304        }
    223305
     
    225307        inline ForwardIterator fill_n( ForwardIterator first, size_t count, const T& value )
    226308        {
    227                 return detail::fill_n_impl( first, count, value,
    228                         bool_constant< sizeof( T ) == 1 && has_trivial_assign<T>::value >() );
     309                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
     310                typedef typename iterator_traits< ForwardIterator >::iterator_category iterator_category;
     311                return detail::fill_n_impl( first, count, static_cast<value_type>( value ),
     312                        bool_constant< sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >(), iterator_category() );
    229313        }
    230314
     
    232316        inline void fill_default( ForwardIterator first, ForwardIterator last )
    233317        {
    234                 // TODO: implement
    235318                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    236                 detail::fill_impl( first, last, value_type(),
    237                         bool_constant< sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >() );
     319                typedef typename iterator_traits< ForwardIterator >::iterator_category iterator_category;
     320                detail::fill_default_impl( first, last,
     321                        bool_constant< sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >(), iterator_category() );
    238322        }
    239323
     
    241325        inline ForwardIterator fill_default_n( ForwardIterator first, size_t count )
    242326        {
    243                 // TODO: implement
    244327                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    245                 return detail::fill_n_impl( first, count, value_type(),
    246                         bool_constant< sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >() );
     328                typedef typename iterator_traits< ForwardIterator >::iterator_category iterator_category;
     329                return detail::fill_default_n_impl( first, count,
     330                        bool_constant< sizeof( value_type ) == 1 && has_trivial_assign<value_type>::value >(), iterator_category() );
     331        }
     332
     333        namespace detail
     334        {
     335                template< typename InputIterator, typename OutputIterator, typename AnyType >
     336                inline OutputIterator copy_impl( InputIterator first, InputIterator last, OutputIterator out, AnyType, input_iterator_tag, forward_iterator_tag )
     337                {
     338                        for ( ; first != last; ++first, ++out )
     339                                *first = *out;
     340                        return out;
     341                }
     342
     343                template< typename BlockAccessIterator, typename OutputIterator >
     344                inline BlockAccessIterator copy_impl( BlockAccessIterator first, BlockAccessIterator last, OutputIterator out, true_type, block_access_iterator_tag, block_access_iterator_tag )
     345                {
     346                        return raw_alias_copy( first, last, out )
     347                }
     348
     349                template< typename InputIterator, typename OutputIterator, typename AnyType >
     350                inline OutputIterator copy_n_impl( InputIterator first, size_t n, OutputIterator out, AnyType, input_iterator_tag, forward_iterator_tag )
     351                {
     352                        for ( ; n-- > 0; ++first, ++out ) *first = *out;
     353                        return out;
     354                }
     355
     356                template< typename BlockAccessIterator, typename OutputIterator >
     357                inline BlockAccessIterator copy_n_impl( BlockAccessIterator first, BlockAccessIterator n, OutputIterator out, true_type, block_access_iterator_tag, block_access_iterator_tag )
     358                {
     359                        return raw_alias_copy_n( first, n, out )
     360                }
     361        }
     362
     363        template< class InputIterator, class OutputIterator >
     364        inline OutputIterator copy( InputIterator first, InputIterator last, OutputIterator out )
     365        {
     366                typedef typename iterator_traits< InputIterator >::value_type value_type;
     367                typedef typename iterator_traits< InputIterator >::iterator_category input_iterator_category;
     368                typedef typename iterator_traits< OutputIterator >::iterator_category output_iterator_category;
     369                return detail::copy_impl( first, last, out,
     370                        has_trivial_copy<value_type>::value, iterator_category(), output_iterator_category() );
     371        }
     372
     373        template< class InputIterator, class OutputIterator >
     374        inline OutputIterator copy_n( InputIterator first, size_t n, OutputIterator out )
     375        {
     376                typedef typename iterator_traits< InputIterator >::value_type value_type;
     377                typedef typename iterator_traits< InputIterator >::iterator_category input_iterator_category;
     378                typedef typename iterator_traits< OutputIterator >::iterator_category output_iterator_category;
     379                return detail::copy_n_impl( first, n, out,
     380                        has_trivial_copy<value_type>::value, iterator_category(), output_iterator_category() );
    247381        }
    248382
  • trunk/nv/stl/array.hh

    r382 r383  
    2424namespace nv
    2525{
    26         using ::std::vector;
     26
     27        struct default_init
     28        {
     29
     30        };
     31
     32        template< typename SizeType >
     33        struct default_next_capacity
     34        {
     35                static SizeType get( SizeType requested, SizeType capacity, SizeType max_size )
     36                {
     37                        SizeType remaining = max_size - capacity;
     38                        if ( remaining < requested ) return 0;
     39                        SizeType additional = nv::max( requested, capacity );
     40                        return ( remaining < additional ? max_size : capacity + additional );
     41                }
     42        };
     43
     44        struct policy_initialize_always
     45        {
     46                template < typename ForwardIterator >
     47                inline static void initialize( ForwardIterator first, ForwardIterator last )
     48                {
     49                        uninitialized_construct( first, last );
     50                }
     51                template < typename InputIterator, typename ForwardIterator >
     52                inline static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
     53                {
     54                        return uninitialized_copy( first, last, out );
     55                }
     56                template < typename ForwardIterator >
     57                inline static void destroy( ForwardIterator first, ForwardIterator last )
     58                {
     59                        uninitialized_destroy( first, last );
     60                }
     61                template < typename ForwardIterator >
     62                inline static void destroy( ForwardIterator first )
     63                {
     64                        destroy_object( first );
     65                }
     66        };
     67
     68        struct policy_initialize_never
     69        {
     70                template < typename ForwardIterator >
     71                inline static void initialize( ForwardIterator, ForwardIterator )
     72                {
     73                }
     74                template < typename InputIterator, typename ForwardIterator >
     75                inline static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
     76                {
     77                        return detail::uninitialized_copy( first, last, out, true_type );
     78                }
     79                template < typename ForwardIterator >
     80                inline static void destroy( ForwardIterator, ForwardIterator )
     81                {
     82                }
     83                template < typename ForwardIterator >
     84                inline static void destroy( ForwardIterator )
     85                {
     86                }
     87        };
     88
     89        struct policy_initialize_standard
     90        {
     91                template < typename ForwardIterator >
     92                inline static void initialize( ForwardIterator first, ForwardIterator last )
     93                {
     94                        typedef typename iterator_traits< ForwardIterator >::value_type value_type;
     95                        if ( !has_trivial_constructor<value_type>() )
     96                                detail::uninitialized_construct_impl( first, last, false_type() );
     97                }
     98                template < typename InputIterator, typename ForwardIterator >
     99                inline static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
     100                {
     101                        return uninitialized_copy( first, last, out );
     102                }
     103                template < typename ForwardIterator >
     104                inline static void destroy( ForwardIterator first, ForwardIterator last )
     105                {
     106                        typedef typename iterator_traits< ForwardIterator >::value_type value_type;
     107                        if ( !has_trivial_destructor<value_type>() )
     108                                detail::uninitialized_destroy_impl( first, last, false_type() );
     109                }
     110                template < typename ForwardIterator >
     111                inline static void destroy( ForwardIterator first )
     112                {
     113                        typedef typename iterator_traits< ForwardIterator >::value_type value_type;
     114                        if ( !has_trivial_destructor<value_type>() )
     115                                destroy_object( first );
     116                }
     117        };
     118
     119        template< typename T >
     120        class dynamic_storage
     121        {
     122        public:
     123                typedef T      value_type;
     124
     125                static constexpr bool is_static = false;
     126                static constexpr bool is_const = false;
     127
     128                constexpr const value_type* data() const { return reinterpret_cast<const value_type*>( m_data ); }
     129                inline    value_type* data() { return reinterpret_cast<T*>( m_data ); }
     130                constexpr const char* raw_data() const { return reinterpret_cast<const char*>( m_data ); }
     131                inline    char* raw_data() { return reinterpret_cast<char*>( m_data ); }
     132
     133        protected:
     134                constexpr dynamic_storage() : m_data( nullptr ) {}
     135                // prevent copying
     136                dynamic_storage( const dynamic_storage& ) = delete;
     137                dynamic_storage& operator=( const dynamic_storage& ) = delete;
     138                // allow move
     139                inline dynamic_storage( dynamic_storage&& other )
     140                        : m_data( other.m_data )
     141                {
     142                        other.m_data = nullptr;
     143                }
     144                inline dynamic_storage& operator=( dynamic_storage&& other  )
     145                {
     146                        if ( this != &other )
     147                        {
     148                                reallocate( 0, false );
     149                                m_data = other.m_data;
     150                        }
     151                        return *this;
     152                }
     153                ~dynamic_storage() = default;
     154
     155                bool reallocate( size_t new_size, bool copy_needed )
     156                {
     157                        if ( copy_needed )
     158                                m_data = (uint8*)nvrealloc( m_data, new_size * sizeof( value_type ) );
     159                        else
     160                        {
     161                                nvfree( m_data );
     162                                m_data = ( new_size > 0 ? (uint8*)nvmalloc( new_size * sizeof( value_type ) ) : nullptr );
     163                        }
     164                        return true; // TODO : alloc check?
     165                }
     166        protected:
     167                uint8* m_data;
     168        };
     169
     170        template< typename T, size_t N >
     171        class static_storage
     172        {
     173        public:
     174                typedef T      value_type;
     175
     176                static constexpr bool is_static = true;
     177                static constexpr bool is_const = false;
     178
     179                constexpr const value_type* data() const { return reinterpret_cast<const value_type*>( m_data ); }
     180                inline    value_type* data() { return reinterpret_cast<T*>( m_data ); }
     181                constexpr const char* raw_data() const { return reinterpret_cast<const char*>( m_data ); }
     182                inline    char* raw_data() { return reinterpret_cast<char*>( m_data ); }
     183
     184        protected:
     185                static constexpr bool reallocate( size_t new_size, bool /*copy_needed*/ ) { return new_size <= N; }
     186
     187                static_storage() = default;
     188
     189                // prevent copying
     190                static_storage( const static_storage& ) = delete;
     191                static_storage& operator=( const static_storage& ) = delete;
     192                // allow move
     193                static_storage( static_storage&& other ) = default;
     194                static_storage& operator=( static_storage&& other ) = default;
     195
     196                ~static_storage() = default;
     197        protected:
     198                typedef aligned_array_t<T, N, alignof( T ) > storage_type;
     199                storage_type m_data;
     200        };
     201
     202        template< typename Storage, size_t N >
     203        class fixed_storage : public Storage
     204        {
     205        public:
     206                typedef size_t                       size_type;
     207                typedef typename Storage::value_type value_type;
     208
     209                static constexpr bool is_fixed = true;
     210
     211                fixed_storage()
     212                {
     213                        Storage::reallocate( N, false );
     214                }
     215                ~fixed_storage()
     216                {
     217                        Storage::reallocate( 0, false );
     218                }
     219                static constexpr size_type max_size() { return N; }
     220                static constexpr size_type capacity() { return N; }
     221                static constexpr size_type size() { return N; }
     222                static constexpr bool empty() { return N == 0; }
     223                static constexpr size_type raw_size() { return sizeof( value_type ) * N; }
     224
     225                operator array_ref< value_type >()             { return array_ref< value_type >( Storage::data(), size() ); }
     226                operator const_array_ref< value_type >() const { return const_array_ref< value_type >( Storage::data(), size() ); }
     227
     228                // allow move
     229                fixed_storage( fixed_storage&& ) = default;
     230                fixed_storage& operator=( fixed_storage&& ) = default;
     231        };
     232
     233        template< typename Storage >
     234        class resizable_storage : public Storage
     235        {
     236        public:
     237                typedef size_t                       size_type;
     238                typedef typename Storage::value_type value_type;
     239
     240                static constexpr bool is_fixed = false;
     241
     242                ~resizable_storage()
     243                {
     244                        if ( m_size > 0 ) reallocate( 0, false );
     245                }
     246                static constexpr size_type max_size() { return size_type( 0x80000000 ); }
     247                constexpr size_t capacity() { return m_size; }
     248                constexpr size_t size() const { return m_size; }
     249                constexpr bool empty() const { return m_size == 0; }
     250                constexpr size_t raw_size() const { return sizeof( value_type ) * m_size; }
     251
     252                operator array_ref< value_type >()             { return array_ref< value_type >( Storage::data(), size() ); }
     253                operator const_array_ref< value_type >() const { return const_array_ref< value_type >( Storage::data(), size() ); }
     254        protected:
     255                constexpr resizable_storage() : m_size( 0 ) {}
     256
     257                // allow move
     258                inline resizable_storage( resizable_storage&& other )
     259                        : Storage( nv::move( other ) ), m_size( other.m_size )
     260                {
     261                        other.m_size = 0;
     262                }
     263                inline resizable_storage& operator=( resizable_storage&& other )
     264                {
     265                        m_size = other.m_size;
     266                        Storage::operator=( nv::move( o ) );
     267                        other.m_size = 0;
     268                        return *this;
     269                }
     270
     271                // TODO: return type error checking
     272                bool try_resize( size_t new_size, bool copy_needed )
     273                {
     274                        if ( new_size != m_size )
     275                        {
     276                                if ( reallocate( new_size, copy_needed ) )
     277                                {
     278                                        m_size = new_size;
     279                                        return true;
     280                                }
     281                                return false;
     282                        }
     283                        return true;
     284                }
     285        protected:
     286                size_type m_size;
     287        };
     288
     289        template< typename Storage, typename NextCapacity = default_next_capacity< size_t > >
     290        class growable_storage : public Storage
     291        {
     292        public:
     293                typedef size_t                       size_type;
     294                typedef typename Storage::value_type value_type;
     295
     296                static constexpr bool is_fixed = false;
     297
     298                ~growable_storage()
     299                {
     300                        if ( m_capacity > 0 ) reallocate( 0, false );
     301                }
     302                static constexpr size_type max_size() { return size_type( 0x80000000 ); }
     303                constexpr size_t capacity() { return m_capacity; }
     304                constexpr size_t size() const { return m_size; }
     305                constexpr bool empty() const { return m_size == 0; }
     306                constexpr size_t raw_size() const { return sizeof( value_type ) * m_size; }
     307
     308                operator array_ref< value_type >()             { return array_ref< value_type >( Storage::data(), size() ); }
     309                operator const_array_ref< value_type >() const { return const_array_ref< value_type >( Storage::data(), size() ); }
     310        protected:
     311                constexpr growable_storage() : m_size( 0 ), m_capacity( 0 ) {}
     312
     313                // allow move
     314                inline growable_storage( growable_storage&& other )
     315                        : Storage( nv::move( other ) ), m_size( other.m_size ), m_capacity( other.m_capacity )
     316                {
     317                        other.m_size     = 0;
     318                        other.m_capacity = 0;
     319                }
     320                inline growable_storage& operator=( growable_storage&& other )
     321                {
     322                        m_size     = other.m_size;
     323                        m_capacity = other.m_capacity;
     324                        Storage::operator=( nv::move( other ) );
     325                        other.m_size     = 0;
     326                        other.m_capacity = 0;
     327                        return *this;
     328                }
     329
     330                // TODO: return type error checking
     331                bool try_grow( size_t amount )
     332                {
     333                        size_type new_size = amount + m_size;
     334                        if ( new_size > m_capacity )
     335                        {
     336                                size_type new_capacity = NextCapacity::get( new_size - m_capacity, m_capacity, max_size() );
     337                                if ( new_capacity > 0 && reallocate( new_capacity, true ) )
     338                                {
     339                                        m_capacity = new_capacity;
     340                                        m_size = new_size;
     341                                }
     342                                else return false;
     343                        }
     344                        m_size = new_size;
     345                        return true;
     346                }
     347                // TODO: return type error checking
     348                bool try_reserve( size_t new_capacity, bool copy_needed )
     349                {
     350                        if ( new_capacity > m_capacity )
     351                        {
     352                                if ( reallocate( new_capacity, copy_needed ) )
     353                                {
     354                                        m_capacity = new_capacity;
     355                                }
     356                                else return false;
     357                        }
     358                        return true;
     359                }
     360                // TODO: return type error checking
     361                bool try_resize( size_t new_size, bool copy_needed )
     362                {
     363                        if ( new_size > m_size )
     364                        {
     365                                if ( try_reserve( new_size, copy_needed ) )
     366                                {
     367                                        m_size = new_size;
     368                                        return true;
     369                                }
     370                                return false;
     371                        }
     372                        m_size = new_size;
     373                        return true;
     374                }
     375        protected:
     376                size_type m_size;
     377                size_type m_capacity;
     378        };
     379
     380
     381        template< typename T, size_t N >
     382        using fixed_static_storage = fixed_storage< static_storage< T, N >, N >;
     383
     384        template< typename T, size_t N >
     385        using fixed_dynamic_storage = fixed_storage< dynamic_storage< T >, N >;
     386
     387        template< typename T >
     388        using resizable_dynamic_storage = resizable_storage< dynamic_storage< T > >;
     389
     390        template< typename T, size_t N >
     391        using resizable_static_storage = resizable_storage< static_storage< T, N > >;
     392
     393        template< typename T >
     394        using growable_dynamic_storage = growable_storage< dynamic_storage< T > >;
     395
     396        template< typename T, size_t N >
     397        using growable_static_storage = growable_storage< static_storage< T, N > >;
     398
     399        template <
     400                typename Storage,
     401                typename InitializePolicy = policy_initialize_standard
     402        >
     403        class fixed_container_allocator : public Storage
     404        {
     405        public:
     406                typedef typename Storage::value_type value_type;
     407                typedef typename Storage::size_type  size_type;
     408
     409                fixed_container_allocator()
     410                {
     411                        InitializePolicy::initialize( data(), data() + Storage::capacity() );
     412                }
     413
     414                explicit fixed_container_allocator( default_init )
     415                {
     416                        uninitialized_construct( data(), data() + Storage::capacity() );
     417                }
     418
     419                explicit fixed_container_allocator( const value_type& v )
     420                {
     421                        uninitialized_fill( data(), data() + Storage::capacity(), v );
     422                }
     423
     424                ~fixed_container_allocator()
     425                {
     426                        InitializePolicy::destroy( data(), data() + Storage::capacity() );
     427                }
     428
     429                // prevent copying
     430                fixed_container_allocator( const fixed_container_allocator& ) = delete;
     431                fixed_container_allocator& operator=( const fixed_container_allocator& ) = delete;
     432                // allow move
     433                fixed_container_allocator( fixed_container_allocator&& ) = default;
     434                fixed_container_allocator& operator=( fixed_container_allocator&& ) = default;
     435        };
     436
     437        template <
     438                typename Storage,
     439                typename InitializePolicy = policy_initialize_standard
     440        >
     441        class sized_container_allocator : public Storage
     442        {
     443        public:
     444                typedef typename Storage::value_type value_type;
     445                typedef typename Storage::size_type  size_type;
     446
     447                inline sized_container_allocator() {}
     448                inline explicit sized_container_allocator( size_type new_size ) { resize( new_size ); }
     449                inline explicit sized_container_allocator( default_init ) { resize( default_init() ); }
     450                inline sized_container_allocator( size_type new_size, const value_type& v ) { resize( new_size, v ); }
     451
     452                // prevent copying
     453                sized_container_allocator( const sized_container_allocator& ) = delete;
     454                sized_container_allocator& operator=( const sized_container_allocator& ) = delete;
     455                // allow move
     456                sized_container_allocator( sized_container_allocator&& ) = default;
     457                sized_container_allocator& operator=( sized_container_allocator&& ) = default;
     458
     459
     460                inline void resize( size_type new_size )
     461                {
     462                        size_type old_size = Storage::size();
     463                        resize_impl( new_size );
     464                        initialize_range( old_size, Storage::size() );
     465                }
     466
     467                inline void resize( size_type new_size, default_init )
     468                {
     469                        size_type old_size = Storage::size();
     470                        resize_impl( new_size );
     471                        initialize_range( old_size, Storage::size(), default_init() );
     472                }
     473
     474                inline void resize( size_type new_size, const value_type& value )
     475                {
     476                        size_type old_size = Storage::size();
     477                        resize_impl( new_size );
     478                        initialize_range( old_size, Storage::size(), value );
     479                }
     480
     481                inline void assign( const value_type* ptr, size_type sz )
     482                {
     483                        if ( Storage::size() > 0 ) InitializePolicy::destroy( Storage::data(), Storage::data() + Storage::size() );
     484                        if ( ptr != nullptr && sz > 0 )
     485                        {
     486                                if ( sz != Storage::size() && Storage::try_resize( sz, false ) )
     487                                        InitializePolicy::copy( ptr, ptr + sz, Storage::data() );
     488                        }
     489                        else Storage::try_resize( 0, false );
     490                }
     491
     492                template< typename InputIterator >
     493                inline void assign( InputIterator first, InputIterator last )
     494                {
     495                        size_type d = distance( first, last );
     496                        if ( d != Storage::size() && Storage::try_resize( sz, false ) )
     497                                InitializePolicy::copy( first, last, Storage::data() );
     498                }
     499
     500                // explicit copy
     501                inline void assign( const sized_container_allocator& other )
     502                {
     503                        assign( other.data(), other.size() );
     504                }
     505
     506                inline void clear()
     507                {
     508                        if ( Storage::size() > 0 )
     509                        {
     510                                InitializePolicy::destroy( Storage::data(), Storage::data() + Storage::size() );
     511                                Storage::try_resize( 0, false );
     512                        }
     513                }
     514
     515                ~sized_container_allocator()
     516                {
     517                        if ( Storage::size() > 0 ) clear();
     518                }
     519
     520        protected:
     521
     522                inline void initialize_range( size_type old_size, size_type new_size )
     523                {
     524                        if ( new_size > old_size ) InitializePolicy::initialize( Storage::data() + old_size, Storage::data() + new_size );
     525                }
     526                inline void initialize_range( size_type old_size, size_type new_size, default_init )
     527                {
     528                        if ( new_size > old_size ) uninitialized_construct( Storage::data() + old_size, Storage::data() + new_size );
     529                }
     530                inline void initialize_range( size_type old_size, size_type new_size, const value_type& value )
     531                {
     532                        if ( new_size > old_size ) uninitialized_fill( Storage::data() + old_size, Storage::data() + new_size, value );
     533                }
     534                inline void resize_impl( size_type new_size )
     535                {
     536                        size_type old_size = Storage::size();
     537                        if ( new_size != old_size )
     538                        {
     539                                if ( new_size < old_size )
     540                                {
     541                                        InitializePolicy::destroy( Storage::data() + new_size, Storage::data() + old_size );
     542                                }
     543                                if ( Storage::try_resize( new_size, true ) )
     544                                {
     545                                        // TODO: error checking
     546                                }
     547                        }
     548                }
     549
     550        };
     551
     552        template <
     553                typename Storage,
     554                typename InitializePolicy = policy_initialize_standard
     555        >
     556        class growing_container_allocator : public sized_container_allocator< Storage, InitializePolicy >
     557        {
     558                typedef sized_container_allocator< Storage, InitializePolicy > inherited;
     559        public:
     560                typedef typename Storage::value_type value_type;
     561                typedef typename Storage::size_type  size_type;
     562
     563                using sized_container_allocator< Storage, InitializePolicy >::sized_container_allocator;
     564
     565                void reserve( size_type new_capacity )
     566                {
     567                        Storage::try_reserve( new_capacity, true );
     568                }
     569                void push_back( const value_type& e )
     570                {
     571                        if ( Storage::try_grow( 1 ) ) copy_construct_object( data() + size() - 1, e );
     572                }
     573                void push_back( value_type&& e )
     574                {
     575                        if ( Storage::try_grow( 1 ) ) move_construct_object( data() + size() - 1, forward<value_type>( e ) );
     576                }
     577                template < typename... Args >
     578                void emplace_back( Args&&... args )
     579                {
     580                        if ( Storage::try_grow( 1 ) ) construct_object( data() + size() - 1, forward<Args>( args )... );
     581                }
     582                void pop_back()
     583                {
     584                        try_resize( size() - 1, true );
     585                }
     586
     587        };
     588
    27589
    28590        template < typename ContainerAllocator >
    29         using array_base = detail::add_random_access< detail::add_iterators < ContainerAllocator > >;
    30 
     591        using array_base_t = detail::add_random_access< detail::add_iterators < ContainerAllocator > >;
    31592
    32593        template< typename T, size_t N >
    33         using array = array_base < fixed_container_allocator < fixed_static_storage< T, N > > >;
     594        using array = array_base_t < fixed_container_allocator < fixed_static_storage< T, N > > >;
    34595       
    35596        template< typename T >
    36         using dynamic_array = array_base < sized_container_allocator< resizable_dynamic_storage< T > > >;
     597        using dynamic_array = array_base_t < sized_container_allocator< resizable_dynamic_storage< T > > >;
     598
     599        template< typename T >
     600        using vector = array_base_t < growing_container_allocator< growable_dynamic_storage< T > > >;
    37601
    38602//      template < typename T, typename ContainerAllocator >
  • trunk/nv/stl/array2d.hh

    r368 r383  
    9595                                        for ( sint32 i = 0; i < min(new_size.y, m_size.y); i++ )
    9696                                        {
    97                                                 std::copy( m_data + m_size.x * i, m_data + m_size.x * i + min( new_size.x, m_size.x ), new_data + m_size.x * i );
     97                                                raw_copy_n( m_data + m_size.x * i, nv::min( new_size.x, m_size.x ), new_data + m_size.x * i );
    9898                                        }
    9999                                }
     
    193193                        for ( sint32 i = 0; i < m_size.y; i++ )
    194194                        {
    195                                 std::copy( m_data + m_size.x * i, m_data + m_size.x * i + m_size.x, m_size.x * i );
     195                                raw_copy_n( m_data + m_size.x * i, m_size.x, m_size.x * i );
    196196                        }
    197197                        return temp;
     
    229229                                // Destination is the start of the destination row.
    230230                                //         Start                              End                                         Destination
    231                                 std::copy( m_data + m_size().x * i + start_x, m_data + m_size().x * i + start_x + size_x, temp.m_data + temp.m_size().x * ( i - start_y ) );
     231                                raw_copy_n( m_data + m_size().x * i + start_x, size_x, temp.m_data + temp.m_size().x * ( i - start_y ) );
    232232                        }
    233233                        return temp;
     
    331331                                // The end position is either the size limit or the end of either array, whichever is smaller.
    332332                                // Destination start is the beginning of the current destination row (which is dest_start_y + i), offset by dest_start_x.
    333                                 std::copy( source.m_data + ( source_start_y + i ) * source.m_size.x + source_start_x,  // Source Start
    334                                                   source.m_data + ( source_start_y + i ) * source.m_size.x + min( source.m_size.x, min( source_start_x + size_x, source_start_x + m_size.x - dest_start_x ) ), // Source End
     333                                pointer base = source.m_data + ( source_start_y + i ) * source.m_size.x;
     334                                raw_copy( base + source_start_x,  // Source Start
     335                                                  base + min( source.m_size.x, min( source_start_x + size_x, source_start_x + m_size.x - dest_start_x ) ), // Source End
    335336                                                  m_data + (dest_start_y + i) * m_size.x + dest_start_x ); // Destination Start
    336337                        }
  • trunk/nv/stl/capi.hh

    r382 r383  
    7373        inline void nvfree( void* p )
    7474        {
    75                 NV_CAPI_CALL( free )( p );
     75                if ( p ) NV_CAPI_CALL( free )( p );
    7676        }
    7777
  • trunk/nv/stl/flags.hh

    r377 r383  
    1616#include <nv/core/common.hh>
    1717#include <nv/stl/traits/transforms.hh>
    18 #include <nv/stl/array.hh>
     18#include <nv/stl/algorithm.hh>
    1919
    2020namespace nv
     
    144144                void assign( const data_type* a_data )
    145145                {
    146                         std::copy( a_data, a_data + data_size, m_data );
     146                        raw_copy_n( a_data, data_size, m_data );
    147147                }
    148148
    149149                void reset()
    150150                {
    151                         std::fill( m_data, m_data + data_size, 0 );
     151                        raw_zero_n( m_data, data_size );
    152152                }
    153153
  • trunk/nv/stl/handle.hh

    r376 r383  
    4343                bool is_valid() const { return !is_nil(); }
    4444                T index() const { return m_index; }
    45                 size_t hash() const { return std::hash<T>()( T( m_counter << IBITS | m_index ) ); }
     45                //size_t hash() const { return std::hash<T>()( T( m_counter << IBITS | m_index ) ); }
     46                size_t hash() const { NV_ASSERT( false, "UNIMPLEMENTED!" ); return 0; }
    4647        protected:
    4748                T m_index   : IBITS;
     
    139140                index_type m_first_free;
    140141                index_type m_last_free;
    141                 std::vector< index_entry > m_entries;
     142                vector< index_entry > m_entries;
    142143        };
    143144
     
    146147        {
    147148        public:
    148                 typedef HANDLE                   handle;
    149                 typedef TINDEX                   index_type;
    150                 typedef std::vector< T >         storage;
    151                 typedef T                        value_type;
     149                typedef HANDLE              handle;
     150                typedef TINDEX              index_type;
     151                typedef vector< T >         storage;
     152                typedef T                   value_type;
    152153                typedef typename storage::iterator        iterator;
    153154                typedef typename storage::const_iterator  const_iterator;
     
    241242                }
    242243
    243                 std::vector< T >          m_data;
    244                 std::vector< handle >     m_handles;
    245                 std::vector< index_type > m_indexes;
     244                vector< T >          m_data;
     245                vector< handle >     m_handles;
     246                vector< index_type > m_indexes;
    246247        };
    247248
     
    251252        {
    252253        public:
    253                 typedef HANDLE                   handle;
    254                 typedef TINDEX                   index_type;
    255                 typedef std::vector< T >        storage;
    256                 typedef T                        value_type;
     254                typedef HANDLE      handle;
     255                typedef TINDEX      index_type;
     256                typedef vector< T > storage;
     257                typedef T           value_type;
    257258                typedef typename storage::iterator        iterator;
    258259                typedef typename storage::const_iterator  const_iterator;
     
    315316}
    316317
    317 namespace std
    318 {
    319         template <
    320                 typename T,
    321                 unsigned IBITS,
    322                 unsigned CBITS,
    323                 typename TAG
    324         >
    325         struct hash<nv::handle<T,IBITS,CBITS,TAG>>
    326         {
    327                 size_t operator()(const nv::handle<T,IBITS,CBITS,TAG>& h) const
    328                 {
    329                         return h.hash();
    330                 }
    331         };
    332 }
    333 
    334318#endif // NV_CORE_HANDLE_HH
  • trunk/nv/stl/memory.hh

    r382 r383  
    7272                static constexpr bool is_fixed    = false;
    7373                static constexpr bool is_const    = false;
    74                 static constexpr size_t type_size = sizeof( value_type );
    7574
    7675                constexpr storage_view()
     
    106105                static constexpr bool is_fixed    = false;
    107106                static constexpr bool is_const    = true;
    108                 static constexpr size_t type_size = sizeof( value_type );
    109107
    110108                constexpr const_storage_view()
     
    112110                constexpr const_storage_view( const value_type* a_data, size_type a_size )
    113111                        : m_data( a_data ), m_size( a_size ) {}
     112                constexpr const_storage_view( const storage_view<T>& view )
     113                        : m_data( view.data() ), m_size( view.size() ) {}
    114114
    115115                void assign( const value_type* a_data, size_type a_size )
     
    142142        }
    143143
     144        template < typename T >
     145        inline void raw_move_construct_object( void* object, T&& original )
     146        {
     147                new ( object )T( move( original ) );
     148        }
     149
     150        template < typename T >
     151        inline void raw_copy_construct_object( void* object, const T& original )
     152        {
     153                new ( object )T( original );
     154        }
     155
    144156        template < typename T, typename ...Args >
    145157        inline void construct_object( T* object, Args&&... params )
    146158        {
    147159                new ( object )T( forward<Args>( params )... );
     160        }
     161
     162        template < typename T >
     163        inline void move_construct_object( T* object, T&& original )
     164        {
     165                new ( object )T( move( original ) );
     166        }
     167
     168        template < typename T >
     169        inline void copy_construct_object( T* object, const T& original )
     170        {
     171                new ( object )T( original );
    148172        }
    149173
     
    257281                inline ForwardIterator uninitialized_copy_impl( InputIterator first, InputIterator last, ForwardIterator out, false_type )
    258282                {
    259                         typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
     283                        typedef typename iterator_traits<ForwardIterator>::value_type value_type;
    260284                        InputIterator src( first );
    261285                        ForwardIterator dest( out );
    262                         for ( ; first != last; ++src, ++dest )
     286                        for ( ; src != last; ++src, ++dest )
    263287                        {
    264288                                ::new ( static_cast<void*>( addressof( *dest ) ) ) value_type( *src );
     
    276300                inline ForwardIterator uninitialized_copy_n_impl( InputIterator first, size_t count, ForwardIterator out, false_type )
    277301                {
    278                         typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
     302                        typedef typename iterator_traits<ForwardIterator>::value_type value_type;
    279303                        InputIterator src( first );
    280304                        ForwardIterator dest( out );
     
    289313                inline ForwardIterator uninitialized_copy_n_impl( InputIterator first, size_t count, ForwardIterator out, true_type )
    290314                {
    291                         typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
     315                        typedef typename iterator_traits<ForwardIterator>::value_type value_type;
    292316                        return ForwardIterator( nvmemmove( out, first, count * sizeof( value_type ) ) );
    293317                }
     
    299323        {
    300324                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    301                 detail::uninitialized_fill_impl( first, last, value, has_trivial_assign<value_type>() );
     325                detail::uninitialized_fill_impl( first, last, value, has_trivial_destructor<value_type>() );
    302326        }
    303327
     
    306330        {
    307331                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    308                 return detail::uninitialized_fill_n_impl( first, count, value, has_trivial_assign<value_type>() );
     332                return detail::uninitialized_fill_n_impl( first, count, value, has_trivial_destructor<value_type>() );
    309333        }
    310334
     
    322346        {
    323347                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    324                 detail::uninitialized_construct_impl( first, last, has_trivial_constructor<value_type>() );
     348                detail::uninitialized_construct_impl( first, last, has_trivial_destructor<value_type>() );
    325349        }
    326350
     
    329353        {
    330354                typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    331                 return detail::uninitialized_construct_n_impl( first, count, has_trivial_constructor<value_type>() );
     355                return detail::uninitialized_construct_n_impl( first, count, has_trivial_destructor<value_type>() );
    332356        }
    333357
     
    428452                        typedef const value_type&                    const_reference;
    429453
     454                        using Super::Super;
     455
    430456                        inline const_reference front() const { NV_ASSERT( !Super::empty(), "front() called on empty data!" ); return Super::data()[0]; }
    431457                        inline const_reference back() const { NV_ASSERT( !Super::empty(), "front() called on empty data!" ); return Super::data()[Super::size() - 1]; }
     
    449475                        typedef const value_type&                    const_reference;
    450476
     477                        using Super::Super;
     478
    451479                        inline reference       front() { NV_ASSERT( !Super::empty(), "front() called on empty data!" );  return Super::data()[0]; }
    452480                        inline const_reference front() const { NV_ASSERT( !Super::empty(), "front() called on empty data!" ); return Super::data()[0]; }
     
    475503        }
    476504
    477         class const_mem_ref : public detail::add_iterators< const_storage_view< char > >
    478         {
    479                 typedef detail::add_iterators< const_storage_view< char > > inherited;
    480         public:
    481                 typedef char                 value_type;
    482                 typedef value_type*          pointer;
    483                 typedef const value_type*    const_pointer;
    484                 typedef value_type&                  reference;
    485                 typedef const value_type&    const_reference;
    486                 typedef size_t               size_type;
    487                 typedef ptrdiff_t            difference_type;
    488                 typedef const_pointer        const_iterator;
    489         public:
    490                 inline const_mem_ref() : inherited() {}
    491                 inline const_mem_ref( const void* p, size_type n ) : inherited( (const char*)p, n ) {}
    492                 inline const_mem_ref( const const_mem_ref& l ) : inherited( l.data(), l.size() ) {}
    493         };
    494 
    495         class mem_ref : public detail::add_iterators< storage_view< char > >
    496         {
    497                 typedef detail::add_iterators< storage_view< char > > inherited;
    498         public:
    499                 typedef char                 value_type;
    500                 typedef value_type*          pointer;
    501                 typedef const value_type*    const_pointer;
    502                 typedef value_type&                  reference;
    503                 typedef const value_type&    const_reference;
    504                 typedef size_t               size_type;
    505                 typedef ptrdiff_t            difference_type;
    506                 typedef pointer              iterator;
    507                 typedef const_pointer        const_iterator;
    508         public:
    509                 inline mem_ref() : inherited() {}
    510                 inline mem_ref( void* p, size_type n ) : inherited( (char*)p, n ) {}
    511                 inline mem_ref( const mem_ref& l ) : inherited( const_cast< char* >( l.data() ), l.size() ) {}
    512         };
    513 
    514         template< typename SizeType >
    515         struct default_next_capacity
    516         {
    517                 static SizeType get( SizeType requested, SizeType capacity )
    518                 {
    519                         SizeType additional = nv::max( requested, capacity );
    520                         return capacity + additional;
    521                 }
    522         };
    523 
    524         struct policy_initialize_always
    525         {
    526                 template < typename ForwardIterator >
    527                 static void initialize( ForwardIterator first, ForwardIterator last )
    528                 {
    529                         typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    530                         uninitialized_construct( first, last, value_type() );
    531                 }
    532                 template < typename InputIterator, typename ForwardIterator >
    533                 static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
    534                 {
    535                         return uninitialized_copy( first, last, out );
    536                 }
    537                 template < typename ForwardIterator >
    538                 static void destroy( ForwardIterator first, ForwardIterator last )
    539                 {
    540                         uninitialized_destroy( first, last );
    541                 }
    542         };
    543 
    544         struct policy_initialize_never
    545         {
    546                 template < typename ForwardIterator >
    547                 static void initialize( ForwardIterator, ForwardIterator )
    548                 {
    549                 }
    550                 template < typename InputIterator, typename ForwardIterator >
    551                 static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
    552                 {
    553                         return detail::uninitialized_copy( first, last, out, true_type );
    554                 }
    555                 template < typename ForwardIterator >
    556                 static void destroy( ForwardIterator, ForwardIterator )
    557                 {
    558                 }
    559         };
    560 
    561         struct policy_initialize_standard
    562         {
    563                 template < typename ForwardIterator >
    564                 static void initialize( ForwardIterator first, ForwardIterator last )
    565                 {
    566                         typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    567                         if ( !has_trivial_constructor<value_type>() )
    568                                 detail::uninitialized_construct_impl( first, last, false_type() );
    569                 }
    570                 template < typename InputIterator, typename ForwardIterator >
    571                 static ForwardIterator copy( InputIterator first, InputIterator last, ForwardIterator out )
    572                 {
    573                         return uninitialized_copy( first, last, out );
    574                 }
    575                 template < typename ForwardIterator >
    576                 static void destroy( ForwardIterator first, ForwardIterator last )
    577                 {
    578                         typedef typename iterator_traits< ForwardIterator >::value_type value_type;
    579                         if ( !has_trivial_destructor<value_type>() )
    580                                 detail::uninitialized_destroy_impl( first, last, false_type() );
    581                 }
    582         };
    583 
    584         template< typename T >
    585         class dynamic_storage
    586         {
    587         public:
    588                 typedef T      value_type;
    589 
    590                 static constexpr bool is_static   = false;
    591                 static constexpr bool is_const    = false;
    592                 static constexpr size_t type_size = sizeof( value_type );
    593 
    594                 constexpr dynamic_storage() : m_data( nullptr ) {}
    595 
    596                 constexpr const value_type* data() const { return reinterpret_cast<const value_type*>( m_data ); }
    597                 inline    value_type* data() { return reinterpret_cast<T*>( m_data ); }
    598                 constexpr const char* raw_data() const { return reinterpret_cast<const char*>( m_data ); }
    599                 inline    char* raw_data() { return reinterpret_cast<char*>( m_data ); }
    600         protected:
    601                 bool reallocate( size_t new_size )
    602                 {
    603                         if ( m_data != 0 || new_size != 0 )
    604                                 m_data = (uint8*)nvrealloc( m_data, new_size * sizeof( value_type ) );
    605                         return true; // TODO : alloc check?
    606                 }
    607         protected:
    608                 uint8* m_data;
    609         };
    610 
    611         template< typename T, size_t N >
    612         class static_storage
    613         {
    614         public:
    615                 typedef T      value_type;
    616 
    617                 static constexpr bool is_static   = true;
    618                 static constexpr bool is_const    = false;
    619                 static constexpr size_t type_size = sizeof( value_type );
    620 
    621                 constexpr const value_type* data() const { return reinterpret_cast<const value_type*>( m_data ); }
    622                 inline    value_type* data() { return reinterpret_cast<T*>( m_data ); }
    623                 constexpr const char* raw_data() const { return reinterpret_cast<const char*>( m_data ); }
    624                 inline    char* raw_data() { return reinterpret_cast<char*>( m_data ); }
    625         protected:
    626                 static constexpr bool reallocate( size_t new_size ) { return new_size <= N; }
    627         protected:
    628                 typedef aligned_array_t<T, N, alignof( T ) > storage_type;
    629                 storage_type m_data;
    630         };
    631 
    632         template< typename Storage, size_t N >
    633         class fixed_storage : public Storage
    634         {
    635         public:
    636                 typedef size_t size_type;
    637 
    638                 static constexpr bool is_fixed = true;
    639 
    640                 fixed_storage()
    641                 {
    642                         Storage::reallocate( N );
    643                 }
    644                 ~fixed_storage()
    645                 {
    646                         Storage::reallocate( 0 );
    647                 }
    648                 static constexpr size_t capacity() { return N; }
    649                 static constexpr size_t size() { return N; }
    650                 static constexpr bool empty() { return N != 0; }
    651                 static constexpr size_t raw_size() { return sizeof( T ) * N; }
    652         };
    653 
    654         template< typename Storage >
    655         class resizable_storage : public Storage
    656         {
    657         public:
    658                 typedef size_t size_type;
    659 
    660                 static constexpr bool is_fixed = false;
    661 
    662                 ~resizable_storage()
    663                 {
    664                         if ( m_size > 0 ) reallocate( 0 );
    665                 }
    666                 constexpr size_t capacity() { return m_size; }
    667                 constexpr size_t size() const { return m_size; }
    668                 constexpr bool empty() const { return m_size != 0; }
    669                 constexpr size_t raw_size() const { return sizeof( value_type ) * m_size; }
    670         protected:
    671                 constexpr resizable_storage() : m_size( 0 ) {}
    672                 // TODO: return type error checking
    673                 bool resize( size_t new_size )
    674                 {
    675                         if ( new_size != m_size )
    676                         {
    677                                 m_size = new_size;
    678                                 return reallocate( m_size );
    679                         }
    680                         return true;
    681                 }
    682         protected:
    683                 size_type m_size;
    684         };
    685 
    686 
    687         template< typename T, size_t N >
    688         using fixed_static_storage  = fixed_storage< static_storage< T, N >, N >;
    689 
    690         template< typename T, size_t N >
    691         using fixed_dynamic_storage = fixed_storage< dynamic_storage< T >, N >;
    692 
    693         template< typename T >
    694         using resizable_dynamic_storage = resizable_storage< dynamic_storage< T > >;
    695 
    696 // TODO:
    697 //      template< typename T, size_t N >
    698 //      using resizable_static_storage  = resizable_storage< static_storage< T, N > >;
    699 
    700 // TODO:
    701 //      template< typename Storage, typename NextCapacity = default_next_capacity >
    702 //      class growable_storage : Storage;
    703 
    704         template <
    705                 typename Storage,
    706                 typename InitializePolicy = policy_initialize_standard
    707         >
    708         class fixed_container_allocator : public Storage
    709         {
    710         public:
    711                 typedef typename Storage::value_type value_type;
    712                 typedef typename Storage::size_type  size_type;
    713 
    714                 fixed_container_allocator()
    715                 {
    716                         InitializePolicy::initialize( data(), data() + Storage::capacity() );
    717                 }
    718 
    719                 ~fixed_container_allocator()
    720                 {
    721                         InitializePolicy::destroy( data(), data() + Storage::capacity() );
    722                 }
    723         };
    724 
    725         template <
    726                 typename Storage,
    727                 typename InitializePolicy = policy_initialize_standard
    728         >
    729         class sized_container_allocator : public Storage
    730         {
    731         public:
    732                 typedef typename Storage::value_type value_type;
    733                 typedef typename Storage::size_type  size_type;
    734 
    735                 sized_container_allocator() {}
    736                 explicit sized_container_allocator( size_type new_size ) { resize( new_size ); }
    737 
    738                 void resize( size_type new_size )
    739                 {
    740                         size_type old_size = Storage::size();
    741                         if ( new_size != old_size )
    742                         {
    743                                 if ( new_size < old_size )
    744                                 {
    745                                         InitializePolicy::destroy( Storage::data() + new_size, Storage::data() + old_size );
    746                                 }
    747                                 Storage::resize( new_size );
    748                                 if ( new_size > old_size )
    749                                 {
    750                                         InitializePolicy::initialize( Storage::data() + old_size, Storage::data() + new_size );
    751                                 }
    752                         }
    753                 }
    754 
    755                 void assign( const value_type* ptr, size_type sz )
    756                 {
    757                         if ( Storage::size() > 0 ) InitializePolicy::destroy( Storage::data(), Storage::data() + Storage::size() );
    758                         if ( ptr != nullptr && sz > 0 )
    759                         {
    760                                 if ( sz != Storage::size() )
    761                                 {
    762                                         Storage::resize( 0 );
    763                                         Storage::resize( sz );
    764                                 }
    765                                 InitializePolicy::copy( ptr, ptr + sz, Storage::data() );
    766                         }
    767                         else Storage::resize( 0 );
    768                 }
    769 
    770                 void clear()
    771                 {
    772                         if ( Storage::size() > 0 )
    773                         {
    774                                 InitializePolicy::destroy( Storage::data(), Storage::data() + Storage::size() );
    775                                 Storage::resize( 0 );
    776                         }
    777                 }
    778 
    779                 ~sized_container_allocator()
    780                 {
    781                         if ( Storage::size() > 0 ) clear();
    782                 }
    783 
    784         };
     505        template < typename T >
     506        using const_array_ref = detail::add_random_access< detail::add_iterators < const_storage_view< T > > >;
     507        template < typename T >
     508        using array_ref       = detail::add_random_access< detail::add_iterators < storage_view< T > > >;
     509        using const_mem_ref = const_array_ref< char >;
     510        using mem_ref       = array_ref< char >;
    785511
    786512}
  • trunk/nv/stl/range.hh

    r377 r383  
    1515#include <nv/core/common.hh>
    1616#include <nv/stl/math.hh>
     17#include <nv/stl/iterator.hh>
    1718#include <nv/stl/traits/transforms.hh>
    18 #include <iterator>
    1919
    2020namespace nv
     
    2525
    2626                template < typename T >
    27                 class forward_iterator_base : public std::iterator< std::input_iterator_tag, T >
     27                class forward_iterator_base : public iterator< input_iterator_tag, T >
    2828                {
    2929                public:
  • trunk/src/formats/assimp_loader.cc

    r382 r383  
    188188}
    189189
    190 bool nv::assimp_loader::load_bones( size_t index, std::vector< mesh_node_data >& bones )
     190bool nv::assimp_loader::load_bones( size_t index, array_ref< mesh_node_data > bones )
    191191{
    192192        if ( m_scene == nullptr ) return false;
     
    285285{
    286286        const aiScene* scene = (const aiScene*)m_scene;
    287         std::vector< mesh_node_data > final_bones;
     287        vector< mesh_node_data > final_bones;
    288288        std::unordered_map< std::string, uint16 > names;
    289289        for ( unsigned int m = 0; m < m_mesh_count; ++m )
    290290        {
    291291                uint16 translate[MAX_BONES];
    292                 std::vector< mesh_node_data > bones;
     292                vector< mesh_node_data > bones;
    293293                const aiMesh*  mesh  = scene->mMeshes[ m ];
    294294                if ( mesh->mNumBones != 0 )
     
    334334        }
    335335        mesh_node_data* bones = new mesh_node_data[ final_bones.size() ];
    336         std::copy( final_bones.begin(), final_bones.end(), bones );
     336        nv::raw_copy( final_bones.begin(), final_bones.end(), bones );
    337337        return new mesh_nodes_data( "bones", final_bones.size(), bones );
    338338}
  • trunk/src/formats/md2_loader.cc

    r376 r383  
    251251        uint32 stats_collision  = 0;
    252252
    253         std::vector< sint32 > index_translation( static_cast< uint32 >( md2->header.num_vertices ), -1 );
     253        vector< sint32 > index_translation( static_cast< uint32 >( md2->header.num_vertices ), -1 );
    254254
    255255        m_new_indexes.clear();
     
    364364        {
    365365                uint16* icp = (uint16*)ic->data;
    366                 std::copy_n( m_new_indexes.data(), m_new_indexes.size(), icp );
     366                raw_copy_n( m_new_indexes.data(), m_new_indexes.size(), icp );
    367367        }
    368368
  • trunk/src/formats/md3_loader.cc

    r376 r383  
    198198        md3->tags     = new md3_tag_t    [ md3->header.num_tags * md3->header.num_frames ];
    199199        md3->surfaces = new md3_surface_t[ md3->header.num_surfaces ];
    200         std::memset( md3->surfaces, 0, static_cast< nv::size_t >( md3->header.num_surfaces ) * sizeof( md3_surface_t ) );
     200        nv::raw_zero_n( md3->surfaces, static_cast< nv::size_t >( md3->header.num_surfaces ) );
    201201
    202202        source.seek( md3->header.ofs_frames, origin::SET );
     
    285285}
    286286
    287 nv::key_raw_channel* nv::md3_loader::load_tags( const std::string& tag )
     287nv::key_raw_channel* nv::md3_loader::load_tags( const string_ref& tag )
    288288{
    289289        md3_t* md3 = (md3_t*)m_md3;
     
    295295                {
    296296                        const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags * f];
    297                         std::string rname((char*)(rtag.name));
     297                        string_ref rname((char*)(rtag.name));
    298298                        if (rname == tag)
    299299                        {
     
    421421        md3_t* md3 = (md3_t*)m_md3;
    422422        uint32 node_count = (uint32)md3->header.num_tags;
    423         if ( node_count == 0 ) return nullptr;;
     423        if ( node_count == 0 ) return nullptr;
    424424        mesh_node_data* nodes = new mesh_node_data[ node_count ];
    425425        for ( uint32 i = 0; i < node_count; ++i )
    426426        {
    427427                const md3_tag_t& rtag = md3->tags[i];
    428                 std::string name( (char*)(rtag.name) );
     428                string_ref name( (char*)(rtag.name) );
    429429
    430430                nodes[i].transform = mat4();
    431                 nodes[i].name      = name;
     431                nodes[i].name      = name.to_string();
    432432                nodes[i].parent_id = -1;
    433433                nodes[i].target_id = -1;
  • trunk/src/formats/md5_loader.cc

    r376 r383  
    4848
    4949        // MESH data
    50         std::vector<md5_joint_info> joint_infos;
    51         std::vector<transform>      base_frames;
     50        dynamic_array< md5_joint_info > joint_infos;
     51        vector< transform >             base_frames;
    5252        size_t num_animated_components = 0;
    5353        size_t frame_rate = 0;
     
    301301                else if ( command == "frame" )
    302302                {
    303                         std::vector<float> frame;
     303                        vector<float> frame;
    304304                        uint32 frame_id;
    305305                        sstream >> frame_id;
     
    454454}
    455455
    456 void md5_loader::build_frame_skeleton( mesh_node_data* nodes, uint32 index, const std::vector<md5_joint_info>& joint_infos, const std::vector<transform>& base_frames, const std::vector<float>& frame_data )
     456void md5_loader::build_frame_skeleton( mesh_node_data* nodes, uint32 index, const const_array_ref<md5_joint_info>& joint_infos, const const_array_ref<transform>& base_frames, const const_array_ref<float>& frame_data )
    457457{
    458458        assert( m_type == ANIMATION );
  • trunk/src/formats/nmd_loader.cc

    r368 r383  
    162162static void nmd_dump_mesh( const mesh_data* mesh, stream& stream_out )
    163163{
    164         const std::vector< mesh_raw_channel* >& data  = mesh->get_raw_channels();
     164        const_array_ref< mesh_raw_channel* > data  = mesh->get_raw_channels();
    165165
    166166        uint32 size = sizeof( nmd_element_header );
  • trunk/src/formats/obj_loader.cc

    r382 r383  
    4444struct obj_reader
    4545{
    46         std::vector< vec3 > v;
    47         std::vector< vec3 > n;
    48         std::vector< vec2 > t;
     46        vector< vec3 > v;
     47        vector< vec3 > n;
     48        vector< vec2 > t;
    4949
    5050        std::string line;
     
    204204        }
    205205        bool m_normals;
    206         std::vector< VTX > m_data;
     206        vector< VTX > m_data;
    207207        virtual void reset() { m_data.clear(); }
    208208        virtual nv::size_t raw_size() const { return m_data.size() * sizeof( VTX ); }
     
    228228        void calculate_tangents()
    229229        {
    230                 //              const std::vector< vec3 >& vp = m_mesh->get_positions();
    231                 //              const std::vector< vec2 >& vt = m_mesh->get_texcoords();
    232                 //              const std::vector< vec3 >& vn = m_mesh->get_normals();
    233                 //              std::vector< vec3 >& tg = m_mesh->get_tangents();
    234 
    235230                nv::size_t count = m_data.size();
    236231                nv::size_t tcount = count / 3;
    237232
    238                 std::vector< vec3 > tan1( count );
    239                 std::vector< vec3 > tan2( count );
     233                vector< vec3 > tan1( count );
     234                vector< vec3 > tan2( count );
    240235
    241236                for ( nv::size_t a = 0; a < tcount; ++a )
     
    335330                {
    336331                        data = new uint8[ reader->raw_size() ];
    337                         std::copy_n( reader->raw_pointer(), reader->raw_size(), data );
     332                        raw_copy_n( reader->raw_pointer(), reader->raw_size(), data );
    338333                }
    339334                channel->data  = data;
  • trunk/src/gfx/image.cc

    r376 r383  
    44
    55#include "nv/gfx/image.hh"
     6#include "nv/stl/algorithm.hh"
    67
    78using namespace nv;
     
    3132                for( int i = 0; i < m_size.y; ++i )
    3233                {
    33                         std::copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline );
     34                        raw_copy( data + i * bline, data + (i + 1) * bline, m_data + bsize - ( i + 1 ) * bline );
    3435                }
    3536
     
    3738        else
    3839        {
    39                 std::copy( data, data + bsize, m_data );
     40                raw_copy( data, data + bsize, m_data );
    4041        }
    4142}
     
    4344void image::fill( uint8 value )
    4445{
    45         std::fill( m_data, m_data + m_size.x * m_size.y * (int)m_depth, value );
     46        raw_fill( m_data, m_data + m_size.x * m_size.y * (int)m_depth, value );
    4647}
    4748
     
    5657        {
    5758                // TODO: test
    58                 std::fill( m_data + bpos + bline * i, m_data + bpos + bline * i + stride, value );
     59                raw_fill( m_data + bpos + bline * i, m_data + bpos + bline * i + stride, value );
    5960        }
    6061}
     
    7374//              memcpy( m_data+((r.pos.y+i)*m_size.x + r.pos.x ) * m_depth,
    7475//                      data + (i*stride), r.size.x * m_depth );
    75                 std::copy( data + i*stride, data + (i+1)*stride, m_data + bpos + bline * i );
     76                raw_copy( data + i*stride, data + (i+1)*stride, m_data + bpos + bline * i );
    7677        }
    7778}
  • trunk/src/gfx/mesh_creator.cc

    r323 r383  
    350350        for ( uint32 i = 0; i < count; ++i )
    351351        {
    352                 std::copy_n( a->data + i * adesc.size, adesc.size, data + i*desc.size );
    353                 std::copy_n( b->data + i * bdesc.size, bdesc.size, data + i*desc.size + adesc.size );
     352                raw_copy_n( a->data + i * adesc.size, adesc.size, data + i*desc.size );
     353                raw_copy_n( b->data + i * bdesc.size, bdesc.size, data + i*desc.size + adesc.size );
    354354        }
    355355        mesh_raw_channel* result = new mesh_raw_channel;
     
    373373        {
    374374                size_t a_size = vtx_size * a->count;
    375                 std::copy_n( a->data, a_size, data );
    376                 std::copy_n( b->data, vtx_size * b->count, data + a_size );             
     375                raw_copy_n( a->data, a_size, data );
     376                raw_copy_n( b->data, vtx_size * b->count, data + a_size );
    377377        }
    378378        else
     
    385385                for ( size_t i = 0; i < frame_count; ++i )
    386386                {
    387                         std::copy_n( a->data + pos_a, frame_size_a, data + pos );
    388                         std::copy_n( b->data + pos_b, frame_size_b, data + pos + frame_size_a );                                pos_a += frame_size_a;
     387                        raw_copy_n( a->data + pos_a, frame_size_a, data + pos );
     388                        raw_copy_n( b->data + pos_b, frame_size_b, data + pos + frame_size_a );                         pos_a += frame_size_a;
    389389                        pos_b += frame_size_b;
    390390                        pos   += frame_size_a + frame_size_b;
  • trunk/src/gfx/skeletal_mesh.cc

    r367 r383  
    4343                        }
    4444
    45                         std::fill( m_pntdata.raw_data(), m_pntdata.raw_data() + m_pntdata.raw_size(), 0 );
     45                        fill( m_pntdata.raw_data(), m_pntdata.raw_data() + m_pntdata.raw_size(), 0 );
    4646                        for ( unsigned int i = 0; i < vertex_count; ++i )
    4747                        {
  • trunk/src/gl/gl_device.cc

    r380 r383  
    221221        const gl_program_info* info = m_programs.get( p );
    222222        {
    223                 uniform_map::const_iterator i = info->m_uniform_map.find( name );
     223                nv::uniform_map::const_iterator i = info->m_uniform_map.find( name );
    224224                if ( i != info->m_uniform_map.end() )
    225225                {
  • trunk/src/io/string_table.cc

    r281 r383  
    66
    77#include "nv/io/string_table.hh"
     8#include <array>
    89
    910nv::string_table_creator::string_table_creator()
  • trunk/src/lua/lua_map_tile.cc

    r378 r383  
    118118                new_tile->ascii = new nv::uchar8[ size ];
    119119        }
    120         std::copy( old_tile->data, old_tile->data + size, new_tile->data );
    121         if ( old_tile->ascii ) std::copy( old_tile->ascii, old_tile->ascii + size, new_tile->ascii );
     120        nv::raw_copy_n( old_tile->data, size, new_tile->data );
     121        if ( old_tile->ascii ) nv::raw_copy_n( old_tile->ascii, size, new_tile->ascii );
    122122
    123123        luaL_getmetatable( L, NLUA_MAP_TILE_METATABLE );
     
    237237        map_tile* tile = nlua_to_pmap_tile( L, 1 );
    238238        // assert( tile^.ascii == nullptr );
    239         std::vector< nv::uint8 > sizes_x = nlua_tobytearray( L, 2 );
    240         std::vector< nv::uint8 > sizes_y = ( lua_istable( L, 3 ) ? nlua_tobytearray( L, 3 ) : sizes_x );
     239        nv::vector< nv::uint8 > sizes_x = nlua_tobytearray( L, 2 );
     240        nv::vector< nv::uint8 > sizes_y;
     241        if ( lua_istable( L, 3 ) )
     242                sizes_y = nlua_tobytearray( L, 2 );
     243        else
     244                sizes_y.assign( sizes_x );
    241245
    242246        nv::uint16 org_x = tile->size_x;
  • trunk/src/lua/lua_raw.cc

    r380 r383  
    262262}
    263263
    264 std::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index )
    265 {
    266         index = lua_absindex( L, index );
    267         std::vector<nv::uint8> result;
     264nv::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index )
     265{
     266        index = lua_absindex( L, index );
     267        nv::vector<nv::uint8> result;
    268268        if ( lua_istable( L, index ) )
    269269        {
Note: See TracChangeset for help on using the changeset viewer.