arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

gliftObject.h

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////
00002 // 7/15/03      Joe M. Kniss    Scientific Computing and Imaging Institute
00003 // School of Computing          University of Utah
00004 //
00005 //  This library is free software; you can redistribute it and/or
00006 //  modify it under the terms of the GNU Lesser General Public
00007 //  License as published by the Free Software Foundation; either
00008 //  version 2.1 of the License, or (at your option) any later version.
00009 //
00010 //  This library is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 //  Lesser General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU Lesser General Public
00016 //  License along with this library; if not, write to the Free Software
00017 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 /////////////////////////////////////////////////////////////////////////
00019 
00020 
00021 /// gliftObject.h
00022 ///  the base class for all Glift Objects
00023 
00024 #ifndef __GLIFT_OBJECT_DOT_H
00025 #define __GLIFT_OBJECT_DOT_H
00026 
00027 #include <iostream>
00028 #include <assert.h>
00029 
00030 namespace glift {
00031 
00032 class GliftObject {
00033 public:
00034    GliftObject() 
00035       : m_err(&std::cerr) 
00036    {}
00037    virtual ~GliftObject()
00038    {}
00039 
00040    //////////////////////////////////////
00041    /// Where do you want gl errors to go?
00042    /// they must go somewhere, so don't set
00043    /// it to zero please.
00044    virtual void          setErrStream(std::ostream *os)
00045    { assert(os); m_err = os; return; }
00046 
00047    //////////////////////////////////////
00048    /// Where are gl errors going?
00049    virtual std::ostream *getErrStream() const { return m_err; }
00050 
00051 protected:
00052 
00053    ///////////////////////////////////////////
00054    /// error reporting, most of these attach
00055    /// the object name, except estr(), which
00056    /// just returns a reference to the stream
00057    ///////////////////////////////////////////
00058 
00059    ///////////////////////////////////////////
00060    /// error report always,
00061    ///  standard: where = function name,
00062    ///            when  = what happend?
00063    /// sometimes you have to dis-abiguate this call:
00064    /// GliftObject::err(), or MyObj::GliftObject::err()
00065    void err(const char *where, const char *when =0) const;
00066    
00067    ///////////////////////////////////////////
00068    /// error report only in debug mode
00069    void derr(const char *where, const char *when =0) const;
00070 
00071    ///////////////////////////////////////////
00072    /// gl error report only in debug mode, only
00073    /// if there is an error, if so return true
00074    bool glerr(const char *where, const char *when =0) const;
00075 
00076    ///////////////////////////////////////////
00077    /// a simpler way, just use the stream!
00078    /// only for always print, this one automatically adds the
00079    /// objects name
00080    std::ostream &err() const;
00081    
00082    ///////////////////////////////////////////
00083    /// this one just gives you the stream
00084    std::ostream &estr() const { assert(m_err); return (*m_err); }
00085 
00086 
00087    mutable std::ostream *m_err;
00088 
00089 };
00090 
00091 /////////////////////////////////////////////////////////////////////////
00092 /////////////////////////////////////////////////////////////////////////
00093 /// some implementation
00094 /////////////////////////////////////////////////////////////////////////
00095 /////////////////////////////////////////////////////////////////////////
00096 
00097 /////////////////////////////////////////////////////////////////////////
00098 /// error
00099 /////////////////////////////////////////////////////////////////////////
00100 inline
00101 void GliftObject::err(const char *where, const char *when) const
00102 {
00103    assert(m_err);
00104    (*m_err) << typeid(*this).name() << "::" << where;
00105    if(when)
00106       (*m_err) << ", " << when;
00107    (*m_err) << "\n";
00108 }
00109 
00110 inline
00111 std::ostream &GliftObject::err() const
00112 {
00113    assert(m_err);
00114    (*m_err) << typeid(*this).name() << "::";
00115    return(*m_err);
00116 
00117 }
00118 /////////////////////////////////////////////////////////////////////////
00119 /// debug error
00120 /////////////////////////////////////////////////////////////////////////
00121 inline
00122 void GliftObject::derr(const char *where, const char *when) const
00123 {
00124 #ifdef _DEBUG
00125    if(!m_err) return;
00126    (*m_err) << typeid(*this).name() << "::" << where;
00127    if(when)
00128       (*m_err) << ", " << when;
00129    (*m_err) << "\n";
00130 #endif
00131 }
00132 
00133 
00134 } /// end namespace glift
00135 
00136 #endif
00137 

Send questions, comments, and bug reports to:
jmk