PropertyData.h
Go to the documentation of this file.
1 /****
2  * ConfigDB/PropertyData.h
3  *
4  * Copyright 2024 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the ConfigDB Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include "PropertyInfo.h"
23 
24 namespace ConfigDB
25 {
31 struct __attribute__((packed)) ArrayId {
32  uint8_t value_[2];
33 
34  constexpr ArrayId(uint16_t value = 0) : value_{uint8_t(value), uint8_t(value >> 8)}
35  {
36  }
37 
38  constexpr operator uint16_t() const
39  {
40  return value_[0] | (value_[1] << 8);
41  }
42 };
43 
44 union __attribute__((packed)) PropertyData {
45  uint8_t uint8;
46  uint16_t uint16;
47  uint32_t uint32;
48  int8_t int8;
49  int16_t int16;
50  int32_t int32;
51  int64_t int64;
52  bool boolean;
56 
57  String getString(const PropertyInfo& info) const;
58 
59  bool setValue(const PropertyInfo& prop, int64_t value);
60 
61  bool setValue(const PropertyInfo& prop, Number value);
62 
63  bool setValue(const PropertyInfo& prop, const char* value, unsigned valueLength);
64 
65  static PropertyData* fromStruct(const PropertyInfo& prop, void* data)
66  {
67  return data ? reinterpret_cast<PropertyData*>(static_cast<uint8_t*>(data) + prop.offset) : nullptr;
68  }
69 
70  static const PropertyData* fromStruct(const PropertyInfo& prop, const void* data)
71  {
72  return fromStruct(prop, const_cast<void*>(data));
73  }
74 };
75 
76 } // namespace ConfigDB
Base-10 floating-point storage format.
Definition: Number.h:343
The String class.
Definition: WString.h:133
Definition: Array.h:26
uint16_t StringId
Defines contained string data using index into string pool.
Definition: PropertyInfo.h:59
Identifies array storage within array pool.
Definition: PropertyData.h:31
constexpr ArrayId(uint16_t value=0)
Definition: PropertyData.h:34
Property metadata.
Definition: PropertyInfo.h:126
uint32_t offset
Location of property data in parent object, OR Alias property index.
Definition: PropertyInfo.h:153
Definition: PropertyData.h:44
StringId string
Definition: PropertyData.h:55
uint8_t uint8
Definition: PropertyData.h:45
String getString(const PropertyInfo &info) const
int64_t int64
Definition: PropertyData.h:51
int32_t int32
Definition: PropertyData.h:50
int16_t int16
Definition: PropertyData.h:49
Number number
Definition: PropertyData.h:53
bool boolean
Definition: PropertyData.h:52
bool setValue(const PropertyInfo &prop, const char *value, unsigned valueLength)
ArrayId array
Definition: PropertyData.h:54
static const PropertyData * fromStruct(const PropertyInfo &prop, const void *data)
Definition: PropertyData.h:70
uint32_t uint32
Definition: PropertyData.h:47
bool setValue(const PropertyInfo &prop, int64_t value)
int8_t int8
Definition: PropertyData.h:48
static PropertyData * fromStruct(const PropertyInfo &prop, void *data)
Definition: PropertyData.h:65
bool setValue(const PropertyInfo &prop, Number value)
uint16_t uint16
Definition: PropertyData.h:46