Hi everybody.I'm having problems understanding the Boost::Serialization library.
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <utility>
#include "FileSystem.h"
#include "fstypes.h"
#include "fsFile.h "
#include "fsFileChunk.h"
#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
using namespace std;
int main(int argc, char *argv[])
{
// string s1 = Path::normalizePath(" http://asdfasd/fasdfa//asdf//");
string fsPath = "./fsImage";
FileSystem_NS * const fs = new FileSystem_NS(fsPath);
fileId_t fid = ++(*fs).nextFileId;
fsFile_Ptr ff(new fsFile(fid));
(*fs).files.insert(pair<string, fsFile_Ptr>("biomynd",ff));
chunkVersion_t cv = 1;
size_t cs = 67108864;
fsFileChunk_Ptr fc(new fsFileChunk(++(*fs).nextChunkId, (*ff).fID, cv, cs));
ff->addChunk(fc);
ofstream ofs("./fsImage");
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << (const FileSystem_NS)(*fs);
// archive and stream closed when destructors are called
}
ofs.close();
FileSystem_NS const *newFilesystem = new FileSystem_NS("lol");
ifstream ifs("./fsImage");
{
// open the archive
boost::archive::text_iarchive ia(ifs);
// restore the schedule from the archive
ia >> (*newFilesystem);
}
ifs.close();
cout << fs->fsImage_Path << endl;
return EXIT_SUCCESS;
}
/************************************************************************
FileSystem.h - Copyright Hannes Baldursson
**************************************************************************/
#ifndef FILESYSTEM_H
#define FILESYSTEM_H
#include "fstypes.h"
#include "fsFile.h"
#include "fsFileChunk.h"
#include <string>
#include <map>
#include <vector>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serializati
#ifdef HAVE_CONFIG_H
#include < config.h>
#endif
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <utility>
#include "FileSystem.h"
#include "fstypes.h"
#include " fsFile.h"
#include "fsFileChunk.h"
#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
using namespace std;
int main(int argc, char *argvon/tracking.hpp>
#include <boost/shared_ptr.hpp>
using namespace std;
// Filesystem namespace
class FileSystem_NS
{
public:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const {
ar & nextFileId;
ar & nextChunkId;
ar & files;
}
fileId_t nextFileId;
chunkId_t nextChunkId;
const string fsImage_Path;
FileSystem_NS(string fsImage = "./fsImage");
map<string, fsFile_Ptr> files; // Maps filenames to fileIds
};
BOOST_CLASS_TRACKING(FileSystem_NS, boost::serialization::track_always)
#endif // FILESYSTEM_H
#ifndef FSFILE_H
#define FSFILE_H
#include <string>
#include <map>
#include "fstypes.h"
#include "fsFileChunk.h"
#include <boost/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
using namespace std;
class fsFile {
public:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const
{
ar & fname;
ar & fID;
ar & chunks;
}
string fname;
fileId_t fID;
vector<fsFileChunk_Ptr> chunks;
// Create a fsFile
fsFile(fileId_t fileID);
void addChunk(fsFileChunk_Ptr ptr);
};
typedef boost::shared_ptr<fsFile> fsFile_Ptr;
BOOST_CLASS_TRACKING(fsFile, boost::serialization::track_always)
#endif
#ifndef FSFILE_CHUNK_H
#define FSFILE_CHUNK_H
#include <vector>
#include <string>
#include "fstypes.h"
#include <boost/shared_ptr.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
using namespace std;
class fsFileChunk {
public:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) const {
ar & cID;
ar & fID;
ar & cVersion;
ar & cSize;
}
chunkId_t cID;
fileId_t fID; // This chunk belongs to file "fileID"
chunkVersion_t cVersion; // Current version
size_t cSize;
std::vector<string> hosts; // vector of hostIP:port for the datanodes that host this chunk.
fsFileChunk(chunkId_t chunkID, fileId_t fileID, chunkVersion_t chunkVersion, size_t chunkSize);
};
typedef boost::shared_ptr<fsFileChunk> fsFileChunk_Ptr;
BOOST_CLASS_TRACKING(fsFileChunk, boost::serialization::track_always)
#endif // FSFILE_CHUNK_H
#ifndef COMMON_FSTYPES_H
#define COMMON_FSTYPES_H
#include <stdint.h>
typedef unsigned long long fileId_t;
typedef unsigned long long chunkId_t;
typedef unsigned int chunkVersion_t;
#endif
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/istream:231: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/home/hannson/Projects/HDFS/src/boost/serialization/access.hpp: In static member function 'static void boost::serialization::access::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile> > > >]':
/home/hannson/Projects/HDFS/src/boost/serialization/serialization.hpp:81: instantiated from 'void boost::serialization::serialize(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile> > > >]'
/home/hannson/Projects/HDFS/src/boost/serialization/serialization.hpp:140: instantiated from 'void boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with Archive = boost::archive::text_iarchive, T = const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile> > > >]'
/home/hannson/Projects/HDFS/src/boost/archive/detail/iserializer.hpp:158: instantiated from 'void boost::archive::detail::iserializer<Archive, T>::load_object_data(boost::archive::detail::basic_iarchive&, void*, unsigned int) const [with Archive = boost::archive::text_iarchive, T = const std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile> > > >]'
/home/hannson/Projects/HDFS/src/hdfs.cpp:70: instantiated from here
/home/hannson/Projects/HDFS/src/boost/serialization/access.hpp:109: error: 'const class std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::shared_ptr<fsFile>, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<ch