Last active
June 20, 2017 08:06
-
-
Save vigsterkr/6b557ad7f4b23280980f7507e79cdbad to your computer and use it in GitHub Desktop.
how to fix serialization of std::vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
virtual void load_serializable_post() throw (ShogunException) | |
{ | |
CSGObject::load_serializable_post(); | |
m_array.assign(m_array_content, m_array_content+num_elements); | |
SG_FREE(m_array_content); | |
m_array.shrink_to_fit(); | |
} | |
/** Can (optionally) be overridden to pre-initialize some member | |
* variables which are not PARAMETER::ADD'ed. Make sure that at | |
* first the overridden method BASE_CLASS::SAVE_SERIALIZABLE_PRE | |
* is called. | |
* | |
* @exception ShogunException Will be thrown if an error | |
* occurres. | |
*/ | |
virtual void save_serializable_pre() throw (ShogunException) | |
{ | |
CSGObject::save_serializable_pre(); | |
m_array.shrink_to_fit(); | |
m_array_content = m_array.data(); | |
} | |
private: | |
/** register parameters */ | |
virtual void init() | |
{ | |
set_generic<T>(); | |
m_parameters->add_vector(&m_array_content, &num_elements, "array", | |
"Memory for dynamic array."); | |
SG_ADD( | |
&free_array, "free_array", "whether array must be freed", | |
MS_NOT_AVAILABLE); | |
SG_ADD(&dim1_size, "dim1_size", "Dimension 1", MS_NOT_AVAILABLE); | |
SG_ADD(&dim2_size, "dim2_size", "Dimension 2", MS_NOT_AVAILABLE); | |
SG_ADD(&dim3_size, "dim3_size", "Dimension 3", MS_NOT_AVAILABLE); | |
} | |
protected: | |
/** underlying array */ | |
std::vector<T> m_array; | |
T* m_array_content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment