util
Namespace for package packageName
Types
| Name | Description |
|---|---|
| MetaData | A structure defining meta data as used by the data loggers |
| MetaSearchResult | A structure defining meta data as used by the data logger's search results |
| PluginLoader | The PluginLoader class. |
| TimeProfiler | |
| Version | @brief A class providing versioning information for the Karabo framework |
| static_or_dyn_cast | Helper functions to compile-time distinguish if a dynamic_cast is needed. |
Functions
| Name | Description |
|---|---|
| bind_weak | Weakly binds member function f to an object of class Obj, but assures shared ownership of the object while f is executed. |
| call | Call a function f with arguments unpacked from a std::tuple f : t : |
| exec_weak_impl | Provides a wrapper with the same signature as f, but securing shared ownership of an object of type Obj before execution of f. |
| exec_weak_impl | Provides a wrapper with the same signature as f, but securing shared ownership of an object of type Obj before execution of f. |
| generateAutoStartHash | @brief Generates an auto-start configuration Hash based on the provided initialization Hash. |
| jsonResultsToInfluxResultSet | Utility function to convert a string into an InfluxResultSet One or multiple concatenated JSON objects containing the results of an InfluxDB query are decoded and filled into a InfluxResultSet object. |
| jsonToHash | @brief Converts a JSON string representation into a Hash object. |
| jsonValueAsString | Utility function to convert a json object. |
| pack | Pack the parameters into a hash for transport over the network. |
| stringDoubleToEpochstamp | Convert an std::string that represents a double of the seconds since Unix epoch to an Epochstamp |
| unpack | Unpack the hash (typically coming from the network) into the parameters given by reference. |
| unpack | Unpack parameters into a tuple holding only references h : Hash with keys a1, a2, etc. encoding function arguments Return : std::tuple |
Function Details
bind_weak
template <typename F, typename Obj, typename... P> auto bind_weak(const F& f, Obj* const o, const P... p) -> decltype(std::bind(exec_weak_impl(f, o), p...))
Weakly binds member function f to an object of class Obj, but assures shared ownership of the object while f is executed. This means that during the lifetime of calling f, the object cannot be destroyed, but destruction is not blocked if f is not being executed but only bound. Class Obj needs to derive from std::enable_shared_from_this and the object pointer o has to be held by a shared_ptr. This means that you cannot use bind_weak within the constructor of Obj nor for objects constructed on the stack. Note that f may have any default constructable return type: If the bound functor will be called when the object is already destroyed, the functor returns a default constructed object of the return type.
Below is an example of how to bind to a boost::asio interface.
void Device::executeStepFunction(int arg, const boost::system::error_code& error) { .... m_timer.async_wait(bind_weak(&Device::executeStepFunction, this, arg + 1, _1)); .... }
f:
: function to bind, give as &Foo::bar
o:
: pointer to object to bind to
p:
: parameters as one would give to std::bind. Placeholders are fully supported.
Return : : bound functor, compatible with boost bind.
call
template <typename F, typename Tuple> void call(F f, Tuple&& t)
Call a function f with arguments unpacked from a std::tuple
f
:
t
:
exec_weak_impl
template <typename Ret, typename... Args, typename Obj> std::function<Ret(Args...)> exec_weak_impl(Ret (Obj::*f)(Args...) const, const Obj* o)
Provides a wrapper with the same signature as f, but securing shared ownership of an object of type Obj before execution of f. Class Obj needs to derive somewhere in its inheritance tree from enable_shared_from_this();
f:
: a const member function, can have any argument types and any return value
o:
: a pointer to an object that has a member function f
Return : a wrapped version of f.
template <typename Ret, typename... Args, typename Obj> std::function<Ret(Args...)> exec_weak_impl(Ret (Obj::*f)(Args...), Obj* o)
Provides a wrapper with the same signature as f, but securing shared ownership of an object of type Obj before execution of f. Class Obj needs to derive somewhere in its inheritance tree from enable_shared_from_this();
f:
: a non-const member function, can have any argument types and any return value
o:
: a pointer to an object that has a member function f
Return : a wrapped version of f.
generateAutoStartHash
karabo::data::Hash generateAutoStartHash(const karabo::data::Hash& initHash)
@brief Generates an auto-start configuration Hash based on the provided initialization Hash.
This function takes an initialization Hash representing the initial configuration of components and constructs an auto-start configuration Hash based on it.
The initialization Hash is expected to have been generated from the JSON for the init string used to autostart devices on a karabo cpp server.
An example conversion should look like this:
initHash: 'data_logger_manager_1' + 'classId' => DataLoggerManager STRING 'serverList' => karabo/dataLogger STRING 'schema_printer1' + 'classId' => SchemaPrinter STRING
Above transforms to autoStart hash: 'autoStart' @ [0] 'DataLoggerManager' + 'deviceId' => data_logger_manager_1 STRING 'serverList' => karabo/dataLogger STRING [1] 'SchemaPrinter' + 'deviceId' => schema_printer1 STRING
initHash
: The initialization Hash containing the initial configuration of components.
Return : A Hash object representing the auto-start configuration based on the provided initialization Hash.
jsonResultsToInfluxResultSet
void jsonResultsToInfluxResultSet(const std::string& jsonResult, InfluxResultSet& influxResult, const std::string& columnPrefixToRemove)
Utility function to convert a string into an InfluxResultSet
One or multiple concatenated JSON objects containing the results of an InfluxDB query are decoded and filled into a InfluxResultSet object.
jsonResult
: : the string containing the JSON object(s)
influxResult
: : the result
columnPrefixToRemove
: : remove this prefix from the column names.
InfluxQL selector functions (e.g. SAMPLE) are
prepended to the column name. Use this argument to
remove said prefixes.
Throw : karabo::util::NotSupportedException in case the column mismatch nlohmann::json exceptions in case of malformatted JSON objects.
jsonToHash
karabo::data::Hash jsonToHash(const std::string& j)
@brief Converts a JSON string representation into a Hash object.
This function parses a JSON string and constructs a corresponding Hash object representing the JSON structure. The JSON string is expected to follow the JSON standard format.
JSON Arrays of Mixed types are unsupported.
JSON types are mapped to C++ types as below:
- JSON Integer -> long long
- JSON Decimal -> double
- JSON empty array -> empty std::vector
jsonString
: A string containing the JSON representation to be converted.
Return : A Hash object representing the parsed JSON structure.
@throws KARABO_PARAMETER_EXCEPTION if the provided JSON string is invalid or cannot be parsed into a Hash object.
jsonValueAsString
boost::optional<std::string> jsonValueAsString(nlohmann::json value)
Utility function to convert a json object.
value
:
Return
: a boost::optional
pack
template <class... Ts> inline void pack(Hash& hash, const Ts&... args)
Pack the parameters into a hash for transport over the network.
hash
: Will be filled with keys a1, a2, etc. and associated values
args
: Any type and number of arguments to associated to hash keys
stringDoubleToEpochstamp
data::Epochstamp stringDoubleToEpochstamp(const std::string& timestampAsDouble)
Convert an std::string that represents a double of the seconds since Unix epoch to an Epochstamp
unpack
template <class... Ts> inline void unpack(const Hash& hash, Ts&... args)
Unpack the hash (typically coming from the network) into the parameters given by reference.
template <typename... Args> auto unpack(const karabo::data::Hash& h) -> decltype(detail::unpack_impl<'1', Args...>::unpack(h))
Unpack parameters into a tuple holding only references
h
: Hash with keys a1, a2, etc. encoding function arguments
Return
: std::tuple