Skip to content

Commit

Permalink
vector<int32_t> and vector<int16_t>
Browse files Browse the repository at this point in the history
this makes identity traits for these two specializations available in plugins

with this change, the `stl_vector_identity` template will be visible to plugins, but the identity objects _themselves_ will not (except for `vector<int32_t>` and `vector<int16_t>`) so any attempt to actually use a `vector` other than one of these two types or of a pointer type (which is covered elsewhere by the `vector<T*>` specialization which is exported) will result in linkage errors
  • Loading branch information
ab9rf committed Jun 6, 2024
1 parent 635f143 commit 4c562a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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());
}
29 changes: 28 additions & 1 deletion 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 @@ -657,16 +659,28 @@ namespace df
template<class T, int sz> struct identity_traits<T [sz]> {
static container_identity *get();
};
#endif

template<class T> struct identity_traits<std::vector<T> > {
static container_identity *get();
};
#endif

template<class T> struct identity_traits<std::vector<T*> > {
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 4c562a3

Please sign in to comment.