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 
00048 namespace Teuchos {
00049 
00050 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00051 class ParameterList; // another parameter type (forward declaration)
00052 #endif
00053 
00054 class ParameterEntry {
00055 
00056 public:
00058 
00060   ParameterEntry();
00061   
00063   ParameterEntry(const ParameterEntry& source);
00064 
00066   template<typename T>
00067   explicit ParameterEntry(T value, bool isDefault = false)
00068   : val_(value),
00069     isUsed_(false),
00070     isDefault_(isDefault)
00071   {}
00072 
00074   ~ParameterEntry() {};
00075 
00077 
00079 
00081   ParameterEntry& operator=(const ParameterEntry& source);
00082 
00090   template<typename T>
00091   void setValue(T value, bool isDefault = false)
00092   {
00093     val_ = value;
00094     isDefault_ = isDefault;
00095   }
00096 
00098   ParameterList& setList(bool isDefault = false);
00099 
00101 
00103    
00109   template<typename T>
00110   T& getValue(T *ptr) const
00111   {
00112     isUsed_ = true;
00113     return const_cast<T&>(Teuchos::any_cast<T>( val_ ));
00114   }
00115 
00121   const any& getAny() const 
00122   {
00123     return val_;
00124   }
00126 
00128   
00130   bool isUsed() const { return isUsed_; }
00131 
00133   bool isList() const { return isList_; }
00134 
00142   template <typename T> 
00143   bool isType() const 
00144   {
00145     return val_.type() == typeid(T);
00146   }
00147 
00149   bool isDefault() const {return isDefault_;}
00151 
00153 
00160   ostream& leftshift(ostream& os) const;
00162 
00163 private:
00164 
00166   void reset();
00167   
00169   any val_;
00170 
00172   bool isList_;
00173 
00175   mutable bool isUsed_;
00176 
00178   mutable bool isDefault_;
00179 
00180 };
00181 
00187 template<typename T>
00188 T& getValue( const ParameterEntry &entry )
00189 {
00190   return entry.getValue((T*)NULL);
00191 }
00192 
00196 inline ostream& operator<<(ostream& os, const ParameterEntry& e) 
00197 { 
00198   return e.leftshift(os);
00199 }
00200 
00201 } // namespace Teuchos
00202 
00203 
00204 #endif

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