cesium-native  0.41.0
ObjectJsonHandler.h
1 #pragma once
2 
3 #include "JsonHandler.h"
4 #include "Library.h"
5 
6 #include <optional>
7 
8 namespace CesiumJsonReader {
9 class CESIUMJSONREADER_API ObjectJsonHandler : public JsonHandler {
10 public:
11  ObjectJsonHandler() noexcept : JsonHandler() {}
12 
13  virtual IJsonHandler* readObjectStart() override /* final */;
14  virtual IJsonHandler* readObjectEnd() override /* final */;
15 
16 protected:
17  virtual IJsonHandler* StartSubObject() noexcept;
18  virtual IJsonHandler* EndSubObject() noexcept;
19 
20  template <typename TAccessor, typename TProperty>
22  property(const char* currentKey, TAccessor& accessor, TProperty& value) {
23  this->_currentKey = currentKey;
24 
25  if constexpr (isOptional<TProperty>::value) {
26  value.emplace();
27  accessor.reset(this, &value.value());
28  } else {
29  accessor.reset(this, &value);
30  }
31 
32  return &accessor;
33  }
34 
35  const char* getCurrentKey() const noexcept;
36 
37  virtual void reportWarning(
38  const std::string& warning,
39  std::vector<std::string>&& context = std::vector<std::string>()) override;
40 
41 protected:
42  void setCurrentKey(const char* key) noexcept;
43 
44 private:
45  template <typename T> struct isOptional {
46  static constexpr bool value = false;
47  };
48 
49  template <typename T> struct isOptional<std::optional<T>> {
50  static constexpr bool value = true;
51  };
52 
53  int32_t _depth = 0;
54  const char* _currentKey = nullptr;
55 };
56 } // namespace CesiumJsonReader
Classes for reading JSON.