UniSet 2.32.1
Schema.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// --------------------------------------------------------------------------
17#ifndef Schema_H_
18#define Schema_H_
19// --------------------------------------------------------------------------
20#include <memory>
21#include <unordered_map>
22#include "Element.h"
23#include "Schema.h"
24// --------------------------------------------------------------------------
25namespace uniset
26{
27 // --------------------------------------------------------------------------
28 class Schema
29 {
30 public:
31 Schema();
32 virtual ~Schema();
33
34 std::shared_ptr<Element> manage( std::shared_ptr<Element> el );
35
36 void remove( std::shared_ptr<Element>& el );
37
38 void link( Element::ElementID rootID, Element::ElementID childID, int numIn );
39 void unlink( Element::ElementID rootID, Element::ElementID childID );
40 void extlink( const std::string& name, Element::ElementID childID, int numIn );
41
42 void setIn( Element::ElementID ID, int inNum, long state );
43 long getOut( Element::ElementID ID );
44
45 struct INLink;
46 struct EXTLink;
47 struct EXTOut;
48
49 typedef std::unordered_map<Element::ElementID, std::shared_ptr<Element>> ElementMap;
50 typedef std::list<INLink> InternalList;
51 typedef std::list<EXTLink> ExternalList;
52 typedef std::list<EXTOut> OutputsList;
53
54 // map iterator
55 typedef ElementMap::const_iterator iterator;
56 inline Schema::iterator begin()
57 {
58 return emap.begin();
59 }
60 inline Schema::iterator end()
61 {
62 return emap.end();
63 }
64 inline int size()
65 {
66 return emap.size();
67 }
68 inline bool empty()
69 {
70 return emap.empty();
71 }
72
73 // int. list iterator
74 typedef InternalList::const_iterator INTiterator;
75 inline Schema::INTiterator intBegin()
76 {
77 return inLinks.begin();
78 }
79 inline Schema::INTiterator intEnd()
80 {
81 return inLinks.end();
82 }
83 inline int intSize()
84 {
85 return inLinks.size();
86 }
87 inline bool intEmpty()
88 {
89 return inLinks.empty();
90 }
91
92 // ext. list iterator
93 typedef ExternalList::const_iterator EXTiterator;
94 inline Schema::EXTiterator extBegin()
95 {
96 return extLinks.begin();
97 }
98 inline Schema::EXTiterator extEnd()
99 {
100 return extLinks.end();
101 }
102 inline int extSize()
103 {
104 return extLinks.size();
105 }
106 inline bool extEmpty()
107 {
108 return extLinks.empty();
109 }
110
111 // ext. out iterator
112 typedef OutputsList::const_iterator OUTiterator;
113 inline Schema::OUTiterator outBegin()
114 {
115 return outList.begin();
116 }
117 inline Schema::OUTiterator outEnd()
118 {
119 return outList.end();
120 }
121 inline int outSize()
122 {
123 return outList.size();
124 }
125 inline bool outEmpty()
126 {
127 return outList.empty();
128 }
129
130 // find
131 std::shared_ptr<Element> find(Element::ElementID id);
132 std::shared_ptr<Element> findExtLink(const std::string& name);
133 std::shared_ptr<Element> findOut(const std::string& name);
134
135 // -----------------------------------------------
136 // внутреннее соединения
137 // между элементами
138 struct INLink
139 {
140 INLink(std::shared_ptr<Element> f, std::shared_ptr<Element> t, int ni):
141 numInput(ni) {}
142 INLink(): numInput(0) {}
143
144 std::shared_ptr<Element> from;
145 std::shared_ptr<Element> to;
146 int numInput;
147 };
148
149 // внешнее соединение
150 // что-то на вход элемента
151 struct EXTLink
152 {
153 EXTLink( const std::string& n, std::shared_ptr<Element> t, int ni):
154 name(n), to(t), numInput(ni) {}
155 EXTLink(): name(""), numInput(0) {}
156
157 std::string name;
158 std::shared_ptr<Element> to;
159 int numInput;
160 };
161
162 // наружный выход
163 struct EXTOut
164 {
165 EXTOut( const std::string& n, std::shared_ptr<Element>& f):
166 name(n), from(f) {}
167 EXTOut(): name("") {}
168
169 std::string name;
170 std::shared_ptr<Element> from;
171 };
172
173 protected:
174 ElementMap emap; // список элементов
175 InternalList inLinks;
176 ExternalList extLinks;
177 OutputsList outList;
178
179 private:
180 };
181 // ---------------------------------------------------------------------------
183 public Schema
184 {
185 public:
186 SchemaXML();
187 virtual ~SchemaXML();
188
189 void read( const std::string& xmlfile );
190
191 protected:
192 };
193 // --------------------------------------------------------------------------
194} // end of namespace uniset
195// ---------------------------------------------------------------------------
196#endif
Definition Schema.h:29
Definition Schema.h:184
Definition Calibration.h:27
Definition Schema.h:164