Permalink
Browse files

Get basic Parser Interface defined.

    This defines the basic Serializer/DeSerializer interface.
    A demo app compiles (but does nothing)
  • Loading branch information...
1 parent 9daf75a commit 500e1293ad2115791c132d15c6e89932e52bd99c @Loki-Astari committed Jan 25, 2015
Showing with 135 additions and 8 deletions.
  1. +2 −2 Makefile
  2. +0 −6 Serialize.cpp
  3. +10 −0 src/Makefile
  4. +10 −0 src/Parser/Makefile
  5. +22 −0 src/Parser/READEME.md
  6. +47 −0 src/Parser/Serialize.h
  7. +44 −0 src/Parser/test.cpp
View
@@ -1,9 +1,9 @@
THORSANVIL_ROOT = $(realpath ./)
-TARGET = Serialize.app
+TARGET = src
-include $(THORSANVIL_ROOT)/build/tools/Makefile
+include $(THORSANVIL_ROOT)/build/tools/Project.Makefile
View
@@ -1,6 +0,0 @@
-
-int main()
-{
- // Fake program so Travis build still work
-}
-
View
@@ -0,0 +1,10 @@
+
+THORSANVIL_ROOT = $(realpath ../)
+
+TARGET = Parser
+
+include $(THORSANVIL_ROOT)/build/tools/Project.Makefile
+
+
+
+
View
@@ -0,0 +1,10 @@
+
+THORSANVIL_ROOT = $(realpath ../../)
+
+TARGET = test.app
+
+include $(THORSANVIL_ROOT)/build/tools/Makefile
+
+
+
+
View
@@ -0,0 +1,22 @@
+
+A framework for implementing parsers onto.
+
+Usage:
+
+ DeSerializer<DstType> parser(jsonParser);
+
+ parser.parse(object1);
+ parser.parse(object2);
+
+ Serializer<SrcType> printer(yamlPrinter);
+
+ printer.print(object1);
+ printer.print(object2);
+
+For simplicity we have stream adapters.
+
+ std::cout << ExportJson(object1);
+
+
+
+
@@ -0,0 +1,47 @@
+
+#ifndef THORS_ANVIL_SERIALIZATION_SERIALIZE_H
+#define THORS_ANVIL_SERIALIZATION_SERIALIZE_H
+
+namespace ThorsAnvil
+{
+ namespace Serialization
+ {
+
+class ParserInterface
+{
+ public:
+ virtual ~ParserInterface() {}
+};
+class PrinterInterface
+{
+ public:
+ virtual ~PrinterInterface() {}
+};
+
+template<typename T>
+class DeSerializer
+{
+ public:
+ DeSerializer(ParserInterface const&)
+ {}
+
+ void parse(T&)
+ {}
+};
+
+template<typename T>
+class Serializer
+{
+ public:
+ Serializer(PrinterInterface const&)
+ {}
+
+ void print(T const&)
+ {}
+};
+
+ }
+}
+
+#endif
+
View
@@ -0,0 +1,44 @@
+
+
+#include "Serialize.h"
+#include <string>
+
+namespace TA = ThorsAnvil::Serialization;
+
+class JsonParser: public TA::ParserInterface
+{
+};
+
+class YamlPrinter: public TA::PrinterInterface
+{
+};
+
+class Test
+{
+ public:
+ int anInt;
+ float aFloat;
+ double aDouble;
+ bool aBool;
+ std::string aString;
+};
+
+
+int main()
+{
+ Test object1{5, 6.7, 8.9, true, "Test"};
+ Test object2{3, 0.14159269, 8, false, "This is a string"};
+
+ JsonParser jsonParser;
+ TA::DeSerializer<Test> parser(jsonParser);
+
+ parser.parse(object1);
+ parser.parse(object2);
+
+ YamlPrinter yamlPrinter;
+ TA::Serializer<Test> printer(yamlPrinter);
+
+ printer.print(object1);
+ printer.print(object2);
+}
+

0 comments on commit 500e129

Please sign in to comment.