Boost Serialization of Generic class with derived classes in list c++

0

I'm working on program with really simple business logi, there is link to github: https://github.com/Anakinud/OOPStudiesProject.git.

Problem is, I want to serialize state of all of three managers, every one uses generic Repository(substitute of SQL database). When I want to serialize data i PaymentManager:

void PaymentManager::SaveState() {
    _paymentRepo->SaveRepo("Payments.txt");
}

Payment has shared_ptr and shared_ptr which are serialized as follow:

template <class Archive>
void Payment::serialize(Archive &ar, const unsigned int version) {
// serialize the data members of Person class
  ar & _id; //string
  ar & _sender; //shared_ptr<Client>
  ar & _recipient; //shared_ptr<Nanny>
  ar & _paymentDate; //boost:gregorian::date;
  ar & _amount; //int
}

Serialization works only in ClientManager, code of seialization Client::serialize:

template <class Archive>
void Client::serialize(Archive &ar, const unsigned int version) {
    // serialize the data members of Person class
    ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Person);
    ar & _address & _employedNanny;
}

And Nanny serialization:

template <class Archive>
void Nanny::serialize(Archive &ar, const unsigned int version) {
    // serialize the data members of Person class
    ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Person);
    ar & _client;
    ar & _nannyType;
    ar & _startDate;
}

To formalize serialization in Repository:

template<class Archive>
void serialize(Archive &ar, const unsigned int version) {
    ar.template register_type<T>();
    ar & _objectsList;
}

And I call PaymentManager::SaveState in tests, when serialization throws exception with info:

fatal error: in "PaymentManagerTesting/SaveData": boost::archive::archive_exception: unregistered class - derived class not registered or exported

When NannyManager fails because of

fatal error: in "NannyTesting/SaveData": memory access violation at address: 0x00000049: no mapping at fault address /home/pobi/elo/Niania/biblioteka/test/NannyManagerTest.cpp(89): last checkpoint: "SaveData" entry.

I don't have any idea why it works with CLientManager but do not with PaymentManager or NannyManager.

c++
generics
serialization
boost
derived-class
asked on Stack Overflow Jan 14, 2018 by Kacper • edited Jan 19, 2018 by Kacper

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0