#include <boost/shared_ptr.hpp>
+#include <Moof/Exception.hh>
+
namespace Mf {
class Serializer
{
+ class Impl;
+ boost::shared_ptr<Impl> impl_;
+
public:
/**
void flush();
+
/**
* This exception is thrown for serializer-related exceptional errors.
*/
- struct Exception : std::runtime_error
+ struct Exception : public Mf::Exception
{
- explicit Exception(const std::string& what_arg) :
- std::runtime_error(what_arg) {}
+ enum
+ {
+ ARCHIVE_TERMINATED = 1024,
+ KEYS_MUST_BE_STRINGS = 1025,
+ RECURSION_TOO_DEEP = 1026,
+ ALREADY_FAILED = 1027,
+ };
+
+ explicit Exception(unsigned error) :
+ Mf::Exception(error) {}
+
+ void raise()
+ {
+ throw *this;
+ }
+
+ const char* what() const throw()
+ {
+ switch (code)
+ {
+ case ARCHIVE_TERMINATED:
+ return "archive is already terminated";
+ case KEYS_MUST_BE_STRINGS:
+ return "map keys must be strings";
+ case RECURSION_TOO_DEEP:
+ return "generator recursion too deep";
+ case ALREADY_FAILED:
+ return "generator already errored out";
+ }
+ return Mf::Exception::what();
+ }
};
-
-private:
- class SerializerImpl;
- boost::shared_ptr<SerializerImpl> impl_;
};
} // namespace Mf