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 
00040 namespace Teuchos {
00041 
00042 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00043 class ParameterList; // another parameter type (forward declaration)
00044 #endif
00045 
00052 class ParameterEntry {
00053 public:
00054 
00056 
00057 
00059   ParameterEntry();
00060   
00062   ParameterEntry(const ParameterEntry& source);
00063 
00065   template<typename T>
00066   explicit ParameterEntry(T value, bool isDefault = false, bool isList = false);
00067 
00069   ~ParameterEntry();
00070 
00072 
00074 
00075 
00077   ParameterEntry& operator=(const ParameterEntry& source);
00078 
00086   template<typename T>
00087   void setValue(T value, bool isDefault = false);
00088 
00090   ParameterList& setList(bool isDefault = false);
00091 
00093 
00095 
00096    
00102   template<typename T>
00103   T& getValue(T *ptr) const;
00104 
00109   any& getAny(bool activeQry = true);
00110 
00115   const any& getAny(bool activeQry = true) const;
00116 
00118 
00120 
00121   
00123   bool isUsed() const;
00124 
00126   bool isList() const;
00127 
00129   template <typename T>
00130   bool isType() const;
00131 
00133   bool isDefault() const;
00134 
00136 
00138 
00145   ostream& leftshift(ostream& os, bool printFlags = true) const;
00146 
00148 
00149 private:
00150 
00152   void reset();
00153   
00155   any val_;
00156 
00158   bool isList_;
00159 
00161   mutable bool isUsed_;
00162 
00164   mutable bool isDefault_;
00165 
00166 };
00167 
00173 template<typename T>
00174 inline T& getValue( const ParameterEntry &entry )
00175 {
00176   return entry.getValue((T*)NULL);
00177 }
00178 
00182 inline bool operator==(const ParameterEntry& e1, const ParameterEntry& e2) 
00183 { 
00184   return (
00185     e1.getAny() == e2.getAny()
00186     && e1.isList()== e2.isList()
00187     && e1.isUsed() == e2.isUsed()
00188     && e1.isDefault() == e2.isDefault()
00189     );
00190 }
00191 
00195 inline bool operator!=(const ParameterEntry& e1, const ParameterEntry& e2) 
00196 { 
00197   return !( e1 == e2 );
00198 }
00199 
00203 inline ostream& operator<<(ostream& os, const ParameterEntry& e) 
00204 { 
00205   return e.leftshift(os);
00206 }
00207 
00208 // ///////////////////////////////////////////
00209 // Inline and Template Function Definitions
00210 
00211 // Constructor/Destructor
00212 
00213 template<typename T>
00214 inline
00215 ParameterEntry::ParameterEntry(T value, bool isDefault, bool isList)
00216   : val_(value),
00217     isList_(isList),
00218     isUsed_(false),
00219     isDefault_(isDefault)
00220 {}
00221 
00222 inline
00223 ParameterEntry::~ParameterEntry()
00224 {}
00225 
00226 // Set Methods
00227 
00228 template<typename T>
00229 inline
00230 void ParameterEntry::setValue(T value, bool isDefault)
00231 {
00232   val_ = value;
00233   isDefault_ = isDefault;
00234 }
00235 
00236 // Get Methods
00237 
00238 template<typename T>
00239 inline
00240 T& ParameterEntry::getValue(T *ptr) const
00241 {
00242   isUsed_ = true;
00243   return const_cast<T&>(Teuchos::any_cast<T>( val_ ));
00244 }
00245 
00246 inline
00247 any& ParameterEntry::getAny(bool activeQry)
00248 { 
00249   if (activeQry == true) {
00250     isUsed_ = true;
00251   }
00252   return val_; 
00253 }
00254 
00255 inline
00256 const any& ParameterEntry::getAny(bool activeQry) const
00257 { 
00258   if (activeQry == true) {
00259     isUsed_ = true;
00260   }
00261   return val_; 
00262 }
00263 
00264 // Attribute Methods
00265 
00266 inline
00267 bool ParameterEntry::isUsed() const
00268 { return isUsed_; }
00269 
00270 inline
00271 bool ParameterEntry::isList() const
00272 { return isList_; }
00273 
00274 template <typename T>
00275 inline
00276 bool ParameterEntry::isType() const
00277 { return val_.type() == typeid(T); }
00278 
00279 inline
00280 bool ParameterEntry::isDefault() const
00281 { return isDefault_; }
00282 
00283 } // namespace Teuchos
00284 
00285 #endif

Generated on Thu Sep 18 12:30:30 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1