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 #include "Teuchos_VerboseObject.hpp" 00030 #include "Teuchos_GlobalMPISession.hpp" 00031 00032 00033 namespace Teuchos { 00034 00035 00036 // Private static data members 00037 00038 00039 RCP<FancyOStream>& VerboseObjectBase::privateDefaultOStream() 00040 { 00041 static RCP<FancyOStream> defaultOStream; 00042 if(defaultOStream.get()==NULL) { 00043 defaultOStream = rcp(new FancyOStream(rcp(&std::cout,false))); 00044 defaultOStream->setOutputToRootOnly(0); 00045 // if(GlobalMPISession::getNProc()>1) 00046 // defaultOStream->setShowProcRank(true); 00047 } 00048 return defaultOStream; 00049 } 00050 00051 00052 // Public static member functions 00053 00054 00055 void VerboseObjectBase::setDefaultOStream( 00056 const RCP<FancyOStream> &defaultOStream 00057 ) 00058 { 00059 privateDefaultOStream() = defaultOStream; 00060 } 00061 00062 00063 RCP<FancyOStream> 00064 VerboseObjectBase::getDefaultOStream() 00065 { 00066 return privateDefaultOStream(); 00067 } 00068 00069 00070 // Constructors/Initializers 00071 00072 00073 VerboseObjectBase::VerboseObjectBase( 00074 const RCP<FancyOStream> &oStream 00075 ) 00076 : thisOverridingOStream_(null) 00077 { 00078 this->initializeVerboseObjectBase(oStream); 00079 } 00080 00081 00082 void VerboseObjectBase::initializeVerboseObjectBase( 00083 const RCP<FancyOStream> &oStream 00084 ) 00085 { 00086 thisOStream_ = oStream; 00087 informUpdatedVerbosityState(); 00088 } 00089 00090 00091 const VerboseObjectBase& 00092 VerboseObjectBase::setOStream(const RCP<FancyOStream> &oStream) const 00093 { 00094 thisOStream_ = oStream; 00095 informUpdatedVerbosityState(); 00096 return *this; 00097 } 00098 00099 00100 const VerboseObjectBase& 00101 VerboseObjectBase::setOverridingOStream( 00102 const RCP<FancyOStream> &oStream 00103 ) const 00104 { 00105 thisOverridingOStream_ = oStream; 00106 informUpdatedVerbosityState(); 00107 return *this; 00108 } 00109 00110 00111 VerboseObjectBase& 00112 VerboseObjectBase::setLinePrefix(const std::string &linePrefix) 00113 { 00114 thisLinePrefix_ = linePrefix; 00115 informUpdatedVerbosityState(); 00116 return *this; 00117 } 00118 00119 00120 // Query functions 00121 00122 00123 RCP<FancyOStream> 00124 VerboseObjectBase::getOStream() const 00125 { 00126 if(!is_null(thisOverridingOStream_)) 00127 return thisOverridingOStream_; 00128 if(is_null(thisOStream_)) 00129 return getDefaultOStream(); 00130 return thisOStream_; 00131 } 00132 00133 00134 RCP<FancyOStream> 00135 VerboseObjectBase::getOverridingOStream() const 00136 { 00137 return thisOverridingOStream_; 00138 } 00139 00140 00141 std::string VerboseObjectBase::getLinePrefix() const 00142 { 00143 return thisLinePrefix_; 00144 } 00145 00146 00147 // Utility functions 00148 00149 00150 OSTab VerboseObjectBase::getOSTab( 00151 const int tabs,const std::string &linePrefix 00152 ) const 00153 { 00154 return OSTab( 00155 this->getOStream(), tabs, linePrefix.length() 00156 ? linePrefix : this->getLinePrefix() 00157 ); 00158 } 00159 00160 00161 // protected 00162 00163 00164 void VerboseObjectBase::informUpdatedVerbosityState() const 00165 {} 00166 00167 00168 } // namespace Teuchos