ArcGIS Procedural Runtime  3.2.10650
EncodeOptions.h
1 /*
2  COPYRIGHT (c) 2012-2024 Esri R&D Center Zurich
3  TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
4  Unpublished material - all rights reserved under the
5  Copyright Laws of the United States and applicable international
6  laws, treaties, and conventions.
7 
8  For additional information, contact:
9  Environmental Systems Research Institute, Inc.
10  Attn: Contracts and Legal Services Department
11  380 New York Street
12  Redlands, California, 92373
13  USA
14 
15  email: contracts@esri.com
16 */
17 
18 #ifndef PRTX_ENCODEOPTIONS_H_
19 #define PRTX_ENCODEOPTIONS_H_
20 
21 #include "prtx.h"
22 #include "prtx/AnnotationBuilder.h"
23 #include "prtx/EncoderInfoBuilder.h"
24 #include "prtx/EncoderFactory.h"
25 
26 #include <string>
27 #include <vector>
28 
29 #ifdef _MSC_VER
30 # pragma warning(push)
31 # pragma warning (disable : 4251 4231 4275 4660)
32 #endif
33 
34 
35 namespace prtx {
36 
37 
41 class PRTX_EXPORTS_API StringEnum {
42 public:
43  struct Item {
44  int id;
45  std::wstring value;
46  std::wstring description;
47  };
48 
49  struct PodItem {
50  int id;
51  const wchar_t* value;
52  const wchar_t* description;
53  };
54 
55 public:
56  StringEnum();
57 
58  template<size_t N>
59  StringEnum(const Item (&items)[N])
60  : mItems(&items[0], &items[N])
61  {
62  init(0);
63  }
64 
65  template<size_t N>
66  StringEnum(const PodItem (&items)[N])
67  : mItems(N)
68  {
69  init(&items[0]);
70  }
71 
72  template<size_t N>
73  StringEnum(const StringEnum& base, const int (&itemsToKeep)[N]) {
74  init(base.beginItems(), base.endItems(), itemsToKeep, N);
75  }
76 
77  void addItem(int id, const wchar_t* value, const wchar_t* description);
78  bool removeItem(int id);
79 
80  template<size_t N>
81  void addItems(const StringEnum& base, const int (&itemsToKeep)[N]) {
82  addItems(base.beginItems(), base.endItems(), itemsToKeep, N);
83  }
84  void removeAllItems();
85 
86  int getIdByValue(const std::wstring& value) const;
87  int getIdByValue(const wchar_t* value) const;
88  const std::wstring& getValueById(int id) const;
89  const wchar_t* getCValueById(int id) const;
90  const std::wstring& operator[](int id) const;
91 
92  typedef std::vector<Item>::const_iterator ItemConstIter;
93 
94  ItemConstIter beginItems() const {
95  return mItems.begin();
96  }
97 
98  ItemConstIter endItems() const {
99  return mItems.end();
100  }
101 
102 private:
103  void init(const PodItem* items);
104  void init(ItemConstIter itemsBegin, ItemConstIter itemsEnd, const int* itemsToKeep, size_t numItemsToKeep);
105  void addItems(ItemConstIter itemsBegin, ItemConstIter itemsEnd, const int* itemsToKeep, size_t numItemsToKeep);
106  void updateIdEqualsIndex();
107 
108 private:
109  std::vector<Item> mItems;
110  bool mIdEqualsIndex;
111 };
112 
113 
126 namespace Annotations {
127 
128 
129 const std::wstring ORDER = L"@Order";
130 const std::wstring LABEL = L"@Label";
131 const std::wstring GROUP = L"@Group";
132 const std::wstring DESCRIPTION = L"@Description";
133 const std::wstring RANGE = L"@Range";
134 const std::wstring POINT2D = L"@Point2D";
135 const std::wstring POINT3D = L"@Point3D";
136 const std::wstring PERLAYER = L"@PerLayer";
137 const std::wstring HIDDEN = L"@Hidden";
138 const std::wstring MANDATORY = L"@Mandatory";
139 
140 
141 } // namespace Annotations
142 
143 
167 class PRTX_EXPORTS_API EncodeOptionsAnnotator {
168 public:
169  class OptionAnnotator;
170 
171 private:
172  template<typename Opt>
173  class AnnotationAdder;
174 
175 public:
183  EncodeOptionsAnnotator& operator=(const EncodeOptionsAnnotator&) = delete;
184 
188  OptionAnnotator option(const std::wstring& optionKey);
189 
193  void setLabel(const std::wstring& optionKey, const std::wstring& label);
194 
198  void setDescription(const std::wstring& optionKey, const std::wstring& desc);
199 
203  void setOrder(const std::wstring& optionKey, const double& order);
204 
208  void setGroup(const std::wstring& optionKey, const std::wstring& groupName, const double& order);
209 
213  void setRange(const std::wstring& optionKey, double min, double max);
214 
218  void setEnumerants(const std::wstring& optionKey, const StringEnum& items);
219 
223  void flagAsPoint2D(const std::wstring& optionKey);
224 
228  void flagAsPoint3D(const std::wstring& optionKey);
229 
233  void flagAsPerLayer(const std::wstring& optionKey, const std::wstring& layerDefault);
234 
238  void flagAsPerLayer(const std::wstring& optionKey, const double& layerDefault);
239 
243  void flagAsPerLayer(const std::wstring& optionKey, const bool& layerDefault);
244 
248  void flagAsPerLayer(const std::wstring& optionKey, const int32_t& layerDefault);
249 
253  void flagAsHidden(const std::wstring& optionKey);
254 
258  void flagAsMandatory(const std::wstring& optionKey);
259 
260 public:
261 
265  class PRTX_EXPORTS_API OptionAnnotator {
266  public:
267  OptionAnnotator(EncodeOptionsAnnotator& annotator, const std::wstring& optionKey)
268  : mAnnotator(annotator), mOptionKey(optionKey) {}
269 
270  OptionAnnotator(const OptionAnnotator& rhs) : mAnnotator(rhs.mAnnotator), mOptionKey(rhs.mOptionKey) { }
271 
272  OptionAnnotator& operator=(const OptionAnnotator&) = delete;
273 
274  public:
275  OptionAnnotator& setLabel(const std::wstring& label) {
276  mAnnotator.setLabel(mOptionKey, label);
277  return *this;
278  }
279 
280  OptionAnnotator& setDescription(const std::wstring& desc) {
281  mAnnotator.setDescription(mOptionKey, desc);
282  return *this;
283  }
284 
285  OptionAnnotator& setOrder(const double& order) {
286  mAnnotator.setOrder(mOptionKey, order);
287  return *this;
288  }
289 
290  OptionAnnotator& setGroup(const std::wstring& name, const double& order) {
291  mAnnotator.setGroup(mOptionKey, name, order);
292  return *this;
293  }
294 
295  OptionAnnotator& flagAsPoint2D() {
296  mAnnotator.flagAsPoint2D(mOptionKey);
297  return *this;
298  }
299 
300  OptionAnnotator& flagAsPoint3D() {
301  mAnnotator.flagAsPoint3D(mOptionKey);
302  return *this;
303  }
304 
305  OptionAnnotator& flagAsHidden() {
306  mAnnotator.flagAsHidden(mOptionKey);
307  return *this;
308  }
309 
310  OptionAnnotator& flagAsMandatory() {
311  mAnnotator.flagAsMandatory(mOptionKey);
312  return *this;
313  }
314 
315  template<typename T> OptionAnnotator& flagAsPerLayer(const T& layerDefault) {
316  mAnnotator.flagAsPerLayer(mOptionKey, layerDefault);
317  return *this;
318  }
319 
320  OptionAnnotator& setRange(double min, double max) {
321  mAnnotator.setRange(mOptionKey, min, max);
322  return *this;
323  }
324 
325  OptionAnnotator& setEnumerants(const StringEnum& items) {
326  mAnnotator.setEnumerants(mOptionKey, items);
327  return *this;
328  }
329 
330  private:
331  EncodeOptionsAnnotator& mAnnotator;
332  const std::wstring& mOptionKey;
333 
334  //friend class EncodeOptionsAnnotator;
335  };
336 
337 protected:
338  EncoderInfoBuilder& mInfoBuilder;
339  AnnotationBuilder mAnnotationBuilder;
340 };
341 
342 
343 } // namespace prtx
344 
345 
346 #ifdef _MSC_VER
347 # pragma warning(pop)
348 #endif
349 
350 
351 #endif /* PRTX_ENCODEOPTIONS_H_ */
Definition: EncodeOptions.h:265
Definition: AnnotationBuilder.h:41
Definition: EncodeOptions.h:43
const std::wstring HIDDEN
Hides the option in the UI.
Definition: EncodeOptions.h:137
Definition: EncoderInfoBuilder.h:48
const std::wstring ORDER
Defines a semantic ordering of the option (one double parameter).
Definition: EncodeOptions.h:129
const std::wstring PERLAYER
Assigns each value of an array option to a layer. Only for array options.
Definition: EncodeOptions.h:136
Definition: EncodeOptions.h:167
The Procedural Runtime eXtension namespace. The prtx namespace contains the tools to extend the Proce...
Definition: AnnotationBuilder.h:35
Definition: EncodeOptions.h:49
const std::wstring MANDATORY
Makes the initial shape attribute mandatory.
Definition: EncodeOptions.h:138
const std::wstring LABEL
Defines a (UI) label for the option (one string parameter).
Definition: EncodeOptions.h:130
const std::wstring POINT2D
Declares an option to be interpreted as a 2D point. Only for array options.
Definition: EncodeOptions.h:134
const std::wstring DESCRIPTION
Adds a description for the option (e.g. for tooltips) (one string parameter).
Definition: EncodeOptions.h:132
Definition: EncodeOptions.h:41
const std::wstring POINT3D
Declares an option to be interpreted as a 3D point. Only for array options.
Definition: EncodeOptions.h:135
const std::wstring GROUP
Defines a (UI) group for the option (one string parameter, one double parameter). ...
Definition: EncodeOptions.h:131
const std::wstring RANGE
Defines a value range for the option (two double parameters).
Definition: EncodeOptions.h:133
const Object * init(const wchar_t *const *prtPlugins, size_t prtPluginsCount, LogLevel logLevel, Status *stat=nullptr)