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
477d629a
Commit
477d629a
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 enum translation into a predefined support lib helper class
parent
aec43dad
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
28 additions
and
128 deletions
+28
-128
example/generated-src/objc/TXSSortItems.mm
example/generated-src/objc/TXSSortItems.mm
+2
-2
example/generated-src/objc/TXSSortOrderTranslator+Private.h
example/generated-src/objc/TXSSortOrderTranslator+Private.h
+0
-13
example/generated-src/objc/TXSSortOrderTranslator.mm
example/generated-src/objc/TXSSortOrderTranslator.mm
+0
-21
src/source/ObjcppGenerator.scala
src/source/ObjcppGenerator.scala
+10
-50
support-lib/objc/DJIMarshal+Private.h
support-lib/objc/DJIMarshal+Private.h
+15
-0
test-suite/generated-src/objc/DBColorTranslator+Private.h
test-suite/generated-src/objc/DBColorTranslator+Private.h
+0
-13
test-suite/generated-src/objc/DBColorTranslator.mm
test-suite/generated-src/objc/DBColorTranslator.mm
+0
-21
test-suite/generated-src/objc/DBTestHelpers.mm
test-suite/generated-src/objc/DBTestHelpers.mm
+1
-2
test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj
test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj
+0
-6
No files found.
example/generated-src/objc/TXSSortItems.mm
View file @
477d629a
...
...
@@ -5,11 +5,11 @@
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "TXSItemList+Private.h"
#import "TXSSortItems+Private.h"
#import "TXSSortItems.h"
#import "TXSSortOrder.h"
#import "TXSSortOrderTranslator+Private.h"
#import "TXSTextboxListenerObjcProxy+Private.h"
#include <exception>
#include <utility>
...
...
@@ -45,7 +45,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
-
(
void
)
sort
:(
TXSSortOrder
)
order
items
:(
TXSItemList
*
)
items
{
try
{
::
textsort
::
sort_order
cppOrder
=
[
TXSSortOrderTranslator
objcSortOrderToCppSortOrder
:
order
]
;
::
textsort
::
sort_order
cppOrder
=
::
djinni
::
Enum
<::
textsort
::
sort_order
,
TXSSortOrder
>::
toCpp
(
order
)
;
::
textsort
::
ItemList
cppItems
=
std
::
move
([
items
cppItemList
]);
_cppRef
->
sort
(
std
::
move
(
cppOrder
),
std
::
move
(
cppItems
));
}
DJINNI_TRANSLATE_EXCEPTIONS
()
...
...
example/generated-src/objc/TXSSortOrderTranslator+Private.h
deleted
100644 → 0
View file @
aec43dad
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSSortOrder.h"
#include "sort_order.hpp"
#import <Foundation/Foundation.h>
@interface
TXSSortOrderTranslator
:
NSObject
+
(
TXSSortOrder
)
cppSortOrderToObjcSortOrder
:(
::
textsort
::
sort_order
)
sortOrder
;
+
(
::
textsort
::
sort_order
)
objcSortOrderToCppSortOrder
:(
TXSSortOrder
)
sortOrder
;
@end
example/generated-src/objc/TXSSortOrderTranslator.mm
deleted
100644 → 0
View file @
aec43dad
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni
#import "TXSSortOrderTranslator+Private.h"
#import <Foundation/Foundation.h>
static_assert
(
__has_feature
(
objc_arc
),
"Djinni requires ARC to be enabled for this file"
);
@implementation
TXSSortOrderTranslator
+
(
TXSSortOrder
)
cppSortOrderToObjcSortOrder
:(
::
textsort
::
sort_order
)
sortOrder
{
return
static_cast
<
TXSSortOrder
>
(
sortOrder
);
}
+
(
::
textsort
::
sort_order
)
objcSortOrderToCppSortOrder
:(
TXSSortOrder
)
sortOrder
{
return
static_cast
<
enum
::
textsort
::
sort_order
>
(
sortOrder
);
}
@end
src/source/ObjcppGenerator.scala
View file @
477d629a
...
...
@@ -47,7 +47,7 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
case
d
:
MDef
=>
d
.
defType
match
{
case
DEnum
=>
body
.
add
(
"#import "
+
q
(
spec
.
objcIncludePrefix
+
headerName
(
d
.
name
)))
body
.
add
(
"#import "
+
q
(
spec
.
objc
IncludePrivatePrefix
+
enumTranslatorHeaderName
(
d
.
name
)
))
body
.
add
(
"#import "
+
q
(
spec
.
objc
BaseLibIncludePrefix
+
"DJIMarshal+Private.h"
))
header
.
add
(
"#import "
+
q
(
spec
.
objcIncludePrefix
+
headerName
(
d
.
name
)))
case
DInterface
=>
header
.
add
(
"#import <Foundation/Foundation.h>"
)
...
...
@@ -72,52 +72,9 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
}
override
def
generateEnum
(
origin
:
String
,
ident
:
Ident
,
doc
:
Doc
,
e
:
Enum
)
{
val
refs
=
new
ObjcRefs
()
refs
.
header
.
add
(
"#import <Foundation/Foundation.h>"
)
refs
.
privHeader
.
add
(
"#import <Foundation/Foundation.h>"
)
refs
.
privHeader
.
add
(
"!#import "
+
q
(
spec
.
objcIncludePrefix
+
headerName
(
ident
)))
refs
.
privHeader
.
add
(
"!#include "
+
q
(
spec
.
objcIncludeCppPrefix
+
spec
.
cppFileIdentStyle
(
ident
)
+
"."
+
spec
.
cppHeaderExt
))
refs
.
body
.
add
(
"#import <Foundation/Foundation.h>"
)
refs
.
body
.
add
(
"!#import "
+
q
(
spec
.
objcIncludePrivatePrefix
+
enumTranslatorHeaderName
(
ident
)))
val
self
=
objcMarshal
.
typename
(
ident
,
e
)
val
cppSelf
=
cppMarshal
.
fqTypename
(
ident
,
e
)
val
name
=
IdentStyle
.
camelUpper
(
ident
)
val
argName
=
idObjc
.
local
(
ident
.
name
)
writeObjcFile
(
enumTranslatorHeaderName
(
ident
.
name
),
origin
,
refs
.
privHeader
,
w
=>
{
w
.
wl
(
"@interface "
+
self
+
"Translator : NSObject"
)
w
.
wl
w
.
wl
(
s
"+ ($self)cpp${name}ToObjc${name}:($cppSelf)$argName;"
)
w
.
wl
(
s
"+ ($cppSelf)objc${name}ToCpp${name}:($self)$argName;"
)
w
.
wl
w
.
wl
(
"@end"
)
})
writeObjcFile
(
enumTranslatorName
(
ident
),
origin
,
refs
.
body
,
w
=>
{
w
.
wl
(
s
"static_assert(__has_feature(objc_arc), "
+
q
(
"Djinni requires ARC to be enabled for this file"
)
+
");"
)
w
.
wl
w
.
wl
(
s
"@implementation "
+
self
+
"Translator"
)
w
.
wl
w
.
wl
(
s
"+ ($self)cpp${name}ToObjc${name}:($cppSelf)${argName}"
)
w
.
braced
{
w
.
wl
(
s
"return static_cast<$self>($argName);"
);
}
w
.
wl
w
.
wl
(
s
"+ ($cppSelf)objc${name}ToCpp${name}:($self)${argName}"
)
w
.
braced
{
w
.
wl
(
s
"return static_cast<enum $cppSelf>($argName);"
)
}
w
.
wl
w
.
wl
(
"@end"
)
})
// No generation required
}
def
enumTranslatorName
(
ident
:
String
)
:
String
=
idObjc
.
ty
(
ident
)
+
"Translator."
+
spec
.
objcExt
def
enumTranslatorHeaderName
(
ident
:
String
)
:
String
=
idObjc
.
ty
(
ident
)
+
"Translator+Private."
+
spec
.
objcHeaderExt
def
headerName
(
ident
:
String
)
:
String
=
idObjc
.
ty
(
ident
)
+
"."
+
spec
.
objcHeaderExt
def
privateHeaderName
(
ident
:
String
)
:
String
=
idObjc
.
ty
(
ident
)
+
"+Private."
+
spec
.
objcHeaderExt
def
bodyName
(
ident
:
String
)
:
String
=
idObjc
.
ty
(
ident
)
+
"."
+
spec
.
objcExt
...
...
@@ -716,11 +673,11 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
val
self
=
idObjc
.
ty
(
typeName
)
d
.
defType
match
{
case
DEnum
=>
val
objcEnum
=
s
"[${self}Translator ${idObjc.method("
cpp_
" + typeName + "
_to_objc_
" + typeName)}:$cppIdent]"
val
cppSelf
=
cppMarshal
.
fqTypename
(
tm
)
if
(
needRef
)
w
.
wl
(
s
"$objcType$objcIdent =
[NSNumber numberWithInt:$objcEnum]
;"
)
w
.
wl
(
s
"$objcType$objcIdent =
::djinni::Enum<$cppSelf, $self>::Boxed::fromCpp($cppIdent)
;"
)
else
w
.
wl
(
s
"$objcType$objcIdent =
$objcEnum
;"
)
w
.
wl
(
s
"$objcType$objcIdent =
::djinni::Enum<$cppSelf, $self>::fromCpp($cppIdent)
;"
)
case
DRecord
=>
w
.
wl
(
s
"$objcType$objcIdent = [[${self} alloc] initWithCpp${IdentStyle.camelUpper(typeName)}:$cppIdent];"
)
case
DInterface
=>
val
ext
=
d
.
body
.
asInstanceOf
[
Interface
].
ext
...
...
@@ -814,8 +771,11 @@ class ObjcppGenerator(spec: Spec) extends Generator(spec) {
val
self
=
idObjc
.
ty
(
typeName
)
d
.
defType
match
{
case
DEnum
=>
val
unboxed
=
if
(
needRef
)
s
"($self)[$objcIdent intValue]"
else
objcIdent
w
.
wl
(
s
"$cppType $cppIdent = [${self}Translator ${idObjc.method("
objc_
" + typeName + "
_to_cpp_
" + typeName)}:$unboxed];"
)
val
cppSelf
=
cppMarshal
.
fqTypename
(
tm
)
if
(
needRef
)
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::Enum<$cppSelf, $self>::Boxed::toCpp($objcIdent);"
)
else
w
.
wl
(
s
"$cppType $cppIdent = ::djinni::Enum<$cppSelf, $self>::toCpp($objcIdent);"
)
case
DRecord
=>
w
.
wl
(
s
"$cppType $cppIdent = std::move([$objcIdent cpp${IdentStyle.camelUpper(typeName)}]);"
)
case
DInterface
=>
val
ext
=
d
.
body
.
asInstanceOf
[
Interface
].
ext
...
...
support-lib/objc/DJIMarshal+Private.h
View file @
477d629a
...
...
@@ -77,4 +77,19 @@ struct F64 : public Primitive<double> {
};
};
template
<
class
CppEnum
,
class
ObjcEnum
>
struct
Enum
{
using
CppType
=
CppEnum
;
using
ObjcType
=
ObjcEnum
;
static
CppType
toCpp
(
ObjcType
e
)
noexcept
{
return
static_cast
<
CppType
>
(
e
);
}
static
ObjcType
fromCpp
(
CppType
e
)
noexcept
{
return
static_cast
<
ObjcType
>
(
e
);
}
struct
Boxed
{
using
ObjcType
=
NSNumber
*
;
static
CppType
toCpp
(
ObjcType
x
)
noexcept
{
return
Enum
::
toCpp
(
static_cast
<
Enum
::
ObjcType
>
([
x
integerValue
]));
}
static
ObjcType
fromCpp
(
CppType
x
)
noexcept
{
return
[
NSNumber
numberWithInteger
:
static_cast
<
NSInteger
>
(
Enum
::
fromCpp
(
x
))];
}
};
};
}
// namespace djinni
test-suite/generated-src/objc/DBColorTranslator+Private.h
deleted
100644 → 0
View file @
aec43dad
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from enum.djinni
#import "DBColor.h"
#include "color.hpp"
#import <Foundation/Foundation.h>
@interface
DBColorTranslator
:
NSObject
+
(
DBColor
)
cppColorToObjcColor
:(
color
)
color
;
+
(
color
)
objcColorToCppColor
:(
DBColor
)
color
;
@end
test-suite/generated-src/objc/DBColorTranslator.mm
deleted
100644 → 0
View file @
aec43dad
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from enum.djinni
#import "DBColorTranslator+Private.h"
#import <Foundation/Foundation.h>
static_assert
(
__has_feature
(
objc_arc
),
"Djinni requires ARC to be enabled for this file"
);
@implementation
DBColorTranslator
+
(
DBColor
)
cppColorToObjcColor
:(
color
)
color
{
return
static_cast
<
DBColor
>
(
color
);
}
+
(
color
)
objcColorToCppColor
:(
DBColor
)
color
{
return
static_cast
<
enum
color
>
(
color
);
}
@end
test-suite/generated-src/objc/DBTestHelpers.mm
View file @
477d629a
...
...
@@ -5,7 +5,6 @@
#import "DBAssortedIntegers+Private.h"
#import "DBClientInterfaceObjcProxy+Private.h"
#import "DBColor.h"
#import "DBColorTranslator+Private.h"
#import "DBMapListRecord+Private.h"
#import "DBNestedCollection+Private.h"
#import "DBPrimitiveList+Private.h"
...
...
@@ -202,7 +201,7 @@ static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for th
try
{
std
::
unordered_map
<
color
,
std
::
string
>
cppM
;
for
(
id
objcKey_0
in
m
)
{
color
cppKey_0
=
[
DBColorTranslator
objcColorToCppColor
:(
DBColor
)[
objcKey_0
intValue
]]
;
color
cppKey_0
=
::
djinni
::
Enum
<
color
,
DBColor
>::
Boxed
::
toCpp
(
objcKey_0
)
;
std
::
string
cppValue_0
([[
m
objectForKey
:
objcKey_0
]
UTF8String
],
[[
m
objectForKey
:
objcKey_0
]
lengthOfBytesUsingEncoding
:
NSUTF8StringEncoding
]);
cppM
.
emplace
(
std
::
move
(
cppKey_0
),
std
::
move
(
cppValue_0
));
}
...
...
test-suite/objc/DjinniObjcTest.xcodeproj/project.pbxproj
View file @
477d629a
...
...
@@ -28,7 +28,6 @@
A242494C1AF192E0003BF8F0
/* DBAssortedIntegers.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A242491B1AF192E0003BF8F0
/* DBAssortedIntegers.mm */
;
};
A242494D1AF192E0003BF8F0
/* DBClientInterfaceObjcProxy.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A242491E1AF192E0003BF8F0
/* DBClientInterfaceObjcProxy.mm */
;
};
A242494E1AF192E0003BF8F0
/* DBClientReturnedRecord.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A24249211AF192E0003BF8F0
/* DBClientReturnedRecord.mm */
;
};
A242494F1AF192E0003BF8F0
/* DBColorTranslator.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A24249241AF192E0003BF8F0
/* DBColorTranslator.mm */
;
};
A24249501AF192E0003BF8F0
/* DBConstants.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A24249271AF192E0003BF8F0
/* DBConstants.mm */
;
};
A24249511AF192E0003BF8F0
/* DBCppException.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A242492A1AF192E0003BF8F0
/* DBCppException.mm */
;
};
A24249521AF192E0003BF8F0
/* DBDateRecord.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
A242492D1AF192E0003BF8F0
/* DBDateRecord.mm */
;
};
...
...
@@ -112,8 +111,6 @@
A24249201AF192E0003BF8F0
/* DBClientReturnedRecord.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
DBClientReturnedRecord.h
;
sourceTree
=
"<group>"
;
};
A24249211AF192E0003BF8F0
/* DBClientReturnedRecord.mm */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.cpp.objcpp
;
path
=
DBClientReturnedRecord.mm
;
sourceTree
=
"<group>"
;
};
A24249221AF192E0003BF8F0
/* DBColor.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
DBColor.h
;
sourceTree
=
"<group>"
;
};
A24249231AF192E0003BF8F0
/* DBColorTranslator+Private.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"DBColorTranslator+Private.h"
;
sourceTree
=
"<group>"
;
};
A24249241AF192E0003BF8F0
/* DBColorTranslator.mm */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.cpp.objcpp
;
path
=
DBColorTranslator.mm
;
sourceTree
=
"<group>"
;
};
A24249251AF192E0003BF8F0
/* DBConstants+Private.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"DBConstants+Private.h"
;
sourceTree
=
"<group>"
;
};
A24249261AF192E0003BF8F0
/* DBConstants.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
DBConstants.h
;
sourceTree
=
"<group>"
;
};
A24249271AF192E0003BF8F0
/* DBConstants.mm */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.cpp.objcpp
;
path
=
DBConstants.mm
;
sourceTree
=
"<group>"
;
};
...
...
@@ -308,8 +305,6 @@
A24249201AF192E0003BF8F0
/* DBClientReturnedRecord.h */
,
A24249211AF192E0003BF8F0
/* DBClientReturnedRecord.mm */
,
A24249221AF192E0003BF8F0
/* DBColor.h */
,
A24249231AF192E0003BF8F0
/* DBColorTranslator+Private.h */
,
A24249241AF192E0003BF8F0
/* DBColorTranslator.mm */
,
A24249251AF192E0003BF8F0
/* DBConstants+Private.h */
,
A24249261AF192E0003BF8F0
/* DBConstants.h */
,
A24249271AF192E0003BF8F0
/* DBConstants.mm */
,
...
...
@@ -491,7 +486,6 @@
A242494D1AF192E0003BF8F0
/* DBClientInterfaceObjcProxy.mm in Sources */
,
A24249731AF192FC003BF8F0
/* assorted_integers.cpp in Sources */
,
A24249561AF192E0003BF8F0
/* DBNestedCollection.mm in Sources */
,
A242494F1AF192E0003BF8F0
/* DBColorTranslator.mm in Sources */
,
);
runOnlyForDeploymentPostprocessing
=
0
;
};
...
...
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