Documentation for OpenFLUID 2.2.0
WareContainer.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 /**
34  @file WareContainer.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37 */
38 
39 
40 #ifndef __OPENFLUID_MACHINE_WARECONTAINER_HPP__
41 #define __OPENFLUID_MACHINE_WARECONTAINER_HPP__
42 
43 
44 #include <string>
45 #include <memory>
46 
47 #include <openfluid/dllexport.hpp>
48 #include <openfluid/ware/TypeDefs.hpp>
49 
50 
51 namespace openfluid { namespace machine {
52 
53 
54 typedef std::string UUID_t;
55 
56 
57 /**
58  @tparam SignatureType the type of the signature to hold in the container
59 */
60 template<class SignatureType>
62 {
63  private:
64 
66 
67  bool m_Valid = false;
68 
69  std::string m_Path;
70 
71  std::unique_ptr<SignatureType> m_Signature;
72 
73  bool m_Ghost = false;
74 
75  std::string m_Message;
76 
77  UUID_t m_LinkUID;
78 
79 
80  public:
81 
82  WareContainer() = delete;
83 
84  WareContainer(const WareContainer&) = delete;
85 
87 
89 
91 
92  virtual ~WareContainer() = default;
93 
94  WareContainer(openfluid::ware::WareType WType) : m_WareType(WType)
95  { }
96 
97  /**
98  Returns the ware type
99  @return The ware type
100  */
102  {
103  return m_WareType;
104  }
105 
106  /**
107  Returns the path of the ware
108  @return The ware path
109  */
110  std::string getPath() const
111  {
112  return m_Path;
113  }
114 
115  /**
116  Sets the path of the ware on disk
117  @param[in] Path the path
118  @throw openfluid::base::FrameworkException if path is already set
119  */
120  void setPath(const std::string& Path)
121  {
122  if (m_Path.empty())
123  {
124  m_Path = Path;
125  }
126  else
127  {
128  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Path already set");
129  }
130  }
131 
132  /**
133  Returns the link UID for parameterization UI
134  @return the link UID
135  */
137  {
138  return m_LinkUID;
139  }
140 
141  /**
142  Sets the link UID for parameterization UI
143  @param[in] UID the UID
144  @throw openfluid::base::FrameworkException if UID is already set
145  */
146  void setLinkUID(const UUID_t& UID)
147  {
148  if (m_LinkUID.empty())
149  {
150  m_LinkUID = UID;
151  }
152  else
153  {
154  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Link UID already set");
155  }
156  }
157 
158  /**
159  Gives the validation status
160  @return true if the conrtainer is valid
161  */
162  bool isValid() const
163  {
164  return m_Valid;
165  }
166 
167  /**
168  Sets the container as valid
169  @note a container cannot be invalidated
170  */
171  void validate()
172  {
173  m_Valid = true;
174  }
175 
176  /**
177  Returns the optional message aosciated to the container
178  @return the message
179  */
180  std::string getMessage() const
181  {
182  return m_Message;
183  }
184 
185  /**
186  Sets the optional message aosciated to the container
187  @param[in] Message the message
188  */
189  void setMessage(const std::string& Message)
190  {
191  m_Message = Message;
192  }
193 
194  /**
195  Returns a const reference to the signature as a unique pointer
196  @return the signature held in the container
197  */
198  const std::unique_ptr<SignatureType>& signature() const
199  {
200  return m_Signature;
201  }
202 
203  /**
204  Indicates if a signature is held by the container
205  @return true if a signature is held
206  */
207  bool hasSignature() const
208  {
209  return (m_Signature.get() != nullptr);
210  }
211 
212  /**
213  Sets the signature
214  @throw openfluid::base::FrameworkException if signature is already set
215  @note after using this method, the signature is owned by the container
216  */
217  void setSignature(SignatureType* Signature)
218  {
219  if (m_Signature)
220  {
221  throw openfluid::base::FrameworkException(OPENFLUID_CODE_LOCATION,"Signature is already set");
222  }
223  else
224  {
225  m_Signature.reset(Signature);
226  }
227  }
228 
229  /**
230  Returns true if the ware is a ghost
231  @return true if the ware is a ghost
232  */
233  bool isGhost() const
234  {
235  return m_Ghost;
236  }
237 
238  /**
239  Marks the ware as ghost
240  @note a container marked as ghost cannot be "unghosted"
241  */
242  void setGhost()
243  {
244  m_Ghost = true;
245  }
246 
247 };
248 
249 
250 } } // namespaces
251 
252 
253 #endif /* __OPENFLUID_MACHINE_WARECONTAINER_HPP__ */
Definition: FrameworkException.hpp:51
Definition: WareContainer.hpp:62
bool isGhost() const
Definition: WareContainer.hpp:233
bool hasSignature() const
Definition: WareContainer.hpp:207
void validate()
Definition: WareContainer.hpp:171
WareContainer(openfluid::ware::WareType WType)
Definition: WareContainer.hpp:94
std::string getPath() const
Definition: WareContainer.hpp:110
void setMessage(const std::string &Message)
Definition: WareContainer.hpp:189
void setPath(const std::string &Path)
Definition: WareContainer.hpp:120
WareContainer(WareContainer &&)=default
void setLinkUID(const UUID_t &UID)
Definition: WareContainer.hpp:146
WareContainer & operator=(WareContainer &&)=default
WareContainer(const WareContainer &)=delete
bool isValid() const
Definition: WareContainer.hpp:162
UUID_t getLinkUID() const
Definition: WareContainer.hpp:136
openfluid::ware::WareType getWareType() const
Definition: WareContainer.hpp:101
std::string getMessage() const
Definition: WareContainer.hpp:180
WareContainer & operator=(const WareContainer &)=delete
void setSignature(SignatureType *Signature)
Definition: WareContainer.hpp:217
const std::unique_ptr< SignatureType > & signature() const
Definition: WareContainer.hpp:198
void setGhost()
Definition: WareContainer.hpp:242
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::string UUID_t
Definition: WareContainer.hpp:54
FilesystemPath Path
Definition: FilesystemPath.hpp:308
WareType
Definition: TypeDefs.hpp:61
Definition: ApplicationException.hpp:47