fw4spl
ConfigurationElementContainer.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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 #include <algorithm>
8 
9 #include "fwRuntime/ConfigurationElement.hpp"
10 #include "fwRuntime/ConfigurationElementContainer.hpp"
11 
12 
13 namespace fwRuntime
14 {
15 
16 namespace
17 {
18 
25 struct HasName
26 {
27  HasName( const std::string & name )
28  : m_name( name )
29  {
30  }
31 
32  bool operator() ( ConfigurationElement::csptr element ) const
33  {
34  return element->getName() == m_name;
35  }
36 
37  private:
38 
39  std::string m_name;
40 };
41 
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 void ConfigurationElementContainer::addConfigurationElement( ConfigurationElement::sptr element )
47 {
48  m_elements.push_back( element );
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55  return m_elements.begin();
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  return m_elements.end();
63 }
64 
65 //------------------------------------------------------------------------------
66 
68 {
69  return m_elements;
70 }
71 
72 //-----------------------------------------------------------------------------
73 
74 bool ConfigurationElementContainer::hasConfigurationElement( const std::string & name ) const
75 {
76  Container::const_iterator found = std::find_if( m_elements.begin(), m_elements.end(), HasName(name) );
77  return found != m_elements.end();
78 }
79 
80 //-----------------------------------------------------------------------------
81 
82 const std::shared_ptr<ConfigurationElement> ConfigurationElementContainer::findConfigurationElement(
83  const std::string & name ) const
84 {
85  Container::const_iterator found = std::find_if( m_elements.begin(), m_elements.end(), HasName(name) );
86 
87  return ( found == m_elements.end() ) ? std::shared_ptr< ConfigurationElement >() : *found;
88 }
89 
90 //-----------------------------------------------------------------------------
91 
93 const
94 {
96 
97  for( Container::const_iterator itCfgElem = m_elements.begin();
98  itCfgElem != m_elements.end();
99  ++itCfgElem )
100  {
101  if ( (*itCfgElem)->getName() == _name )
102  {
103  container.addConfigurationElement( (*itCfgElem) );
104  }
105  }
106 
107  return container;
108 }
109 
110 //-----------------------------------------------------------------------------
111 
113 {
114  return m_elements.size();
115 }
116 
117 //-----------------------------------------------------------------------------
118 
119 } // namespace fwRuntime
FWRUNTIME_API void addConfigurationElement(std::shared_ptr< ConfigurationElement > element)
Adds a new configuration element to the extension.
FWRUNTIME_API Iterator begin()
Retrieves the iterator on the first managed configuration element.
FWRUNTIME_API bool hasConfigurationElement(const std::string &name) const
Test if has an configuration corresponding to the specified name.
std::vector< std::shared_ptr< ConfigurationElement > > Container
Defines the configuration element container type.
FWRUNTIME_API ConfigurationElementContainer findAllConfigurationElement(const std::string &name) const
Retrieves the configurations corresponding to the specified name.
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
FWRUNTIME_API size_t size() const
Return the number of configurations.
Defines the generic configuration element container class.
FWRUNTIME_API const Container & getElements() const
Returns the configuration element container.
FWRUNTIME_API Iterator end()
Retrieves the iterator on the end of the configuration element container.
Container::iterator Iterator
Defines the configuration element container type.
FWRUNTIME_API const std::shared_ptr< ConfigurationElement > findConfigurationElement(const std::string &name) const
Retrieves the first configuration corresponding to the specified name.