Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/angavrilov/dfhack into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
quietust committed Oct 8, 2014
2 parents eed684a + 6046d68 commit cdcc0d2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
5 changes: 1 addition & 4 deletions library/DataDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ void *type_identity::allocate() {

bool type_identity::copy(void *tgt, const void *src) {
if (can_allocate() && tgt && src)
{
do_copy(tgt, src);
return true;
}
return do_copy(tgt, src);
else
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions library/DataStaticsFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ namespace df {
stl_bit_vector_identity identity_traits<std::vector<bool> >::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;

#undef NUMBER_IDENTITY_TRAITS
Expand Down
7 changes: 5 additions & 2 deletions library/LuaTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,11 @@ static void MakePrimitiveMetatable(lua_State *state, type_identity *type)
// Index the fields
lua_newtable(state);

EnableMetaField(state, base+2, "value", type);
AssociateId(state, base+3, 1, "value");
if (type->type() != IDTYPE_OPAQUE)
{
EnableMetaField(state, base+2, "value", type);
AssociateId(state, base+3, 1, "value");
}

// Add the iteration metamethods
PushStructMethod(state, base+1, base+3, meta_struct_next);
Expand Down
11 changes: 6 additions & 5 deletions library/include/DataDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ namespace DFHack
IDTYPE_STRUCT,
IDTYPE_CLASS,
IDTYPE_BUFFER,
IDTYPE_STL_PTR_VECTOR
IDTYPE_STL_PTR_VECTOR,
IDTYPE_OPAQUE
};

typedef void *(*TAllocateFn)(void*,const void*);
Expand All @@ -78,7 +79,7 @@ namespace DFHack

virtual bool can_allocate() { return true; }
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); }

public:
Expand Down Expand Up @@ -116,7 +117,7 @@ namespace DFHack

virtual bool can_allocate() { return (allocator != 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; }
public:
virtual bool isPrimitive() { return false; }
Expand Down Expand Up @@ -166,7 +167,7 @@ namespace DFHack
protected:
virtual bool can_allocate() { return true; }
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); }

public:
Expand Down Expand Up @@ -199,7 +200,7 @@ namespace DFHack
protected:
virtual bool can_allocate() { return true; }
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); }

public:
Expand Down
17 changes: 17 additions & 0 deletions library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ namespace DFHack
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 {
type_identity *target;

Expand Down Expand Up @@ -170,6 +181,7 @@ namespace df
{
using DFHack::function_identity_base;
using DFHack::primitive_identity;
using DFHack::opaque_identity;
using DFHack::pointer_identity;
using DFHack::container_identity;
using DFHack::ptr_container_identity;
Expand Down Expand Up @@ -488,6 +500,11 @@ namespace df
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*> {
static ptr_string_identity identity;
static ptr_string_identity *get() { return &identity; }
Expand Down
12 changes: 12 additions & 0 deletions library/include/df/custom/file_compressorst.methods.inc
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit cdcc0d2

Please sign in to comment.