Skip to content

Commit 4c562a3

Browse files
committed
vector<int32_t> and vector<int16_t>
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
1 parent 635f143 commit 4c562a3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

library/DataIdentity.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ namespace df {
5858
OPAQUE_IDENTITY_TRAITS(std::weak_ptr<df::widget_container>);
5959

6060
buffer_container_identity buffer_container_identity::base_instance;
61+
62+
DFHACK_EXPORT stl_container_identity<std::vector<int32_t> > stl_vector_int32_t_identity("vector", identity_traits<int32_t>::get());
63+
DFHACK_EXPORT stl_container_identity<std::vector<int16_t> > stl_vector_int16_t_identity("vector", identity_traits<int16_t>::get());
6164
}

library/include/DataIdentity.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ namespace df
370370
return ((uint8_t*)ptr) + idx * item->byte_size();
371371
}
372372
};
373+
#endif
373374

374375
template<class T>
375376
class stl_container_identity : public container_identity {
@@ -406,6 +407,7 @@ namespace df
406407
}
407408
};
408409

410+
#ifdef BUILD_DFHACK_LIB
409411
template<class T>
410412
class ro_stl_container_identity : public container_identity {
411413
protected:
@@ -657,16 +659,28 @@ namespace df
657659
template<class T, int sz> struct identity_traits<T [sz]> {
658660
static container_identity *get();
659661
};
662+
#endif
660663

661664
template<class T> struct identity_traits<std::vector<T> > {
662665
static container_identity *get();
663666
};
664-
#endif
665667

666668
template<class T> struct identity_traits<std::vector<T*> > {
667669
static stl_ptr_vector_identity *get();
668670
};
669671

672+
// explicit specializations for these two types
673+
// for availability in plugins
674+
675+
template<> struct identity_traits<std::vector<int32_t> > {
676+
static container_identity* get();
677+
};
678+
679+
template<> struct identity_traits<std::vector<int16_t> > {
680+
static container_identity* get();
681+
};
682+
683+
670684
#ifdef BUILD_DFHACK_LIB
671685
template<class T> struct identity_traits<std::deque<T> > {
672686
static container_identity *get();
@@ -739,6 +753,19 @@ namespace df
739753
return &identity;
740754
}
741755

756+
// explicit specializations for these two types
757+
// for availability in plugins
758+
759+
extern DFHACK_EXPORT stl_container_identity<std::vector<int32_t> > stl_vector_int32_t_identity;
760+
inline container_identity* identity_traits<std::vector<int32_t> >::get() {
761+
return &stl_vector_int32_t_identity;
762+
}
763+
764+
extern DFHACK_EXPORT stl_container_identity<std::vector<int16_t> > stl_vector_int16_t_identity;
765+
inline container_identity* identity_traits<std::vector<int16_t> >::get() {
766+
return &stl_vector_int16_t_identity;
767+
}
768+
742769
#ifdef BUILD_DFHACK_LIB
743770
template<class T>
744771
inline container_identity *identity_traits<std::deque<T> >::get() {

0 commit comments

Comments
 (0)