00001 /** @file tcl/obj.cc c++ wrapper class for Tcl_Obj, to handle 00002 ref-counting and type conversions */ 00003 /////////////////////////////////////////////////////////////////////// 00004 // 00005 // Copyright (c) 2001-2004 California Institute of Technology 00006 // Copyright (c) 2004-2007 University of Southern California 00007 // Rob Peters <rjpeters at usc dot edu> 00008 // 00009 // created: Wed Jul 11 18:30:47 2001 00010 // commit: $Id: obj.cc 11876 2009-10-22 15:53:06Z icore $ 00011 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/tcl/obj.cc $ 00012 // 00013 // -------------------------------------------------------------------- 00014 // 00015 // This file is part of GroovX 00016 // [http://ilab.usc.edu/rjpeters/groovx/] 00017 // 00018 // GroovX is free software; you can redistribute it and/or modify it 00019 // under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation; either version 2 of the License, or 00021 // (at your option) any later version. 00022 // 00023 // GroovX is distributed in the hope that it will be useful, but 00024 // WITHOUT ANY WARRANTY; without even the implied warranty of 00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00026 // General Public License for more details. 00027 // 00028 // You should have received a copy of the GNU General Public License 00029 // along with GroovX; if not, write to the Free Software Foundation, 00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00031 // 00032 /////////////////////////////////////////////////////////////////////// 00033 00034 #ifndef GROOVX_TCL_OBJ_CC_UTC20050628162420_DEFINED 00035 #define GROOVX_TCL_OBJ_CC_UTC20050628162420_DEFINED 00036 00037 #include "tcl/obj.h" 00038 00039 #include <tcl.h> 00040 00041 tcl::obj::obj() : m_obj(Tcl_NewObj()) { incr_ref(m_obj); } 00042 00043 void tcl::obj::append(const tcl::obj& other) 00044 { 00045 make_unique(); 00046 Tcl_AppendObjToObj(m_obj, other.m_obj); 00047 } 00048 00049 bool tcl::obj::is_shared() const 00050 { 00051 return Tcl_IsShared(m_obj); 00052 } 00053 00054 void tcl::obj::make_unique() const 00055 { 00056 if (is_shared()) 00057 { 00058 Tcl_Obj* new_obj = Tcl_DuplicateObj(m_obj); 00059 assign(new_obj); 00060 } 00061 } 00062 00063 const char* tcl::obj::tcltype_name() const 00064 { 00065 const Tcl_ObjType* type = m_obj->typePtr; 00066 00067 return type ? type->name : "(none)"; 00068 } 00069 00070 void tcl::obj::incr_ref(Tcl_Obj* obj) 00071 { 00072 Tcl_IncrRefCount(obj); 00073 } 00074 00075 void tcl::obj::decr_ref(Tcl_Obj* obj) 00076 { 00077 Tcl_DecrRefCount(obj); 00078 } 00079 00080 static const char __attribute__((used)) vcid_groovx_tcl_obj_cc_utc20050628162420[] = "$Id: obj.cc 11876 2009-10-22 15:53:06Z icore $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/tcl/obj.cc $"; 00081 #endif // !GROOVX_TCL_OBJ_CC_UTC20050628162420_DEFINED