Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
xmlApi.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/memory>
9#include <ext/typeinfo>
10
11#include <alib/deque>
12#include <alib/map>
13#include <alib/string>
14#include "sax/Token.h"
16
17#include "object/Object.h"
18#include "object/AnyObject.h"
19
20#include <global/GlobalData.h>
21
23
24namespace core {
25
26template < typename T >
27struct xmlApi;
28
29class xmlApiInputContext : public ext::deque < sax::Token >::iterator {
30 ext::map < unsigned, object::Object > idToInstanceContexts;
31
32public:
33 explicit xmlApiInputContext ( const ext::deque < sax::Token >::iterator & iter ) : ext::deque < sax::Token >::iterator ( iter ) {
34 }
35
37 return idToInstanceContexts;
38 }
39
40};
41
42class xmlApiOutputContext : public ext::deque < sax::Token > {
43 ext::map < object::Object, unsigned > instanceToIdContexts;
44 unsigned idMaxContext = 0;
45
46public:
47 xmlApiOutputContext ( ) = default;
48
50 return instanceToIdContexts;
51 }
52
53 unsigned & idMax ( ) {
54 return idMaxContext;
55 }
56
57};
58
59template < >
60struct xmlApi < object::Object > {
61public:
62 class GroupParser {
63 public:
65
66 virtual ~GroupParser ( ) noexcept = default;
67 };
68
69private:
70 static ext::map < std::string, std::unique_ptr < GroupParser > > & parseFunctions ( );
71
72 template < class Type >
73 class ParserRegister : public GroupParser {
74 public:
75 object::Object parse ( ext::deque < sax::Token >::iterator & input ) override {
76 return object::Object ( xmlApi < Type >::parse ( input ) );
77 }
78
79 };
80
81public:
82 class GroupComposer {
83 public:
84 virtual void compose ( ext::deque < sax::Token > & input, const object::Object & group ) = 0;
85
86 virtual ~GroupComposer( ) noexcept = default;
87 };
88
89private:
90 static ext::map < std::string, std::unique_ptr < GroupComposer > > & composeFunctions ( );
91
92 template < class Type >
93 class ComposerRegister : public GroupComposer {
94 public:
95 void compose ( ext::deque < sax::Token > & input, const object::Object & group ) override {
96 xmlApi < Type >::compose ( input, static_cast < const object::AnyObject < Type > & > ( group.getData ( ) ).getData ( ) );
97 }
98
99 };
100
101public:
102 static void unregisterXmlReader ( const std::string & tagName, const std::string & typeName );
103
104 template < class Type >
105 static void unregisterXmlReader ( ) {
106 unregisterXmlReader ( xmlApi < Type >::xmlTagName ( ), ext::to_string < Type > ( ) );
107 }
108
109 static void registerXmlReader ( std::string tagName, const std::string & typeName, std::unique_ptr < GroupParser > entry );
110
111 template < class Type >
112 static void registerXmlReader ( ) {
113 registerXmlReader ( xmlApi < Type >::xmlTagName ( ), ext::to_string < Type > ( ), std::unique_ptr < GroupParser > ( new ParserRegister < Type > ( ) ) );
114 }
115
116 static void unregisterXmlWriter ( const std::string & type, const std::string & typeName );
117
118 template < class Type >
119 static void unregisterXmlWriter ( ) {
120 unregisterXmlWriter ( ext::to_string < object::AnyObject < Type > > ( ), ext::to_string < Type > ( ) );
121 }
122
123 static void registerXmlWriter ( std::string type, const std::string & typeName, std::unique_ptr < GroupComposer > entry );
124
125 template < class Type >
126 static void registerXmlWriter ( ) {
127 registerXmlWriter ( ext::to_string < object::AnyObject < Type > > ( ), ext::to_string < Type > ( ), std::unique_ptr < GroupComposer > ( new ComposerRegister < Type > ( ) ) );
128 }
129
130 static object::Object parseRef ( xmlApiInputContext & input );
131
132 static object::Object parseUnique ( xmlApiInputContext & input );
133
134 static object::Object parseObject ( xmlApiInputContext & input, const std::string & tagName );
135
136 static object::Object parse ( xmlApiInputContext & input, const std::string & tagName );
137
139
140 static bool first ( const ext::deque < sax::Token >::const_iterator & input );
141
142 static std::string xmlTagName ( );
143
144 static void composeRef ( xmlApiOutputContext & output, typename ext::map < object::Object, unsigned >::iterator & elem );
145
146 static void composeUnique ( xmlApiOutputContext & output, const object::Object & data );
147
148 static void composeObject ( xmlApiOutputContext & output, const object::Object & data );
149
150 static void compose ( ext::deque < sax::Token > & data, const object::Object & object );
151
152};
153
154} /* namespace core */
155
Definition: xmlApi.hpp:29
ext::map< unsigned, object::Object > & idToInstance()
Definition: xmlApi.hpp:36
xmlApiInputContext(const ext::deque< sax::Token >::iterator &iter)
Definition: xmlApi.hpp:33
Definition: xmlApi.hpp:42
unsigned & idMax()
Definition: xmlApi.hpp:53
ext::map< object::Object, unsigned > & instanceToId()
Definition: xmlApi.hpp:49
virtual void compose(ext::deque< sax::Token > &input, const object::Object &group)=0
virtual ~GroupComposer() noexcept=default
virtual ~GroupParser() noexcept=default
virtual object::Object parse(ext::deque< sax::Token >::iterator &input)=0
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
typename std::map< T, R, Cmp, Alloc >::iterator iterator
The iterator type is inheried.
Definition: map.hpp:101
Represents an adaptor of any type to a class in type hierarchy of objects in the algorithms library.
Definition: AnyObject.h:37
Definition: Object.h:16
const AnyObjectBase & getData() const
Definition: Object.h:142
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
Type
Definition: MeasurementTypes.hpp:20
Definition: AnyObject.h:28
Definition: ComposerException.cpp:8
Definition: FordFulkerson.hpp:16
static void unregisterXmlWriter()
Definition: xmlApi.hpp:119
static void unregisterXmlReader()
Definition: xmlApi.hpp:105
static void registerXmlReader()
Definition: xmlApi.hpp:112
static void registerXmlWriter()
Definition: xmlApi.hpp:126
Definition: xmlApi.hpp:27