Add read-only container_identity for std::map

develop
lethosor 2022-12-30 00:45:00 -05:00
parent f72b3524ae
commit feeefcf149
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 36 additions and 0 deletions

@ -394,6 +394,7 @@ namespace df
template<class T>
class ro_stl_container_identity : public container_identity {
protected:
const char *name;
public:
@ -419,6 +420,30 @@ namespace df
}
};
template<class T>
class ro_stl_assoc_container_identity : public ro_stl_container_identity<T> {
type_identity *key_identity;
type_identity *item_identity;
public:
ro_stl_assoc_container_identity(const char *name, type_identity *key, type_identity *item)
: ro_stl_container_identity<T>(name, item),
key_identity(key),
item_identity(item)
{}
virtual std::string getFullName(type_identity*) override {
return std::string(ro_stl_assoc_container_identity<T>::name) + "<" + key_identity->getFullName() + ", " + item_identity->getFullName() + ">";
}
protected:
virtual void *item_pointer(type_identity *item, void *ptr, int idx) override {
auto iter = (*(T*)ptr).begin();
for (; idx > 0; idx--) ++iter;
return (void*)&iter->second;
}
};
class bit_array_identity : public bit_container_identity {
public:
/*
@ -609,6 +634,10 @@ namespace df
static container_identity *get();
};
template<class KT, class T> struct identity_traits<std::map<KT, T>> {
static container_identity *get();
};
template<> struct identity_traits<BitArray<int> > {
static bit_array_identity identity;
static bit_container_identity *get() { return &identity; }
@ -679,6 +708,13 @@ namespace df
return &identity;
}
template<class KT, class T>
inline container_identity *identity_traits<std::map<KT, T>>::get() {
typedef std::map<KT, T> container;
static ro_stl_assoc_container_identity<container> identity("map", identity_traits<KT>::get(), identity_traits<T>::get());
return &identity;
}
template<class T>
inline bit_container_identity *identity_traits<BitArray<T> >::get() {
static bit_array_identity identity(identity_traits<T>::get());