|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 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; // another parameter type (forward declaration) 00046 #endif 00047 00054 class TEUCHOS_LIB_DLL_EXPORT 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 inline 00135 T& getValue(T *ptr) const; 00136 00141 inline 00142 any& getAny(bool activeQry = true); 00143 00148 inline 00149 const any& getAny(bool activeQry = true) const; 00150 00152 00154 00155 00157 inline 00158 bool isUsed() const; 00159 00161 bool isList() const; 00162 00164 template <typename T> 00165 inline 00166 bool isType() const; 00167 00169 inline 00170 bool isDefault() const; 00171 00173 inline 00174 std::string docString() const; 00175 00177 inline 00178 RCP<const ParameterEntryValidator> validator() const; 00179 00181 00183 00190 std::ostream& leftshift(std::ostream& os, bool printFlags = true) const; 00191 00193 00194 private: 00195 00197 void reset(); 00198 00200 any val_; 00201 00203 mutable bool isUsed_; 00204 00206 mutable bool isDefault_; 00207 00209 std::string docString_; 00210 00212 //use pragmas to disable some false positive warnings for windows sharedlib export 00213 #ifdef _MSC_VER 00214 #pragma warning(push) 00215 #pragma warning(disable:4251) 00216 #endif 00217 RCP<const ParameterEntryValidator> validator_; 00218 #ifdef _MSC_VER 00219 #pragma warning(pop) 00220 #endif 00221 00222 }; 00223 00229 template<typename T> 00230 inline T& getValue( const ParameterEntry &entry ) 00231 { 00232 return entry.getValue((T*)NULL); 00233 } 00234 00238 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2) 00239 { 00240 return ( 00241 e1.getAny() == e2.getAny() 00242 && e1.isList()== e2.isList() 00243 && e1.isUsed() == e2.isUsed() 00244 && e1.isDefault() == e2.isDefault() 00245 ); 00246 } 00247 00251 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2) 00252 { 00253 return !( e1 == e2 ); 00254 } 00255 00259 inline std::ostream& operator<<(std::ostream& os, const ParameterEntry& e) 00260 { 00261 return e.leftshift(os); 00262 } 00263 00264 // /////////////////////////////////////////// 00265 // Inline and Template Function Definitions 00266 00267 // Constructor/Destructor 00268 00269 template<typename T> 00270 inline 00271 ParameterEntry::ParameterEntry( 00272 T value_in, 00273 bool isDefault_in, 00274 bool /*isList_in*/, // 2007/11/26: rabartl: ToDo: This arg is ignored and should be removed! 00275 const std::string &docString_in, 00276 RCP<const ParameterEntryValidator> const& validator_in 00277 ) 00278 : val_(value_in), 00279 isUsed_(false), 00280 isDefault_(isDefault_in), 00281 docString_(docString_in), 00282 validator_(validator_in) 00283 {} 00284 00285 inline 00286 ParameterEntry::~ParameterEntry() 00287 {} 00288 00289 // Set Methods 00290 00291 template<typename T> 00292 inline 00293 void ParameterEntry::setValue( 00294 T value_in, bool isDefault_in, const std::string &docString_in, 00295 RCP<const ParameterEntryValidator> const& validator_in 00296 ) 00297 { 00298 val_ = value_in; 00299 isDefault_ = isDefault_in; 00300 if(docString_in.length()) 00301 docString_ = docString_in; 00302 if(validator_in.get()) 00303 validator_ = validator_in; 00304 } 00305 00306 // Get Methods 00307 00308 template<typename T> 00309 inline 00310 T& ParameterEntry::getValue(T * /*ptr*/) const 00311 { 00312 isUsed_ = true; 00313 return const_cast<T&>(Teuchos::any_cast<T>( val_ )); 00314 } 00315 00316 inline 00317 any& ParameterEntry::getAny(bool activeQry) 00318 { 00319 if (activeQry == true) { 00320 isUsed_ = true; 00321 } 00322 return val_; 00323 } 00324 00325 inline 00326 const any& ParameterEntry::getAny(bool activeQry) const 00327 { 00328 if (activeQry == true) { 00329 isUsed_ = true; 00330 } 00331 return val_; 00332 } 00333 00334 // Attribute Methods 00335 00336 inline 00337 bool ParameterEntry::isUsed() const 00338 { return isUsed_; } 00339 00340 template <typename T> 00341 inline 00342 bool ParameterEntry::isType() const 00343 { return val_.type() == typeid(T); } 00344 00345 inline 00346 bool ParameterEntry::isDefault() const 00347 { return isDefault_; } 00348 00349 inline 00350 std::string ParameterEntry::docString() const 00351 { return docString_; } 00352 00353 inline 00354 RCP<const ParameterEntryValidator> 00355 ParameterEntry::validator() const 00356 { return validator_; } 00357 00358 } // namespace Teuchos 00359 00360 #endif
1.7.4