|
Teuchos - Trilinos Tools Package
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 00043 #ifndef TEUCHOS_PARAMETER_ENTRY_H 00044 #define TEUCHOS_PARAMETER_ENTRY_H 00045 00050 #include "Teuchos_ConfigDefs.hpp" 00051 #include "Teuchos_any.hpp" 00052 #include "Teuchos_RCP.hpp" 00053 #include "Teuchos_ParameterEntryValidator.hpp" 00054 00055 namespace Teuchos { 00056 00057 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00058 class ParameterList; // another parameter type (forward declaration) 00059 #endif 00060 00067 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT ParameterEntry { 00068 00069 public: 00070 00073 00075 typedef unsigned int ParameterEntryID; 00076 00078 00080 00081 00083 ParameterEntry(); 00084 00086 ParameterEntry(const ParameterEntry& source); 00087 00089 template<typename T> 00090 explicit ParameterEntry( 00091 T value, bool isDefault = false, bool isList = false, 00092 const std::string &docString = "", 00093 RCP<const ParameterEntryValidator> const& validator = null 00094 ); 00095 00097 00099 00100 00102 ParameterEntry& operator=(const ParameterEntry& source); 00103 00111 template<typename T> 00112 void setValue( 00113 T value, bool isDefault = false, 00114 const std::string &docString = "", 00115 RCP<const ParameterEntryValidator> const& validator = null 00116 ); 00117 00124 void setAnyValue( 00125 const any &value, bool isDefault = false 00126 ); 00127 00129 void setValidator( 00130 RCP<const ParameterEntryValidator> const& validator 00131 ); 00132 00134 void setDocString(const std::string &docString); 00135 00137 ParameterList& setList( 00138 bool isDefault = false, 00139 const std::string &docString = "" 00140 ); 00141 00143 00145 00146 00152 template<typename T> 00153 inline 00154 T& getValue(T *ptr) const; 00155 00160 inline 00161 any& getAny(bool activeQry = true); 00162 00167 inline 00168 const any& getAny(bool activeQry = true) const; 00169 00171 00173 00174 00176 inline 00177 bool isUsed() const; 00178 00180 bool isList() const; 00181 00183 template <typename T> 00184 inline 00185 bool isType() const; 00186 00188 bool isArray() const; 00189 // 00191 bool isTwoDArray() const; 00192 00194 inline 00195 bool isDefault() const; 00196 00198 inline 00199 std::string docString() const; 00200 00202 inline 00203 RCP<const ParameterEntryValidator> validator() const; 00204 00206 00208 00209 00215 std::ostream& leftshift(std::ostream& os, bool printFlags = true) const; 00216 00220 static const std::string& getTagName(){ 00221 static const std::string tagName = "Parameter"; 00222 return tagName; 00223 } 00224 00226 00227 private: 00228 00230 void reset(); 00231 00233 any val_; 00234 00236 mutable bool isUsed_; 00237 00239 mutable bool isDefault_; 00240 00242 std::string docString_; 00243 00245 //use pragmas to disable some false positive warnings for windows sharedlib export 00246 #ifdef _MSC_VER 00247 #pragma warning(push) 00248 #pragma warning(disable:4251) 00249 #endif 00250 RCP<const ParameterEntryValidator> validator_; 00251 #ifdef _MSC_VER 00252 #pragma warning(pop) 00253 #endif 00254 00255 }; 00256 00262 template<typename T> 00263 inline T& getValue( const ParameterEntry &entry ) 00264 { 00265 return entry.getValue(static_cast<T*>(0)); 00266 } 00267 00273 template<typename T> 00274 inline T& getValue(RCP<const ParameterEntry> entry) 00275 { 00276 return entry->getValue(static_cast<T*>(0)); 00277 } 00278 00282 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2) 00283 { 00284 return ( 00285 e1.getAny() == e2.getAny() 00286 && e1.isList()== e2.isList() 00287 && e1.isUsed() == e2.isUsed() 00288 && e1.isDefault() == e2.isDefault() 00289 ); 00290 } 00291 00295 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2) 00296 { 00297 return !( e1 == e2 ); 00298 } 00299 00303 inline std::ostream& operator<<(std::ostream& os, const ParameterEntry& e) 00304 { 00305 return e.leftshift(os); 00306 } 00307 00308 // /////////////////////////////////////////// 00309 // Inline and Template Function Definitions 00310 00311 // Constructor/Destructor 00312 00313 template<typename T> 00314 inline 00315 ParameterEntry::ParameterEntry( 00316 T value_in, 00317 bool isDefault_in, 00318 bool /*isList_in*/, // 2007/11/26: rabartl: ToDo: This arg is ignored and should be removed! 00319 const std::string &docString_in, 00320 RCP<const ParameterEntryValidator> const& validator_in 00321 ) 00322 : val_(value_in), 00323 isUsed_(false), 00324 isDefault_(isDefault_in), 00325 docString_(docString_in), 00326 validator_(validator_in) 00327 {} 00328 00329 // Set Methods 00330 00331 template<typename T> 00332 inline 00333 void ParameterEntry::setValue( 00334 T value_in, bool isDefault_in, const std::string &docString_in, 00335 RCP<const ParameterEntryValidator> const& validator_in 00336 ) 00337 { 00338 val_ = value_in; 00339 isDefault_ = isDefault_in; 00340 if(docString_in.length()) 00341 docString_ = docString_in; 00342 if(validator_in.get()) 00343 validator_ = validator_in; 00344 } 00345 00346 // Get Methods 00347 00348 template<typename T> 00349 inline 00350 T& ParameterEntry::getValue(T * /*ptr*/) const 00351 { 00352 isUsed_ = true; 00353 return const_cast<T&>(Teuchos::any_cast<T>( val_ )); 00354 } 00355 00356 inline 00357 any& ParameterEntry::getAny(bool activeQry) 00358 { 00359 if (activeQry == true) { 00360 isUsed_ = true; 00361 } 00362 return val_; 00363 } 00364 00365 inline 00366 const any& ParameterEntry::getAny(bool activeQry) const 00367 { 00368 if (activeQry == true) { 00369 isUsed_ = true; 00370 } 00371 return val_; 00372 } 00373 00374 // Attribute Methods 00375 00376 inline 00377 bool ParameterEntry::isUsed() const 00378 { return isUsed_; } 00379 00380 template <typename T> 00381 inline 00382 bool ParameterEntry::isType() const 00383 { return val_.type() == typeid(T); } 00384 00385 inline 00386 bool ParameterEntry::isDefault() const 00387 { return isDefault_; } 00388 00389 inline 00390 std::string ParameterEntry::docString() const 00391 { return docString_; } 00392 00393 inline 00394 RCP<const ParameterEntryValidator> 00395 ParameterEntry::validator() const 00396 { return validator_; } 00397 00398 00399 } // namespace Teuchos 00400 00401 00402 #endif
1.7.6.1