Я хочу сериализовать дерево с boost :: serialization.
У меня есть класс "cexp_node", который выглядит примерно так:
class cexp_node{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned in version)
{
ar & id;
ar & children;
ar & parent;
ar & isSelected;
}
uint32_t id;
std::map<uint32_t, boost::shared_ptr<cexp_node>> children;
boost::shared_ptr<cexp_node> parent;
bool isSelected;
}
И класс cexp_leaf:
class cexp_leaf: public cexp_node {
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<cexp_node>(*this);
ar & additionalId;
}
std::string additionalId;
}
И дерево:
class cexp_tree{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & root;
ar & leaves;
}
boost::shared_ptr<cexp_node> root;
std::map<uint32_t, boost::weak_ptr<cexp_leaf>> leaves;
}
В дереве есть член листья , который содержит указатели на все листья дерева.
Вот как я заполняю свое дерево (эта функция вызывается для каждого листа):
void cexp_tree::parseNodeMembershipsIntoCexpTree(boost::shared_ptr<cexp_node> node,
uint32_t level,
std::list<std::string> const& names,
std::vector<uint32_t> const& level2OtherId){
if(level==level2community.size()){ //leaf
for(const std::string & name : names){
auto newleaf = boost::make_shared<cexp_leaf>(name, node->getId(), node->getOtherId(), node);
boost::weak_ptr<cexp_leaf> newleaf2 = newleaf;
uint32_t key = someHashFunktion(name);
node->getChildren()[key]= newleaf;
this->cmpsInLeaves[key] = newleaf2;
}
}else{ //inner-node
uint32_t otherID {level2OtherId.at(level)};
uint32_t ID {node->getChildren().size()};
auto iter {node->getChildren().lower_bound(otherID)};
if(iter != node->getChildren().end() && !(node->getChildren().key_comp()(communityID, iter->first)) && !(node->getChildren().empty())){
cexp_tree::parseNodeMembershipsIntoCexpTree(iter->second, level+1, names, level2OtherId);
}else{
auto newNode =boost::make_shared<cexp_node>(otherID, ID, node);
node->getChildren().emplace(otherID, newNode);
iter = node->getChildren().find(otherID);
cexp_tree::parseNodeMembershipsIntoCexpTree(iter->second, level+1, names, level2OtherId);
}
}
}
Теперь, когда я сериализую cexp_tree , я получаю повышение :: archive :: archive_exception, что (): конфликт указателей.
Более конкретно, я получаю этоисключение, когда я пытаюсь сериализовать cexp_tree :: leaves . Когда я исключаю cexp_tree :: leaves из сериализации, все остальное прекрасно работает для остальной части дерева.
Кто-нибудь может помочь? Заранее спасибо!