obj.h

Go to the documentation of this file.
00001 /** @file tcl/obj.h c++ wrapper class for Tcl_Obj, to handle
00002     ref-counting and type conversions */
00003 
00004 ///////////////////////////////////////////////////////////////////////
00005 //
00006 // Copyright (c) 1999-2004 California Institute of Technology
00007 // Copyright (c) 2004-2007 University of Southern California
00008 // Rob Peters <rjpeters at usc dot edu>
00009 //
00010 // created: Tue May 11 13:44:19 1999
00011 // commit: $Id: obj.h 11876 2009-10-22 15:53:06Z icore $
00012 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/tcl/obj.h $
00013 //
00014 // --------------------------------------------------------------------
00015 //
00016 // This file is part of GroovX
00017 //   [http://ilab.usc.edu/rjpeters/groovx/]
00018 //
00019 // GroovX is free software; you can redistribute it and/or modify it
00020 // under the terms of the GNU General Public License as published by
00021 // the Free Software Foundation; either version 2 of the License, or
00022 // (at your option) any later version.
00023 //
00024 // GroovX is distributed in the hope that it will be useful, but
00025 // WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027 // General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License
00030 // along with GroovX; if not, write to the Free Software Foundation,
00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00032 //
00033 ///////////////////////////////////////////////////////////////////////
00034 
00035 #ifndef GROOVX_TCL_OBJ_H_UTC20050628162421_DEFINED
00036 #define GROOVX_TCL_OBJ_H_UTC20050628162421_DEFINED
00037 
00038 typedef struct Tcl_Obj Tcl_Obj;
00039 
00040 namespace tcl
00041 {
00042   class obj;
00043 }
00044 
00045 ///////////////////////////////////////////////////////////////////////
00046 /**
00047  *
00048  * This class acts as a reference counted smart pointer to Tcl_Obj. It
00049  * manages the reference count of a held Tcl_Obj*, and also defines a
00050  * conversion operator back to Tcl_Obj* in order to provide access to
00051  * Tcl_Obj's interface.
00052  *
00053  **/
00054 ///////////////////////////////////////////////////////////////////////
00055 
00056 class tcl::obj
00057 {
00058 public:
00059   /// Default constructor with a shared and empty Tcl_Obj*.
00060   obj();
00061 
00062   /// Construct with a Tcl_Obj*.
00063   obj(Tcl_Obj* obj) : m_obj(obj) { incr_ref(m_obj); }
00064 
00065   /// Destructor.
00066   ~obj() { decr_ref(m_obj); }
00067 
00068   /// Copy constructor.
00069   obj(const obj& x) :
00070     m_obj(x.m_obj)
00071     {
00072       incr_ref(m_obj);
00073     }
00074 
00075   /// Assignment operator from obj.
00076   obj& operator=(const obj& x)
00077     {
00078       assign(x.m_obj); return *this;
00079     }
00080 
00081   /// Assignment operator from Tcl_Obj*.
00082   obj& operator=(Tcl_Obj* x)
00083     {
00084       assign(x); return *this;
00085     }
00086 
00087   Tcl_Obj* get() const { return m_obj; }
00088 
00089   void append(const tcl::obj& other);
00090 
00091   bool is_shared() const;
00092   bool is_unique() const { return !is_shared(); }
00093 
00094   void make_unique() const;
00095 
00096   const char* tcltype_name() const;
00097 
00098 private:
00099   static void incr_ref(Tcl_Obj* obj);
00100   static void decr_ref(Tcl_Obj* obj);
00101 
00102   void assign(Tcl_Obj* x) const
00103     {
00104       if (m_obj != x)
00105         {
00106           decr_ref(m_obj);
00107           m_obj = x;
00108           incr_ref(m_obj);
00109         }
00110     }
00111 
00112   mutable Tcl_Obj* m_obj;
00113 };
00114 
00115 static const char __attribute__((used)) vcid_groovx_tcl_obj_h_utc20050628162421[] = "$Id: obj.h 11876 2009-10-22 15:53:06Z icore $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/tcl/obj.h $";
00116 #endif // !GROOVX_TCL_OBJ_H_UTC20050628162421_DEFINED
Generated on Sun May 8 08:42:22 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3