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// USA 00023 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00024 // 00025 // *********************************************************************** 00026 // @HEADER 00027 00028 #ifndef TEUCHOS_DESCRIBABLE_HPP 00029 #define TEUCHOS_DESCRIBABLE_HPP 00030 00031 #include "Teuchos_VerbosityLevel.hpp" 00032 #include "Teuchos_FancyOStream.hpp" 00033 #include "Teuchos_LabeledObject.hpp" 00034 00035 00036 namespace Teuchos { 00037 00038 00067 class Describable : virtual public LabeledObject { 00068 public: 00069 00071 static const EVerbosityLevel verbLevel_default; 00072 00074 00075 00086 virtual std::string description() const; 00087 00123 virtual void describe( 00124 FancyOStream &out, 00125 const EVerbosityLevel verbLevel = verbLevel_default 00126 ) const; 00127 00128 }; 00129 00130 00131 // Describable stream manipulator state class 00132 // 00133 // This is not a class that a user needs to see and that is why it is not 00134 // being given doxygen documentation! 00135 struct DescribableStreamManipulatorState { 00136 const Describable &describable; 00137 const EVerbosityLevel verbLevel; 00138 DescribableStreamManipulatorState( 00139 const Describable &_describable, 00140 const EVerbosityLevel _verbLevel = VERB_MEDIUM 00141 ) 00142 :describable(_describable) 00143 ,verbLevel(_verbLevel) 00144 {} 00145 }; 00146 00147 00169 inline DescribableStreamManipulatorState describe( 00170 const Describable &describable, 00171 const EVerbosityLevel verbLevel = Describable::verbLevel_default 00172 ) 00173 { 00174 return DescribableStreamManipulatorState(describable,verbLevel); 00175 } 00176 00177 00204 inline 00205 std::ostream& operator<<( 00206 std::ostream& os, const DescribableStreamManipulatorState& d 00207 ) 00208 { 00209 d.describable.describe(*getFancyOStream(Teuchos::rcp(&os,false)),d.verbLevel); 00210 return os; 00211 } 00212 00213 // 00214 // RAB: Note: The above function works with an std::ostream object even 00215 // through Describable::describe(...) requires a FancyOStream object. We must 00216 // write the stream manipulator in terms of std::ostream, or compound output 00217 // statements like: 00218 // 00219 // void foo( FancyOStream &out, Describable &d, EVerbLevel verbLevel ) 00220 // { 00221 // out << "\nThis is the describable object d:" << describe(d,verbLevel); 00222 // } 00223 // 00224 // will not work correctly. The problem is that the first output 00225 // 00226 // out << "\nThis is the describable object d:" 00227 // 00228 // must return a reference to an std::ostream object. This should mean that 00229 // the next statement, which is basically: 00230 // 00231 // static_cast<std::ostream&>(out) << DescribableStreamManipulatorState 00232 // 00233 // should not even compile. However, under gcc 3.4.3, the code did compile 00234 // but did not call the above function. Instead, it set up some type of 00235 // infinite recursion that resulted in a segfault due to the presence of the 00236 // Teuchos::any class! 00237 // 00238 00239 00240 } // namespace Teuchos 00241 00242 #endif // TEUCHOS_DESCRIBABLE_HPP