X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FDeserializer.cc;fp=src%2Fdeserializer.cc;h=8bf230fe68627054e225fd54aa8b48ad9f15a1aa;hp=929c3c12183fdf3c5f10ccee3cbb6e09a7a065ea;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/deserializer.cc b/src/Moof/Deserializer.cc similarity index 66% rename from src/deserializer.cc rename to src/Moof/Deserializer.cc index 929c3c1..8bf230f 100644 --- a/src/deserializer.cc +++ b/src/Moof/Deserializer.cc @@ -31,30 +31,30 @@ #include -#include "serializable.hh" -#include "deserializer.hh" +#include "Deserializer.hh" +#include "Serializable.hh" -namespace dc { +namespace Mf { -class deserializer::deserializer_impl +class Deserializer::DeserializerImpl { public: - deserializer_impl(const std::string& filePath, bool comments = false, + DeserializerImpl(const std::string& filePath, bool comments = false, bool check = false) { std::ifstream* input = new std::ifstream(filePath.c_str()); init(*input, true, comments, check); } - deserializer_impl(std::istream& input, bool comments = false, + DeserializerImpl(std::istream& input, bool comments = false, bool check = false) { init(input, false, comments, check); } - ~deserializer_impl() + ~DeserializerImpl() { while (!parsed.empty()) { @@ -71,49 +71,49 @@ public: void throwError() { - unsigned char* errorMsg = yajl_get_error(hand, 0, 0, 0); - deserializer::exception problem((char*)errorMsg); - yajl_free_error(hand, errorMsg); - throw problem; + unsigned char* errorStr = yajl_get_error(hand, 0, 0, 0); + Deserializer::Exception exception((char*)errorStr); + yajl_free_error(hand, errorStr); + throw exception; } static int parsedNull(void* ctx) { - ((deserializer_impl*)ctx)->parsed.push(new null); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableNull); return 1; } static int parsedBoolean(void* ctx, int value) { - ((deserializer_impl*)ctx)->parsed.push(new wrapped_boolean(value)); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableBoolean(value)); return 1; } static int parsedInteger(void* ctx, long value) { - ((deserializer_impl*)ctx)->parsed.push(new wrapped_integer(value)); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableInteger(value)); return 1; } static int parsedFloat(void* ctx, double value) { - ((deserializer_impl*)ctx)->parsed.push(new wrapped_real(value)); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableReal(value)); return 1; } static int parsedString(void* ctx, const unsigned char* value, unsigned length) { - wrapped_string* parsed = new wrapped_string(std::string((char*)value, - length)); - ((deserializer_impl*)ctx)->parsed.push(parsed); + SerializableString* parsed = + new SerializableString(std::string((char*)value, length)); + ((DeserializerImpl*)ctx)->parsed.push(parsed); return 1; } static int parsedBeginMap(void* ctx) { - ((deserializer_impl*)ctx)->parsed.push(new wrapped_dictionary); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableMap); return 1; } @@ -126,19 +126,19 @@ public: static int parsedEndMap(void* ctx) { - ((deserializer_impl*)ctx)->parsed.push(0); + ((DeserializerImpl*)ctx)->parsed.push(0); return 1; } static int parsedBeginArray(void* ctx) { - ((deserializer_impl*)ctx)->parsed.push(new wrapped_array); + ((DeserializerImpl*)ctx)->parsed.push(new SerializableArray); return 1; } static int parsedEndArray(void* ctx) { - ((deserializer_impl*)ctx)->parsed.push(0); + ((DeserializerImpl*)ctx)->parsed.push(0); return 1; } @@ -177,7 +177,7 @@ public: std::istream* in; bool deleteWhenDone; - std::queue parsed; + std::queue parsed; private: void init(std::istream& input, bool deleteIn, bool comments, bool check) @@ -186,17 +186,17 @@ private: // internal data structures but rather keeps a pointer to this static const yajl_callbacks callbacks = { - deserializer_impl::parsedNull, - deserializer_impl::parsedBoolean, - deserializer_impl::parsedInteger, - deserializer_impl::parsedFloat, + DeserializerImpl::parsedNull, + DeserializerImpl::parsedBoolean, + DeserializerImpl::parsedInteger, + DeserializerImpl::parsedFloat, 0, - deserializer_impl::parsedString, - deserializer_impl::parsedBeginMap, - deserializer_impl::parsedMapKey, - deserializer_impl::parsedEndMap, - deserializer_impl::parsedBeginArray, - deserializer_impl::parsedEndArray + DeserializerImpl::parsedString, + DeserializerImpl::parsedBeginMap, + DeserializerImpl::parsedMapKey, + DeserializerImpl::parsedEndMap, + DeserializerImpl::parsedBeginArray, + DeserializerImpl::parsedEndArray }; in = &input; @@ -208,46 +208,46 @@ private: }; -deserializer::deserializer(const std::string& filePath, bool comments, +Deserializer::Deserializer(const std::string& filePath, bool comments, bool check) : // pass through - impl(new deserializer::deserializer_impl(filePath, comments, check)) {} + impl_(new Deserializer::DeserializerImpl(filePath, comments, check)) {} -deserializer::deserializer(std::istream& input, bool comments, bool check) : +Deserializer::Deserializer(std::istream& input, bool comments, bool check) : // pass through - impl(new deserializer::deserializer_impl(input, comments, check)) {} + impl_(new Deserializer::DeserializerImpl(input, comments, check)) {} -serializable_ptr deserializer::deserialize() +SerializablePtr Deserializer::deserialize() { - serializable* ptr = pullNext(); + Serializable* ptr = pullNext(); if (ptr) { ptr->deserialize(*this); } - return serializable_ptr(ptr); + return SerializablePtr(ptr); } -serializable* deserializer::pullNext() +Serializable* Deserializer::pullNext() { - impl->parse(); - if (!impl->parsed.empty()) + impl_->parse(); + if (!impl_->parsed.empty()) { - serializable* ptr = impl->parsed.front(); + Serializable* ptr = impl_->parsed.front(); return ptr; } return 0; } -void deserializer::pop() +void Deserializer::pop() { // pass through - impl->parsed.pop(); + impl_->parsed.pop(); } -} // namespace dc +} // namespace Mf /** vim: set ts=4 sw=4 tw=80: *************************************************/