1 #ifndef oo_ObjSelector_H__
2 #define oo_ObjSelector_H__
34 autoDelete_ = autoDelete;
40 if (parent_ != NULL) {
41 parent_->me_.second = NULL;
47 typedef typename std::map<std::string, Info*> Funcs;
48 typedef typename std::map<std::string, Info*>::iterator FuncsIterator;
50 static Funcs& funcs() {
58 Info* info =
new Info(parent, ptr, autoDelete);
64 std::pair<std::string, Info*> me_;
70 add(name, NULL, obj, autoDelete);
77 add(obj->
type(), NULL, obj, autoDelete);
84 if (funcs().find(name) != funcs().end()) {
94 if (funcs().find(
name) == funcs().end())
return NULL;
95 return funcs()[
name]->pointer_;
103 if(ptr == NULL)
return NULL;
111 for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) {
112 if (it->second->pointer_ == obj ||
113 (it->second->pointer_ != NULL &&
114 it->second->pointer_->type() == obj->
type())) {
125 for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) {
126 if (it->second->pointer_ == obj ||
127 (it->second->pointer_ != NULL &&
128 it->second->pointer_->type() == obj->
type())) {
132 return std::string();
138 static std::vector<std::string>
names() {
139 std::vector<std::string> ret;
140 for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++)
141 ret.push_back(it->first);
150 me_.second = add(me_.first,
this, obj, autoDelete);
157 me_.first = obj->
type();
158 me_.second = add(me_.first,
this, obj, autoDelete);
163 if (me_.second != NULL) {
171 static bool write(FILE* f,
bool binary,
ObjBase* obj,
unsigned int fg) {
172 if (!
exist(obj))
return false;
173 char const* nme =
name(obj).c_str();
174 size_t len = strlen(nme);
176 if (fwrite(&len,
sizeof(
size_t ), 1, f) < 1)
return false;
177 if (fwrite(nme ,
sizeof(
char ), len, f) < len)
return false;
178 if (fwrite(&fg ,
sizeof(
unsigned int), 1, f) < 1)
return false;
180 if (fprintf(f,
"%s %u\n", nme, fg) < 2)
return false;
182 return obj->
write(f, binary, fg);
189 static char name[2048];
193 if (fread(&len,
sizeof(
size_t ), 1, f) < 1)
return NULL;
194 if (fread(name,
sizeof(
char ), len, f) < len)
return NULL;
195 if (fread(&fg ,
sizeof(
unsigned int), 1, f) < 1)
return NULL;
198 if (fscanf(f,
"%s %u", name, &fg) < 2)
return NULL;
201 if (ret != NULL && ret->
read(f, binary, fg) ==
false) {
213 #endif // oo_ObjSelector_H__