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(std::ostream & os) const;
00127 
00129   virtual int ReportError(const std::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   std::string toString(const int& x) const {
00146      char s[100];
00147      sprintf(s, "%d", x);
00148      return std::string(s);
00149 }
00150   std::string toString(const long long& x) const {
00151      char s[100];
00152      sprintf(s, "%lld", x);
00153      return std::string(s);
00154 }
00155 
00156   std::string toString(const double& x) const {
00157      char s[100];
00158      sprintf(s, "%g", x);
00159      return std::string(s);
00160 }
00161 
00162 
00163  private:
00164   Epetra_Object& operator=(const Epetra_Object& src) {
00165     SetLabel(src.Label());
00166     return *this;
00167   }
00168 
00169   char * Label_;
00170 
00171 };
00172 
00173 inline std::ostream& operator<<(std::ostream& os, const Epetra_Object& obj)
00174 {
00175   if (Epetra_FormatStdout) {
00176 /*    const Epetra_fmtflags  olda = os.setf(ios::right,ios::adjustfield);
00177     const Epetra_fmtflags  oldf = os.setf(ios::scientific,ios::floatfield);
00178     const int              oldp = os.precision(12); */
00179 
00180     os << obj.Label() << std::endl;
00181     obj.Print(os);
00182 
00183 /*    os.setf(olda,ios::adjustfield);
00184     os.setf(oldf,ios::floatfield);
00185     os.precision(oldp); */
00186   }
00187   else {
00188 
00189     os << obj.Label();
00190     obj.Print(os);
00191   }
00192 
00193   return os;
00194 }
00195 
00201 #define EPETRA_TEST_FOR_EXCEPTION(throw_exception_test,errCode,msg) \
00202 { \
00203     const bool throw_exception = (throw_exception_test); \
00204     if(throw_exception) { \
00205         std::ostringstream omsg; \
00206       omsg \
00207         << __FILE__ << ":" << __LINE__ << ":" \
00208         << " Throw test that evaluated to true: "#throw_exception_test << ":" \
00209         << "Error message : " << msg; \
00210       throw ReportError(omsg.str(),errCode); \
00211     } \
00212 }
00213 
00214 #endif /* EPETRA_OBJECT_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines