fw4spl
ConfigurationElement.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwRuntime/config.hpp"
10 #include "fwRuntime/ConfigurationElementContainer.hpp"
11 #include "fwRuntime/RuntimeException.hpp"
12 
13 #include <fwCore/base.hpp>
14 
15 #include <map>
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 namespace fwRuntime
22 {
23 struct Bundle;
24 struct Executable;
25 
26 namespace io
27 {
28 struct BundleDescriptorReader;
29 }
30 }
31 
32 namespace fwRuntime
33 {
34 
39 struct FWRUNTIME_CLASS_API ConfigurationElement : public ConfigurationElementContainer,
40  public std::enable_shared_from_this< ConfigurationElement >
41 {
42 
43  friend struct ::fwRuntime::io::BundleDescriptorReader;
44 
46  ((( const std::shared_ptr< Bundle > ))(( const std::string ))),
48  __FWCORE_GENERATE_CAST(__FWCORE_GET_CLASSNAME((ConfigurationElement)), __FWCORE_TYPEDEF_ROOTCLASS_NAME)
51 
55  typedef std::pair< bool, std::string > AttributePair;
56 
60  struct NoSuchAttribute : public ::fwCore::Exception
61  {
62  NoSuchAttribute(const std::string& attr) :
63  ::fwCore::Exception(std::string("No such attribute: ") + attr)
64  {
65  }
66  };
67 
73  FWRUNTIME_API const std::shared_ptr< Bundle > getBundle() const noexcept;
74 
90  FWRUNTIME_API const std::string getAttributeValue(const std::string& name) const noexcept;
91 
108  FWRUNTIME_API const std::string getExistingAttributeValue(const std::string& name) const;
109 
124  FWRUNTIME_API const AttributePair getSafeAttributeValue(const std::string& name) const noexcept;
125 
131  FWRUNTIME_API const std::string getName() const noexcept;
132 
138  FWRUNTIME_API const std::string getValue() const noexcept;
139 
147  FWRUNTIME_API bool hasAttribute(const std::string& name) const noexcept;
148 
152  FWRUNTIME_API const std::map<std::string, std::string> getAttributes() const noexcept;
153 
157  FWRUNTIME_API friend std::ostream& operator<<(std::ostream& _sstream,
158  ConfigurationElement& _configurationElement);
159 
170  FWRUNTIME_API std::vector < ConfigurationElement::sptr > find(
171  std::string name = "",
172  std::string attribute = "",
173  std::string attributeValue = "",
174  int depth = 1
175  );
176 
180  FWRUNTIME_API virtual ~ConfigurationElement();
181 
182  protected:
183 
192  FWRUNTIME_API ConfigurationElement(const std::shared_ptr<Bundle> bundle, const std::string& name);
193 
202  FWRUNTIME_API void setAttributeValue(const std::string& name, const std::string& value) noexcept;
203 
209  FWRUNTIME_API void setValue(const std::string& value) noexcept;
210 
211  private:
212 
216  typedef std::map<std::string, std::string> AttributeContainer;
217 
221  const std::string m_name;
222 
226  std::string m_value;
227 
231  AttributeContainer m_attributes;
232 
238  void operator=(const ConfigurationElement&) noexcept;
239 
243  const std::weak_ptr<Bundle> m_bundle;
244 };
245 
246 } // namespace fwRuntime
STL namespace.
std::pair< bool, std::string > AttributePair
Defines the attribute pair type.
This namespace fwCore provides common foundations for FW4SPL.
Definition: BaseObject.hpp:16
Defines the configuration element class.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
#define fwCoreInterfaceIsTypeOfMacro(_classinfo_)
Generate getSptr and getConstSptr methods.
#define fwCoreInterfaceMacro()
Generate getSptr and getConstSptr methods.
Defines the generic configuration element container class.
#define fwCoreClassFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate methods for classes with one factory.
Defines the a class for attributes exceptions.