Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
1c98aa6a
Commit
1c98aa6a
authored
May 14, 2015
by
Miro Knejp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix conversion warnings in Objc marshalling
parent
b38789e6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
37 deletions
+37
-37
support-lib/objc/DJIMarshal+Private.h
support-lib/objc/DJIMarshal+Private.h
+37
-37
No files found.
support-lib/objc/DJIMarshal+Private.h
View file @
1c98aa6a
...
@@ -29,8 +29,8 @@ struct Bool {
...
@@ -29,8 +29,8 @@ struct Bool {
struct
Boxed
{
struct
Boxed
{
using
ObjcType
=
NSNumber
*
;
using
ObjcType
=
NSNumber
*
;
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
assert
(
x
);
return
[
x
boolValue
]
?
true
:
false
;
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
assert
(
x
);
return
Bool
::
toCpp
([
x
boolValue
])
;
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithBool
:
x
?
YES
:
NO
];
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithBool
:
Bool
::
fromCpp
(
x
)
];
}
};
};
};
};
...
@@ -41,46 +41,42 @@ struct Primitive {
...
@@ -41,46 +41,42 @@ struct Primitive {
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
x
;
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
x
;
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
x
;
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
x
;
}
};
struct
I8
:
public
Primitive
<
I8
,
int8_t
>
{
struct
Boxed
{
struct
Boxed
{
using
ObjcType
=
NSNumber
*
;
using
ObjcType
=
NSNumber
*
;
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
[
x
charValue
]
;
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
assert
(
x
);
return
static_cast
<
CppType
>
(
Self
::
unbox
(
x
))
;
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithChar
:
x
]
;
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
Self
::
box
(
x
)
;
}
};
};
};
};
struct
I16
:
public
Primitive
<
I16
,
int16_t
>
{
class
I8
:
public
Primitive
<
I8
,
int8_t
>
{
struct
Boxed
{
friend
Primitive
<
I8
,
int8_t
>
;
using
ObjcType
=
NSNumber
*
;
static
char
unbox
(
Boxed
::
ObjcType
x
)
noexcept
{
return
[
x
charValue
];
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
[
x
shortValue
];
}
static
Boxed
::
ObjcType
box
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithChar
:
static_cast
<
char
>
(
x
)];
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithShort
:
x
];
}
};
};
};
struct
I32
:
public
Primitive
<
I32
,
int32_t
>
{
class
I16
:
public
Primitive
<
I16
,
int16_t
>
{
struct
Boxed
{
friend
Primitive
<
I16
,
int16_t
>
;
using
ObjcType
=
NSNumber
*
;
static
short
unbox
(
Boxed
::
ObjcType
x
)
noexcept
{
return
[
x
shortValue
];
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
[
x
intValue
];
}
static
Boxed
::
ObjcType
box
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithShort
:
static_cast
<
short
>
(
x
)];
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithInt
:
x
];
}
};
};
};
struct
I64
:
public
Primitive
<
I64
,
int64_t
>
{
class
I32
:
public
Primitive
<
I32
,
int32_t
>
{
struct
Boxed
{
friend
Primitive
<
I32
,
int32_t
>
;
using
ObjcType
=
NSNumber
*
;
static
int
unbox
(
Boxed
::
ObjcType
x
)
noexcept
{
return
[
x
intValue
];
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
[
x
longLongValue
];
}
static
Boxed
::
ObjcType
box
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithInt
:
static_cast
<
int
>
(
x
)];
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithLongLong
:
x
];
}
};
};
};
struct
F64
:
public
Primitive
<
F64
,
double
>
{
class
I64
:
public
Primitive
<
I64
,
int64_t
>
{
struct
Boxed
{
friend
Primitive
<
I64
,
int64_t
>
;
using
ObjcType
=
NSNumber
*
;
static
long
long
unbox
(
Boxed
::
ObjcType
x
)
noexcept
{
return
[
x
longLongValue
];
}
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
[
x
doubleValue
];
}
static
Boxed
::
ObjcType
box
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithLongLong
:
static_cast
<
long
long
>
(
x
)];
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithDouble
:
x
];
}
};
};
class
F64
:
public
Primitive
<
F64
,
double
>
{
friend
Primitive
<
F64
,
double
>
;
static
CppType
unbox
(
Boxed
::
ObjcType
x
)
noexcept
{
return
[
x
doubleValue
];
}
static
Boxed
::
ObjcType
box
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithDouble
:
x
];
}
};
};
template
<
class
CppEnum
,
class
ObjcEnum
>
template
<
class
CppEnum
,
class
ObjcEnum
>
...
@@ -105,13 +101,15 @@ struct String {
...
@@ -105,13 +101,15 @@ struct String {
using
Boxed
=
String
;
using
Boxed
=
String
;
static
CppType
toCpp
(
ObjcType
string
)
{
static
CppType
toCpp
(
ObjcType
string
)
{
assert
(
string
);
return
{[
string
UTF8String
],
[
string
lengthOfBytesUsingEncoding
:
NSUTF8StringEncoding
]};
return
{[
string
UTF8String
],
[
string
lengthOfBytesUsingEncoding
:
NSUTF8StringEncoding
]};
}
}
static
ObjcType
fromCpp
(
const
CppType
&
string
)
{
static
ObjcType
fromCpp
(
const
CppType
&
string
)
{
assert
(
string
.
size
()
<=
std
::
numeric_limits
<
NSUInteger
>::
max
());
assert
(
string
.
size
()
<=
std
::
numeric_limits
<
NSUInteger
>::
max
());
// Using the pointer from .data() on an empty string is UB
return
[[
NSString
alloc
]
initWithBytes
:
string
.
data
()
return
string
.
empty
()
?
@""
:
[[
NSString
alloc
]
initWithBytes
:
string
.
data
()
length
:
string
.
size
()
encoding
:
NSUTF8StringEncoding
];
length:
static_cast
<
NSUInteger
>
(
string
.
size
())
encoding:
NSUTF8StringEncoding
];
}
}
};
};
...
@@ -126,8 +124,8 @@ struct Date {
...
@@ -126,8 +124,8 @@ struct Date {
}
}
static
ObjcType
fromCpp
(
const
CppType
&
date
)
{
static
ObjcType
fromCpp
(
const
CppType
&
date
)
{
return
[
NSDate
dateWithTimeIntervalSince1970
:
using
namespace
std
::
chrono
;
::
std
:
:
chrono
::
duration_cast
<::
std
::
chrono
::
duration
<
double
>>
(
date
.
time_since_epoch
()).
count
()];
return
[
NSDate
dateWithTimeIntervalSince1970
:
duration_cast
<
duration
<
double
>>
(
date
.
time_since_epoch
()).
count
()];
}
}
};
};
...
@@ -139,6 +137,7 @@ struct Binary {
...
@@ -139,6 +137,7 @@ struct Binary {
using
Boxed
=
Binary
;
using
Boxed
=
Binary
;
static
CppType
toCpp
(
ObjcType
data
)
{
static
CppType
toCpp
(
ObjcType
data
)
{
assert
(
data
);
auto
bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
data
.
bytes
);
auto
bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
data
.
bytes
);
return
data
.
length
>
0
?
CppType
{
bytes
,
bytes
+
data
.
length
}
:
CppType
{};
return
data
.
length
>
0
?
CppType
{
bytes
,
bytes
+
data
.
length
}
:
CppType
{};
}
}
...
@@ -146,11 +145,11 @@ struct Binary {
...
@@ -146,11 +145,11 @@ struct Binary {
static
ObjcType
fromCpp
(
const
CppType
&
bytes
)
{
static
ObjcType
fromCpp
(
const
CppType
&
bytes
)
{
assert
(
bytes
.
size
()
<=
std
::
numeric_limits
<
NSUInteger
>::
max
());
assert
(
bytes
.
size
()
<=
std
::
numeric_limits
<
NSUInteger
>::
max
());
// Using the pointer from .data() on an empty vector is UB
// Using the pointer from .data() on an empty vector is UB
return
bytes
.
empty
()
?
[
NSData
data
]
:
[
NSData
dataWithBytes
:
bytes
.
data
()
length
:
bytes
.
size
()];
return
bytes
.
empty
()
?
[
NSData
data
]
:
[
NSData
dataWithBytes
:
bytes
.
data
()
length:
static_cast
<
NSUInteger
>
(
bytes
.
size
())];
}
}
};
};
template
<
template
<
class
>
class
OptionalType
,
class
T
>
template
<
template
<
class
>
class
OptionalType
,
class
T
>
class
Optional
{
class
Optional
{
public:
public:
...
@@ -183,8 +182,9 @@ public:
...
@@ -183,8 +182,9 @@ public:
assert
(
array
);
assert
(
array
);
auto
v
=
CppType
();
auto
v
=
CppType
();
v
.
reserve
(
array
.
count
);
v
.
reserve
(
array
.
count
);
for
(
EObjcType
value
in
array
)
for
(
EObjcType
value
in
array
)
{
v
.
push_back
(
T
::
Boxed
::
toCpp
(
value
));
v
.
push_back
(
T
::
Boxed
::
toCpp
(
value
));
}
return
v
;
return
v
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment