X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FSerializer.hh;h=4329e6f9a0c99b615ad25c67d727379d1b41af46;hb=fdfba4553433b9b2804c2772c7645211b828c2ea;hp=7d54834fb01fb4a1e3773ef26afdfe1a8ee30511;hpb=5fa5f117f28922a7e539a432367960c1a61f837d;p=chaz%2Fyoink diff --git a/src/Moof/Serializer.hh b/src/Moof/Serializer.hh index 7d54834..4329e6f 100644 --- a/src/Moof/Serializer.hh +++ b/src/Moof/Serializer.hh @@ -40,12 +40,17 @@ #include +#include + namespace Mf { class Serializer { + class Impl; + boost::shared_ptr impl_; + public: /** @@ -95,19 +100,45 @@ 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 impl_; }; } // namespace Mf