Teuchos_ParameterEntry.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TEUCHOS_PARAMETER_ENTRY_H
00031 #define TEUCHOS_PARAMETER_ENTRY_H
00032
00037 #include "Teuchos_ConfigDefs.hpp"
00038 #include "Teuchos_any.hpp"
00039 #include "Teuchos_RCP.hpp"
00040 #include "Teuchos_ParameterEntryValidator.hpp"
00041
00042 namespace Teuchos {
00043
00044 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00045 class ParameterList;
00046 #endif
00047
00054 class ParameterEntry {
00055 public:
00056
00058
00059
00061 ParameterEntry();
00062
00064 ParameterEntry(const ParameterEntry& source);
00065
00067 template<typename T>
00068 explicit ParameterEntry(
00069 T value, bool isDefault = false, bool isList = false,
00070 const std::string &docString = "",
00071 RCP<const ParameterEntryValidator> const& validator = null
00072 );
00073
00075 ~ParameterEntry();
00076
00078
00080
00081
00083 ParameterEntry& operator=(const ParameterEntry& source);
00084
00092 template<typename T>
00093 void setValue(
00094 T value, bool isDefault = false,
00095 const std::string &docString = "",
00096 RCP<const ParameterEntryValidator> const& validator = null
00097 );
00098
00105 void setAnyValue(
00106 const any &value, bool isDefault = false
00107 );
00108
00110 void setValidator(
00111 RCP<const ParameterEntryValidator> const& validator
00112 );
00113
00115 void setDocString(const std::string &docString);
00116
00118 ParameterList& setList(
00119 bool isDefault = false,
00120 const std::string &docString = ""
00121 );
00122
00124
00126
00127
00133 template<typename T>
00134 T& getValue(T *ptr) const;
00135
00140 any& getAny(bool activeQry = true);
00141
00146 const any& getAny(bool activeQry = true) const;
00147
00149
00151
00152
00154 bool isUsed() const;
00155
00157 bool isList() const;
00158
00160 template <typename T>
00161 bool isType() const;
00162
00164 bool isDefault() const;
00165
00167 std::string docString() const;
00168
00170 RCP<const ParameterEntryValidator> validator() const;
00171
00173
00175
00182 std::ostream& leftshift(std::ostream& os, bool printFlags = true) const;
00183
00185
00186 private:
00187
00189 void reset();
00190
00192 any val_;
00193
00195 mutable bool isUsed_;
00196
00198 mutable bool isDefault_;
00199
00201 std::string docString_;
00202
00204 RCP<const ParameterEntryValidator> validator_;
00205
00206 };
00207
00213 template<typename T>
00214 inline T& getValue( const ParameterEntry &entry )
00215 {
00216 return entry.getValue((T*)NULL);
00217 }
00218
00222 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2)
00223 {
00224 return (
00225 e1.getAny() == e2.getAny()
00226 && e1.isList()== e2.isList()
00227 && e1.isUsed() == e2.isUsed()
00228 && e1.isDefault() == e2.isDefault()
00229 );
00230 }
00231
00235 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2)
00236 {
00237 return !( e1 == e2 );
00238 }
00239
00243 inline std::ostream& operator<<(std::ostream& os, const ParameterEntry& e)
00244 {
00245 return e.leftshift(os);
00246 }
00247
00248
00249
00250
00251
00252
00253 template<typename T>
00254 inline
00255 ParameterEntry::ParameterEntry(
00256 T value_in,
00257 bool isDefault_in,
00258 bool ,
00259 const std::string &docString_in,
00260 RCP<const ParameterEntryValidator> const& validator_in
00261 )
00262 : val_(value_in),
00263 isUsed_(false),
00264 isDefault_(isDefault_in),
00265 docString_(docString_in),
00266 validator_(validator_in)
00267 {}
00268
00269 inline
00270 ParameterEntry::~ParameterEntry()
00271 {}
00272
00273
00274
00275 template<typename T>
00276 inline
00277 void ParameterEntry::setValue(
00278 T value_in, bool isDefault_in, const std::string &docString_in,
00279 RCP<const ParameterEntryValidator> const& validator_in
00280 )
00281 {
00282 val_ = value_in;
00283 isDefault_ = isDefault_in;
00284 if(docString_in.length())
00285 docString_ = docString_in;
00286 if(validator_in.get())
00287 validator_ = validator_in;
00288 }
00289
00290
00291
00292 template<typename T>
00293 inline
00294 T& ParameterEntry::getValue(T * ) const
00295 {
00296 isUsed_ = true;
00297 return const_cast<T&>(Teuchos::any_cast<T>( val_ ));
00298 }
00299
00300 inline
00301 any& ParameterEntry::getAny(bool activeQry)
00302 {
00303 if (activeQry == true) {
00304 isUsed_ = true;
00305 }
00306 return val_;
00307 }
00308
00309 inline
00310 const any& ParameterEntry::getAny(bool activeQry) const
00311 {
00312 if (activeQry == true) {
00313 isUsed_ = true;
00314 }
00315 return val_;
00316 }
00317
00318
00319
00320 inline
00321 bool ParameterEntry::isUsed() const
00322 { return isUsed_; }
00323
00324 template <typename T>
00325 inline
00326 bool ParameterEntry::isType() const
00327 { return val_.type() == typeid(T); }
00328
00329 inline
00330 bool ParameterEntry::isDefault() const
00331 { return isDefault_; }
00332
00333 inline
00334 std::string ParameterEntry::docString() const
00335 { return docString_; }
00336
00337 inline
00338 RCP<const ParameterEntryValidator>
00339 ParameterEntry::validator() const
00340 { return validator_; }
00341
00342 }
00343
00344 #endif