I'm using SFML and cereal to serialize/deserialize data and I want to do that for sf::vector2
and sf::vector3
class:
Data.h
#include <SFML\System.hpp>
#include <fstream>
#include <iostream>
#include "cereal-1.2.2\include\cereal\archives\xml.hpp"
#include "cereal-1.2.2\include\cereal\types\map.hpp"
struct DataInfo {
map<string, sf::Vector2f> vector2FloatData;
map<string, sf::Vector3f> vector3FloatData;
map<string, sf::Vector2i> vector2IntData;
map<string, sf::Vector3i> vector3IntData;
template <class Archive>
void serialize(Archive & ar)
{
ar(vector2FloatData, vector3FloatData, vector2IntData, vector3IntData);
}
};
main.cpp
int Main()
{
std::ofstream file("Test.xml");
cereal::XMLOutputArchive archive(file);
DataInfo data;
archive(data);
return 0;
}
But cereal doesn't know what are sf::vectors
and i get the following error:
Error C2338 cereal could not find any output serialization functions for the provided type and archive combination.
I know that exist CEREAL_REGISTER_TYPE()
but i don't know how to make it work.
Adding to Data.h:
#include "cereal-1.2.2\include\cereal\types\polymorphic.hpp"
CEREAL_REGISTER_TYPE(sf::Vector2f)
CEREAL_REGISTER_TYPE(sf::Vector3f)
CEREAL_REGISTER_TYPE(sf::Vector2i)
CEREAL_REGISTER_TYPE(sf::Vector3i)
I get this error:
Error C2338 Attempting to register non polymorphic type.
Any idea?
Thanks.