Epetra Package Browser (Single Doxygen Collection) Development
Epetra_Object.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_OBJECT_H
00045 #define EPETRA_OBJECT_H
00046 
00047 #include "Epetra_CombineMode.h"
00048 #include "Epetra_DataAccess.h"
00049 #include "Epetra_ConfigDefs.h"
00050 
00052 
00057 class EPETRA_LIB_DLL_EXPORT Epetra_Object {
00058     
00059   public:
00061 
00062 
00063 
00067   Epetra_Object(int TracebackModeIn = -1, bool set_label = true);
00068 
00070 
00072   Epetra_Object(const char * const Label, int TracebackModeIn = -1);
00073 
00075 
00077   Epetra_Object(const Epetra_Object& Object);
00078 
00080 
00082   virtual ~Epetra_Object();
00084   
00086 
00087 
00089 
00091   virtual void SetLabel(const char * const Label);
00092 
00094 
00096   virtual const char * Label() const;
00097 
00099 
00111   static void SetTracebackMode(int TracebackModeValue);
00112 
00114   static int GetTracebackMode();
00115 
00117   static std::ostream& GetTracebackStream();
00118 
00120 
00122 
00123 
00126   virtual void Print(ostream & os) const;
00127 
00129   virtual int ReportError(const string Message, int ErrorCode) const;
00131 
00132   
00133 // TracebackMode controls how much traceback information is printed when run time 
00134 // integer errors are detected:
00135 // = 0 - No information report
00136 // = 1 - Fatal (negative) values are reported
00137 // = 2 - All values (except zero) reported.
00138 
00139 // Default is set to 1.  Can be set to different value using SetTracebackMode() method in
00140 // Epetra_Object class
00141   static int TracebackMode;
00142 
00143 
00144  protected:
00145   string toString(const int& x) const {
00146      char s[100];
00147      sprintf(s, "%d", x);
00148      return string(s);
00149 }
00150 
00151   string toString(const double& x) const {
00152      char s[100];
00153      sprintf(s, "%g", x);
00154      return string(s);
00155 }
00156   
00157 
00158  private:
00159   Epetra_Object& operator=(const Epetra_Object& src) {
00160     SetLabel(src.Label());
00161     return *this;
00162   }
00163 
00164   char * Label_;
00165 
00166 };
00167 
00168 inline ostream& operator<<(ostream& os, const Epetra_Object& obj)
00169 {
00170   if (Epetra_FormatStdout) {
00171 /*    const Epetra_fmtflags  olda = os.setf(ios::right,ios::adjustfield);
00172     const Epetra_fmtflags  oldf = os.setf(ios::scientific,ios::floatfield);
00173     const int              oldp = os.precision(12); */
00174 
00175     os << obj.Label() << endl;
00176     obj.Print(os);
00177 
00178 /*    os.setf(olda,ios::adjustfield);
00179     os.setf(oldf,ios::floatfield);
00180     os.precision(oldp); */
00181   }
00182   else {
00183 
00184     os << obj.Label();
00185     obj.Print(os);
00186   }
00187   
00188   return os;
00189 }
00190 
00196 #define EPETRA_TEST_FOR_EXCEPTION(throw_exception_test,errCode,msg) \
00197 { \
00198     const bool throw_exception = (throw_exception_test); \
00199     if(throw_exception) { \
00200         std::ostringstream omsg; \
00201       omsg \
00202         << __FILE__ << ":" << __LINE__ << ":" \
00203         << " Throw test that evaluated to true: "#throw_exception_test << ":" \
00204         << "Error message : " << msg; \
00205       throw ReportError(omsg.str(),errCode); \
00206     } \
00207 }
00208 
00209 #endif /* EPETRA_OBJECT_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines