Skip to content

Commit

Permalink
Merge pull request #4676 from ab9rf/vector-identities
Browse files Browse the repository at this point in the history
`vector<int32_t>` and `vector<int16_t>`
  • Loading branch information
myk002 authored Jun 6, 2024
2 parents d040a3f + 7b55030 commit 9d21275
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/DataIdentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ namespace df {
OPAQUE_IDENTITY_TRAITS(std::weak_ptr<df::widget_container>);

buffer_container_identity buffer_container_identity::base_instance;

DFHACK_EXPORT stl_container_identity<std::vector<int32_t> > stl_vector_int32_t_identity("vector", identity_traits<int32_t>::get());
DFHACK_EXPORT stl_container_identity<std::vector<int16_t> > stl_vector_int16_t_identity("vector", identity_traits<int16_t>::get());
}
27 changes: 27 additions & 0 deletions library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ namespace df
return ((uint8_t*)ptr) + idx * item->byte_size();
}
};
#endif

template<class T>
class stl_container_identity : public container_identity {
Expand Down Expand Up @@ -406,6 +407,7 @@ namespace df
}
};

#ifdef BUILD_DFHACK_LIB
template<class T>
class ro_stl_container_identity : public container_identity {
protected:
Expand Down Expand Up @@ -667,6 +669,18 @@ namespace df
static stl_ptr_vector_identity *get();
};

// explicit specializations for these two types
// for availability in plugins

template<> struct identity_traits<std::vector<int32_t> > {
static container_identity* get();
};

template<> struct identity_traits<std::vector<int16_t> > {
static container_identity* get();
};


#ifdef BUILD_DFHACK_LIB
template<class T> struct identity_traits<std::deque<T> > {
static container_identity *get();
Expand Down Expand Up @@ -739,6 +753,19 @@ namespace df
return &identity;
}

// explicit specializations for these two types
// for availability in plugins

extern DFHACK_EXPORT stl_container_identity<std::vector<int32_t> > stl_vector_int32_t_identity;
inline container_identity* identity_traits<std::vector<int32_t> >::get() {
return &stl_vector_int32_t_identity;
}

extern DFHACK_EXPORT stl_container_identity<std::vector<int16_t> > stl_vector_int16_t_identity;
inline container_identity* identity_traits<std::vector<int16_t> >::get() {
return &stl_vector_int16_t_identity;
}

#ifdef BUILD_DFHACK_LIB
template<class T>
inline container_identity *identity_traits<std::deque<T> >::get() {
Expand Down

0 comments on commit 9d21275

Please sign in to comment.