00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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