summaryrefslogtreecommitdiff
path: root/library/include/DataIdentity.h
diff options
context:
space:
mode:
Diffstat (limited to 'library/include/DataIdentity.h')
-rw-r--r--library/include/DataIdentity.h42
1 files changed, 41 insertions, 1 deletions
diff --git a/library/include/DataIdentity.h b/library/include/DataIdentity.h
index dcd0ae97..21dc68d1 100644
--- a/library/include/DataIdentity.h
+++ b/library/include/DataIdentity.h
@@ -115,6 +115,8 @@ namespace DFHack
virtual void lua_item_read(lua_State *state, int fname_idx, void *ptr, int idx);
virtual void lua_item_write(lua_State *state, int fname_idx, void *ptr, int idx, int val_index);
+ virtual bool is_readonly() { return false; }
+
virtual bool resize(void *ptr, int size) { return false; }
virtual bool erase(void *ptr, int index) { return false; }
virtual bool insert(void *ptr, int index, void *pitem) { return false; }
@@ -343,6 +345,33 @@ namespace df
}
};
+ template<class T>
+ class ro_stl_container_identity : public container_identity {
+ const char *name;
+
+ public:
+ ro_stl_container_identity(const char *name, type_identity *item, enum_identity *ienum = NULL)
+ : container_identity(sizeof(T), &allocator_fn<T>, item, ienum), name(name)
+ {}
+
+ std::string getFullName(type_identity *item) {
+ return name + container_identity::getFullName(item);
+ }
+
+ virtual bool is_readonly() { return true; }
+ virtual bool resize(void *ptr, int size) { return false; }
+ virtual bool erase(void *ptr, int size) { return false; }
+ virtual bool insert(void *ptr, int idx, void *item) { return false; }
+
+ protected:
+ virtual int item_count(void *ptr, CountMode) { return ((T*)ptr)->size(); }
+ virtual void *item_pointer(type_identity *item, void *ptr, int idx) {
+ auto iter = (*(T*)ptr).begin();
+ for (; idx > 0; idx--) ++iter;
+ return (void*)&*iter;
+ }
+ };
+
class bit_array_identity : public bit_container_identity {
public:
/*
@@ -361,7 +390,7 @@ namespace df
}
virtual bool resize(void *ptr, int size) {
- ((container*)ptr)->resize(size);
+ ((container*)ptr)->resize(size*8);
return true;
}
@@ -517,6 +546,10 @@ namespace df
static container_identity *get();
};
+ template<class T> struct identity_traits<std::set<T> > {
+ static container_identity *get();
+ };
+
template<> struct identity_traits<BitArray<int> > {
static bit_array_identity identity;
static bit_container_identity *get() { return &identity; }
@@ -580,6 +613,13 @@ namespace df
}
template<class T>
+ inline container_identity *identity_traits<std::set<T> >::get() {
+ typedef std::set<T> container;
+ static ro_stl_container_identity<container> identity("set", 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());
return &identity;