00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJEMBED_H
00019 #define TJEMBED_H
00020
00021 #include <tjutils/tjutils.h>
00022
00028 template<class T,class E>
00029 class Embed {
00030
00031 public:
00032 Embed() {}
00033
00034 ~Embed() {
00035 clear_instances();
00036 }
00037
00038 void clear_instances() {
00039 for(typename STD_list<T*>::iterator it=instances.begin();it!=instances.end();++it) delete (*it);
00040 instances.clear();
00041 }
00042
00043 T& set_embed_body (const E& embeddedBody) {
00044 T* embedptr=static_cast<T*>(this);
00045 T* newinst;
00046 if(embedptr) newinst=new T(*embedptr);
00047 else newinst=new T();
00048 newinst->set_body(embeddedBody);
00049 newinst->set_label(STD_string(newinst->get_label())+itos(instances.size()));
00050 instances.push_back(newinst);
00051 return *newinst;
00052 }
00053
00054 T& set_embed_body (E& embeddedBody) {
00055 T* embedptr=static_cast<T*>(this);
00056 T* newinst;
00057 if(embedptr) newinst=new T(*embedptr);
00058 else newinst=new T();
00059 newinst->set_body(embeddedBody);
00060 newinst->set_label(STD_string(newinst->get_label())+itos(instances.size()));
00061 instances.push_back(newinst);
00062 return *newinst;
00063 }
00064
00065
00066 typedef typename STD_list<T*>::iterator institer;
00067 institer get_inst_begin() {return instances.begin();}
00068 institer get_inst_end() {return instances.end();}
00069
00070 typedef typename STD_list<T*>::const_iterator constinstiter;
00071 constinstiter get_const_inst_begin() const {return instances.begin();}
00072 constinstiter get_const_inst_end() const {return instances.end();}
00073
00074 private:
00075 STD_list<T*> instances;
00076 };
00077
00080 #endif