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
00031
00032 #ifndef GROOVX_TCL_OBJPKG_CC_UTC20050626084017_DEFINED
00033 #define GROOVX_TCL_OBJPKG_CC_UTC20050626084017_DEFINED
00034
00035 #include "objpkg.h"
00036
00037 #include "nub/objdb.h"
00038 #include "nub/object.h"
00039
00040 #include "tcl/list.h"
00041 #include "tcl/pkg.h"
00042
00043 #include "rutz/iter.h"
00044
00045 #include "rutz/trace.h"
00046 #include "rutz/debug.h"
00047 GVX_DBG_REGISTER
00048
00049 using rutz::shared_ptr;
00050
00051
00052
00053
00054
00055
00056
00057 tcl::obj_caster::obj_caster() {}
00058
00059 tcl::obj_caster::~obj_caster() {}
00060
00061 bool tcl::obj_caster::is_id_my_type(nub::uid uid) const
00062 {
00063 nub::soft_ref<nub::object> item(uid);
00064 return (item.is_valid() && is_my_type(item.get()));
00065 }
00066
00067 namespace
00068 {
00069 int count_all(shared_ptr<tcl::obj_caster> caster)
00070 {
00071 nub::objectdb& instance = nub::objectdb::instance();
00072 int count = 0;
00073 for (nub::objectdb::iterator itr(instance.objects()); itr.is_valid(); ++itr)
00074 {
00075 if (caster->is_my_type(*itr))
00076 ++count;
00077 }
00078 return count;
00079 }
00080
00081 tcl::list find_all(shared_ptr<tcl::obj_caster> caster)
00082 {
00083 nub::objectdb& instance = nub::objectdb::instance();
00084
00085 tcl::list result;
00086
00087 for (nub::objectdb::iterator itr(instance.objects()); itr.is_valid(); ++itr)
00088 {
00089 if (caster->is_my_type(*itr))
00090 result.append((*itr)->id());
00091 }
00092
00093 return result;
00094 }
00095
00096 void remove_all(shared_ptr<tcl::obj_caster> caster)
00097 {
00098 nub::objectdb& instance = nub::objectdb::instance();
00099 for (nub::objectdb::iterator itr(instance.objects());
00100 itr.is_valid();
00101 )
00102 {
00103 dbg_eval(3, (*itr)->id());
00104 dbg_dump(3, *(*itr)->get_counts());
00105
00106 if (caster->is_my_type(*itr) && (*itr)->is_unshared())
00107 {
00108 nub::uid remove_me = (*itr)->id();
00109 ++itr;
00110 instance.remove(remove_me);
00111 }
00112 else
00113 {
00114 ++itr;
00115 }
00116 }
00117 }
00118
00119 bool is_my_type(shared_ptr<tcl::obj_caster> caster, nub::uid id)
00120 {
00121 return caster->is_id_my_type(id);
00122 }
00123
00124 unsigned int get_sizeof(shared_ptr<tcl::obj_caster> caster)
00125 {
00126 return caster->get_sizeof();
00127 }
00128 }
00129
00130 void tcl::def_basic_type_cmds(tcl::pkg* pkg,
00131 shared_ptr<tcl::obj_caster> caster,
00132 const rutz::file_pos& src_pos)
00133 {
00134 GVX_TRACE("tcl::def_basic_type_cmds");
00135
00136 const int flags = tcl::NO_EXPORT;
00137
00138 pkg->def_vec( "is", "objref(s)",
00139 rutz::bind_first(is_my_type, caster), 1, src_pos, flags );
00140 pkg->def( "count_all", "",
00141 rutz::bind_first(count_all, caster), src_pos, flags );
00142 pkg->def( "find_all", "",
00143 rutz::bind_first(find_all, caster), src_pos, flags );
00144 pkg->def( "remove_all", "",
00145 rutz::bind_first(remove_all, caster), src_pos, flags );
00146 pkg->def( "sizeof", "",
00147 rutz::bind_first(get_sizeof, caster), src_pos, flags );
00148 }
00149
00150 static const char __attribute__((used)) vcid_groovx_tcl_objpkg_cc_utc20050626084017[] = "$Id: objpkg.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00151 #endif // !GROOVX_TCL_OBJPKG_CC_UTC20050626084017_DEFINED