#include "demo_dynamic_properties.h"
#include <string>
#include <fstream>
ADTF_PLUGIN(
"Demo Dynamic Properties Filter Plugin", cDynamicPropertiesFilter);
cDynamicPropertiesFilter::cProperties::cProperties(cDynamicPropertiesFilter& oFilter, std::string strPropertyName):
m_oFilter(oFilter),
m_strPropertyName(strPropertyName)
{
m_propFilename.SetDescription("Select a single file.");
m_oFilter.RegisterPropertyVariable(m_strPropertyName.c_str(), m_propFilename);
}
cDynamicPropertiesFilter::cProperties::~cProperties()
{
object_ptr<IProperties> pProperties;
if (
IS_OK(m_oFilter.GetProperties(pProperties)))
{
pProperties->RemoveProperty(m_strPropertyName.c_str());
}
}
cDynamicPropertiesFilter::cDynamicPropertiesFilter()
{
m_nDynamicPropertyByProperty.SetDescription("Amount of property instances");
m_nDynamicPropertyByProperty.SetPropertyChangedCallback([this]()
{
m_lstProperties.clear();
for (uint32_t nIndex = 0; nIndex < m_nDynamicPropertyByProperty; nIndex++)
{
m_lstProperties.push_back(std::make_unique<cProperties>(*
this, std::string(
"by_property_") +
std::to_string(nIndex)));
}
});
RegisterPropertyVariable("dynamic_property_by_property", m_nDynamicPropertyByProperty);
m_nDynamicPropertyByFile.SetDescription("A text file with properties per line");
m_nDynamicPropertyByFile.SetPropertyChangedCallback([this]()
{
m_lstPropertiesFromFile.clear();
std::ifstream oFile(m_nDynamicPropertyByFile->GetPtr());
std::string strPropertyByLine;
while (std::getline(oFile, strPropertyByLine))
{
m_lstPropertiesFromFile.push_back(std::make_unique<cProperties>(*this, strPropertyByLine));
}
});
RegisterPropertyVariable("dynamic_property_by_file", m_nDynamicPropertyByFile);
set_description(*
this,
"Use this filter to provide a dynamic amount of properties.");
set_help_link(*
this,
"$(ADTF_DIR)/doc/adtf_html/page_demo_dynamic_properties.html");
}
Copyright © Audi Electronics Venture GmbH.
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
#define IS_OK(s)
Check if result is OK.
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
void set_description(base::ant::IConfiguration &oConfig, const char *strDescription)
Sets description information.
void set_help_link(base::ant::IConfiguration &oConfig, const char *strUrl)
Set the link to the corresponding help/documentation.