Merge pull request #2547 from lethosor/codegen-stl-map-stub+v50

[v50] Add read-only container_identity for std::map
develop
Myk 2023-01-05 15:35:27 -08:00 committed by GitHub
commit a5b11065db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 0 deletions

@ -394,6 +394,7 @@ namespace df
template<class T> template<class T>
class ro_stl_container_identity : public container_identity { class ro_stl_container_identity : public container_identity {
protected:
const char *name; const char *name;
public: 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 { class bit_array_identity : public bit_container_identity {
public: public:
/* /*
@ -609,6 +634,10 @@ namespace df
static container_identity *get(); 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> > { template<> struct identity_traits<BitArray<int> > {
static bit_array_identity identity; static bit_array_identity identity;
static bit_container_identity *get() { return &identity; } static bit_container_identity *get() { return &identity; }
@ -679,6 +708,13 @@ namespace df
return &identity; 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> template<class T>
inline bit_container_identity *identity_traits<BitArray<T> >::get() { inline bit_container_identity *identity_traits<BitArray<T> >::get() {
static bit_array_identity identity(identity_traits<T>::get()); static bit_array_identity identity(identity_traits<T>::get());