#include <yajl/yajl_parse.h>
-#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())
{
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;
}
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;
}
std::istream* in;
bool deleteWhenDone;
- std::queue<serializable*> parsed;
+ std::queue<Serializable*> parsed;
private:
void init(std::istream& input, bool deleteIn, bool comments, bool check)
// 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;
};
-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: *************************************************/