Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Object.cpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10// Kris
11// 07.08.03 -- Move into Teuchos package/namespace
12
13#include "Teuchos_Object.hpp"
14
15namespace Teuchos {
16
17// Set TracebackMode value to default.
18int Object::tracebackMode = -1;
19
21{
22 tracebackMode = (tracebackModeIn != -1) ? tracebackModeIn : tracebackMode;
23}
24
26 label_ (label_in) // this does a deep copy of the input string
27{
28 tracebackMode = (tracebackModeIn != -1) ? tracebackModeIn : tracebackMode;
29}
30
31Object::Object (const std::string& label_in, int tracebackModeIn) :
32 label_ (label_in)
33{
34 tracebackMode = (tracebackModeIn != -1) ? tracebackModeIn : tracebackMode;
35}
36
37void Object::setLabel (const char* theLabel) {
38 label_ = std::string (theLabel);
39}
40
48
50{
51 int temp = Object::tracebackMode;
52 if (temp == -1) {
54 }
55 return(temp);
56}
57
58void Object::print (std::ostream& /* os */) const
59{
60 // os << label_; // No need to print label, since std::ostream does it already
61}
62
63int Object::reportError (const std::string message, int errorCode) const
64{
65 using std::cerr;
66 using std::endl;
67
68 // mfh 23 Nov 2014: I found the following message here:
69 //
70 // NOTE: We are extracting a C-style std::string from Message because
71 // the SGI compiler does not have a real std::string class with
72 // the << operator. Some day we should get rid of ".c_str()"
73 //
74 // All the compilers we support now have a correct implementation of
75 // std::string, so I've corrected the code below to use std::string
76 // instead.
77
78 if (tracebackMode == 1 && errorCode < 0) {
79 // Report fatal error
80 cerr << endl << "Error in Teuchos Object with label: " << label_
81 << endl << "Teuchos Error: " << message << " Error Code: "
82 << errorCode << endl;
83 return errorCode;
84 }
85 if (tracebackMode == 2 && errorCode != 0) {
86 cerr << endl << "Error in Teuchos Object with label: " << label_
87 << endl << "Teuchos Error: " << message << " Error Code: "
88 << errorCode << endl;
89 return errorCode;
90 }
91 return errorCode;
92}
93
94const char* Object::label () const
95{
96 return label_.c_str ();
97}
98
99std::ostream& operator<< (std::ostream& os, const Teuchos::Object& obj)
100{
101 os << obj.label () << std::endl;
102 obj.print (os);
103 return os;
104}
105
106} // namespace Teuchos
The base Teuchos object.
The base Teuchos class.
virtual void print(std::ostream &os) const
Print the object to the given output stream.
static int getTracebackMode()
Get the value of the Object error traceback report mode.
virtual const char * label() const
Access the object's label (LEGACY; return std::string instead).
static void setTracebackMode(int tracebackModeValue)
Set the value of the Object error traceback report mode.
virtual int reportError(const std::string message, int errorCode) const
Report an error with this Object.
Object(int tracebackModeIn=-1)
Default Constructor.
Smart reference counting pointer class for automatic garbage collection.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...