Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ParameterEntry.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TEUCHOS_PARAMETER_ENTRY_H
11 #define TEUCHOS_PARAMETER_ENTRY_H
12 
17 #include "Teuchos_ConfigDefs.hpp"
18 #include "Teuchos_any.hpp"
19 #include "Teuchos_RCP.hpp"
21 
22 namespace Teuchos {
23 
24 #ifndef DOXYGEN_SHOULD_SKIP_THIS
25 class ParameterList; // another parameter type (forward declaration)
26 #endif
27 
35 
36 public:
37 
40 
42  typedef unsigned int ParameterEntryID;
43 
45 
47 
48 
51 
53  ParameterEntry(const ParameterEntry& source);
54 
57 
59  template <typename T, typename = std::enable_if_t< ! std::is_same_v<std::decay_t<T>, ParameterEntry>>>
60  explicit ParameterEntry(
61  T&& value, bool isDefault = false, bool isList = false,
62  const std::string &docString = "",
63  RCP<const ParameterEntryValidator> const& validator = null
64  );
65 
67 
69 
70 
72  ParameterEntry& operator=(const ParameterEntry& source);
73 
75  ParameterEntry& operator=(ParameterEntry&&);
76 
84  template<typename T>
85  void setValue(
86  T value, bool isDefault = false,
87  const std::string &docString = "",
88  RCP<const ParameterEntryValidator> const& validator = null
89  );
90 
97  void setAnyValue(
98  const any &value, bool isDefault = false
99  );
100 
102  void setValidator(
103  RCP<const ParameterEntryValidator> const& validator
104  );
105 
107  void setDocString(const std::string &docString);
108 
110  ParameterList& setList(
111  bool isDefault = false,
112  const std::string &docString = ""
113  );
114 
116 
118 
119 
125  template<typename T>
126  inline
127  T& getValue(T *ptr) const;
128 
133  inline
134  any& getAny(bool activeQry = true);
135 
140  inline
141  const any& getAny(bool activeQry = true) const;
142 
144 
146 
147 
149  inline
150  bool isUsed() const;
151 
153  bool isList() const;
154 
156  template <typename T>
157  inline
158  bool isType() const;
159 
161  bool isArray() const;
162  //
164  bool isTwoDArray() const;
165 
167  inline
168  bool isDefault() const;
169 
171  inline
172  std::string docString() const;
173 
175  inline
176  RCP<const ParameterEntryValidator> validator() const;
177 
179 
181 
182 
188  std::ostream& leftshift(std::ostream& os, bool printFlags = true) const;
189 
193  static const std::string& getTagName(){
194  static const std::string tagName = "Parameter";
195  return tagName;
196  }
197 
199 
200 private:
201 
203  void reset();
204 
207 
209  mutable bool isUsed_;
210 
212  mutable bool isDefault_;
213 
215  std::string docString_;
216 
218 //use pragmas to disable some false positive warnings for windows sharedlib export
219 #ifdef _MSC_VER
220 #pragma warning(push)
221 #pragma warning(disable:4251)
222 #endif
224 #ifdef _MSC_VER
225 #pragma warning(pop)
226 #endif
227 
228 };
229 
235 template<typename T>
236 inline T& getValue( const ParameterEntry &entry )
237 {
238  return entry.getValue(static_cast<T*>(0));
239 }
240 
246 template<typename T>
248 {
249  return entry->getValue(static_cast<T*>(0));
250 }
251 
255 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2)
256 {
257  return (
258  e1.getAny() == e2.getAny()
259  && e1.isList()== e2.isList()
260  && e1.isUsed() == e2.isUsed()
261  && e1.isDefault() == e2.isDefault()
262  );
263 }
264 
268 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2)
269 {
270  return !( e1 == e2 );
271 }
272 
276 inline std::ostream& operator<<(std::ostream& os, const ParameterEntry& e)
277 {
278  return e.leftshift(os);
279 }
280 
281 // ///////////////////////////////////////////
282 // Inline and Template Function Definitions
283 
284 // Constructor/Destructor
285 
286 template<typename T, typename>
287 inline
289  T&& value_in,
290  bool isDefault_in,
291  bool /*isList_in*/, // 2007/11/26: rabartl: ToDo: This arg is ignored and should be removed!
292  const std::string &docString_in,
293  RCP<const ParameterEntryValidator> const& validator_in
294  )
295  : val_(std::forward<T>(value_in)),
296  isUsed_(false),
297  isDefault_(isDefault_in),
298  docString_(docString_in),
299  validator_(validator_in)
300 {
301 }
302 
303 // Set Methods
304 
305 template<typename T>
306 inline
308  T value_in, bool isDefault_in, const std::string &docString_in,
309  RCP<const ParameterEntryValidator> const& validator_in
310  )
311 {
312  val_ = value_in;
313  isDefault_ = isDefault_in;
314  if(docString_in.length())
315  docString_ = docString_in;
316  if(validator_in.get())
317  validator_ = validator_in;
318 }
319 
320 // Get Methods
321 
322 template<typename T>
323 inline
324 T& ParameterEntry::getValue(T * /*ptr*/) const
325 {
326  isUsed_ = true;
327  return const_cast<T&>(Teuchos::any_cast<T>( val_ ));
328 }
329 
330 inline
331 any& ParameterEntry::getAny(bool activeQry)
332 {
333  if (activeQry == true) {
334  isUsed_ = true;
335  }
336  return val_;
337 }
338 
339 inline
340 const any& ParameterEntry::getAny(bool activeQry) const
341 {
342  if (activeQry == true) {
343  isUsed_ = true;
344  }
345  return val_;
346 }
347 
348 // Attribute Methods
349 
350 inline
352 { return isUsed_; }
353 
354 template <typename T>
355 inline
357 { return val_.type() == typeid(T); }
358 
359 inline
361 { return isDefault_; }
362 
363 inline
364 std::string ParameterEntry::docString() const
365 { return docString_; }
366 
367 inline
370 { return validator_; }
371 
372 
373 } // namespace Teuchos
374 
375 
376 #endif
Modified boost::any class for holding a templated value.
void setValue(T value, bool isDefault=false, const std::string &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method that uses the input value type to determine the type of parameter.
ParameterEntry()
Default Constructor.
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
bool isDefault_
Was this parameter a default value assigned by a &quot;get&quot; function?
std::ostream & leftshift(std::ostream &os, bool printFlags=true) const
Output a non-list parameter to the given output stream.
This object is held as the &quot;value&quot; in the Teuchos::ParameterList std::map.
static const std::string & getTagName()
Get the string that should be used as the tag name for all parameters when they are serialized to xml...
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
bool isType() const
Test the type of the data being contained.
T * get() const
Get the raw C++ pointer to the underlying object.
bool isDefault() const
Indicate whether this entry takes on the default value.
Modified boost::any class, which is a container for a templated value.
T & getValue(T *ptr) const
Templated get method that uses the input pointer type to determine the type of parameter to return...
bool operator==(const ParameterEntry &e1, const ParameterEntry &e2)
Returns true if two ParameterEntry objects are equal.
bool operator!=(const ParameterEntry &e1, const ParameterEntry &e2)
Returns true if two ParameterEntry objects are not equal.
T & getValue(RCP< const ParameterEntry > entry)
A templated helper function for returning the value of type T held in the ParameterEntry object...
std::string docString_
Optional documentation field.
any val_
Templated Datatype.
bool isList() const
Return whether or not the value itself is a list.
A list of parameters of arbitrary type.
RCP< const ParameterEntryValidator > validator_
Optional validator object.
T & getValue(const ParameterEntry &entry)
A templated helper function for returning the value of type T held in the ParameterEntry object...
#define TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
any & getAny(bool activeQry=true)
Direct access to the Teuchos::any data value underlying this object. The bool argument activeQry (def...
Smart reference counting pointer class for automatic garbage collection.
const std::type_info & type() const
Return the type of value being stored.
std::string docString() const
Return the (optional) documentation std::string.
bool isUsed() const
Return whether or not the value has been used; i.e., whether or not the value has been retrieved via ...
Reference-counted pointer class and non-member templated function implementations.
std::ostream & operator<<(std::ostream &os, const ParameterEntry &e)
Output stream operator for handling the printing of parameter entries.
bool isUsed_
Has this parameter been accessed by a &quot;get&quot; function?