20 #ifndef jsonserial_vector_hpp
21 #define jsonserial_vector_hpp
23 namespace jsonserial {
25 template <
class T,
class Alloc>
26 struct is_std_vector<std::vector<T,Alloc>> : std::true_type {};
28 template <
class Alloc>
29 struct is_std_vector<std::vector<bool,Alloc>> : std::true_type {};
32 struct JSonArrayImpl<T, typename std::enable_if<is_std_vector<T>::value>::type>
34 struct Ptr {
size_t index; JObjectPtr* jsp;};
36 JSonArrayImpl(T& cont) : cont_(cont) {cont_.clear();}
38 void add(JSonSerial& js, JSonClass::Creator* cr, JKString& s)
override {
39 cont_.resize(cont_.size()+1);
41 readArrayValue(js, cont_.back(), objptr, cr, s);
43 if (objptr && objptr->init_) pointers_.push_back(Ptr{cont_.size()-1, objptr});
46 void end(JSonSerial&)
override {
47 cont_.shrink_to_fit();
48 if (pointers_.size() > 1) fixPointers<T>(cont_, pointers_);
52 static void fixPointers(
typename std::enable_if<!is_smart_ptr<typename C::value_type>::value,C>::type &,
53 std::vector<Ptr> &) {}
56 static void fixPointers(
typename std::enable_if<is_smart_ptr<typename C::value_type>::value,C>::type & cont,
57 std::vector<Ptr> & pointers) {
58 for (
auto& it : pointers) it.jsp->shared_ = &cont[it.index];
61 std::vector<Ptr> pointers_;