list.cc

Go to the documentation of this file.
00001 
00005 
00006 //
00007 // Copyright (c) 2001-2004 California Institute of Technology
00008 // Copyright (c) 2004-2007 University of Southern California
00009 // Rob Peters <rjpeters at usc dot edu>
00010 //
00011 // created: Wed Jul 11 12:32:35 2001
00012 // commit: $Id: list.cc 10065 2007-04-12 05:54:56Z rjpeters $
00013 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/tcl/list.cc $
00014 //
00015 // --------------------------------------------------------------------
00016 //
00017 // This file is part of GroovX.
00018 //   [http://ilab.usc.edu/rjpeters/groovx/]
00019 //
00020 // GroovX is free software; you can redistribute it and/or modify it
00021 // under the terms of the GNU General Public License as published by
00022 // the Free Software Foundation; either version 2 of the License, or
00023 // (at your option) any later version.
00024 //
00025 // GroovX is distributed in the hope that it will be useful, but
00026 // WITHOUT ANY WARRANTY; without even the implied warranty of
00027 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00028 // General Public License for more details.
00029 //
00030 // You should have received a copy of the GNU General Public License
00031 // along with GroovX; if not, write to the Free Software Foundation,
00032 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00033 //
00035 
00036 #ifndef GROOVX_TCL_LIST_CC_UTC20050628162420_DEFINED
00037 #define GROOVX_TCL_LIST_CC_UTC20050628162420_DEFINED
00038 
00039 #include "tcl/list.h"
00040 
00041 #include "rutz/error.h"
00042 
00043 #include <tcl.h>
00044 
00045 #include "rutz/trace.h"
00046 #include "rutz/debug.h"
00047 GVX_DBG_REGISTER
00048 
00049 tcl::list tcl::aux_convert_to(Tcl_Obj* obj, tcl::list*)
00050 {
00051 GVX_TRACE("tcl::aux_convert_to(tcl::list*)");
00052 
00053   return tcl::list(obj);
00054 }
00055 
00056 tcl::obj tcl::aux_convert_from(tcl::list list_value)
00057 {
00058 GVX_TRACE("tcl::aux_convert_from(tcl::list)");
00059 
00060   return list_value.as_obj();
00061 }
00062 
00063 tcl::list::list() :
00064   m_list_obj(Tcl_NewListObj(0,0)),
00065   m_elements(0),
00066   m_length(0)
00067 {
00068 GVX_TRACE("tcl::list::list");
00069   split();
00070 }
00071 
00072 tcl::list::list(const tcl::obj& x) :
00073   m_list_obj(x),
00074   m_elements(0),
00075   m_length(0)
00076 {
00077 GVX_TRACE("tcl::list::list");
00078   split();
00079 }
00080 
00081 void tcl::list::split() const
00082 {
00083 GVX_TRACE("tcl::list::split");
00084 
00085   int count;
00086   if ( Tcl_ListObjGetElements(0, m_list_obj.get(), &count, &m_elements)
00087        != TCL_OK)
00088     {
00089       throw rutz::error("couldn't split Tcl list", SRC_POS);
00090     }
00091 
00092   GVX_ASSERT(count >= 0);
00093   m_length = static_cast<unsigned int>(count);
00094 }
00095 
00096 void tcl::list::do_append(const tcl::obj& obj, unsigned int times)
00097 {
00098 GVX_TRACE("tcl::list::do_append");
00099 
00100   m_list_obj.make_unique();
00101 
00102   while (times--)
00103     if ( Tcl_ListObjAppendElement(0, m_list_obj.get(), obj.get())
00104          != TCL_OK )
00105       {
00106         throw rutz::error("couldn't append to Tcl list", SRC_POS);
00107       }
00108 
00109   invalidate();
00110 }
00111 
00112 Tcl_Obj* tcl::list::at(unsigned int index) const
00113 {
00114 GVX_TRACE("tcl::list::at");
00115 
00116   update();
00117 
00118   if (index >= m_length)
00119     throw rutz::error("index was out of range in Tcl list access",
00120                       SRC_POS);
00121 
00122   dbg_eval(3, index); dbg_eval_nl(3, m_elements[index]);
00123 
00124   return m_elements[index];
00125 }
00126 
00127 unsigned int tcl::list::get_obj_list_length(Tcl_Obj* obj)
00128 {
00129 GVX_TRACE("tcl::list::get_obj_list_length");
00130 
00131   int len;
00132   if ( Tcl_ListObjLength(0, obj, &len) != TCL_OK)
00133     {
00134       throw rutz::error("couldn't get list length of Tcl object",
00135                         SRC_POS);
00136     }
00137 
00138   GVX_ASSERT(len >= 0);
00139 
00140   return static_cast<unsigned int>(len);
00141 }
00142 
00143 static const char __attribute__((used)) vcid_groovx_tcl_list_cc_utc20050628162420[] = "$Id: list.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00144 #endif // !GROOVX_TCL_LIST_CC_UTC20050628162420_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:41 2008 by Doxygen version 1.5.5.