00001
00003
00004
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
00033
00034 #ifndef GROOVX_TCL_DICT_CC_UTC20050628162420_DEFINED
00035 #define GROOVX_TCL_DICT_CC_UTC20050628162420_DEFINED
00036
00037 #include "tcl/dict.h"
00038
00039 #include "rutz/error.h"
00040 #include "rutz/fstring.h"
00041 #include "rutz/sfmt.h"
00042
00043 #include <tcl.h>
00044
00045 #include "rutz/trace.h"
00046 #include "rutz/debug.h"
00047 GVX_DBG_REGISTER
00048
00049 #if ((TCL_MAJOR_VERSION == 8) \
00050 && (TCL_MINOR_VERSION >= 5)) \
00051 || (TCL_MAJOR_VERSION > 8)
00052 # define HAVE_TCL_DICT
00053 #else
00054 # undef HAVE_TCL_DICT
00055 #endif
00056
00057 tcl::dict tcl::aux_convert_to(Tcl_Obj* obj, tcl::dict*)
00058 {
00059 GVX_TRACE("tcl::aux_convert_to(tcl::dict*)");
00060
00061 return tcl::dict(obj);
00062 }
00063
00064 tcl::obj tcl::aux_convert_from(tcl::dict dict_value)
00065 {
00066 GVX_TRACE("tcl::aux_convert_from(tcl::dict)");
00067
00068 return dict_value.as_obj();
00069 }
00070
00071 #ifndef HAVE_TCL_DICT
00072 namespace
00073 {
00074 void error_no_dict_support()
00075 {
00076 throw rutz::error("tcl::dict requires Tcl version >= 8.5", SRC_POS);
00077 }
00078 }
00079
00080 void tcl::dict::do_put(const char*, tcl::obj)
00081 {
00082 error_no_dict_support();
00083 GVX_ASSERT(0);
00084 }
00085
00086 tcl::obj tcl::dict::do_get(const char*) const
00087 {
00088 error_no_dict_support();
00089 GVX_ASSERT(0);
00090 return tcl::obj();
00091 }
00092
00093 #else
00094
00095 void tcl::dict::do_put(const char* key, tcl::obj val)
00096 {
00097 GVX_TRACE("tcl::dict::do_put");
00098
00099 tcl::obj key_obj = tcl::convert_from(key);
00100 if (Tcl_DictObjPut(0, m_obj.get(), key_obj.get(), val.get()) != TCL_OK)
00101 {
00102 throw rutz::error(rutz::sfmt("couldn't put object in dict "
00103 "with key: %s", key), SRC_POS);
00104 }
00105 }
00106
00107 tcl::obj tcl::dict::do_get(const char* key) const
00108 {
00109 GVX_TRACE("tcl::dict::do_get");
00110
00111 Tcl_Obj* dest = 0;
00112
00113 tcl::obj key_obj = tcl::convert_from(key);
00114
00115 if (Tcl_DictObjGet(0, m_obj.get(), key_obj.get(), &dest) == TCL_OK)
00116 {
00117 if (dest != 0)
00118 return tcl::obj(dest);
00119 }
00120
00121 throw rutz::error(rutz::sfmt("couldn't get value from dict "
00122 "with key: %s", key), SRC_POS);
00123 }
00124
00125 #endif // defined(HAVE_TCL_DICT)
00126
00127 static const char __attribute__((used)) vcid_groovx_tcl_dict_cc_utc20050628162420[] = "$Id: dict.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00128 #endif // !GROOVX_TCL_DICT_CC_UTC20050628162420_DEFINED