Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
DataTypes.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. All rights reserved
3 */
4#ifndef _Stroika_Frameworks_UPnP_DataTypes_h_
5#define _Stroika_Frameworks_UPnP_DataTypes_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <cstdint>
10#include <optional>
11#include <variant>
12
15#include "Stroika/Foundation/Common/Concepts.h"
17#include "Stroika/Foundation/Common/GUID.h"
23
24/**
25 * \file
26 *
27 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
28 */
29
30/**
31 * UPnP's data types (UPnP Device Architecture 1.1, section 2.5): each a state variable's dataType, and so the type of an action's
32 * argument and an event's value - always sent as text, with no mark of its type: the reader knows it from the service's
33 * description, or its code. ToText writes a value as UPnP does, and FromText reads one back, as UPnP says to.
34 *
35 * Each data type has its C++ type; each C++ type, its default data type (marked * in the table) - so where code knows its
36 * values' types, ToText (v) and FromText<T> (text) need no data type; where a value is of another data type than its C++ type's
37 * default - a BLOB as bin.hex, a double as fixed.14.4 - or code learns a value's type only as it runs, from a service's
38 * description, say, the data type is given: ToText (v, DataType::eBinHex), FromText (text, dataType) - a Value, then.
39 *
40 * data type (DataType) C++ type written as
41 * boolean (eBoolean) * bool 1 or 0 (read: also true/false, yes/no - any case)
42 * ui1, ui2, ui4, ui8 (eUI1 ...) * uint8_t ... uint64_t decimal (read: a leading + and zeros allowed; out of range: none)
43 * i1, i2, i4, i8 (eI1 ...) * int8_t ... int64_t decimal, - if negative
44 * int (eInt) int32_t as i4
45 * r4 (eR4) * float decimal - the fewest digits that read back exactly - E before an
46 * r8 *, number, float (eR8 ...) double exponent (no NaN or infinity: UPnP has none)
47 * fixed.14.4 (eFixed14_4) double decimal, no more than 4 digits after the point (nor 14 before)
48 * char (eChar) * Characters::Character itself
49 * string (eString) * String itself (read: as is - not trimmed)
50 * date (eDate) * Time::Date ISO 8601: 2026-10-08
51 * dateTime (eDateTime) Time::DateTime ISO 8601, without its time zone: 2026-10-08T14:30:05
52 * dateTime.tz (eDateTimeTZ) * Time::DateTime ISO 8601, with its time zone if it has one
53 * time (eTime) * Time::TimeOfDay ISO 8601: 14:30:05
54 * time.tz (eTimeTZ) Time::TimeOfDay as time (read: a time zone after it ignored - TimeOfDay has none)
55 * bin.base64 (eBinBase64) * Memory::BLOB base64, on one line
56 * bin.hex (eBinHex) Memory::BLOB hexadecimal, lower case
57 * uri (eURI) * IO::Network::URI itself
58 * uuid (eUUID) * Common::GUID 8-4-4-4-12 hexadecimal digits, no braces
59 *
60 * Each is read with spaces round it ignored - but a string, or a char, as it is.
61 */
63
65
66 /**
67 * \brief UPnP's data types - each named, as a service's description names it (Common::DefaultNames): ui2, fixed.14.4, ...
68 */
69 enum class DataType : uint8_t {
70 eUI1,
71 eUI2,
72 eUI4,
73 eUI8,
74 eI1,
75 eI2,
76 eI4,
77 eI8,
78 eInt,
79 eR4,
80 eR8,
81 eNumber,
82 eFixed14_4,
83 eFloat,
84 eChar,
85 eString,
86 eDate,
87 eDateTime,
88 eDateTimeTZ,
89 eTime,
90 eTimeTZ,
91 eBoolean,
92 eBinBase64,
93 eBinHex,
94 eURI,
95 eUUID,
96
97 Stroika_Define_Enum_Bounds (eUI1, eUUID)
98 };
99
100 /**
101 * \brief A value of any of UPnP's data types, as its C++ type (the table above) - for code that learns a value's type as it
102 * runs
103 *
104 * \note Not DataExchange::VariantValue: it has no type for a time of day, a URI, a uuid or a char, and just one each for
105 * integers, unsigned integers and floats - so a ui1 and a ui4, an r4 and an r8, would be the same to it. Here each has
106 * the C++ type of its own size and kind. (Data types sharing a C++ type - r8 and fixed.14.4, say - are told apart by the
107 * DataType given with the value.)
108 */
109 using Value = variant<bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double,
112
113 /**
114 * \brief The C++ types of UPnP's data types: Value's
115 */
116 template <typename T>
117 concept IValue =
118 Foundation::Common::IAnyOf<T, bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double,
119 Foundation::Characters::Character, String, Foundation::Time::Date, Foundation::Time::DateTime,
120 Foundation::Time::TimeOfDay, Foundation::Memory::BLOB, Foundation::IO::Network::URI, Foundation::Common::GUID>;
121
122 /**
123 * \brief The data type a T is written as, given none: its default (marked * in the table above)
124 */
125 template <IValue T>
126 constexpr DataType DefaultDataType ();
127
128 /**
129 * \brief Whether T is t's C++ type (the table above)
130 */
131 template <IValue T>
132 constexpr bool IsTypeOf (DataType t);
133
134 /**
135 * \brief v, as UPnP writes it: as t, if given, else as its C++ type's default data type (the table above)
136 *
137 * \pre t, if given, is a data type whose C++ type is v's (IsTypeOf)
138 * \pre a float or double: finite - UPnP has no NaN or infinity; as fixed.14.4, less than 10^14 from 0
139 */
140 template <IValue T>
141 String ToText (const T& v);
142 String ToText (const Value& v); ///< \brief v, as UPnP writes it: as t, if given, else as its C++ type's default data type
143 String ToText (const Value& v, DataType t); ///< \brief v, as UPnP writes it: as t, if given, else as its C++ type's default data type
144
145 /**
146 * \brief text read as UPnP reads it: as t, if given, else as T's default data type (the table above) - nullopt if it is not
147 * one: not a number, say, or a number out of its type's range. Given only t, a Value of t's C++ type.
148 *
149 * \pre t, if given with T, is a data type whose C++ type is T (IsTypeOf)
150 */
151 template <IValue T>
152 optional<T> FromText (const String& text);
153 template <IValue T>
154 optional<T> FromText (const String& text, DataType t); ///< \brief text read as UPnP reads it: as t, if given, else as T's default data type
155 optional<Value> FromText (const String& text, DataType t); ///< \brief text read as UPnP reads it: as t, if given, else as T's default data type
156
157}
158
159/*
160 ********************************************************************************
161 ***************************** Implementation Details ***************************
162 ********************************************************************************
163 */
164#include "DataTypes.inl"
165
166#endif /*_Stroika_Frameworks_UPnP_DataTypes_h_*/
#define Stroika_Define_Enum_Bounds(FIRST_ITEM, LAST_ITEM)
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
Concept: trivial shorthand for variadic same_as A or same_as B, or ...
Definition Concepts.h:122
The C++ types of UPnP's data types: Value's.
Definition DataTypes.h:117
variant< bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, Foundation::Characters::Character, String, Foundation::Time::Date, Foundation::Time::DateTime, Foundation::Time::TimeOfDay, Foundation::Memory::BLOB, Foundation::IO::Network::URI, Foundation::Common::GUID > Value
A value of any of UPnP's data types, as its C++ type (the table above) - for code that learns a value...
Definition DataTypes.h:111
constexpr bool IsTypeOf(DataType t)
Whether T is t's C++ type (the table above)
Definition DataTypes.inl:82
DataType
UPnP's data types - each named, as a service's description names it (Common::DefaultNames): ui2,...
Definition DataTypes.h:69
optional< T > FromText(const String &text)
text read as UPnP reads it: as t, if given, else as T's default data type (the table above) - nullopt...
String ToText(const T &v)
v, as UPnP writes it: as t, if given, else as its C++ type's default data type (the table above)
constexpr DataType DefaultDataType()
The data type a T is written as, given none: its default (marked * in the table above)
Definition DataTypes.inl:13