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
3c1bd658
Commit
3c1bd658
authored
Mar 22, 2015
by
Miro Knejp
Committed by
Jacob Potter
May 01, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract binary translation into a predefined support lib helper class
parent
5f3d02e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
7 deletions
+24
-7
example/generated-src/objc/TXSItemList.mm
example/generated-src/objc/TXSItemList.mm
+2
-4
src/source/ObjcppGenerator.scala
src/source/ObjcppGenerator.scala
+3
-3
support-lib/objc/DJIMarshal+Private.h
support-lib/objc/DJIMarshal+Private.h
+19
-0
No files found.
example/generated-src/objc/TXSItemList.mm
View file @
3c1bd658
...
@@ -41,9 +41,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
...
@@ -41,9 +41,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
std
::
vector
<
NSString
*>
_itemsTempVector
;
std
::
vector
<
NSString
*>
_itemsTempVector
;
_itemsTempVector
.
reserve
(
itemList
.
items
.
size
());
_itemsTempVector
.
reserve
(
itemList
.
items
.
size
());
for
(
const
auto
&
cppValue_0
:
itemList
.
items
)
{
for
(
const
auto
&
cppValue_0
:
itemList
.
items
)
{
NSString
*
objcValue_0
=
[[
NSString
alloc
]
initWithBytes
:
cppValue_0
.
data
()
NSString
*
objcValue_0
=
::
djinni
::
String
::
fromCpp
(
cppValue_0
);
length:
cppValue_0
.
length
()
encoding:
NSUTF8StringEncoding
];
_itemsTempVector
.
push_back
(
objcValue_0
);
_itemsTempVector
.
push_back
(
objcValue_0
);
}
}
_items
=
[
NSArray
arrayWithObjects
:
&
_itemsTempVector
[
0
]
count
:
_itemsTempVector
.
size
()];
_items
=
[
NSArray
arrayWithObjects
:
&
_itemsTempVector
[
0
]
count
:
_itemsTempVector
.
size
()];
...
@@ -56,7 +54,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
...
@@ -56,7 +54,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
std
::
vector
<
std
::
string
>
items
;
std
::
vector
<
std
::
string
>
items
;
items
.
reserve
([
_items
count
]);
items
.
reserve
([
_items
count
]);
for
(
NSString
*
objcValue_0
in
_items
)
{
for
(
NSString
*
objcValue_0
in
_items
)
{
std
::
string
cppValue_0
([
objcValue_0
UTF8String
],
[
objcValue_0
lengthOfBytesUsingEncoding
:
NSUTF8StringEncoding
]
);
std
::
string
cppValue_0
=
::
djinni
::
String
::
toCpp
(
objcValue_0
);
items
.
push_back
(
std
::
move
(
cppValue_0
));
items
.
push_back
(
std
::
move
(
cppValue_0
));
}
}
return
::
textsort
::
ItemList
(
return
::
textsort
::
ItemList
(
...
...
src/source/ObjcppGenerator.scala
View file @
3c1bd658
...
@@ -626,7 +626,8 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
...
@@ -626,7 +626,8 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
w
.
wl
(
s
"std::chrono::duration_cast<std::chrono::duration<double>>($cppIdent.time_since_epoch()).count()];"
)
w
.
wl
(
s
"std::chrono::duration_cast<std::chrono::duration<double>>($cppIdent.time_since_epoch()).count()];"
)
}
}
}
}
case
MBinary
=>
w
.
wl
(
s
"$objcType$objcIdent = [NSData dataWithBytes:(&$cppIdent[0]) length:($cppIdent.size())];"
)
case
MBinary
=>
w
.
wl
(
s
"$objcType$objcIdent = ::djinni::Binary::fromCpp($cppIdent);"
)
case
MOptional
=>
throw
new
AssertionError
(
"optional should have been special cased"
)
case
MOptional
=>
throw
new
AssertionError
(
"optional should have been special cased"
)
case
MList
=>
case
MList
=>
val
objcName
=
"objcValue_"
+
valueLevel
val
objcName
=
"objcValue_"
+
valueLevel
...
@@ -735,8 +736,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
...
@@ -735,8 +736,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::String::toCpp($objcIdent);"
)
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::String::toCpp($objcIdent);"
)
case
MDate
=>
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::convert_date([$objcIdent timeIntervalSince1970]);"
)
case
MDate
=>
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::convert_date([$objcIdent timeIntervalSince1970]);"
)
case
MBinary
=>
case
MBinary
=>
w
.
wl
(
s
"$cppType $cppIdent([$objcIdent length]);"
)
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::Binary::toCpp($objcIdent);"
)
w
.
wl
(
s
"[$objcIdent getBytes:(static_cast<void *>($cppIdent.data())) length:[$objcIdent length]];"
)
case
MOptional
=>
throw
new
AssertionError
(
"optional should have been special cased"
)
case
MOptional
=>
throw
new
AssertionError
(
"optional should have been special cased"
)
case
MList
=>
case
MList
=>
val
cppName
=
"cppValue_"
+
valueLevel
val
cppName
=
"cppValue_"
+
valueLevel
...
...
support-lib/objc/DJIMarshal+Private.h
View file @
3c1bd658
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#include <cstdint>
#include <cstdint>
#include <string>
#include <string>
#include <vector>
static_assert
(
__has_feature
(
objc_arc
),
"Djinni requires ARC to be enabled for this file"
);
static_assert
(
__has_feature
(
objc_arc
),
"Djinni requires ARC to be enabled for this file"
);
...
@@ -110,4 +111,22 @@ struct String {
...
@@ -110,4 +111,22 @@ struct String {
}
}
};
};
struct
Binary
{
using
CppType
=
std
::
vector
<
uint8_t
>
;
using
ObjcType
=
NSData
*
;
using
Boxed
=
Binary
;
static
CppType
toCpp
(
ObjcType
data
)
{
auto
bytes
=
reinterpret_cast
<
const
uint8_t
*>
(
data
.
bytes
);
return
data
.
length
>
0
?
CppType
{
bytes
,
bytes
+
data
.
length
}
:
CppType
{};
}
static
ObjcType
fromCpp
(
const
CppType
&
bytes
)
{
assert
(
bytes
.
size
()
<=
std
::
numeric_limits
<
NSUInteger
>::
max
());
// Using the pointer from .data() on an empty vector is UB
return
bytes
.
empty
()
?
[
NSData
data
]
:
[
NSData
dataWithBytes
:
bytes
.
data
()
length
:
bytes
.
size
()];
}
};
}
// namespace djinni
}
// namespace djinni
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