summaryrefslogtreecommitdiff
path: root/library/DataDefs.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-22 10:56:32 +0400
committerAlexander Gavrilov2012-03-22 10:56:32 +0400
commit27824642d90a8bca445af4e6f5d51a89d8317708 (patch)
treec30921b54f0971c37c775f11aeabaa258fe5b217 /library/DataDefs.cpp
parentad10303cecd1e60a2e50b85a5f6f08656ff1bbf9 (diff)
downloaddfhack-27824642d90a8bca445af4e6f5d51a89d8317708.tar.gz
dfhack-27824642d90a8bca445af4e6f5d51a89d8317708.tar.bz2
dfhack-27824642d90a8bca445af4e6f5d51a89d8317708.tar.xz
Minor refactoring of container indexing and object allocation.
Diffstat (limited to 'library/DataDefs.cpp')
-rw-r--r--library/DataDefs.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp
index 9576afb7..6fcd1141 100644
--- a/library/DataDefs.cpp
+++ b/library/DataDefs.cpp
@@ -40,6 +40,37 @@ distribution.
using namespace DFHack;
+
+void *type_identity::do_allocate_pod() {
+ void *p = malloc(size);
+ memset(p, 0, size);
+ return p;
+}
+
+void type_identity::do_copy_pod(void *tgt, const void *src) {
+ memmove(tgt, src, size);
+};
+
+void *type_identity::allocate() {
+ if (can_allocate())
+ return do_allocate();
+ else
+ return NULL;
+}
+
+bool type_identity::copy(void *tgt, const void *src) {
+ if (can_allocate() && tgt && src)
+ do_copy(tgt, src);
+ else
+ return false;
+}
+
+void *enum_identity::do_allocate() {
+ void *p = malloc(byte_size());
+ memcpy(p, &first_item_value, std::min(byte_size(), sizeof(int64_t)));
+ return p;
+}
+
/* The order of global object constructor calls is
* undefined between compilation units. Therefore,
* this list has to be plain data, so that it gets
@@ -95,19 +126,19 @@ void compound_identity::Init(Core *core)
*/
}
-bitfield_identity::bitfield_identity(size_t size, TAllocateFn alloc,
+bitfield_identity::bitfield_identity(size_t size,
compound_identity *scope_parent, const char *dfhack_name,
int num_bits, const bitfield_item_info *bits)
- : compound_identity(size, alloc, scope_parent, dfhack_name), bits(bits), num_bits(num_bits)
+ : compound_identity(size, NULL, scope_parent, dfhack_name), bits(bits), num_bits(num_bits)
{
}
-enum_identity::enum_identity(size_t size, TAllocateFn alloc,
+enum_identity::enum_identity(size_t size,
compound_identity *scope_parent, const char *dfhack_name,
type_identity *base_type,
int64_t first_item_value, int64_t last_item_value,
const char *const *keys)
- : compound_identity(size, alloc, scope_parent, dfhack_name),
+ : compound_identity(size, NULL, scope_parent, dfhack_name),
first_item_value(first_item_value), last_item_value(last_item_value),
keys(keys), base_type(base_type)
{