ADTF Display Toolbox
Loading...
Searching...
No Matches
adtf_display_toolbox_base.h
Go to the documentation of this file.
1
7#pragma once
8
9#include "runtimeconfig.h"
10
11#include <adtfbase/configuration_intf.h>
12#include <adtfbase/configuration.h>
13
14namespace adtf
15{
16namespace disptb
17{
18
20static constexpr char property_separator[] = ".";
21
29inline std::string BuildPropertyName(std::string const& prefix, std::string const& prop_name)
30{
31 return (prefix + std::string(property_separator) + prop_name);
32}
33
43template<typename T>
44void AttachPropertyEntry(const tChar* prop_name_prefix,
45 const tChar* prop_name,
46 T const& prop_val,
47 adtf::base::ant::IConfiguration& configuration)
48{
49 std::string full_prop_name = BuildPropertyName(prop_name_prefix, prop_name);
50 adtf::base::set_property<T>(configuration, full_prop_name.c_str(), prop_val);
51}
52
62template<typename T>
63T GetPropertyValue(std::string const& prop_name_prefix,
64 std::string const& prop_name,
65 adtf::base::ant::IConfiguration const& configuration)
66{
67 std::string full_prop_name = BuildPropertyName(prop_name_prefix, prop_name);
68 return adtf::base::get_property<T>(configuration, full_prop_name.c_str());
69}
70
79inline bool HasProperty(std::string const& prop_name_prefix,
80 std::string const& prop_name,
81 adtf::base::ant::IConfiguration const& configuration)
82{
83 adtf::ucom::object_ptr<const adtf::base::ant::IProperties> pProperties;
84 configuration.GetProperties(pProperties);
85
86 std::string full_prop_name = BuildPropertyName(prop_name_prefix, prop_name);
87 return pProperties->Exists(full_prop_name.c_str());
88}
89
100template<typename ValueType>
101ValueType RestorePropertyValue(std::string const& prefix,
102 std::string const& prop_name,
103 adtf::base::ant::IConfiguration const& configuration)
104{
105 if (!HasProperty(prefix, prop_name, configuration))
106 {
107 std::string info = "Could not find property '";
108 info.append(adtf::disptb::BuildPropertyName(prefix, prop_name));
109 info.append("' for restoring its value.\n");
110 LOG_WARNING(info.c_str());
111 }
112
113 // call GetPropertyValue always, it will deliver a default value in case property does not exist
114 return GetPropertyValue<ValueType>(prefix, prop_name, configuration);
115}
116
117} // namespace disptb
118
119} // namespace adtf
Namespace for functionality provided by the Display Toolbox.
std::string BuildPropertyName(std::string const &prefix, std::string const &prop_name)
Rule to build a full property name, based on its prefix and (base) name.
static constexpr char property_separator[]
Define a separator for properties.
T GetPropertyValue(std::string const &prop_name_prefix, std::string const &prop_name, adtf::base::ant::IConfiguration const &configuration)
Retrieves the value of a property from a given configuration.
void AttachPropertyEntry(const tChar *prop_name_prefix, const tChar *prop_name, T const &prop_val, adtf::base::ant::IConfiguration &configuration)
Attaches a property and its value to a given configuration.
bool HasProperty(std::string const &prop_name_prefix, std::string const &prop_name, adtf::base::ant::IConfiguration const &configuration)
Query whether a configuration contains a property.
ValueType RestorePropertyValue(std::string const &prefix, std::string const &prop_name, adtf::base::ant::IConfiguration const &configuration)
Restores the value of a property from a given configuration.
Main namespace.
Copyright © Audi Electronics Venture GmbH.