You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* migrate C++/CLI support from https://github.com/iit-reacts/djinni to new project structure
* add documentation of C++/CLI support
* update integration tests to include testing for C++/CLI
* add additional commandline options that where missing in the iit-reacts implementation:
* --cppcli-base-lib-include-prefix
* --cppcli-include-cpp-prefix
* fix some IntelliJ IDEA Code Analysis warnings
* improve "generated code usage" documentation
* make sure the generated file list always uses unix paths, even on Windows. This is helpful as CMake (which is eventually the tool that will process the file) cannot handle Windows paths.
* add python support to Readme feature list.
Add all generated files to your build target, and link against the [djinni-support-lib](https://github.com/cross-language-cpp/djinni-support-lib).
149
+
150
+
C++/CLI sources have to be compiled with MSVC and the [`/clr` (Common Language Runtime Compilation)](https://docs.microsoft.com/en-us/cpp/build/reference/clr-common-language-runtime-compilation?view=msvc-160) option.
- Binary (`binary`). This is implemented as `std::vector<uint8_t>` in C++, `byte[]` in Java,
81
-
`NSData` in Objective-C, and an object supporting the `buffer` interface in Python.
81
+
`NSData` in Objective-C, an object supporting the `buffer` interface in Python, and `System.Array<System.Byte>` in C#.
82
82
- Date (`date`). This is `chrono::system_clock::time_point` in C++, `Date` in Java,
83
-
`NSDate` in Objective-C, and `datetime.datetime` in Python.
83
+
`NSDate` in Objective-C, `datetime.datetime` in Python, and `System.DateTime` in C#.
84
84
- List (`list<type>`). This is `vector<T>` in C++, `ArrayList` in Java, `NSArray`
85
-
in Objective-C, and `List` in Python. Primitives in a list will be boxed in Java and Objective-C.
85
+
in Objective-C, `List` in Python, and `System.Collections.Generic.List` in C#.
86
+
Primitives in a list will be boxed in Java and Objective-C.
86
87
- Set (`set<type>`). This is `unordered_set<T>` in C++, `HashSet` in Java, `NSSet` in
87
-
Objective-C, and `Set` in Python. Primitives in a set will be boxed in Java and Objective-C.
88
+
Objective-C, `Set` in Python, and `System.Collections.Generic.HashSet` in C#.
89
+
Primitives in a set will be boxed in Java and Objective-C.
88
90
- Map (`map<typeA, typeB>`). This is `unordered_map<K, V>` in C++, `HashMap` in Java,
89
-
`NSDictionary` in Objective-C, and `Dictionary` in Python. Primitives in a map will be boxed in Java
90
-
and Objective-C.
91
+
`NSDictionary` in Objective-C, `Dictionary` in Python, and `System.Collections.Generic.Dictionary`in C#.
92
+
Primitives in a map will be boxed in Java and Objective-C.
91
93
- Enumerations / Flags
92
94
- Optionals (`optional<typeA>`). This is `std::experimental::optional<T>` in C++11, object /
93
95
boxed primitive reference in Java (which can be `null`), and object / NSNumber strong
@@ -96,14 +98,16 @@ The available data types for a record, argument, or return value are:
96
98
deep-copy the contents.
97
99
98
100
## Types
101
+
99
102
An IDL file can contain 4 kinds of declarations: enums, flags, records, and interfaces.
100
103
101
-
*[**Enums**](#enums) become C++ enum classes, Java enums, ObjC `NS_ENUM`s, or Python `IntEnum`s.
102
-
*[**Flags**](#flags) become C++ enum classes with convenient bit-oriented operators, Java enums with `EnumSet`, ObjC `NS_OPTIONS`, or Python `IntFlag`s.
104
+
*[**Enums**](#enums) become C++ enum classes, Java enums, ObjC `NS_ENUM`s, Python `IntEnum`s, or C# `System.Enum`s.
105
+
*[**Flags**](#flags) become C++ enum classes with convenient bit-oriented operators, Java enums with `EnumSet`,
106
+
ObjC `NS_OPTIONS`, Python `IntFlag`s, or C# `System.Enum`s with the [`[Flags]` Attribute](https://docs.microsoft.com/en-us/dotnet/api/system.flagsattribute?view=net-5.0).
103
107
*[**Records**](#records) are pure-data value objects.
104
108
*[**Interfaces**](#interfaces) are objects with defined methods to call (in C++, passed by `shared_ptr`). Djinni
105
109
produces code allowing an interface implemented in C++ to be transparently used from ObjC,
106
-
Java, or Python and vice versa.
110
+
Java, Python or C#, and vice versa.
107
111
108
112
### Enums
109
113
@@ -116,7 +120,7 @@ my_enum = enum {
116
120
```
117
121
118
122
Enums are translated to C++ `enum class`es with underlying type `int`, ObjC `NS_ENUM`s with
119
-
underlying type `NSInteger`, Java enums, and Python `IntEnum`s.
123
+
underlying type `NSInteger`, Java enums, Python `IntEnum`s, and C# `System.Enum`s.
120
124
121
125
### Flags
122
126
@@ -132,8 +136,8 @@ my_flags = flags {
132
136
133
137
Flags are translated to C++ `enum class`es with underlying type `unsigned` and a generated set of
134
138
overloaded bitwise operators for convenience, ObjC `NS_OPTIONS` with underlying type `NSUInteger`,
135
-
Java `EnumSet<>`, and Python `IntFlag`. Contrary to the above enums, the enumerants of flags
136
-
represent single bits instead of integral values.
139
+
Java `EnumSet<>`, Python `IntFlag`, and C# `System.Enum`s with the [`[Flags]` Attribute](https://docs.microsoft.com/en-us/dotnet/api/system.flagsattribute?view=net-5.0).
140
+
Contrary to the above enums, the enumerants of flags represent single bits instead of integral values.
137
141
138
142
In the above example the elements marked with `none` and `all` are given special meaning. In C++,
139
143
ObjC, and Python the `no_flags` option is generated with a value that has no bits set (i.e. `0`),
@@ -168,7 +172,7 @@ records (so a record cannot contain itself).
168
172
#### Extensions
169
173
170
174
To support extra fields and/or methods, a record can be "extended" in any language. To extend a
171
-
record in a language, you can add a `+c` (C++), `+j` (Java), `+o` (ObjC), or `+p` (Python) flag
175
+
record in a language, you can add a `+c` (C++), `+j` (Java), `+o` (ObjC), `+p` (Python), or `+s` (C#) flag
172
176
after the record tag. The generated type will have a `Base` suffix, and you should create a derived
173
177
type without the suffix that extends the record type.
174
178
@@ -186,7 +190,7 @@ another_record = record {
186
190
187
191
For record types, Haskell-style "deriving" declarations are supported to generate some common
188
192
methods. Djinni is capable of generating equality and order comparators, implemented as operator
189
-
overloading in C++ and standard comparison functions in Java, Objective-C, and Python.
193
+
overloading in C++ and standard comparison functions in Java, Objective-C, Python and C#.
# This interface will be implemented in Java, ObjC, and Python and can be called from C++.
213
-
my_client_interface = interface +j +o +p {
216
+
# This interface will be implemented in Java, ObjC, Python and C# and can be called from C++.
217
+
my_client_interface = interface +j +o +p +s {
214
218
log_string(str: string): bool;
215
219
}
216
220
```
217
221
218
222
Interfaces are objects with defined methods to call (in C++, passed by `shared_ptr`). Djinni
219
223
produces code allowing an interface implemented in C++ to be transparently used from ObjC,
220
-
Java or Python and vice versa.
224
+
Java Python or C# and vice versa.
221
225
222
226
#### Special Methods for C++ Only
223
-
`+c` interfaces (implementable only in C++) can have methods flagged with the special keywords const and static which have special effects in C++:
227
+
`+c` interfaces (implementable only in C++) can have methods flagged with the special keywords const and static which
228
+
have special effects in C++:
224
229
225
230
special_methods = interface +c {
226
231
const accessor_method();
227
232
static factory_method();
228
233
}
229
234
230
235
-`const` methods will be declared as const in C++, though this cannot be enforced on callers in other languages, which lack this feature.
231
-
-`static` methods will become a static method of the C++ class, which can be called from other languages without an object. This is often useful for factory methods to act as a cross-language constructor.
236
+
-`static` methods will become a static method of the C++ class, which can be called from other languages without an object.
237
+
This is often useful for factory methods to act as a cross-language constructor.
232
238
233
239
#### Exception Handling
234
240
When an interface implemented in C++ throws a `std::exception`, it will be translated to a
235
-
`java.lang.RuntimeException` in Java, an `NSException` in Objective-C or a `RuntimeError` in Python.
241
+
`java.lang.RuntimeException` in Java, an `NSException` in Objective-C, a `RuntimeError` in Python,
242
+
or a `System.Exception` in C#.
236
243
The `what()` message will be translated as well.
237
244
238
245
#### Constants
239
-
Constants can be defined within interfaces and records. In Java, Python and C++ they are part of the
246
+
Constants can be defined within interfaces and records. In Java, Python, C# and C++ they are part of the
240
247
generated class; and in Objective-C, constant names are globals with the name of the
241
248
interface/record prefixed. Example:
242
249
243
250
```
244
-
record_with_const = record +c +j +o +p {
251
+
record_with_const = record +c +j +o +p +s {
245
252
const const_value: i32 = 8;
246
253
}
247
254
```
248
255
249
256
will be `RecordWithConst::CONST_VALUE` in C++, `RecordWithConst.CONST_VALUE` in Java,
250
-
`RecordWithConst.CONST_VALUE` in Python, and `RecordWithConstConstValue` in Objective-C.
257
+
`RecordWithConst.CONST_VALUE` in Python, `RecordWithConst.ConstValue` in C#, and `RecordWithConstConstValue` in Objective-C.
251
258
252
259
## Comments
253
260
254
261
```
255
262
# This is a comment
256
263
```
257
264
258
-
If comments are are placed **on top or inside a type definition**, they will be converted to
265
+
If comments are placed **on top or inside a type definition**, they will be converted to
259
266
**Javadoc / Doxygen compatible** comments in the generated Java/C++/Objective-C interfaces, or a
260
-
Python **docstring**.
267
+
Python **docstring**. Comments are currently not available in C#.
0 commit comments