Skip to content

Commit aa22cbc

Browse files
committed
fixup! common: Add jansson support header
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
1 parent b53e97b commit aa22cbc

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

common/include/villas/jansson.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/* Jansson support header.
2+
*
3+
* Author: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
4+
* SPDX-FileCopyrightText: 2014-2026 Institute for Automation of Complex Power Systems, RWTH Aachen University
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
18
#pragma once
29

310
#include <initializer_list>
@@ -10,9 +17,9 @@
1017

1118
namespace villas {
1219

13-
// smart pointer for ::json_t values.
20+
// Smart pointer for ::json_t values.
1421
//
15-
// this class mirrors the interface of std::shared_ptr using the internal reference count of ::json_t
22+
// This class mirrors the interface of std::shared_ptr using the internal reference count of ::json_t.
1623
class JanssonPtr {
1724
public:
1825
JanssonPtr() : inner(nullptr) {}
@@ -59,27 +66,27 @@ class JanssonPtr {
5966
::json_t *inner;
6067
};
6168

62-
// type trait helper for applying variadic default promotions
69+
// Type trait helper for applying variadic default promotions.
6370
template <typename T> class va_default_promote {
6471
static auto impl() {
6572
using U = std::decay_t<T>;
6673
if constexpr (std::is_enum_v<U>) {
6774
if constexpr (std::is_convertible_v<U, std::underlying_type_t<U>>) {
68-
// unscoped enumerations are converted to their underlying type and then promoted using integer promotions
75+
// Unscoped enumerations are converted to their underlying type and then promoted using integer promotions.
6976
return std::type_identity<
7077
decltype(+std::declval<std::underlying_type_t<U>>())>();
7178
} else {
72-
// scoped enumeration handling is implementation defined just pass them without promotions
79+
// Scoped enumeration handling is implementation defined just pass them without promotions.
7380
return std::type_identity<U>();
7481
}
7582
} else if constexpr (std::is_same_v<float, U>) {
76-
// float values are promoted to double
83+
// Floating point values are promoted to double.
7784
return std::type_identity<double>();
7885
} else if constexpr (std::is_integral_v<U>) {
79-
// integral values are promoted using integer promotions
86+
// Integral values are promoted using integer promotions.
8087
return std::type_identity<decltype(+std::declval<U>())>();
8188
} else {
82-
// default case without any promotions
89+
// The default case without any promotions.
8390
return std::type_identity<U>();
8491
}
8592
}
@@ -90,7 +97,7 @@ template <typename T> class va_default_promote {
9097

9198
template <typename T> using va_default_promote_t = va_default_promote<T>::type;
9299

93-
// helper type for validating format strings
100+
// A helper type for validating format strings.
94101
enum class JanssonFormatArg {
95102
KEY,
96103
STRING,
@@ -104,7 +111,7 @@ enum class JanssonFormatArg {
104111
JSON,
105112
};
106113

107-
// make a JanssonFormatArg from a type using template specializations
114+
// Make a JanssonFormatArg for a type.
108115
template <typename T> consteval JanssonFormatArg makeJanssonFormatArg() {
109116
if (std::is_same_v<T, char const>)
110117
return JanssonFormatArg::KEY;
@@ -134,13 +141,13 @@ template <typename T> consteval JanssonFormatArg makeJanssonFormatArg() {
134141
template <typename T>
135142
constexpr static JanssonFormatArg janssonFormatArg = makeJanssonFormatArg<T>();
136143

137-
// helper type for validating format strings with nested structures
144+
// Helper type for validating format strings with nested structures.
138145
enum class JanssonNestedStructure {
139146
OBJECT,
140147
ARRAY,
141148
};
142149

143-
// compile time validator for json_unpack-style format strings
150+
// Compile time validator for json_unpack-style format strings.
144151
template <typename... Args> class JanssonUnpackFormatString {
145152
public:
146153
consteval JanssonUnpackFormatString(char const *fmt) : fmt(fmt) {
@@ -295,7 +302,7 @@ void janssonUnpack(::json_t *json,
295302
throw RuntimeError("Could not unpack json value: {}", err.text);
296303
}
297304

298-
// compile time validator for json_pack-style format strings
305+
// Compile time validator for json_pack-style format strings.
299306
template <typename... Args> class JanssonPackFormatString {
300307
public:
301308
consteval JanssonPackFormatString(char const *fmt) : fmt(fmt) {

0 commit comments

Comments
 (0)