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 #include "Epetra_CombineMode.h"
48 #include "Epetra_DataAccess.h"
49 #include "Epetra_ConfigDefs.h"
50 
52 
57 class EPETRA_LIB_DLL_EXPORT Epetra_Object {
58 
59  public:
61 
62 
67  Epetra_Object(int TracebackModeIn = -1, bool set_label = true);
68 
70 
72  Epetra_Object(const char * const Label, int TracebackModeIn = -1);
73 
75 
77  Epetra_Object(const Epetra_Object& Object);
78 
80 
82  virtual ~Epetra_Object();
84 
86 
87 
89 
91  virtual void SetLabel(const char * const Label);
92 
94 
96  virtual const char * Label() const;
97 
99 
111  static void SetTracebackMode(int TracebackModeValue);
112 
114  static int GetTracebackMode();
115 
117  static std::ostream& GetTracebackStream();
118 
120 
122 
123 
126  virtual void Print(std::ostream & os) const;
127 
129  virtual int ReportError(const std::string Message, int ErrorCode) const;
131 
132 
133 // TracebackMode controls how much traceback information is printed when run time
134 // integer errors are detected:
135 // = 0 - No information report
136 // = 1 - Fatal (negative) values are reported
137 // = 2 - All values (except zero) reported.
138 
139 // Default is set to 1. Can be set to different value using SetTracebackMode() method in
140 // Epetra_Object class
141  static int TracebackMode;
142 
143 
144  protected:
145  std::string toString(const int& x) const {
146  char s[100];
147  snprintf(s, sizeof(s), "%d", x);
148  return std::string(s);
149 }
150  std::string toString(const long long& x) const {
151  char s[100];
152  snprintf(s, sizeof(s), "%lld", x);
153  return std::string(s);
154 }
155 
156  std::string toString(const double& x) const {
157  char s[100];
158  snprintf(s, sizeof(s), "%g", x);
159  return std::string(s);
160 }
161 
162 
163  private:
165  SetLabel(src.Label());
166  return *this;
167  }
168 
169  char * Label_;
170 
171 };
172 
173 inline std::ostream& operator<<(std::ostream& os, const Epetra_Object& obj)
174 {
175  if (Epetra_FormatStdout) {
176 /* const Epetra_fmtflags olda = os.setf(ios::right,ios::adjustfield);
177  const Epetra_fmtflags oldf = os.setf(ios::scientific,ios::floatfield);
178  const int oldp = os.precision(12); */
179 
180  os << obj.Label() << std::endl;
181  obj.Print(os);
182 
183 /* os.setf(olda,ios::adjustfield);
184  os.setf(oldf,ios::floatfield);
185  os.precision(oldp); */
186  }
187  else {
188 
189  os << obj.Label();
190  obj.Print(os);
191  }
192 
193  return os;
194 }
195 
201 #define EPETRA_TEST_FOR_EXCEPTION(throw_exception_test,errCode,msg) \
202 { \
203  const bool throw_exception = (throw_exception_test); \
204  if(throw_exception) { \
205  std::ostringstream omsg; \
206  omsg \
207  << __FILE__ << ":" << __LINE__ << ":" \
208  << " Throw test that evaluated to true: "#throw_exception_test << ":" \
209  << "Error message : " << msg; \
210  throw ReportError(omsg.str(),errCode); \
211  } \
212 }
213 
214 #endif /* EPETRA_OBJECT_H */
215 
216 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
217 #ifdef __GNUC__
218 #warning "The Epetra package is deprecated"
219 #endif
220 #endif
221 
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:57
std::string toString(const long long &x) const
Epetra_DataAccess Mode enumerable type.