Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ObjectiveCPP/include/ObjectiveCPP/List.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ namespace ObjectiveCPP
for( auto v: vector )
{
{
id o;
NSObject * o;

o = [ ObjCClass alloc ];
i = reinterpret_cast< id ( * )( id, SEL, T ) >( [ o methodForSelector: initMethod ] );

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

Expand All @@ -100,7 +100,7 @@ namespace ObjectiveCPP
std::list< T > ListFromArray( NSArray * array, SEL getter )
{
std::list< T > l;
id o;
NSObject * o;
T ( * i )( id, SEL );

if( [ ObjCClass instancesRespondToSelector: getter ] )
Expand All @@ -111,7 +111,7 @@ namespace ObjectiveCPP
{
i = reinterpret_cast< T ( * )( id, SEL ) >( [ o methodForSelector: getter ] );

if( i != NULL )
if( i != nullptr )
{
l.push_back( i( o, getter ) );
}
Expand Down
12 changes: 6 additions & 6 deletions ObjectiveCPP/include/ObjectiveCPP/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ namespace ObjectiveCPP
for( auto p: map )
{
{
id oK;
id oV;
NSObject< NSCopying > * oK;
NSObject * oV;

oK = [ ObjCClassK alloc ];
oV = [ ObjCClassV alloc ];
iK = reinterpret_cast< id ( * )( id, SEL, TK ) >( [ oK methodForSelector: initMethodK ] );
iV = reinterpret_cast< id ( * )( id, SEL, TV ) >( [ oV methodForSelector: initMethodV ] );

if( iK != NULL && iV != NULL )
if( iK != nullptr && iV != nullptr )
{
oK = iK( oK, initMethodK, p.first );
oV = iV( oV, initMethodV, p.second );
Expand Down Expand Up @@ -99,8 +99,8 @@ namespace ObjectiveCPP
std::map< TK, TV > MapFromDictionary( NSDictionary * dictionary, SEL getterK, SEL getterV )
{
std::map< TK, TV > m;
id oK;
id oV;
NSObject * oK;
NSObject * oV;
TK ( * iK )( id, SEL );
TV ( * iV )( id, SEL );

Expand All @@ -115,7 +115,7 @@ namespace ObjectiveCPP
iK = reinterpret_cast< TK ( * )( id, SEL ) >( [ oK methodForSelector: getterK ] );
iV = reinterpret_cast< TV ( * )( id, SEL ) >( [ oV methodForSelector: getterV ] );

if( iK != NULL && iV != NULL )
if( iK != nullptr && iV != nullptr )
{
m.insert( { iK( oK, getterK ), iV( oV, getterV ) } );
}
Expand Down
8 changes: 4 additions & 4 deletions ObjectiveCPP/include/ObjectiveCPP/NSString+ObjectiveCPP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ NS_ASSUME_NONNULL_BEGIN
+ ( NSStringEncoding )defaultCPPStringEncoding;
+ ( void )setDefaultCPPStringEncoding: ( NSStringEncoding )encoding;

+ ( instancetype )stringWithCPPString: ( const std::string & )cppString;
+ ( instancetype )stringWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )enc;
+ ( NSString * )stringWithCPPString: ( const std::string & )cppString;
+ ( NSString * )stringWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )enc;
+ ( std::string )cppStringWithContentsOfFile: ( NSString * )path encoding: ( NSStringEncoding )enc error: ( NSError * __autoreleasing * )error;
+ ( std::string )cppStringWithContentsOfFile: ( NSString * )path usedEncoding: ( nullable NSStringEncoding * )enc error: ( NSError * __autoreleasing * )error;
+ ( std::string )cppStringWithContentsOfURL: ( NSURL * )url encoding: ( NSStringEncoding )enc error: ( NSError * __autoreleasing * )error;
+ ( std::string )cppStringWithContentsOfURL: ( NSURL * )url usedEncoding: ( nullable NSStringEncoding * )enc error: ( NSError * __autoreleasing * )error;

- ( instancetype )initWithCPPString: ( const std::string & )cppString;
- ( instancetype )initWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )encoding;
- ( NSString * )initWithCPPString: ( const std::string & )cppString;
- ( NSString * )initWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )encoding;

- ( std::string )cppString;
- ( std::string )cppStringUsingEncoding: ( NSStringEncoding )encoding;
Expand Down
8 changes: 4 additions & 4 deletions ObjectiveCPP/include/ObjectiveCPP/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ namespace ObjectiveCPP
for( auto it = begin; it != end; it++ )
{
{
id o;
NSObject * o;

o = [ ObjCClass alloc ];
i = reinterpret_cast< id ( * )( id, SEL, T ) >( [ o methodForSelector: initMethod ] );

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

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace ObjectiveCPP
std::vector< T > VectorFromArray( NSArray * array, SEL getter )
{
std::vector< T > v;
id o;
NSObject * o;
T ( * i )( id, SEL );

if( [ ObjCClass instancesRespondToSelector: getter ] )
Expand All @@ -126,7 +126,7 @@ namespace ObjectiveCPP
{
i = reinterpret_cast< T ( * )( id, SEL ) >( [ o methodForSelector: getter ] );

if( i != NULL )
if( i != nullptr )
{
v.push_back( i( o, getter ) );
}
Expand Down
8 changes: 4 additions & 4 deletions ObjectiveCPP/source/NSString+ObjectiveCPP.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ + ( void )setDefaultCPPStringEncoding: ( NSStringEncoding )encoding
}
}

+ ( instancetype )stringWithCPPString: ( const std::string & )cppString
+ ( NSString * )stringWithCPPString: ( const std::string & )cppString
{
NSString * str;

Expand All @@ -63,7 +63,7 @@ + ( instancetype )stringWithCPPString: ( const std::string & )cppString
return ( str ) ? str : @"";
}

+ ( instancetype )stringWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )enc
+ ( NSString * )stringWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )enc
{
NSString * str;

Expand Down Expand Up @@ -92,7 +92,7 @@ + ( instancetype )stringWithCPPString: ( const std::string & )cppString encoding
return [ [ NSString stringWithContentsOfURL: url usedEncoding: enc error: error ] cppStringUsingEncoding: *( enc ) ];
}

- ( instancetype )initWithCPPString: ( const std::string & )cppString
- ( NSString * )initWithCPPString: ( const std::string & )cppString
{
NSString * str;

Expand All @@ -101,7 +101,7 @@ - ( instancetype )initWithCPPString: ( const std::string & )cppString
return ( str ) ? str : @"";
}

- ( instancetype )initWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )encoding
- ( NSString * )initWithCPPString: ( const std::string & )cppString encoding: ( NSStringEncoding )encoding
{
NSString * str;

Expand Down
18 changes: 9 additions & 9 deletions Unit-Tests/Test-List.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - ( instancetype )initWithSTDString: ( std::string )s
TEST( ObjectiveCPP_List, ArrayFromList_String )
{
std::list< std::string > l = { "hello, world", "hello, universe" };
NSArray * a;
NSArray< NSString * > * a;

a = ObjectiveCPP::ArrayFromList( l );

Expand All @@ -83,8 +83,8 @@ - ( instancetype )initWithSTDString: ( std::string )s

TEST( ObjectiveCPP_List, ArrayFromList_Bool )
{
std::list< bool > l = { true, false, true };
NSArray * a;
std::list< bool > l = { true, false, true };
NSArray< NSNumber * > * a;

a = ObjectiveCPP::ArrayFromList( l );

Expand All @@ -102,8 +102,8 @@ - ( instancetype )initWithSTDString: ( std::string )s
template< typename T >
void ObjectiveCPP_List_ArrayFromList_Number_T( void )
{
std::list< T > l = { 0, 1, 2, 42 };
NSArray * a;
std::list< T > l = { 0, 1, 2, 42 };
NSArray< NSNumber * > * a;

a = ObjectiveCPP::ArrayFromList( l );

Expand Down Expand Up @@ -138,8 +138,8 @@ void ObjectiveCPP_List_ArrayFromList_Number_T( void )

TEST( ObjectiveCPP_List, ArrayFromList_Custom )
{
std::list< std::string > l = { "hello, world", "hello, universe" };
NSArray * a;
std::list< std::string > l = { "hello, world", "hello, universe" };
NSArray< ObjectiveCPP_List_Test * > * a;

a = ObjectiveCPP::ArrayFromList< std::string, ObjectiveCPP_List_Test >( l, @selector( initWithSTDString: ) );

Expand All @@ -148,8 +148,8 @@ void ObjectiveCPP_List_ArrayFromList_Number_T( void )
ASSERT_TRUE( [ a[ 0 ] isKindOfClass: [ ObjectiveCPP_List_Test class ] ] );
ASSERT_TRUE( [ a[ 1 ] isKindOfClass: [ ObjectiveCPP_List_Test class ] ] );

ASSERT_TRUE( ( ( ObjectiveCPP_List_Test * )a[ 0 ] ).string == "hello, world" );
ASSERT_TRUE( ( ( ObjectiveCPP_List_Test * )a[ 1 ] ).string == "hello, universe" );
ASSERT_TRUE( a[ 0 ].string == "hello, world" );
ASSERT_TRUE( a[ 1 ].string == "hello, universe" );
}

TEST( ObjectiveCPP_List, ListFromArray_String )
Expand Down
16 changes: 8 additions & 8 deletions Unit-Tests/Test-Map.mm
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ - ( instancetype )initWithSTDString: ( std::string )s

TEST( ObjectiveCPP_Map, DictionaryFromMap_Int_Int )
{
std::map< int, int > m = { { 0, 1 }, { 2, 3 }, { 42, 43 } };
NSDictionary * d;
std::map< int, int > m = { { 0, 1 }, { 2, 3 }, { 42, 43 } };
NSDictionary< NSNumber *, NSNumber * > * d;

d = ObjectiveCPP::DictionaryFromMap< int, NSNumber >( m, @selector( initWithInt: ) );

Expand All @@ -111,8 +111,8 @@ - ( instancetype )initWithSTDString: ( std::string )s

TEST( ObjectiveCPP_Map, DictionaryFromMap_String_String )
{
std::map< std::string, std::string > m = { { "hello", "world" }, { "foo", "bar" } };
NSDictionary * d;
std::map< std::string, std::string > m = { { "hello", "world" }, { "foo", "bar" } };
NSDictionary< NSString *, NSString * > * d;

d = ObjectiveCPP::DictionaryFromMap( m );

Expand All @@ -130,8 +130,8 @@ - ( instancetype )initWithSTDString: ( std::string )s

TEST( ObjectiveCPP_Map, ArrayFromVector_String_Custom )
{
std::map< std::string, std::string > m = { { "hello", "world" }, { "foo", "bar" } };
NSDictionary * d;
std::map< std::string, std::string > m = { { "hello", "world" }, { "foo", "bar" } };
NSDictionary< NSObject< NSCopying > *, ObjectiveCPP_Map_Test_V * > * d;

d = ObjectiveCPP::DictionaryFromMap< std::string, std::string, NSString, ObjectiveCPP_Map_Test_V >( m, @selector( initWithCPPString: ), @selector( initWithSTDString: ) );

Expand All @@ -143,8 +143,8 @@ - ( instancetype )initWithSTDString: ( std::string )s
ASSERT_TRUE( [ [ d objectForKey: @"hello" ] isKindOfClass: [ ObjectiveCPP_Map_Test_V class ] ] );
ASSERT_TRUE( [ [ d objectForKey: @"foo" ] isKindOfClass: [ ObjectiveCPP_Map_Test_V class ] ] );

ASSERT_TRUE( ( ( ObjectiveCPP_Map_Test_K * )[ d objectForKey: @"hello" ] ).string == "world" );
ASSERT_TRUE( ( ( ObjectiveCPP_Map_Test_V * )[ d objectForKey: @"foo" ] ).string == "bar" );
ASSERT_TRUE( [ d objectForKey: @"hello" ].string == "world" );
ASSERT_TRUE( [ d objectForKey: @"foo" ].string == "bar" );
}

TEST( ObjectiveCPP_Map, MapFromDictionary_String_String )
Expand Down
18 changes: 13 additions & 5 deletions Unit-Tests/Test-NSString+ObjectiveCPP.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,37 @@
TEST( ObjectiveCPP_NSString, cppStringWithContentsOfURL_encoding_error )
{
NSError * e;
NSURL * u1;
NSURL * u2;

e = nil;
e = nil;
u1 = [ NSURL URLWithString: @"file:///etc/hosts" ];
u2 = [ NSURL URLWithString: @"file:///foo/bar" ];

ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: [ NSURL URLWithString: @"file:///etc/hosts" ] encoding: NSUTF8StringEncoding error: &e ].length() > 0 );
ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: u1 encoding: NSUTF8StringEncoding error: &e ].length() > 0 );
ASSERT_TRUE( e == nil );

ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: [ NSURL URLWithString: @"file:///foo/bar" ] encoding: NSUTF8StringEncoding error: &e ].length() == 0 );
ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: u2 encoding: NSUTF8StringEncoding error: &e ].length() == 0 );
ASSERT_TRUE( e != nil );
}

TEST( ObjectiveCPP_NSString, cppStringWithContentsOfURL_usedEncoding_error )
{
NSError * e;
NSStringEncoding enc;
NSURL * u1;
NSURL * u2;

e = nil;
enc = 0;
u1 = [ NSURL URLWithString: @"file:///etc/hosts" ];
u2 = [ NSURL URLWithString: @"file:///foo/bar" ];

ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: [ NSURL URLWithString: @"file:///etc/hosts" ] usedEncoding: &enc error: &e ].length() > 0 );
ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: u1 usedEncoding: &enc error: &e ].length() > 0 );
ASSERT_TRUE( e == nil );
ASSERT_TRUE( enc != 0 );

ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: [ NSURL URLWithString: @"file:///foo/bar" ] usedEncoding: &enc error: &e ].length() == 0 );
ASSERT_TRUE( [ NSString cppStringWithContentsOfURL: u2 usedEncoding: &enc error: &e ].length() == 0 );
ASSERT_TRUE( e != nil );
ASSERT_TRUE( enc != 0 );
}
Expand Down
18 changes: 9 additions & 9 deletions Unit-Tests/Test-Vector.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - ( instancetype )initWithSTDString: ( std::string )s
TEST( ObjectiveCPP_Vector, ArrayFromVector_String )
{
std::vector< std::string > v = { "hello, world", "hello, universe" };
NSArray * a;
NSArray< NSString * > * a;

a = ObjectiveCPP::ArrayFromVector( v );

Expand All @@ -83,8 +83,8 @@ - ( instancetype )initWithSTDString: ( std::string )s

TEST( ObjectiveCPP_Vector, ArrayFromVector_Bool )
{
std::vector< bool > v = { true, false, true };
NSArray * a;
std::vector< bool > v = { true, false, true };
NSArray< NSNumber * > * a;

a = ObjectiveCPP::ArrayFromVector( v );

Expand All @@ -102,8 +102,8 @@ - ( instancetype )initWithSTDString: ( std::string )s
template< typename T >
void ObjectiveCPP_Vector_ArrayFromVector_Number_T( void )
{
std::vector< T > v = { 0, 1, 2, 42 };
NSArray * a;
std::vector< T > v = { 0, 1, 2, 42 };
NSArray< NSNumber * > * a;

a = ObjectiveCPP::ArrayFromVector( v );

Expand Down Expand Up @@ -138,8 +138,8 @@ void ObjectiveCPP_Vector_ArrayFromVector_Number_T( void )

TEST( ObjectiveCPP_Vector, ArrayFromVector_Custom )
{
std::vector< std::string > v = { "hello, world", "hello, universe" };
NSArray * a;
std::vector< std::string > v = { "hello, world", "hello, universe" };
NSArray< ObjectiveCPP_Vector_Test * > * a;

a = ObjectiveCPP::ArrayFromVector< std::string, ObjectiveCPP_Vector_Test >( v, @selector( initWithSTDString: ) );

Expand All @@ -148,8 +148,8 @@ void ObjectiveCPP_Vector_ArrayFromVector_Number_T( void )
ASSERT_TRUE( [ a[ 0 ] isKindOfClass: [ ObjectiveCPP_Vector_Test class ] ] );
ASSERT_TRUE( [ a[ 1 ] isKindOfClass: [ ObjectiveCPP_Vector_Test class ] ] );

ASSERT_TRUE( ( ( ObjectiveCPP_Vector_Test * )a[ 0 ] ).string == "hello, world" );
ASSERT_TRUE( ( ( ObjectiveCPP_Vector_Test * )a[ 1 ] ).string == "hello, universe" );
ASSERT_TRUE( a[ 0 ].string == "hello, world" );
ASSERT_TRUE( a[ 1 ].string == "hello, universe" );
}

TEST( ObjectiveCPP_List, VectorFromArray_String )
Expand Down