| 144 | |
| 145 | == Public API design considerations == |
| 146 | |
| 147 | We use [https://swig.org/ SWIG] to generate wrappers to MapGuide's C++ public API surface in PHP, Java and .net. |
| 148 | |
| 149 | When introducing a new API to MapGuide, you should use the least-common-denominator subset of C++ language features/constructs to best facilitate wrapper generation across all 3 managed language targets, **even if this is not the most optimal method** in terms of C++ runtime performance. |
| 150 | |
| 151 | The following should be used for method parameters and return types: |
| 152 | |
| 153 | * Allowed method parameter types |
| 154 | * Basic primitive types `bool/BYTE/INT16/INT32/INT64/float/double` |
| 155 | * Raw pointer to any public MapGuide API class |
| 156 | * For strings, only `std::wstring` (aliased in MapGuide as `STRING`) is permitted and only by const reference (aliased in MapGuide as `CREFSTRING`) |
| 157 | * For arrays/collections, use a raw pointer to any subclass of `MgCollection` |
| 158 | * For byte buffers or binary content, use a raw pointer to `MgByteReader` |
| 159 | * Allowed method return types |
| 160 | * Basic primitive types `bool/BYTE/INT16/INT32/INT64/float/double` |
| 161 | * Raw pointer to any public MapGuide API class |
| 162 | * For strings, only `std::wstring` (aliased in MapGuide as `STRING`) is permitted and only by value |
| 163 | * For byte buffers or binary content, return a raw pointer to `MgByteReader` |
| 164 | |
| 165 | Do not bother/try making public API methods `const`-correct, it will not affect SWIG interface generation and may even complicate or break it in some cases. |
| 166 | |
| 167 | Anything not on the above list is something assumed to not be reliably SWIG-wrappable with consistent behavior across our 3 managed language targets and should not be used. |
| 168 | |
| 169 | When naming methods, use a name that is unlikely to collide with reserved/built-in method names of any language target or methods that would be auto-generated by SWIG for given language target. For example: |
| 170 | * `delete` is a bad name for a new public API method because this is the name of the method SWIG auto-generates for Java proxy classes |
| 171 | * `finalize` is a bad name for a new public API method because this is the name of the built-in method in Java classes that will be called when an object is about to be garbage collected |
| 172 | |
| 173 | For private/internal methods, you are free to name and define method parameters and return type in any way you see fit for best C++ runtime performance. |
699 | | |
700 | | Standard C++ smart pointer notes: |
701 | | 1. Never use auto_ptr objects as elements of STL containers because auto_ptr does not quite meet the requirements of a type you can put into containers (i.e. copies of auto_ptrs are not equivalent). |
702 | | 1. Never use an array as an auto_ptr argument because auto_ptr's destructor invokes only non-array delete. |
| 729 | |
| 730 | Some smart pointer notes: |
| 731 | |
| 732 | 1. Don't use `auto_ptr`. This is deprecated in C++11 and removed in C++17 onwards. Most/all cases where you'd think to use `auto_ptr` you can use `unique_ptr` instead |
| 733 | 2. If using `unique_ptr`, you may be tempted to use `std::make_unique`, but this is a C++14 standard library feature and we require code to be compiled in C++11 standards mode. If/when MapGuide/FDO adopts C++14 or higher as the base language standard version, usage of this API will be permitted. |
| 734 | |