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   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 
00117 
00119   
00121   bool isUsed() const { return isUsed_; }
00122 
00124   bool isList() const { return isList_; }
00126 
00128 
00135   ostream& leftshift(ostream& os) const;
00137 
00138 private:
00139 
00141   void reset();
00142   
00144   any val_;
00145 
00147   bool isList_;
00148 
00150   mutable bool isUsed_;
00151 
00153   mutable bool isDefault_;
00154 
00155 };
00156 
00162 template<typename T>
00163 T& getValue( const ParameterEntry &entry )
00164 {
00165   return entry.getValue((T*)NULL);
00166 }
00167 
00171 inline ostream& operator<<(ostream& os, const ParameterEntry& e) 
00172 { 
00173   return e.leftshift(os);
00174 }
00175 
00176 } // namespace Teuchos
00177 
00178 
00179 #endif

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