Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_Object.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef EPETRA_OBJECT_H
45 #define EPETRA_OBJECT_H
46 
47 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
48 #ifdef __GNUC__
49 #warning "The Epetra package is deprecated"
50 #endif
51 #endif
52 
53 
54 
55 #include "Epetra_CombineMode.h"
56 #include "Epetra_DataAccess.h"
57 #include "Epetra_ConfigDefs.h"
58 
60 
65 class EPETRA_LIB_DLL_EXPORT Epetra_Object {
66 
67  public:
69 
70 
75  Epetra_Object(int TracebackModeIn = -1, bool set_label = true);
76 
78 
80  Epetra_Object(const char * const Label, int TracebackModeIn = -1);
81 
83 
85  Epetra_Object(const Epetra_Object& Object);
86 
88 
90  virtual ~Epetra_Object();
92 
94 
95 
97 
99  virtual void SetLabel(const char * const Label);
100 
102 
104  virtual const char * Label() const;
105 
107 
119  static void SetTracebackMode(int TracebackModeValue);
120 
122  static int GetTracebackMode();
123 
125  static std::ostream& GetTracebackStream();
126 
128 
130 
131 
134  virtual void Print(std::ostream & os) const;
135 
137  virtual int ReportError(const std::string Message, int ErrorCode) const;
139 
140 
141 // TracebackMode controls how much traceback information is printed when run time
142 // integer errors are detected:
143 // = 0 - No information report
144 // = 1 - Fatal (negative) values are reported
145 // = 2 - All values (except zero) reported.
146 
147 // Default is set to 1. Can be set to different value using SetTracebackMode() method in
148 // Epetra_Object class
149  static int TracebackMode;
150 
151 
152  protected:
153  std::string toString(const int& x) const {
154  char s[100];
155  snprintf(s, sizeof(s), "%d", x);
156  return std::string(s);
157 }
158  std::string toString(const long long& x) const {
159  char s[100];
160  snprintf(s, sizeof(s), "%lld", x);
161  return std::string(s);
162 }
163 
164  std::string toString(const double& x) const {
165  char s[100];
166  snprintf(s, sizeof(s), "%g", x);
167  return std::string(s);
168 }
169 
170 
171  private:
173  SetLabel(src.Label());
174  return *this;
175  }
176 
177  char * Label_;
178 
179 };
180 
181 inline std::ostream& operator<<(std::ostream& os, const Epetra_Object& obj)
182 {
183  if (Epetra_FormatStdout) {
184 /* const Epetra_fmtflags olda = os.setf(ios::right,ios::adjustfield);
185  const Epetra_fmtflags oldf = os.setf(ios::scientific,ios::floatfield);
186  const int oldp = os.precision(12); */
187 
188  os << obj.Label() << std::endl;
189  obj.Print(os);
190 
191 /* os.setf(olda,ios::adjustfield);
192  os.setf(oldf,ios::floatfield);
193  os.precision(oldp); */
194  }
195  else {
196 
197  os << obj.Label();
198  obj.Print(os);
199  }
200 
201  return os;
202 }
203 
209 #define EPETRA_TEST_FOR_EXCEPTION(throw_exception_test,errCode,msg) \
210 { \
211  const bool throw_exception = (throw_exception_test); \
212  if(throw_exception) { \
213  std::ostringstream omsg; \
214  omsg \
215  << __FILE__ << ":" << __LINE__ << ":" \
216  << " Throw test that evaluated to true: "#throw_exception_test << ":" \
217  << "Error message : " << msg; \
218  throw ReportError(omsg.str(),errCode); \
219  } \
220 }
221 
222 #endif /* EPETRA_OBJECT_H */
virtual void Print(std::ostream &os) const
Print object to an output stream Print method.
std::string toString(const double &x) const
static int TracebackMode
std::ostream & operator<<(std::ostream &os, const Epetra_Object &obj)
Epetra_Combine Mode enumerable type.
const bool Epetra_FormatStdout
virtual const char * Label() const
Epetra_Object Label access funtion.
std::string toString(const int &x) const
Epetra_Object & operator=(const Epetra_Object &src)
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:65
std::string toString(const long long &x) const
Epetra_DataAccess Mode enumerable type.