Skip to content
Snippets Groups Projects
Commit 11bba97b authored by Ramin Yaghoubzadeh Torky's avatar Ramin Yaghoubzadeh Torky
Browse files

Porting to json, work in progress

parent 43603d85
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,8 @@
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2015 Sociable Agents Group
* Copyright (c) 2009-2015 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
......@@ -30,8 +31,8 @@
* Excellence Initiative.
*/
#ifndef __IPAACA_JSON_H__
#define __IPAACA_JSON_H__
#ifndef __ipaaca_json_H__
#define __ipaaca_json_H__
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
......
......@@ -38,9 +38,47 @@
#error "Please do not include this file directly, use ipaaca.h instead"
#endif
IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
{
protected:
//IPAACA_MEMBER_VAR_EXPORT rapidjson::Document* _json_parent_node;
//IPAACA_MEMBER_VAR_EXPORT rapidjson::Document* _json_node;
IPAACA_MEMBER_VAR_EXPORT Payload* _payload;
IPAACA_MEMBER_VAR_EXPORT std::string _key;
public:
IPAACA_HEADER_EXPORT PayloadEntryProxy(Payload* payload, const std::string& key);
IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(const std::string& value);
IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(const char* value);
IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(double value);
IPAACA_HEADER_EXPORT PayloadEntryProxy& operator=(bool value);
IPAACA_HEADER_EXPORT operator std::string();
IPAACA_HEADER_EXPORT operator long();
IPAACA_HEADER_EXPORT operator double();
IPAACA_HEADER_EXPORT operator bool();
IPAACA_HEADER_EXPORT std::string to_str();
//long to_int() { return operator long(); ;
IPAACA_HEADER_EXPORT long to_long();
IPAACA_HEADER_EXPORT double to_float();
IPAACA_HEADER_EXPORT bool to_bool();
// getters
IPAACA_HEADER_EXPORT template<typename T> T get(); // specializations below
// setters
};
// Available interpretations of payload entries (or children thereof) below.
// Usage of standard complex data structures (vector etc.) currently entails
// casting all entries to a uniform type (a-priori choice: std::string).
IPAACA_HEADER_EXPORT template<> long PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> double PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> bool PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> std::string PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> std::vector<std::string> PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> std::list<std::string> PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> std::map<std::string, std::string> PayloadEntryProxy::get();
//}}}
IPAACA_HEADER_EXPORT class PayloadEntryProxy//{{{
/*
IPAACA_HEADER_EXPORT class LegacyStringPayloadEntryProxy//{{{
{
protected:
IPAACA_MEMBER_VAR_EXPORT Payload* _payload;
......@@ -76,6 +114,7 @@ IPAACA_HEADER_EXPORT template<> std::list<std::string> PayloadEntryProxy::get();
IPAACA_HEADER_EXPORT template<> std::map<std::string, std::string> PayloadEntryProxy::get();
//}}}
*/
IPAACA_HEADER_EXPORT class Payload//{{{
{
......@@ -90,7 +129,8 @@ IPAACA_HEADER_EXPORT class Payload//{{{
friend class CallbackIUPayloadUpdate;
protected:
IPAACA_MEMBER_VAR_EXPORT std::string _owner_name;
IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> _store;
IPAACA_MEMBER_VAR_EXPORT rapidjson::Document _json_document;
//IPAACA_MEMBER_VAR_EXPORT std::map<std::string, std::string> _store;
IPAACA_MEMBER_VAR_EXPORT boost::weak_ptr<IUInterface> _iu;
protected:
IPAACA_HEADER_EXPORT void initialize(boost::shared_ptr<IUInterface> iu);
......
......@@ -98,6 +98,11 @@
#include <rsb/rsbexports.h>
#endif
// new json-based payload API, used in several classes
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/filestream.h"
#include <cstdio>
/// marking pure virtual functions for extra readability
#define _IPAACA_ABSTRACT_
......
......@@ -168,6 +168,7 @@ IPAACA_EXPORT std::string IUConverter::serialize(const AnnotatedData& data, std:
}
pbo->set_access_mode(a_m);
pbo->set_read_only(obj->read_only());
// TODO JSONIZE
for (std::map<std::string, std::string>::const_iterator it=obj->_payload._store.begin(); it!=obj->_payload._store.end(); ++it) {
protobuf::PayloadItem* item = pbo->add_payload();
item->set_key(it->first);
......@@ -216,6 +217,7 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche
obj->_committed = pbo->committed();
obj->_read_only = pbo->read_only();
obj->_access_mode = IU_ACCESS_PUSH;
// TODO JSONIZE
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
obj->_payload._store[it.key()] = it.value();
......@@ -245,6 +247,7 @@ IPAACA_EXPORT AnnotatedData IUConverter::deserialize(const std::string& wireSche
obj->_committed = pbo->committed();
obj->_read_only = pbo->read_only();
obj->_access_mode = IU_ACCESS_MESSAGE;
// TODO JSONIZE
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
obj->_payload._store[it.key()] = it.value();
......@@ -302,6 +305,7 @@ IPAACA_EXPORT std::string MessageConverter::serialize(const AnnotatedData& data,
}
pbo->set_access_mode(a_m);
pbo->set_read_only(obj->read_only());
// TODO JSONIZE
for (std::map<std::string, std::string>::const_iterator it=obj->_payload._store.begin(); it!=obj->_payload._store.end(); ++it) {
protobuf::PayloadItem* item = pbo->add_payload();
item->set_key(it->first);
......@@ -347,6 +351,7 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir
obj->_committed = pbo->committed();
obj->_read_only = pbo->read_only();
obj->_access_mode = IU_ACCESS_PUSH;
// TODO JSONIZE
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
obj->_payload._store[it.key()] = it.value();
......@@ -375,6 +380,7 @@ IPAACA_EXPORT AnnotatedData MessageConverter::deserialize(const std::string& wir
obj->_committed = pbo->committed();
obj->_read_only = pbo->read_only();
obj->_access_mode = IU_ACCESS_MESSAGE;
// TODO JSONIZE
for (int i=0; i<pbo->payload_size(); i++) {
const protobuf::PayloadItem& it = pbo->payload(i);
obj->_payload._store[it.key()] = it.value();
......@@ -414,12 +420,14 @@ IPAACA_EXPORT std::string IUPayloadUpdateConverter::serialize(const AnnotatedDat
pbo->set_revision(obj->revision);
pbo->set_writer_name(obj->writer_name);
pbo->set_is_delta(obj->is_delta);
// TODO JSONIZE
for (std::map<std::string, std::string>::const_iterator it=obj->new_items.begin(); it!=obj->new_items.end(); ++it) {
protobuf::PayloadItem* item = pbo->add_new_items();
item->set_key(it->first);
item->set_value(it->second);
item->set_type("str"); // FIXME other types than str (later)
}
// TODO JSONIZE
for (std::vector<std::string>::const_iterator it=obj->keys_to_remove.begin(); it!=obj->keys_to_remove.end(); ++it) {
pbo->add_keys_to_remove(*it);
}
......@@ -438,10 +446,12 @@ AnnotatedData IUPayloadUpdateConverter::deserialize(const std::string& wireSchem
obj->revision = pbo->revision();
obj->writer_name = pbo->writer_name();
obj->is_delta = pbo->is_delta();
// TODO JSONIZE
for (int i=0; i<pbo->new_items_size(); i++) {
const protobuf::PayloadItem& it = pbo->new_items(i);
obj->new_items[it.key()] = it.value();
}
// TODO JSONIZE
for (int i=0; i<pbo->keys_to_remove_size(); i++) {
obj->keys_to_remove.push_back(pbo->keys_to_remove(i));
}
......
......@@ -3,7 +3,8 @@
* "Incremental Processing Architecture
* for Artificial Conversational Agents".
*
* Copyright (c) 2009-2015 Sociable Agents Group
* Copyright (c) 2009-2015 Social Cognitive Systems Group
* (formerly the Sociable Agents Group)
* CITEC, Bielefeld University
*
* http://opensource.cit-ec.de/projects/ipaaca/
......@@ -30,6 +31,7 @@
* Excellence Initiative.
*/
#include <ipaaca/ipaaca.h>
#include <ipaaca/ipaaca-json.h>
using namespace rapidjson;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment