Xcos ecore: fix datatype definition
[scilab.git] / scilab / modules / scicos / includes / XMIResource.hxx
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2016-2016 - Scilab Enterprises - Clement DAVID
4  *
5  * This file is hereby licensed under the terms of the GNU GPL v2.0,
6  * pursuant to article 5.3.4 of the CeCILL v.2.1.
7  * This file was originally licensed under the terms of the CeCILL v2.1,
8  * and continues to be available under such terms.
9  * For more information, see the COPYING file which you should have received
10  * along with this program.
11  */
12
13 #include "utilities.hxx"
14 #include "Controller.hxx"
15 #include "model/BaseObject.hxx"
16
17 #include "dynlib_scicos.h"
18
19 #include <map>
20 #include <array>
21 #include <string>
22 #include <vector>
23
24 extern "C" {
25 #include <libxml/xmlwriter.h>
26 #include <libxml/xmlreader.h>
27 }
28
29 namespace org_scilab_modules_scicos
30 {
31
32 class SCICOS_IMPEXP XMIResource
33 {
34
35 public:
36     XMIResource(ScicosID id);
37     ~XMIResource();
38
39     int save(const char* uri);
40     int load(const char* uri);
41
42 private:
43     /*
44      * Save helpers
45      */
46     int writeDatatype(xmlTextWriterPtr writer, const std::vector<int>& datatype);
47     int writePoint(xmlTextWriterPtr writer, double x, double y);
48     int writeGeometry(xmlTextWriterPtr writer, ScicosID id, kind_t kind);
49     int writeAbstractLayer(xmlTextWriterPtr writer, ScicosID id, kind_t kind);
50     int writeAbstractBaseObject(xmlTextWriterPtr writer, ScicosID id, kind_t kind);
51     int writeDiagram(xmlTextWriterPtr writer);
52     int writeSimulationConfig(xmlTextWriterPtr writer, ScicosID id);
53     int writeBlock(xmlTextWriterPtr writer, ScicosID id);
54     int writePort(xmlTextWriterPtr writer, enum object_properties_t container, ScicosID id);
55     int writeLink(xmlTextWriterPtr writer, ScicosID id);
56     int writeAnnotation(xmlTextWriterPtr writer, ScicosID id);
57
58     /*
59      * Load helpers
60      */
61     int loadDoubleArray(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o);
62     int loadIntArray(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o);
63     int loadStringArray(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o);
64     int loadEncodedStringArray(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o);
65     int loadBase64(xmlTextReaderPtr reader, enum object_properties_t property, const model::BaseObject& o);
66     int loadDatatype(xmlTextReaderPtr reader, const model::BaseObject& o);
67     int loadPoint(xmlTextReaderPtr reader, const model::BaseObject& o);
68     int loadGeometry(xmlTextReaderPtr reader, const model::BaseObject& o);
69     int loadAbstractBaseObject(xmlTextReaderPtr reader, const model::BaseObject& o);
70     int loadDiagram(xmlTextReaderPtr reader, const model::BaseObject& o);
71     int loadSimulationConfig(xmlTextReaderPtr reader, const model::BaseObject& o);
72     int loadBlock(xmlTextReaderPtr reader, const model::BaseObject& o);
73     int loadPort(xmlTextReaderPtr reader, const model::BaseObject& o);
74     int loadLink(xmlTextReaderPtr reader, const model::BaseObject& o);
75     int loadAnnotation(xmlTextReaderPtr reader, const model::BaseObject& o);
76
77     int processNode(xmlTextReaderPtr reader);
78     int processElement(xmlTextReaderPtr reader);
79     int processText(xmlTextReaderPtr reader);
80     int processEndElement(xmlTextReaderPtr reader);
81
82 private:
83     /* shared controller */
84     Controller controller;
85     /* id of the diagram */
86     ScicosID root;
87
88     /*
89      * load shared variables
90      */
91
92     /* interned string indexes */
93     enum xcosNames
94     {
95         e_Annotation,
96         e_BaseObject,
97         e_Block,
98         e_CompiledRepresentation,
99         e_Diagram,
100         e_Geometry,
101         e_Layer,
102         e_Link,
103         e_Point,
104         e_Port,
105         e_PortKind,
106         e_SimulationConfig,
107         e_absoluteTolerance,
108         e_base64,
109         e_blocktype,
110         e_child,
111         e_color,
112         e_columns,
113         e_connectedSignal,
114         e_context,
115         e_controlPoint,
116         e_datatype,
117         e_debugLevel,
118         e_deltaH,
119         e_deltaT,
120         e_dependsOnT,
121         e_dependsOnU,
122         e_description,
123         e_destinationPort,
124         e_dstate,
125         e_ein,
126         e_eout,
127         e_equations,
128         e_expression,
129         e_exprs,
130         e_finalTime,
131         e_firing,
132         e_font,
133         e_fontSize,
134         e_functionAPI,
135         e_functionName,
136         e_geometry,
137         e_height,
138         e_implicit,
139         e_in,
140         e_interfaceFunction,
141         e_ipar,
142         e_kind,
143         e_label,
144         e_lineHeight,
145         e_lineWidth,
146         e_nmode,
147         e_nzcross,
148         e_odstate,
149         e_opar,
150         e_out,
151         e_parent,
152         e_parentDiagram,
153         e_path,
154         e_properties,
155         e_realtimeScale,
156         e_relativeTolerance,
157         e_rows,
158         e_rpar,
159         e_solver,
160         e_sourceBlock,
161         e_sourcePort,
162         e_state,
163         e_style,
164         e_timeTolerance,
165         e_title,
166         e_type,
167         e_uid,
168         e_version,
169         e_width,
170         e_x,
171         e_xcos,
172         e_y,
173         NB_XCOS_NAMES
174     };
175     /* temporary interned string content (owned by a reader) */
176     std::array<const xmlChar*, NB_XCOS_NAMES> constXcosNames;
177     /* temporary interned xcos namespace (owned by a reader) */
178     const xmlChar* xcosNamespaceUri;
179     /* temporary interned xsi namespace (owned by a reader) */
180     const xmlChar* xsiNamespaceUri;
181
182     /* stack uid / kind used */
183     std::vector<model::BaseObject> processed;
184
185     /* store the parent of a text node */
186     enum xcosNames parent;
187
188     /* uid string - ScicosID  map */
189     std::map<std::string, ScicosID> references;
190     /* reference to resolve after loading the whole file */
191     struct unresolvedReference
192     {
193         unresolvedReference(ScicosID id, kind_t kind, enum object_properties_t prop, std::string uid)
194             : m_id(id), m_kind(kind), m_prop(prop), m_uid(uid) {}
195         ScicosID m_id;
196         kind_t m_kind;
197         enum object_properties_t m_prop;
198         std::string m_uid;
199     };
200     /* temporary unresolved references */
201     std::vector<unresolvedReference> unresolved;
202 };
203
204 }
205