source: pacpusframework/trunk/src/PacpusLib/XmlComponentConfig.cpp@ 91

Last change on this file since 91 was 91, checked in by DHERBOMEZ Gérald, 11 years ago

Improvement of the build system to avoid some workarounds

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1// %pacpus:license{
2// This file is part of the PACPUS framework distributed under the
3// CECILL-C License, Version 1.0.
4// %pacpus:license}
5/// @author Gerald Dherbomez <firstname.surname@utc.fr>
6/// @version $Id: XmlComponentConfig.cpp 91 2013-05-19 10:32:48Z gdherbom $
7
8#include <Pacpus/kernel/XmlComponentConfig.h>
9#include <Pacpus/kernel/Log.h>
10#include <Pacpus/kernel/XmlConfigFile.h>
11
12using namespace pacpus;
13using namespace std;
14
15DECLARE_STATIC_LOGGER("pacpus.core.XmlComponentConfig");
16
17static const string kPropertyComponentType = "type";
18
19XmlComponentConfig::XmlComponentConfig(const QString& name)
20{
21 LOG_TRACE("XmlComponentConfig(QString)");
22
23 // Get the pointer to the document and create the component.
24 parentDocument_ = XmlConfigFile::create();
25 if (name != QString::null)
26 component_ = parentDocument_->createComponent(name);
27}
28
29/// Destructor.
30XmlComponentConfig::~XmlComponentConfig()
31{
32 LOG_TRACE("~XmlComponentConfig()");
33}
34
35void XmlComponentConfig::addProperty(const QString& name)
36{
37 if (hasProperty(name))
38 {
39 LOG_ERROR("cannot add component property:"
40 << " component '" << component_.tagName() << "'"
41 << " already contains property '" << name << "'"
42 << " and its value is '" << component_.attribute(name) << "'"
43 );
44 return;
45 }
46
47 // The property does not exist, it can be added.
48 component_.setAttribute(name, 0);
49 LOG_INFO("property '" << name << "'"
50 << " was added to the component " << component_.tagName() << "'"
51 << " and set to '" << component_.attribute(name) << "'"
52 );
53}
54
55int XmlComponentConfig::delProperty(const QString& name)
56{
57 if (!hasProperty(name))
58 {
59 LOG_WARN("cannot delete compoenent property '" << name << "'"
60 << " of component '" << component_.tagName() << "'"
61 << ". Component does not contain this property."
62 );
63 return false;
64 }
65
66 // The property exists, it can be removed.
67 component_.removeAttribute(name);
68 LOG_INFO("property '" << name << "' "
69 << " of component '" << component_.tagName() << "'"
70 << " was deleted"
71 );
72
73 return true;
74}
75
76QString XmlComponentConfig::getProperty(const QString& name, const QString& defaultValue) const
77{
78 if (!hasProperty(name))
79 {
80 LOG_WARN("cannot retrieve component property '" << name << "'"
81 << " of component '" << component_.tagName() << "'"
82 << ". Component does not contain this property."
83 );
84 return defaultValue;
85 }
86
87 // The property exists, the value can be retrieved.
88 return component_.attribute(name);
89}
90
91bool XmlComponentConfig::getBoolProperty(const QString& name, bool defaultValue) const
92{
93 return hasProperty(name) ? getProperty(name) == "true" : defaultValue;
94}
95
96int XmlComponentConfig::getIntProperty(const QString& name, int defaultValue) const
97{
98 return hasProperty(name) ? getProperty(name).toInt() : defaultValue;
99}
100
101double XmlComponentConfig::getDoubleProperty(const QString& name, double defaultValue) const
102{
103 return hasProperty(name) ? getProperty(name).toDouble() : defaultValue;
104}
105
106void XmlComponentConfig::setProperty(const QString& name, const QString& value)
107{
108 component_.setAttribute(name, value);
109 LOG_INFO("property " << name
110 << " of the component " << component_.tagName()
111 << " was set to : " << value
112 );
113}
114
115bool XmlComponentConfig::hasProperty(const QString& name) const
116{
117 return component_.hasAttribute(name);
118}
119
120QDomElement XmlComponentConfig::qDomElement() const
121{
122 return component_;
123}
124
125void XmlComponentConfig::localCopy(const QDomElement& elementToCopy)
126{
127 component_ = elementToCopy;
128}
129
130QString const XmlComponentConfig::getComponentName() const
131{
132 return component_.tagName();
133}
134
135QString const XmlComponentConfig::getComponentType() const
136{
137 return getProperty(kPropertyComponentType.c_str());
138}
Note: See TracBrowser for help on using the repository browser.