ECSTASY
All in the name
Loading...
Searching...
No Matches
INode.hpp
Go to the documentation of this file.
1
11
12#ifndef UTIL_SERIALIZATION_INODE_HPP_
13#define UTIL_SERIALIZATION_INODE_HPP_
14
15#include <chrono>
16#include <memory>
17#include <optional>
18#include <string>
19#include <string_view>
20
21namespace util::serialization
22{
23 class IObjectNode;
24 class IArrayNode;
25
32 class INode {
33 public:
42 enum class Type {
43 Unknown = -1,
44 Null,
45 Object,
46 Array,
47 String,
48 Integer,
49 Float,
50 Boolean,
51 Date,
52 Time,
53 DateTime,
54 Count
55 };
56
59
62
64 using DateTime = std::chrono::high_resolution_clock::time_point;
65
67 virtual ~INode() = default;
68
72
81 [[nodiscard]] virtual Type getType() const noexcept = 0;
82
91 [[nodiscard]] virtual bool isType(Type type) const noexcept = 0;
92
101 [[nodiscard]] virtual bool isNull() const noexcept = 0;
102
111 [[nodiscard]] virtual bool isObject() const noexcept = 0;
112
121 [[nodiscard]] virtual bool isArray() const noexcept = 0;
122
131 [[nodiscard]] virtual bool isString() const noexcept = 0;
132
141 [[nodiscard]] virtual bool isInteger() const noexcept = 0;
142
151 [[nodiscard]] virtual bool isFloat() const noexcept = 0;
152
161 [[nodiscard]] virtual bool isBoolean() const noexcept = 0;
162
171 [[nodiscard]] virtual bool isDate() const noexcept = 0;
172
181 [[nodiscard]] virtual bool isTime() const noexcept = 0;
182
191 [[nodiscard]] virtual bool isDateTime() const noexcept = 0;
192
196
207 [[nodiscard]] virtual const IObjectNode &asObject() const = 0;
208
219 [[nodiscard]] virtual IObjectNode &asObject() = 0;
220
230 [[nodiscard]] virtual std::optional<std::reference_wrapper<const IObjectNode>> tryAsObject() const noexcept = 0;
231
241 [[nodiscard]] virtual std::optional<std::reference_wrapper<IObjectNode>> tryAsObject() noexcept = 0;
242
253 [[nodiscard]] virtual const IArrayNode &asArray() const = 0;
254
265 [[nodiscard]] virtual IArrayNode &asArray() = 0;
266
276 [[nodiscard]] virtual std::optional<std::reference_wrapper<const IArrayNode>> tryAsArray() const noexcept = 0;
277
287 [[nodiscard]] virtual std::optional<std::reference_wrapper<IArrayNode>> tryAsArray() noexcept = 0;
288
299 [[nodiscard]] virtual std::string_view asString() const = 0;
300
310 [[nodiscard]] virtual std::optional<std::string_view> tryAsString() const noexcept = 0;
311
322 [[nodiscard]] virtual int64_t asInteger() const = 0;
323
333 [[nodiscard]] virtual std::optional<int64_t> tryAsInteger() const noexcept = 0;
334
345 [[nodiscard]] virtual double asFloat() const = 0;
346
356 [[nodiscard]] virtual std::optional<double> tryAsFloat() const noexcept = 0;
357
368 [[nodiscard]] virtual bool asBoolean() const = 0;
369
379 [[nodiscard]] virtual std::optional<bool> tryAsBoolean() const noexcept = 0;
380
391 [[nodiscard]] virtual Date asDate() const = 0;
392
402 [[nodiscard]] virtual std::optional<Date> tryAsDate() const noexcept = 0;
403
414 [[nodiscard]] virtual Time asTime() const = 0;
415
425 [[nodiscard]] virtual std::optional<Time> tryAsTime() const noexcept = 0;
426
437 [[nodiscard]] virtual DateTime asDateTime() const = 0;
438
448 [[nodiscard]] virtual std::optional<DateTime> tryAsDateTime() const noexcept = 0;
449 };
450
452 using NodePtr = std::shared_ptr<INode>;
454 using NodeCPtr = std::shared_ptr<const INode>;
455
457 using NodeView = std::weak_ptr<INode>;
459 using NodeCView = std::weak_ptr<const INode>;
460} // namespace util::serialization
461
462#endif /* !UTIL_SERIALIZATION_INODE_HPP_ */
Serialization node.
Definition INode.hpp:32
virtual bool isObject() const noexcept=0
Check if the node type is Type::Object.
virtual std::optional< Time > tryAsTime() const noexcept=0
Try to get the node time value.
virtual const IArrayNode & asArray() const =0
Get the array node value.
std::chrono::year_month_day Date
Type::Date underlying type.
Definition INode.hpp:58
virtual Time asTime() const =0
Get the time node value.
virtual bool isDate() const noexcept=0
Check if the node type is Type::Date.
virtual const IObjectNode & asObject() const =0
Value getter ///.
virtual Type getType() const noexcept=0
Types check ///.
virtual std::string_view asString() const =0
Get the string node value.
virtual std::optional< double > tryAsFloat() const noexcept=0
Try to get the node float value.
std::chrono::nanoseconds Time
Type::Time underlying type.
Definition INode.hpp:61
std::chrono::high_resolution_clock::time_point DateTime
Type::DateTime underlying type.
Definition INode.hpp:64
virtual std::optional< std::string_view > tryAsString() const noexcept=0
Try to get the node string value.
virtual bool isDateTime() const noexcept=0
Check if the node type is Type::DateTime.
virtual int64_t asInteger() const =0
Get the integer node value.
virtual std::optional< DateTime > tryAsDateTime() const noexcept=0
Try to get the node datetime value.
virtual std::optional< int64_t > tryAsInteger() const noexcept=0
Try to get the node integer value.
virtual bool isInteger() const noexcept=0
Check if the node type is Type::Integer.
virtual ~INode()=default
Default destructor.
virtual bool isTime() const noexcept=0
Check if the node type is Type::Time.
virtual DateTime asDateTime() const =0
Get the datetime node value.
virtual bool isType(Type type) const noexcept=0
Check if the node type is type.
virtual bool isFloat() const noexcept=0
Check if the node type is Type::Float.
virtual double asFloat() const =0
Get the float node value.
virtual bool isBoolean() const noexcept=0
Check if the node type is Type::Boolean.
virtual bool isNull() const noexcept=0
Check if the node type is Type::Null.
virtual bool isString() const noexcept=0
Check if the node type is Type::String.
Type
Available node types.
Definition INode.hpp:42
@ Float
Floating point number node.
@ Boolean
Boolean value node.
@ Array
Node containing multiple unnamed nodes. (similar to a std::vector<string>)
@ Object
Node containing multiple named nodes. (similar to a std::map<string, INode>)
@ Integer
Integer number node.
@ Null
Null node (none/null).
@ Count
Keep last - number of available node types.
virtual std::optional< bool > tryAsBoolean() const noexcept=0
Try to get the node boolean value.
virtual bool isArray() const noexcept=0
Check if the node type is Type::Array.
virtual Date asDate() const =0
Get the date node value.
virtual std::optional< Date > tryAsDate() const noexcept=0
Try to get the node date value.
virtual bool asBoolean() const =0
Get the boolean node value.
virtual std::optional< std::reference_wrapper< const IArrayNode > > tryAsArray() const noexcept=0
Try to get the node array value.
virtual std::optional< std::reference_wrapper< const IObjectNode > > tryAsObject() const noexcept=0
Try to get the node object value.