sdbus++: add minint/maxint support for integer default values
Allow default values of minint and maxint for integer types using the
`std::numeric_limits::{min,max}`.
Tested:
Generated cpp files with
```
./tools/sdbus++-gen-meson --command cpp --tool "./tools/sdbus++" \
--directory "." --output "." test
```
test.interface.yaml
```
properties:
- name: test0
type: uint64
default: minint
- name: test1
type: uint64
default: maxint
- name: test2
type: uint64
```
Snippet of server.hpp
```
uint64_t _test0 = 0;
uint64_t _test1 = std::numeric_limits<uint64_t>::max();
uint64_t _test2{};
```
Change-Id: I38ae3be783211ca0c4e6af9c1e20816579276c9e
Signed-off-by: Willy Tu <wltu@google.com>
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/docs/interface.md b/docs/interface.md
index 635bfb6..32c810e 100644
--- a/docs/interface.md
+++ b/docs/interface.md
@@ -87,7 +87,7 @@
### Special type values
-For 'double' types it is possible to express one of the special values:
+For floating-point types it is possible to express one of the special values:
* 'NaN' (case-insensitive)
- A quiet-type not-a-number value.
* 'Infinity' (case-insensitive)
@@ -97,6 +97,12 @@
* 'Epsilon' (case-insensitive)
- An epsilon value.
+For integer types it is possible to express one of the special values:
+ * 'minint' (case-insensitive)
+ - The mininum value the integer type can hold.
+ * 'maxint' (case-insensitive)
+ - The maximum value the integer type can hold.
+
### Containers
Container types can also be expressed, but the contained-type should be
expressed within square-brackets `[]`. The following containers are supported:
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 5de653c..a3f43eb 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -26,19 +26,27 @@
# Wrap string type default values with double-quotes
self.defaultValue = "\"" + self.defaultValue + "\""
elif(isinstance(self.defaultValue, str) and
- self.typeName.lower() == "double"):
+ self.is_floating_point()):
if self.defaultValue.lower() == "nan":
self.defaultValue = \
- 'std::numeric_limits<double>::quiet_NaN()'
+ f'std::numeric_limits<{self.cppTypeName}>::quiet_NaN()'
elif self.defaultValue.lower() == "infinity":
self.defaultValue = \
- 'std::numeric_limits<double>::infinity()'
+ f'std::numeric_limits<{self.cppTypeName}>::infinity()'
elif self.defaultValue.lower() == "-infinity":
self.defaultValue = \
- '-std::numeric_limits<double>::infinity()'
+ f'-std::numeric_limits<{self.cppTypeName}>::infinity()'
elif self.defaultValue.lower() == "epsilon":
self.defaultValue = \
- 'std::numeric_limits<double>::epsilon()'
+ f'std::numeric_limits<{self.cppTypeName}>::epsilon()'
+ elif(isinstance(self.defaultValue, str) and
+ self.is_integer()):
+ if self.defaultValue.lower() == "maxint":
+ self.defaultValue = \
+ f'std::numeric_limits<{self.cppTypeName}>::max()'
+ elif self.defaultValue.lower() == "minint":
+ self.defaultValue = \
+ f'std::numeric_limits<{self.cppTypeName}>::min()'
super(Property, self).__init__(**kwargs)