00001
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
00032
00034
00035 #ifndef GROOVX_TCL_OBJPKG_H_UTC20050626084018_DEFINED
00036 #define GROOVX_TCL_OBJPKG_H_UTC20050626084018_DEFINED
00037
00038 #include "nub/objfactory.h"
00039
00040 #include "rutz/shared_ptr.h"
00041
00042 namespace rutz
00043 {
00044 struct file_pos;
00045 }
00046
00047 namespace tcl
00048 {
00049 class obj_caster;
00050 class pkg;
00051 }
00052
00053 namespace nub
00054 {
00055 class object;
00056 }
00057
00058
00060
00061 class tcl::obj_caster
00062 {
00063 protected:
00064 obj_caster();
00065
00066 public:
00067 virtual ~obj_caster();
00068
00069 virtual bool is_my_type(const nub::object* obj) const = 0;
00070
00071 virtual unsigned int get_sizeof() const = 0;
00072
00073 bool is_not_my_type(const nub::object* obj) const { return !is_my_type(obj); }
00074
00075 bool is_id_my_type(nub::uid uid) const;
00076
00077 bool is_id_not_my_type(nub::uid uid) const { return !is_id_my_type(uid); }
00078 };
00079
00080 namespace tcl
00081 {
00083 template <class C>
00084 class cobj_caster : public obj_caster
00085 {
00086 public:
00087 virtual unsigned int get_sizeof() const
00088 {
00089 return sizeof(C);
00090 }
00091
00092 virtual bool is_my_type(const nub::object* obj) const
00093 {
00094 return (obj != 0 && dynamic_cast<const C*>(obj) != 0);
00095 }
00096 };
00097
00098 void def_basic_type_cmds(pkg* pkg, rutz::shared_ptr<obj_caster> caster,
00099 const rutz::file_pos& src_pos);
00100
00101 template <class C>
00102 void def_basic_type_cmds(pkg* pkg, const rutz::file_pos& src_pos)
00103 {
00104 rutz::shared_ptr<obj_caster> caster(new cobj_caster<C>);
00105 def_basic_type_cmds(pkg, caster, src_pos);
00106 }
00107
00108 template <class C>
00109 void def_creator(pkg*, const char* alias_name = 0)
00110 {
00111 const char* origName =
00112 nub::obj_factory::instance().register_creator(&C::make);
00113
00114 if (alias_name != 0)
00115 nub::obj_factory::instance().register_alias(origName, alias_name);
00116 }
00117 }
00118
00119 static const char __attribute__((used)) vcid_groovx_tcl_objpkg_h_utc20050626084018[] = "$Id: objpkg.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00120 #endif // !GROOVX_TCL_OBJPKG_H_UTC20050626084018_DEFINED