Teuchos_ParameterEntry.hpp

Go to the documentation of this file.
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 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   RCP<const ParameterEntryValidator> validator_;
00213 
00214 };
00215 
00221 template<typename T>
00222 inline T& getValue( const ParameterEntry &entry )
00223 {
00224   return entry.getValue((T*)NULL);
00225 }
00226 
00230 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2) 
00231 { 
00232   return (
00233     e1.getAny() == e2.getAny()
00234     && e1.isList()== e2.isList()
00235     && e1.isUsed() == e2.isUsed()
00236     && e1.isDefault() == e2.isDefault()
00237     );
00238 }
00239 
00243 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2) 
00244 { 
00245   return !( e1 == e2 );
00246 }
00247 
00251 inline std::ostream& operator<<(std::ostream& os, const ParameterEntry& e) 
00252 { 
00253   return e.leftshift(os);
00254 }
00255 
00256 // ///////////////////////////////////////////
00257 // Inline and Template Function Definitions
00258 
00259 // Constructor/Destructor
00260 
00261 template<typename T>
00262 inline
00263 ParameterEntry::ParameterEntry(
00264   T value_in,
00265   bool isDefault_in,
00266   bool /*isList_in*/, // 2007/11/26: rabartl: ToDo: This arg is ignored and should be removed!
00267   const std::string &docString_in,
00268   RCP<const ParameterEntryValidator> const& validator_in
00269   )
00270   : val_(value_in),
00271     isUsed_(false),
00272     isDefault_(isDefault_in),
00273     docString_(docString_in),
00274     validator_(validator_in)
00275 {}
00276 
00277 inline
00278 ParameterEntry::~ParameterEntry()
00279 {}
00280 
00281 // Set Methods
00282 
00283 template<typename T>
00284 inline
00285 void ParameterEntry::setValue(
00286   T value_in, bool isDefault_in, const std::string &docString_in,
00287   RCP<const ParameterEntryValidator> const& validator_in
00288   )
00289 {
00290   val_ = value_in;
00291   isDefault_ = isDefault_in;
00292   if(docString_in.length())
00293     docString_ = docString_in;
00294   if(validator_in.get())
00295     validator_ = validator_in;
00296 }
00297 
00298 // Get Methods
00299 
00300 template<typename T>
00301 inline
00302 T& ParameterEntry::getValue(T * /*ptr*/) const
00303 {
00304   isUsed_ = true;
00305   return const_cast<T&>(Teuchos::any_cast<T>( val_ ));
00306 }
00307 
00308 inline
00309 any& ParameterEntry::getAny(bool activeQry)
00310 { 
00311   if (activeQry == true) {
00312     isUsed_ = true;
00313   }
00314   return val_; 
00315 }
00316 
00317 inline
00318 const any& ParameterEntry::getAny(bool activeQry) const
00319 { 
00320   if (activeQry == true) {
00321     isUsed_ = true;
00322   }
00323   return val_; 
00324 }
00325 
00326 // Attribute Methods
00327 
00328 inline
00329 bool ParameterEntry::isUsed() const
00330 { return isUsed_; }
00331 
00332 template <typename T>
00333 inline
00334 bool ParameterEntry::isType() const
00335 { return val_.type() == typeid(T); }
00336 
00337 inline
00338 bool ParameterEntry::isDefault() const
00339 { return isDefault_; }
00340 
00341 inline
00342 std::string ParameterEntry::docString() const
00343 { return docString_; }
00344 
00345 inline
00346 RCP<const ParameterEntryValidator>
00347 ParameterEntry::validator() const
00348 { return validator_; }
00349 
00350 } // namespace Teuchos
00351 
00352 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:14:00 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1