Property.h
Go to the documentation of this file.
1 /****
2  * ConfigDB/Property.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 "PropertyData.h"
23 
24 namespace ConfigDB
25 {
26 class Store;
27 
32 {
33 public:
34  PropertyConst() = default;
35 
42  : propinfo(&info), store(&store), data(data)
43  {
44  }
45 
49  String getValue() const;
50 
51  explicit operator bool() const
52  {
53  return store;
54  }
55 
61 
65  const PropertyInfo& info() const
66  {
67  return *propinfo;
68  }
69 
70 protected:
72  const Store* store{};
73  const PropertyData* data{};
74 };
75 
79 class Property : public PropertyConst
80 {
81 public:
82  Property() = default;
83 
92  {
93  }
94 
101  bool setJsonValue(const char* value, size_t valueLength);
102 
103  bool setJsonValue(const String& value)
104  {
105  return setJsonValue(value.c_str(), value.length());
106  }
107 
108 protected:
110 };
111 
112 } // namespace ConfigDB
Read-only access to a key/value pair stored in an object, or a simple array value.
Definition: Property.h:32
const PropertyData * data
Definition: Property.h:73
PropertyConst(const Store &store, const PropertyInfo &info, const PropertyData *data)
Create a PropertyConst instance.
Definition: Property.h:41
const Store * store
Definition: Property.h:72
const PropertyInfo * propinfo
Definition: Property.h:71
String getValue() const
Retrieve the property value as a string.
const PropertyInfo & info() const
Access property type information.
Definition: Property.h:65
String getJsonValue() const
Get property value as a valid JSON string.
Adds write access for a key/value pair stored in an object, or a simple array value.
Definition: Property.h:80
bool setJsonValue(const String &value)
Definition: Property.h:103
bool setJsonValue(const char *value, size_t valueLength)
Set property value given its JSON string representation.
const PropertyData * defaultData
Definition: Property.h:109
Property(const Store &store, const PropertyInfo &info, const PropertyData *data, const PropertyData *defaultData)
Create a Property instance.
Definition: Property.h:90
Manages access to an object store, typically one file.
Definition: ConfigDB/src/include/ConfigDB/Store.h:43
The String class.
Definition: WString.h:133
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:609
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:238
Definition: Array.h:26
Property metadata.
Definition: PropertyInfo.h:126
static const PropertyInfo empty
Definition: PropertyInfo.h:156
Definition: PropertyData.h:44