Epetra_Object.h

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 /*
00004 ************************************************************************
00005 
00006               Epetra: Linear Algebra Services Package 
00007                 Copyright (2001) Sandia Corporation
00008 
00009 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 license for use of this work by or on behalf of the U.S. Government.
00011 
00012 This library is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation; either version 2.1 of the
00015 License, or (at your option) any later version.
00016  
00017 This library is distributed in the hope that it will be useful, but
00018 WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021  
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 USA
00026 Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00027 
00028 ************************************************************************
00029 */
00030 //@HEADER
00031 
00032 #ifndef EPETRA_OBJECT_H
00033 #define EPETRA_OBJECT_H
00034 
00035 #include "Epetra_CombineMode.h"
00036 #include "Epetra_DataAccess.h"
00037 #include "Epetra_ConfigDefs.h"
00038 
00040 
00045 class Epetra_Object {
00046     
00047   public:
00049 
00050 
00051 
00055   Epetra_Object(int TracebackModeIn = -1, bool set_label = true);
00056 
00058 
00060   Epetra_Object(const char * const Label, int TracebackModeIn = -1);
00061 
00063 
00065   Epetra_Object(const Epetra_Object& Object);
00066 
00068 
00070   virtual ~Epetra_Object();
00072   
00074 
00075 
00077 
00079   virtual void SetLabel(const char * const Label);
00080 
00082 
00084   virtual const char * Label() const;
00085 
00087 
00099   static void SetTracebackMode(int TracebackModeValue);
00100 
00102   static int GetTracebackMode();
00103 
00105   static std::ostream& GetTracebackStream();
00106 
00108 
00110 
00111 
00114   virtual void Print(ostream & os) const;
00115 
00117   virtual int ReportError(const string Message, int ErrorCode) const;
00119 
00120   
00121 // TracebackMode controls how much traceback information is printed when run time 
00122 // integer errors are detected:
00123 // = 0 - No information report
00124 // = 1 - Fatal (negative) values are reported
00125 // = 2 - All values (except zero) reported.
00126 
00127 // Default is set to 1.  Can be set to different value using SetTracebackMode() method in
00128 // Epetra_Object class
00129   static int TracebackMode;
00130 
00131 
00132  protected:
00133   string toString(const int& x) const {
00134      char s[100];
00135      sprintf(s, "%d", x);
00136      return string(s);
00137 }
00138 
00139   string toString(const double& x) const {
00140      char s[100];
00141      sprintf(s, "%g", x);
00142      return string(s);
00143 }
00144   
00145 
00146  private:
00147   Epetra_Object& operator=(const Epetra_Object& src) {
00148     SetLabel(src.Label());
00149     return *this;
00150   }
00151 
00152   char * Label_;
00153 
00154 };
00155 
00156 inline ostream& operator<<(ostream& os, const Epetra_Object& obj)
00157 {
00158   if (Epetra_FormatStdout) {
00159 /*    const Epetra_fmtflags  olda = os.setf(ios::right,ios::adjustfield);
00160     const Epetra_fmtflags  oldf = os.setf(ios::scientific,ios::floatfield);
00161     const int              oldp = os.precision(12); */
00162 
00163     os << obj.Label() << endl;
00164     obj.Print(os);
00165 
00166 /*    os.setf(olda,ios::adjustfield);
00167     os.setf(oldf,ios::floatfield);
00168     os.precision(oldp); */
00169   }
00170   else {
00171 
00172     os << obj.Label();
00173     obj.Print(os);
00174   }
00175   
00176   return os;
00177 }
00178 
00184 #define EPETRA_TEST_FOR_EXCEPTION(throw_exception_test,errCode,msg) \
00185 { \
00186     const bool throw_exception = (throw_exception_test); \
00187     if(throw_exception) { \
00188         std::ostringstream omsg; \
00189       omsg \
00190         << __FILE__ << ":" << __LINE__ << ":" \
00191         << " Throw test that evaluated to true: "#throw_exception_test << ":" \
00192         << "Error message : " << msg; \
00193       throw ReportError(omsg.str(),errCode); \
00194     } \
00195 }
00196 
00197 #endif /* EPETRA_OBJECT_H */

Generated on Wed May 12 21:41:05 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7