dict.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2004-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: Mon May 24 16:21:12 2004
00010 // commit: $Id: dict.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/tcl/dict.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 //
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(); // can't happen, but placate compiler
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

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.