I have gotten cereal to work previously so I am copy and pasting furiously, but of no avail. I simply cannot see the difference. The following works perfectly (following the cereal manual):
Serialization handler (the serializer includes all the headers of the bois he shall serialize):
#include <filesystem>
#include <config.h>
#include <cereal/archives/binary.hpp>
#include <cereal/types/vector.hpp>
#include <cereal/types/string.hpp>
#include <cereal/access.hpp>
#include <fstream>
class Serialize
{
public:
template<typename T>
static void ExportData(int &ec, T &object, const std::string &filename){
std::string path = std::filesystem::current_path() /= filename;
std::ofstream ofs(path);
if(ofs.is_open()){
cereal::BinaryOutputArchive oarchive(ofs);
oarchive(object);
ofs.close();
}
else
ec = Error::Log(2, "Serialize", __func__, "File " + path + " for deserialization could not be opened");
};
template<typename T>
static void ImportData(int &ec, T &object, const std::string &filename){
std::string path = std::filesystem::current_path() /= filename;
std::ifstream ifs(path);
if(ifs.is_open()){
cereal::BinaryInputArchive iarchive(ifs);
iarchive(object);
ifs.close();
}
else
ec = Error::Log(1, "Serialize", __func__, "File " + path + " for serialization could not be opened");
};
Data class (template reference T, this one works like a charm):
#include <cereal/access.hpp>
class FileTransfer : public QObject
{
Q_OBJECT
public:
typedef struct {
int iterations;
int iterations_without_size_chg;
float total_size;
float runtime;
std::vector<std::string> paths;
std::vector<float> sizes;
} Folders;
private:
Folders folders_ { 0, 0, 0, 0, 0, 0, 0, 0, {}, {} };
friend class cereal::access;
template<class Archive>
void save(Archive &ar) const { ar(folders_.paths); };
template<class Archive>
void load(Archive &ar){ ar(last_transfer_list_); }
};
The other class will not work with the serialize class:
#pragma once
#include <QObject>
#include <QDir>
#include <vector>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <error.h>
#include <cereal/access.hpp>
class Config : public QObject
{
Q_OBJECT
public:
typedef struct{
std::vector<std::string> tokens;
std::vector<std::string> values;
} Params;
private:
struct{
bool avoid_last_file_list = false;
bool pls = tru
} data_;
friend class cereal::access;
template<class Archive>
void save(Archive &ar) const { ar(data_); };
template<class Archive>
void load(Archive &ar){ ar(data_); }
};
The latter always gives me the compile error:
ArchiveType & processImpl(T const &)
{
static_assert(traits::detail::count_output_serializers<T, ArchiveType>::value != 0,
"cereal could not find any output serialization functions for the provided type and archive combination. \n\n "
"Types must either have a serialize function, load/save pair, or load_minimal/save_minimal pair (you may not mix these). \n "
"Serialize functions generally have the following signature: \n\n "
"template<class Archive> \n "
" void serialize(Archive & ar) \n "
" { \n "
" ar( member1, member2, member3 ); \n "
" } \n\n " );
Either I am too stupid or there is no difference. I tried switchting out includes like a mad man, typing the serial data otherwise etc. etc. Dunno what to do.
Aucun commentaire:
Enregistrer un commentaire