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 
00062   Object(int tracebackModeIn = -1);
00063 
00065 
00067   Object(const char* label, int tracebackModeIn = -1);
00068 
00070 
00072   Object(const Object& obj);
00073 
00075 
00077   virtual ~Object();
00078 
00080   
00082 
00084 
00086   virtual void setLabel(const char* label);
00087 
00089 
00101   static void setTracebackMode(int tracebackModeValue);
00102 
00104 
00106 
00108 
00110   virtual char* label() const;  
00111 
00113   static int getTracebackMode();
00114 
00116 
00118 
00120   virtual void print(ostream& os) const;
00122 
00124 
00126   virtual int reportError(const string message, int errorCode) const 
00127   {
00128   // NOTE:  We are extracting a C-style string from Message because 
00129   //        the SGI compiler does not have a real string class with 
00130   //        the << operator.  Some day we should get rid of ".c_str()"
00131   if ( (tracebackMode==1) && (errorCode < 0) )
00132   {  // Report fatal error
00133      cerr << endl << "Error in Teuchos Object with label: " << label_ << endl 
00134      << "Teuchos Error:  " << message.c_str() << "  Error Code:  " << errorCode << endl;
00135      return(errorCode);
00136         }
00137   if ( (tracebackMode==2) && (errorCode != 0 ) ) 
00138   {
00139      cerr << endl << "Error in Teuchos Object with label: " << label_ << endl 
00140      << "Teuchos Error:  " << message.c_str() << "  Error Code:  " << errorCode << endl;
00141      return(errorCode);
00142   }
00143   return(errorCode);
00144   }
00145 
00147 
00148   static int tracebackMode;  
00149 
00150  protected:
00151 
00152  private:
00153 
00154   char* label_;
00155 
00156 }; // class Object
00157 
00161 inline ostream& operator<<(ostream& os, const Teuchos::Object& Obj)
00162 {
00163   os << Obj.label() << endl;
00164   Obj.print(os);
00165  
00166   return os;
00167 }
00168 
00169 } // namespace Teuchos
00170 
00171 // #include "Teuchos_Object.cpp"
00172 
00173 
00174 #endif /* _TEUCHOS_OBJECT_HPP_ */

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