Documentation for OpenFLUID 2.2.0
WareRegistry.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  @file WareRegistry.hpp
34 
35  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
36 */
37 
38 
39 #ifndef __OPENFLUID_MACHINE_WAREREGISTRY_HPP__
40 #define __OPENFLUID_MACHINE_WAREREGISTRY_HPP__
41 
42 
44 
45 
46 namespace openfluid { namespace machine {
47 
48 
49 template<class SignatureType>
51 {
52  public:
53 
54  /**
55  Container type to store ware containers indexed by ID
56  */
57  using WaresByID_t = std::map<openfluid::ware::WareID_t,WareContainer<SignatureType>>;
58 
59  /**
60  Container type to store ware containers indexed by path
61  */
62  using WaresByPath_t = std::map<std::string,WareContainer<SignatureType>>;
63 
64 
65  private:
66 
67  /**
68  Returns an empty built container
69  @return The container
70  */
71  virtual WareContainer<SignatureType> createWareContainer() const = 0;
72 
73 
74  protected:
75 
77 
79 
82 
83  virtual ~WareRegistry()
84  { }
85 
86  /**
87  Adds a container in the registry, as an available or errored ware
88  @param[in] Container the container to add
89  @return true if the container was successfully added, false otherwise
90  */
92  {
93  if (Container.isValid())
94  {
95  if (Container.hasSignature())
96  {
97  const auto ID = Container.signature()->ID;
98  m_AvailableWares.emplace(ID,std::move(Container));
99  }
100  else
101  {
102  const auto Path = Container.getPath();
103  m_ErroredWares.emplace(Path,std::move(Container));
104  }
105  return true;
106  }
107  return false;
108  }
109 
110 
111  public:
112 
113  virtual bool addWare(const openfluid::ware::WareID_t& ID) = 0;
114 
115  virtual void discoverWares(const std::string IDPattern) = 0;
116 
117  /**
118  Clear all wares containers from the registry
119  */
120  void clearWares()
121  {
122  m_AvailableWares.clear();
123  m_ErroredWares.clear();
124  }
125 
126  /**
127  Returns the container of the ware given by its ID
128  @param[in] ID The ID of the ware
129  @return The container of the requested ware, an invalid container if not found
130  */
132  {
133  auto it = m_AvailableWares.find(ID);
134 
135  if (it != m_AvailableWares.end())
136  {
137  return it->second;
138  }
139 
140  return m_InvalidWareContainer;
141  }
142 
143  /**
144  Returns the available wares, indexed by ID
145  @return an ID-container map of wares
146  */
148  {
149  return m_AvailableWares;
150  }
151 
152  /**
153  Returns the errored wares, indexed by path
154  @return a path-container map of wares
155  */
157  {
158  return m_ErroredWares;
159  }
160 
161  /**
162  Returns true if a ware has been already registered with the given ID
163  @param[in] ID The ID of the ware
164  @return true if the ware is registered
165  */
167  {
168  return (m_AvailableWares.find(ID) != m_AvailableWares.end());
169  }
170 
171  virtual void clear() = 0;
172 
173 };
174 
175 
176 } } // namespaces
177 
178 
179 #endif /* __OPENFLUID_MACHINE_WAREREGISTRY_HPP__ */
Definition: WareContainer.hpp:62
bool hasSignature() const
Definition: WareContainer.hpp:207
std::string getPath() const
Definition: WareContainer.hpp:110
bool isValid() const
Definition: WareContainer.hpp:162
const std::unique_ptr< SignatureType > & signature() const
Definition: WareContainer.hpp:198
Definition: WareRegistry.hpp:51
virtual void discoverWares(const std::string IDPattern)=0
bool add(WareContainer< SignatureType > Container)
Definition: WareRegistry.hpp:91
const WaresByID_t & availableWares() const
Definition: WareRegistry.hpp:147
const WaresByPath_t & erroredWares() const
Definition: WareRegistry.hpp:156
std::map< openfluid::ware::WareID_t, WareContainer< SignatureType > > WaresByID_t
Definition: WareRegistry.hpp:57
WareContainer< SignatureType > m_InvalidWareContainer
Definition: WareRegistry.hpp:80
std::map< std::string, WareContainer< SignatureType > > WaresByPath_t
Definition: WareRegistry.hpp:62
virtual ~WareRegistry()
Definition: WareRegistry.hpp:83
const WareContainer< SignatureType > & wareContainer(const openfluid::ware::WareID_t &ID) const
Definition: WareRegistry.hpp:131
virtual bool addWare(const openfluid::ware::WareID_t &ID)=0
WaresByID_t m_AvailableWares
Definition: WareRegistry.hpp:76
WaresByPath_t m_ErroredWares
Definition: WareRegistry.hpp:78
bool hasAvailableWare(const openfluid::ware::WareID_t &ID) const
Definition: WareRegistry.hpp:166
void clearWares()
Definition: WareRegistry.hpp:120
FilesystemPath Path
Definition: FilesystemPath.hpp:308
std::string WareID_t
Definition: TypeDefs.hpp:49
Definition: ApplicationException.hpp:47