Teuchos_VerboseObject.cpp

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 namespace Teuchos {
00033 
00034 // Private static data members
00035 
00036 RefCountPtr<FancyOStream>& VerboseObjectBase::privateDefaultOStream()
00037 {
00038   static RefCountPtr<FancyOStream> defaultOStream;
00039   if(defaultOStream.get()==NULL) {
00040     defaultOStream = rcp(new FancyOStream(rcp(&std::cout,false)));
00041     defaultOStream->setOutputToRootOnly(0);
00042 //    if(GlobalMPISession::getNProc()>1)
00043 //      defaultOStream->setShowProcRank(true);
00044   }
00045   return defaultOStream;
00046 }
00047 
00048 // Public static member functions
00049 
00050 void VerboseObjectBase::setDefaultOStream( const RefCountPtr<FancyOStream> &defaultOStream )
00051 {
00052   privateDefaultOStream() = defaultOStream;
00053 }
00054 
00055 RefCountPtr<FancyOStream>
00056 VerboseObjectBase::getDefaultOStream()
00057 {
00058   return privateDefaultOStream();
00059 }
00060 
00061 // Constructors/Initializers
00062 
00063 VerboseObjectBase::VerboseObjectBase(
00064   const RefCountPtr<FancyOStream>   &oStream
00065   )
00066 {
00067   this->initializeVerboseObjectBase(oStream);
00068 }
00069 
00070 void VerboseObjectBase::initializeVerboseObjectBase(
00071   const RefCountPtr<FancyOStream>   &oStream
00072   )
00073 {
00074   thisOStream_ = oStream;
00075 }
00076 
00077 const VerboseObjectBase& VerboseObjectBase::setOStream(const RefCountPtr<FancyOStream> &oStream) const
00078 {
00079   thisOStream_ = oStream;
00080   return *this;
00081 }
00082 
00083 VerboseObjectBase& VerboseObjectBase::setLinePrefix(const std::string &linePrefix)
00084 {
00085   thisLinePrefix_ = linePrefix;
00086   return *this;
00087 }
00088 
00089 // Query functions
00090 
00091 RefCountPtr<FancyOStream>
00092 VerboseObjectBase::getOStream() const
00093 {
00094   if(!thisOStream_.get())
00095     return getDefaultOStream();
00096   return thisOStream_;
00097 }
00098 
00099 std::string VerboseObjectBase::getLinePrefix() const
00100 {
00101   return thisLinePrefix_;
00102 }
00103 
00104 // Utility functions
00105 
00106 OSTab VerboseObjectBase::getOSTab(const int tabs,const std::string &linePrefix) const
00107 {
00108   return OSTab( this->getOStream(), tabs, linePrefix.length() ? linePrefix : this->getLinePrefix() );
00109 }
00110 
00111 } // namespace Teuchos

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