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 #ifndef TEUCHOS_DESCRIBABLE_HPP 00030 #define TEUCHOS_DESCRIBABLE_HPP 00031 00032 #include "Teuchos_VerbosityLevel.hpp" 00033 #include "Teuchos_FancyOStream.hpp" 00034 00035 namespace Teuchos { 00036 00062 class Describable { 00063 public: 00064 00066 static const EVerbosityLevel verbLevel_default; 00067 00069 virtual ~Describable() {} 00070 00072 00073 00083 virtual std::string description() const; 00084 00114 virtual void describe( 00115 FancyOStream &out 00116 ,const EVerbosityLevel verbLevel = verbLevel_default 00117 ) const; 00118 00119 }; 00120 00121 // Describable stream manipulator state class 00122 // 00123 // This is not a class that a user needs to see and that is why it is not 00124 // being given doxygen documentation! 00125 struct DescribableStreamManipulatorState { 00126 const Describable &describable; 00127 const EVerbosityLevel verbLevel; 00128 DescribableStreamManipulatorState( 00129 const Describable &_describable 00130 ,const EVerbosityLevel _verbLevel=VERB_MEDIUM 00131 ) 00132 :describable(_describable) 00133 ,verbLevel(_verbLevel) 00134 {} 00135 }; 00136 00156 inline DescribableStreamManipulatorState describe( 00157 const Describable &describable 00158 ,const EVerbosityLevel verbLevel = Describable::verbLevel_default 00159 ) 00160 { 00161 return DescribableStreamManipulatorState(describable,verbLevel); 00162 } 00163 00188 inline 00189 std::ostream& operator<<( std::ostream& os, const DescribableStreamManipulatorState& d ) 00190 { 00191 d.describable.describe(*getFancyOStream(Teuchos::rcp(&os,false)),d.verbLevel); 00192 return os; 00193 } 00194 00195 // 00196 // RAB: Note: The above function works with an std::ostream object even 00197 // through Describable::describe(...) requires a FancyOStream object. We must 00198 // write the stream manipulator in terms of std::ostream, or compound right 00199 // statements like: 00200 // 00201 // void foo( FancyOStream &out, Describable &d, EVerbLevel verbLevel ) 00202 // { 00203 // out << "\nThis is the describable object d:" << describe(d,verbLevel); 00204 // } 00205 // 00206 // will not work currectly. The problem is that the first output 00207 // 00208 // out << "\nThis is the describable object d:" 00209 // 00210 // must return a reference to an std::ostream object. This should mean that 00211 // the next statement, which is basically: 00212 // 00213 // static_cast<std::ostream&>(out) << DescribableStreamManipulatorState 00214 // 00215 // should not even compile. However, under gcc 3.4.3, the code did compile 00216 // but did not call the above function. Instead, it set up some type of 00217 // infinite recursion that resulted in a segfault. 00218 // 00219 00220 } // namespace Teuchos 00221 00222 #endif // TEUCHOS_DESCRIBABLE_HPP
1.3.9.1