Skip to content

Commit

Permalink
Added ObjectiveCPP::ArrayFromVectorIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Feb 13, 2018
1 parent f9aeb0f commit 23a982e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ObjectiveCPP/include/ObjectiveCPP/Vector.hpp
Expand Up @@ -58,17 +58,24 @@ namespace ObjectiveCPP
NSArray * ArrayFromVector( const std::vector< float > & vector );
NSArray * ArrayFromVector( const std::vector< double > & vector );

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
#endif
template < typename T, typename ObjCClass >
NSArray * ArrayFromVector( const std::vector< T > & vector, SEL initMethod )
NSArray * ArrayFromVectorIterator( typename std::vector< T >::const_iterator begin, typename std::vector< T >::const_iterator end, SEL initMethod )
#ifdef __clang__
#pragma clang diagnostic pop
#endif
{
NSMutableArray * a;
id ( * i )( id, SEL, T );

a = [ NSMutableArray arrayWithCapacity: vector.size() ];
a = [ [ NSMutableArray alloc ] init ];

if( [ ObjCClass instancesRespondToSelector: initMethod ] )
{
for( auto v: vector )
for( auto it = begin; it != end; it++ )
{
{
id o;
Expand All @@ -78,7 +85,7 @@ namespace ObjectiveCPP

if( i != NULL )
{
o = i( o, initMethod, v );
o = i( o, initMethod, *( it ) );

if( o != nil )
{
Expand All @@ -96,6 +103,12 @@ namespace ObjectiveCPP
return [ NSArray arrayWithArray: a ];
}

template < typename T, typename ObjCClass >
NSArray * ArrayFromVector( const std::vector< T > & vector, SEL initMethod )
{
return ArrayFromVectorIterator< T, ObjCClass >( vector.cbegin(), vector.cend(), initMethod );
}

template < typename T, typename ObjCClass >
std::vector< T > VectorFromArray( NSArray * array, SEL getter )
{
Expand Down

0 comments on commit 23a982e

Please sign in to comment.