value: add TypeStore

This commit is contained in:
Adrien Béraud committed 2018-03-06 10:29:01 -05:00
1 parent 09f080220f
commit ca9a367803
2 files changed
+16 -4

No files matched your search

+3 -4
View File
@@ -99,11 +99,10 @@ public:
bool isRunning(sa_family_t af = 0) const;
virtual void registerType(const ValueType& type) {
types[type.id] = type;
types.registerType(type);
}
const ValueType& getType(ValueType::Id type_id) const {
const auto& t_it = types.find(type_id);
return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second;
return types.getType(type_id);
}
/**
@@ -350,7 +349,7 @@ private:
uint64_t oldsecret {};
// registred types
std::map<ValueType::Id, ValueType> types;
TypeStore types;
// are we a bootstrap node ?
// note: Any running node can be used as a bootstrap node.
+13
View File
@@ -109,6 +109,19 @@ struct OPENDHT_PUBLIC ValueType {
EditPolicy editPolicy {DEFAULT_EDIT_POLICY};
};
class TypeStore {
public:
void registerType(const ValueType& type) {
types[type.id] = type;
}
const ValueType& getType(ValueType::Id type_id) const {
const auto& t_it = types.find(type_id);
return (t_it == types.end()) ? ValueType::USER_DATA : t_it->second;
}
private:
std::map<ValueType::Id, ValueType> types {};
};
/**
* A "value" is data potentially stored on the Dht, with some metadata.
*