Epetra Package Browser (Single Doxygen Collection) Development
Epetra_Object.cpp
Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2001 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 #include "Epetra_Object.h"
00044 
00045 #ifdef HAVE_EPETRA_TEUCHOS
00046 #include "Teuchos_VerboseObject.hpp"
00047 #endif
00048 
00049 //=============================================================================
00050 Epetra_Object::Epetra_Object(int TracebackModeIn, bool set_label) 
00051   : Label_(0)
00052 {
00053   if (set_label) {
00054     SetLabel("Epetra::Object");
00055   }
00056   TracebackMode = (TracebackModeIn != -1) ? TracebackModeIn : TracebackMode;
00057 }
00058 
00059 //=============================================================================
00060 Epetra_Object::Epetra_Object(const char * const Label_in, 
00061            int TracebackModeIn) 
00062   : Label_(0)
00063 {
00064   SetLabel(Label_in);
00065   TracebackMode = (TracebackModeIn != -1) ? TracebackModeIn : TracebackMode;
00066 }
00067 //=============================================================================
00068 Epetra_Object::Epetra_Object(const Epetra_Object& Object)
00069   : Label_(0)
00070 {
00071   SetLabel(Object.Label_);
00072 }
00073 
00074 // Set TracebackMode value to default
00075 int Epetra_Object::TracebackMode(-1);
00076 
00077 void Epetra_Object::SetTracebackMode(int TracebackModeValue) {
00078   if (TracebackModeValue < 0) TracebackModeValue = 0;
00079   Epetra_Object TempObject(TracebackModeValue);
00080 }
00081 
00082 int Epetra_Object::GetTracebackMode() {
00083   int temp = Epetra_Object::TracebackMode;
00084   if (temp==-1) temp = DefaultTracebackMode;
00085   return(temp);
00086 }
00087 
00088 std::ostream& Epetra_Object::GetTracebackStream() {
00089 #ifdef HAVE_EPETRA_TEUCHOS
00090   return (*Teuchos::VerboseObjectBase::getDefaultOStream());
00091 #else
00092   return cerr;
00093 #endif
00094 }
00095 
00096 //=============================================================================
00097 void Epetra_Object::Print(ostream & os) const {
00098   (void)os;//prevents unused variable compiler-warning
00099   // os << Label_; // No need to print label, since ostream does it already
00100   return;
00101 }
00102 //=============================================================================
00103 int Epetra_Object::ReportError(const string Message, int ErrorCode) const {
00104 #ifndef EPETRA_NO_ERROR_REPORTS
00105   // NOTE:  We are extracting a C-style string from Message because
00106   //        the SGI compiler does not have a real string class with 
00107   //        the << operator.  Some day we should get rid of ".c_str()"
00108   if (
00109     ( ErrorCode < 0 && Epetra_Object::GetTracebackMode() > 0 )
00110     ||
00111     ( ErrorCode > 0 && Epetra_Object::GetTracebackMode() > 1 )
00112     )
00113   {
00114     GetTracebackStream()
00115       << endl << "Error in Epetra Object with label:  " << Label_ << endl
00116       << "Epetra Error:  " << Message.c_str() << "  Error Code:  " << ErrorCode << endl;
00117   }
00118 #endif
00119   return(ErrorCode);
00120 }
00121 //=============================================================================
00122 Epetra_Object::~Epetra_Object()  
00123 {
00124   if (Label_!=0) {
00125     delete [] Label_;
00126     Label_ = 0;
00127   }
00128 }
00129 //=============================================================================
00130 const char * Epetra_Object::Label() const {
00131   return(Label_);
00132 }
00133 //=============================================================================
00134 void Epetra_Object::SetLabel(const char * const Label_in)
00135 { 
00136   if (Label_!=0) {
00137     delete [] Label_;
00138     Label_ = 0;
00139   }
00140   if (Label_in==0) return;
00141   Label_ = new char[std::strlen(Label_in)+1];
00142   std::strcpy(Label_,Label_in);
00143   return;
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines