Hi all,
I don't understand why the following code does not work. I get an
unregistered class exception.
AJ
#include
#include
#include
#include
#include <string>
#include <sstream>
#include <iostream>
namespace pbb { // BEGIN NAMESPACE pbb
namespace internal { // BEGIN NAMESPACE internal
/**
* The base class for all requests to be made of a server.
*/
class server_request
{
friend class boost::serialization::access;
public:
virtual ~server_request();
virtual std::string description() = 0;
private:
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
}
};
class hello_request : public server_request
{
friend class boost::serialization::access;
public:
virtual ~hello_request();
virtual std::string description();
private:
template <typename Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & boost::serialization::base_object(*this);
}
};
} // END NAMESPACE internal
} // END NAMESPACE pbb
namespace pbb { // BEGIN NAMESPACE pbb
namespace internal { // BEGIN NAMESPACE internal
server_request::~server_request()
{
}
hello_request::~hello_request()
{
}
std::string hello_request::description()
{
return "HELLO REQUEST";
}
} // END NAMESPACE internal
} // END NAMESPACE pbb
BOOST_CLASS_EXPORT(pbb::internal::server_request);
BOOST_CLASS_EXPORT(pbb::internal::hello_request);
void msave(const pbb::internal::server_request& request,
boost::archive::text_oarchive& o)
{
o << request;
}
pbb::internal::server_request* mload(boost::archive::text_iarchive& in)
{
pbb::internal::server_request* r;
in >> r;
return r;
}
int main()
{
// Create a string stream for I/O
std::stringstream stream;
pbb::internal::server_request* request = new pbb::internal::hello_request();
// Write a server request
{
boost::archive::text_oarchive out_archive(stream);
msave(*request, out_archive);
}
// Read a server request
pbb::internal::server_request* incoming_request;
{
boost::archive::text_iarchive in_archive(stream);
incoming_request = mload(in_archive);
}
std::cout << incoming_request->description() << std::endl;
}