]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Serializer.cc
considerable refactoring
[chaz/yoink] / src / Moof / Serializer.cc
index a93eb5ab0d8ffd1e132777dcf2798854bdc1017d..570ee5a624c954cc95acd5c2e74ef50196b4a836 100644 (file)
 namespace Mf {
 
 
-class Serializer::SerializerImpl
+struct Serializer::Impl
 {
-public:
-       SerializerImpl(const std::string& filePath, const std::string& indent = "")
+       Impl(const std::string& filePath, const std::string& indent = "")
        {
                std::ofstream* output = new std::ofstream(filePath.c_str());
                init(*output, true, indent);
        }
 
-       SerializerImpl(std::ostream& output, const std::string& indent = "")
+       Impl(std::ostream& output, const std::string& indent = "")
        {
                init(output, false, indent);
        }
 
-       ~SerializerImpl()
+       ~Impl()
        {
                if (deleteWhenDone)
                {
@@ -60,18 +59,18 @@ public:
                yajl_gen_free(gen);
        }
 
-       static void throwError(yajl_gen_status err)
+       static void raise(yajl_gen_status err)
        {
                switch (err)
                {
                        case yajl_gen_generation_complete:
-                               throw Serializer::Exception("the archive has already terminated");
+                               throw Serializer::Exception(Exception::ARCHIVE_TERMINATED);
                        case yajl_gen_keys_must_be_strings:
-                               throw Serializer::Exception("map keys must be strings");
+                               throw Serializer::Exception(Exception::KEYS_MUST_BE_STRINGS);
                        case yajl_max_depth_exceeded:
-                               throw Serializer::Exception("maximum archive depth exceeded");
+                               throw Serializer::Exception(Exception::RECURSION_TOO_DEEP);
                        case yajl_gen_in_error_state:
-                               throw Serializer::Exception("serializer already in error state");
+                               throw Serializer::Exception(Exception::ALREADY_FAILED);
                        case yajl_gen_status_ok:
                                ; // There is no error here.  Move along...
                }
@@ -83,6 +82,7 @@ public:
        bool                    deleteWhenDone;
 
 private:
+
        void init(std::ostream& output, bool deleteOut, const std::string& indent)
        {
                yajl_gen_config config;
@@ -108,11 +108,11 @@ private:
 
 Serializer::Serializer(const std::string& filePath, const std::string& indent) :
        // pass through
-       impl_(new Serializer::SerializerImpl(filePath, indent)) {}
+       impl_(new Serializer::Impl(filePath, indent)) {}
 
 Serializer::Serializer(std::ostream& output, const std::string& indent) :
        // pass through
-       impl_(new Serializer::SerializerImpl(output, indent)) {}
+       impl_(new Serializer::Impl(output, indent)) {}
 
 Serializer::~Serializer()
 {
@@ -123,30 +123,26 @@ Serializer::~Serializer()
 void Serializer::push(long value)
 {
        yajl_gen_status stat = yajl_gen_integer(impl_->gen, value);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::push(double value)
 {
        yajl_gen_status stat = yajl_gen_double(impl_->gen, value);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::push(bool value)
 {
        yajl_gen_status stat = yajl_gen_bool(impl_->gen, value);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::push(const std::string& value)
 {
        yajl_gen_status stat = yajl_gen_string(impl_->gen,
                        (const unsigned char*)value.c_str(), value.length());
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::push(const std::wstring& value)
@@ -157,37 +153,32 @@ void Serializer::push(const std::wstring& value)
 void Serializer::pushNull()
 {
        yajl_gen_status stat = yajl_gen_null(impl_->gen);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 
 void Serializer::pushMapHead()
 {
        yajl_gen_status stat = yajl_gen_map_open(impl_->gen);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::pushMapTail()
 {
        yajl_gen_status stat = yajl_gen_map_close(impl_->gen);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::pushArrayHead()
 {
        yajl_gen_status stat = yajl_gen_array_open(impl_->gen);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 void Serializer::pushArrayTail()
 {
        yajl_gen_status stat = yajl_gen_array_close(impl_->gen);
-       if (stat != yajl_gen_status_ok)
-               Serializer::SerializerImpl::throwError(stat);
+       if (stat != yajl_gen_status_ok) Serializer::Impl::raise(stat);
 }
 
 
This page took 0.024021 seconds and 4 git commands to generate.