summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp')
-rw-r--r--staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp64
1 files changed, 30 insertions, 34 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
index 7e14fbc0014..84bdc0a45d0 100644
--- a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
+++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp
@@ -27,18 +27,28 @@ public:
bool erase(RuntimeClass * c);
const RuntimeClass * classFromId(unsigned id) const;
const RuntimeClass * classFromName(const char * name) const;
- const char * id2Name(unsigned id) const;
- unsigned name2Id(const char * name) const;
bool empty() const { return _listById.empty(); }
private:
- struct GetId { uint32_t operator() (const RuntimeClass * f) const { return f->id(); } };
- struct HashId { size_t operator() (const RuntimeClass * f) const { return f->id(); } };
- struct EqualId { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return a->id() == b->id(); } };
- struct GetName { const char * operator() (const RuntimeClass * f) const { return f->name(); } };
- struct HashName { size_t operator() (const RuntimeClass * f) const { return hashValue(f->name()); } };
- struct EqualName { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return strcmp(a->name(), b->name()) == 0; } };
- typedef hash_set<RuntimeClass *, HashId, EqualId> IdList;
- typedef hash_set<RuntimeClass *, HashName, EqualName> NameList;
+ struct HashId {
+ uint32_t operator() (const RuntimeClass * f) const { return f->id(); }
+ uint32_t operator() (uint32_t id) const { return id; }
+ };
+ struct EqualId {
+ bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return a->id() == b->id(); }
+ bool operator() (const RuntimeClass * a, uint32_t b) const { return a->id() == b; }
+ bool operator() (uint32_t a, const RuntimeClass * b) const { return a == b->id(); }
+ };
+ struct HashName {
+ uint32_t operator() (const RuntimeClass * f) const { return hashValue(f->name()); }
+ uint32_t operator() (const char * name) const { return hashValue(name); }
+ };
+ struct EqualName {
+ bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return strcmp(a->name(), b->name()) == 0; }
+ bool operator() (const RuntimeClass * a, const char * b) const { return strcmp(a->name(), b) == 0; }
+ bool operator() (const char * a, const RuntimeClass * b) const { return strcmp(a, b->name()) == 0; }
+ };
+ using IdList = hash_set<RuntimeClass *, HashId, EqualId>;
+ using NameList = hash_set<RuntimeClass *, HashName, EqualName>;
IdList _listById;
NameList _listByName;
};
@@ -69,14 +79,14 @@ bool Register::append(Identifiable::RuntimeClass * c)
const Identifiable::RuntimeClass * Register::classFromId(unsigned id) const
{
- IdList::const_iterator it(_listById.find<uint32_t, GetId, hash<uint32_t>, std::equal_to<uint32_t> >(id));
- return (it != _listById.end()) ? *it : NULL;
+ IdList::const_iterator it(_listById.find<uint32_t>(id));
+ return (it != _listById.end()) ? *it : nullptr;
}
const Identifiable::RuntimeClass * Register::classFromName(const char *name) const
{
- NameList::const_iterator it(_listByName.find<const char *, GetName, hash<const char *>, std::equal_to<const char *> >(name));
- return (it != _listByName.end()) ? *it : NULL;
+ NameList::const_iterator it(_listByName.find<const char *>(name));
+ return (it != _listByName.end()) ? *it : nullptr;
}
Register * _register = nullptr;
@@ -115,7 +125,7 @@ Identifiable::RuntimeClass::RuntimeClass(RuntimeInfo * info_) :
}
}
}
- if (_register == NULL) {
+ if (_register == nullptr) {
_register = new Register();
}
if (! _register->append(this)) {
@@ -131,7 +141,7 @@ Identifiable::RuntimeClass::~RuntimeClass()
}
if (_register->empty()) {
delete _register;
- _register = NULL;
+ _register = nullptr;
}
}
@@ -142,20 +152,6 @@ bool Identifiable::RuntimeClass::inherits(unsigned cid) const
return (cid == cur->_id);
}
-class SortById : public std::binary_function<const Identifiable::RuntimeClass *, const Identifiable::RuntimeClass *, bool> {
-public:
- bool operator() (const Identifiable::RuntimeClass * x, const Identifiable::RuntimeClass * y) const {
- return x->id() < y->id();
- }
-};
-
-class SortByName : public std::binary_function<const Identifiable::RuntimeClass *, const Identifiable::RuntimeClass *, bool> {
-public:
- bool operator() (const Identifiable::RuntimeClass * x, const Identifiable::RuntimeClass * y) const {
- return strcmp(x->name(), y->name()) < 0;
- }
-};
-
Serializer & operator << (Serializer & os, const Identifiable & obj)
{
os.put(Identifiable::classIdField, obj.getClass().id());
@@ -199,16 +195,16 @@ Identifiable::UP Identifiable::create(Deserializer & is)
is.get(classIdField, cid);
UP obj;
const Identifiable::RuntimeClass *rtc = Identifiable::classFromId(cid);
- if (rtc == NULL) {
- if ((_classLoader != NULL) && _classLoader->hasClass(cid)) {
+ if (rtc == nullptr) {
+ if ((_classLoader != nullptr) && _classLoader->hasClass(cid)) {
_classLoader->loadClass(cid);
rtc = Identifiable::classFromId(cid);
- if (rtc == NULL) {
+ if (rtc == nullptr) {
throw std::runtime_error(make_string("Failed loading class for Identifiable with classId %d(%0x)", cid, cid));
}
}
}
- if (rtc != NULL) {
+ if (rtc != nullptr) {
obj.reset(rtc->create());
if (obj.get()) {
obj->deserialize(is);