Teuchos_Object.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 // Kris
00030 // 07.08.03 -- Move into Teuchos package/namespace
00031 
00032 #ifndef _TEUCHOS_OBJECT_HPP_
00033 #define _TEUCHOS_OBJECT_HPP_
00034 
00039 #include "Teuchos_ConfigDefs.hpp"
00040 #include "Teuchos_DataAccess.hpp"
00041 
00050 namespace Teuchos
00051 {
00052 
00053 class Object
00054 {
00055   public:
00057 
00058 
00059 
00063   Object(int tracebackModeIn = -1);
00064 
00066 
00068   Object(const char* label, int tracebackModeIn = -1);
00069 
00071 
00073   Object(const Object& obj);
00074 
00076 
00078   virtual ~Object();
00079 
00081   
00083 
00084 
00086 
00088   virtual void setLabel(const char* label);
00089 
00091 
00103   static void setTracebackMode(int tracebackModeValue);
00104 
00106 
00108 
00109 
00111 
00113   virtual char* label() const;  
00114 
00116   static int getTracebackMode();
00117 
00119 
00121 
00122 
00124   virtual void print(ostream& os) const;
00126 
00128 
00129 
00131   virtual int reportError(const string message, int errorCode) const 
00132   {
00133   // NOTE:  We are extracting a C-style string from Message because 
00134   //        the SGI compiler does not have a real string class with 
00135   //        the << operator.  Some day we should get rid of ".c_str()"
00136   if ( (tracebackMode==1) && (errorCode < 0) )
00137   {  // Report fatal error
00138      cerr << endl << "Error in Teuchos Object with label: " << label_ << endl 
00139      << "Teuchos Error:  " << message.c_str() << "  Error Code:  " << errorCode << endl;
00140      return(errorCode);
00141         }
00142   if ( (tracebackMode==2) && (errorCode != 0 ) ) 
00143   {
00144      cerr << endl << "Error in Teuchos Object with label: " << label_ << endl 
00145      << "Teuchos Error:  " << message.c_str() << "  Error Code:  " << errorCode << endl;
00146      return(errorCode);
00147   }
00148   return(errorCode);
00149   }
00150 
00152 
00153   static int tracebackMode;  
00154 
00155  protected:
00156 
00157  private:
00158 
00159   char* label_;
00160 
00161 }; // class Object
00162 
00166 inline ostream& operator<<(ostream& os, const Teuchos::Object& Obj)
00167 {
00168   os << Obj.label() << endl;
00169   Obj.print(os);
00170  
00171   return os;
00172 }
00173 
00174 } // namespace Teuchos
00175 
00176 // #include "Teuchos_Object.cpp"
00177 
00178 
00179 #endif /* _TEUCHOS_OBJECT_HPP_ */

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