Merge branch 'develop' of https://github.com/angavrilov/dfhack into develop

develop
Quietust 2014-10-08 11:30:06 -05:00
commit cdcc0d228d
7 changed files with 50 additions and 12 deletions

@ -67,10 +67,7 @@ void *type_identity::allocate() {
bool type_identity::copy(void *tgt, const void *src) { bool type_identity::copy(void *tgt, const void *src) {
if (can_allocate() && tgt && src) if (can_allocate() && tgt && src)
{ return do_copy(tgt, src);
do_copy(tgt, src);
return true;
}
else else
return false; return false;
} }

@ -39,6 +39,14 @@ namespace df {
stl_bit_vector_identity identity_traits<std::vector<bool> >::identity; stl_bit_vector_identity identity_traits<std::vector<bool> >::identity;
bit_array_identity identity_traits<BitArray<int> >::identity; bit_array_identity identity_traits<BitArray<int> >::identity;
static void *fstream_allocator_fn(void *out, const void *in) {
if (out) { /* *(T*)out = *(const T*)in;*/ return NULL; }
else if (in) { delete (std::fstream*)in; return (std::fstream*)in; }
else return new std::fstream();
}
opaque_identity identity_traits<std::fstream>::identity(
sizeof(std::fstream), fstream_allocator_fn, "fstream");
buffer_container_identity buffer_container_identity::base_instance; buffer_container_identity buffer_container_identity::base_instance;
#undef NUMBER_IDENTITY_TRAITS #undef NUMBER_IDENTITY_TRAITS

@ -1256,8 +1256,11 @@ static void MakePrimitiveMetatable(lua_State *state, type_identity *type)
// Index the fields // Index the fields
lua_newtable(state); lua_newtable(state);
EnableMetaField(state, base+2, "value", type); if (type->type() != IDTYPE_OPAQUE)
AssociateId(state, base+3, 1, "value"); {
EnableMetaField(state, base+2, "value", type);
AssociateId(state, base+3, 1, "value");
}
// Add the iteration metamethods // Add the iteration metamethods
PushStructMethod(state, base+1, base+3, meta_struct_next); PushStructMethod(state, base+1, base+3, meta_struct_next);

@ -61,7 +61,8 @@ namespace DFHack
IDTYPE_STRUCT, IDTYPE_STRUCT,
IDTYPE_CLASS, IDTYPE_CLASS,
IDTYPE_BUFFER, IDTYPE_BUFFER,
IDTYPE_STL_PTR_VECTOR IDTYPE_STL_PTR_VECTOR,
IDTYPE_OPAQUE
}; };
typedef void *(*TAllocateFn)(void*,const void*); typedef void *(*TAllocateFn)(void*,const void*);
@ -78,7 +79,7 @@ namespace DFHack
virtual bool can_allocate() { return true; } virtual bool can_allocate() { return true; }
virtual void *do_allocate() { return do_allocate_pod(); } virtual void *do_allocate() { return do_allocate_pod(); }
virtual void do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); } virtual bool do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); return true; }
virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); } virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); }
public: public:
@ -116,7 +117,7 @@ namespace DFHack
virtual bool can_allocate() { return (allocator != NULL); } virtual bool can_allocate() { return (allocator != NULL); }
virtual void *do_allocate() { return allocator(NULL,NULL); } virtual void *do_allocate() { return allocator(NULL,NULL); }
virtual void do_copy(void *tgt, const void *src) { allocator(tgt,src); } virtual bool do_copy(void *tgt, const void *src) { return allocator(tgt,src) == tgt; }
virtual bool do_destroy(void *obj) { return allocator(NULL,obj) == obj; } virtual bool do_destroy(void *obj) { return allocator(NULL,obj) == obj; }
public: public:
virtual bool isPrimitive() { return false; } virtual bool isPrimitive() { return false; }
@ -166,7 +167,7 @@ namespace DFHack
protected: protected:
virtual bool can_allocate() { return true; } virtual bool can_allocate() { return true; }
virtual void *do_allocate() { return do_allocate_pod(); } virtual void *do_allocate() { return do_allocate_pod(); }
virtual void do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); } virtual bool do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); return true; }
virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); } virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); }
public: public:
@ -199,7 +200,7 @@ namespace DFHack
protected: protected:
virtual bool can_allocate() { return true; } virtual bool can_allocate() { return true; }
virtual void *do_allocate(); virtual void *do_allocate();
virtual void do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); } virtual bool do_copy(void *tgt, const void *src) { do_copy_pod(tgt, src); return true; }
virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); } virtual bool do_destroy(void *obj) { return do_destroy_pod(obj); }
public: public:

@ -65,6 +65,17 @@ namespace DFHack
virtual identity_type type() { return IDTYPE_PRIMITIVE; } virtual identity_type type() { return IDTYPE_PRIMITIVE; }
}; };
class DFHACK_EXPORT opaque_identity : public constructed_identity {
std::string name;
public:
opaque_identity(size_t size, TAllocateFn alloc, const std::string &name)
: constructed_identity(size, alloc), name(name) {};
virtual std::string getFullName() { return name; }
virtual identity_type type() { return IDTYPE_OPAQUE; }
};
class DFHACK_EXPORT pointer_identity : public primitive_identity { class DFHACK_EXPORT pointer_identity : public primitive_identity {
type_identity *target; type_identity *target;
@ -170,6 +181,7 @@ namespace df
{ {
using DFHack::function_identity_base; using DFHack::function_identity_base;
using DFHack::primitive_identity; using DFHack::primitive_identity;
using DFHack::opaque_identity;
using DFHack::pointer_identity; using DFHack::pointer_identity;
using DFHack::container_identity; using DFHack::container_identity;
using DFHack::ptr_container_identity; using DFHack::ptr_container_identity;
@ -488,6 +500,11 @@ namespace df
static stl_string_identity *get() { return &identity; } static stl_string_identity *get() { return &identity; }
}; };
template<> struct DFHACK_EXPORT identity_traits<std::fstream> {
static opaque_identity identity;
static opaque_identity *get() { return &identity; }
};
template<> struct DFHACK_EXPORT identity_traits<char*> { template<> struct DFHACK_EXPORT identity_traits<char*> {
static ptr_string_identity identity; static ptr_string_identity identity;
static ptr_string_identity *get() { return &identity; } static ptr_string_identity *get() { return &identity; }

@ -0,0 +1,12 @@
file_compressorst& operator=(const file_compressorst &in) {
compressed = in.compressed;
/* fstream cannot be assigned */
in_buffer = in.in_buffer;
in_buffersize = in.in_buffersize;
in_buffer_amount_loaded = in.in_buffer_amount_loaded;
in_buffer_position = in.in_buffer_position;
out_buffer = in.out_buffer;
out_buffersize = in.out_buffersize;
out_buffer_amount_written = in.out_buffer_amount_written;
return *this;
}

@ -1 +1 @@
Subproject commit 93606b34b78a94b201704adb5c9ae28af304cdb1 Subproject commit 5541b66cef283e57c32551f69cc3fd87cff966d2