Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_Object.cpp
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 #include "Epetra_Object.h"
44 
45 #ifdef HAVE_EPETRA_TEUCHOS
47 #endif
48 
49 //=============================================================================
50 Epetra_Object::Epetra_Object(int TracebackModeIn, bool set_label)
51  : Label_(0)
52 {
53  if (set_label) {
54  SetLabel("Epetra::Object");
55  }
56  TracebackMode = (TracebackModeIn != -1) ? TracebackModeIn : TracebackMode;
57 }
58 
59 //=============================================================================
60 Epetra_Object::Epetra_Object(const char * const Label_in,
61  int TracebackModeIn)
62  : Label_(0)
63 {
64  SetLabel(Label_in);
65  TracebackMode = (TracebackModeIn != -1) ? TracebackModeIn : TracebackMode;
66 }
67 //=============================================================================
69  : Label_(0)
70 {
71  SetLabel(Object.Label_);
72 }
73 
74 // Set TracebackMode value to default
76 
77 void Epetra_Object::SetTracebackMode(int TracebackModeValue) {
78  if (TracebackModeValue < 0) TracebackModeValue = 0;
79  Epetra_Object TempObject(TracebackModeValue);
80 }
81 
84  if (temp==-1) temp = DefaultTracebackMode;
85  return(temp);
86 }
87 
89 #ifdef HAVE_EPETRA_TEUCHOS
90  return (*Teuchos::VerboseObjectBase::getDefaultOStream());
91 #else
92  return std::cerr;
93 #endif
94 }
95 
96 //=============================================================================
97 void Epetra_Object::Print(std::ostream & os) const {
98  (void)os;//prevents unused variable compiler-warning
99  // os << Label_; // No need to print label, since ostream does it already
100  return;
101 }
102 //=============================================================================
103 int Epetra_Object::ReportError(const std::string Message, int ErrorCode) const {
104 #ifndef EPETRA_NO_ERROR_REPORTS
105  // NOTE: We are extracting a C-style string from Message because
106  // the SGI compiler does not have a real string class with
107  // the << operator. Some day we should get rid of ".c_str()"
108  if (
109  ( ErrorCode < 0 && Epetra_Object::GetTracebackMode() > 0 )
110  ||
111  ( ErrorCode > 0 && Epetra_Object::GetTracebackMode() > 1 )
112  )
113  {
115  << std::endl << "Error in Epetra Object with label: " << Label_ << std::endl
116  << "Epetra Error: " << Message.c_str() << " Error Code: " << ErrorCode << std::endl;
117  }
118 #endif
119  return(ErrorCode);
120 }
121 //=============================================================================
123 {
124  if (Label_!=0) {
125  delete [] Label_;
126  Label_ = 0;
127  }
128 }
129 //=============================================================================
130 const char * Epetra_Object::Label() const {
131  return(Label_);
132 }
133 //=============================================================================
134 void Epetra_Object::SetLabel(const char * const Label_in)
135 {
136  if (Label_!=0) {
137  delete [] Label_;
138  Label_ = 0;
139  }
140  if (Label_in==0) return;
141  Label_ = new char[std::strlen(Label_in)+1];
142  std::strcpy(Label_,Label_in);
143  return;
144 }
virtual void Print(std::ostream &os) const
Print object to an output stream Print method.
virtual void SetLabel(const char *const Label)
Epetra_Object Label definition using char *.
static void SetTracebackMode(int TracebackModeValue)
Set the value of the Epetra_Object error traceback report mode.
static int TracebackMode
virtual const char * Label() const
Epetra_Object Label access funtion.
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:65
Epetra_Object(int TracebackModeIn=-1, bool set_label=true)
Epetra_Object Constructor.
static int GetTracebackMode()
Get the value of the Epetra_Object error report mode.
virtual ~Epetra_Object()
Epetra_Object Destructor.
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
static std::ostream & GetTracebackStream()
Get the output stream for error reporting.
const int DefaultTracebackMode