MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
tixy2.h
Go to the documentation of this file.
1 #ifndef MIDAS_TIXY_H
2 #define MIDAS_TIXY_H
3 
4 // There is conflict name XMLDocument in msxml and tinyxml.
5 // Solution 1:
6 // This define have to be before first win32 include.
7 #define WIN32_LEAN_AND_MEAN
8 
9 #include "gelib.h"
10 #include "tinyxml2.h"
11 
12 
18 using namespace tinyxml2;
19 
20 namespace midaspace {
21 
22 // Solution 2:
23 // #include "gelib.h"
24 // #include "tinyxml2.h"
25 //
26 // namespace TXML = tinyxml2;
27 // XMLDocument -> TXML::XMLDocument
28 
29 
30 
34 
35 XMLDocument* openTXdcPN (const char *path, const char *name);
36 XMLDocument* openTXdcPNSS (const char *path, const char *name, const char *suff, const char *suff2);
37 
38 
39 
44 
45 class Stream
46 {
47 
48  protected:
49  char state;
51  const char *filename;
52 
53  FILE *str_file;
55  const char *str_string;
56 
57  public:
59  Stream (void) { state = '-'; type = STRM_void; filename = NULL; str_file = NULL; str_tixel = NULL; str_string = NULL; }
61  Stream (Stream_type tp) { state = '-'; type = tp; filename = NULL; str_file = NULL; str_tixel = NULL; str_string = NULL; }
63  Stream (FILE *stream) { state = '-'; type = STRM_file; filename = NULL; str_file = stream; str_tixel = NULL; str_string = NULL; }
64  Stream (XMLNode *stream) { state = '-'; type = STRM_tixel; filename = NULL; str_file = NULL; str_tixel = stream; str_string = NULL; }
65  Stream (const char *stream) { state = '-'; type = STRM_string; filename = NULL; str_file = NULL; str_tixel = NULL; str_string = stream; }
67  virtual ~Stream() { delete [] filename; }
68 
70 
74  void open (Stream_type t, const char *rw, const char *&fn, XMLNode *node=NULL)
75  {
76  if (state != '-') errol;
77  //# only these rw are accepted
78  if (rw[1] != '\0') errol;
79  if (*rw != 'r' && *rw != 'w') errol;
80  state = *rw;
81  type = t;
82  if (filename) delete [] filename;
83  filename = fn; fn = NULL;
84 
85  switch (type) {
86  case STRM_file: this->str_file = _openFileN (rw, filename, filename); break;
87  case STRM_tixel:
88  if (state == 'w') this->str_tixel = node;
89  else if (state == 'r') errol;
90  else errol;
91  break;
92  case STRM_void: {
93  if (*rw != 'r' || node) errol;
94 
95  FILE *in = _openFileN("r", filename, filename);
96  char c = getc(in); ungetc(c, in);
97 
98  if (c=='#') { type = STRM_file; str_file = in; }
99  else if (c=='<') { type = STRM_tixel; str_tixel = new XMLDocument(true, COLLAPSE_WHITESPACE);
100  XMLError err = ((XMLDocument*)str_tixel)->LoadFile(in);
101  if (err!=XML_NO_ERROR && err!=XML_SUCCESS) _errorr2 ("File %s has not valid syntax", filename);
102  fclose (in); }
103  else _errorr2 ("File %s doesnot start neither with character '#' nor '<'", filename);
104 
105  break;
106  }
107  case STRM_string: errol; break;
108  default: _errorr ("unsuported stream type");
109  }
110  }
111 
112  void close (void)
113  {
114  switch (type) {
115  case STRM_file: fclose (str_file); break;
116  case STRM_tixel:
117  if (state == 'w') str_tixel->GetDocument()->SaveFile(filename);
118  else if (state == 'r') ;
119  else errol;
120 
121  delete str_tixel->GetDocument();
122  break;
123  case STRM_string: errol; break;
124  default: _errorr ("unsuported stream type");
125  }
126 
127  state = '-';
128  }
129 
130 
131  //void initiate (XMLNode *stream) { checkin_type(STRM_tixel); if (str_tixel != NULL) _errorr ("not nul"); str_tixel = stream; }
132  //void reinitiate (XMLNode *stream) { checkin_type(STRM_tixel); str_tixel = stream; }
133 
134  void redefine (FILE *stream) { type = STRM_file; str_file = stream; str_tixel = NULL; str_string = NULL; }
135  void redefine (XMLNode *stream) { type = STRM_tixel; str_file = NULL; str_tixel = stream; str_string = NULL; }
136  void redefine (const char *stream) { type = STRM_string; str_file = NULL; str_tixel = NULL; str_string = stream; }
137 
139  FILE * file(void) { check_type(STRM_file); return str_file; }
140  XMLNode * tixnod(void) { check_type(STRM_tixel); return str_tixel; }
141  XMLElement * tixel(void) { check_type(STRM_tixel); return str_tixel->ToElement(); }
142  //XMLDocument* tixdoc(void) { check_type(STRM_tixel); return str_tixel->ToDocument(); }
143  XMLDocument* tix_doc(void) { check_type(STRM_tixel); return str_tixel->GetDocument(); }
144 
145  const char * string(void) { check_type(STRM_string); return str_string;}
146  const char ** pstring(void){ check_type(STRM_string); return &str_string;}
147 
148  Stream_type give_type (void) { return type; }
149 
150  bool isFile (void) { return (type == STRM_file); }
151  bool isTixel (void) { return (type == STRM_tixel); }
152  bool isString (void) { return (type == STRM_string); }
153 
154  bool relink_downF (void) { check_type(STRM_tixel); str_tixel = this->str_tixel->FirstChild(); return (str_tixel) ? true : false; }
155  bool relink_downL (void) { check_type(STRM_tixel); str_tixel = this->str_tixel->LastChild(); return (str_tixel) ? true : false; }
156  bool relink_up (void) { check_type(STRM_tixel); str_tixel = this->str_tixel->Parent(); return (str_tixel) ? true : false; }
157  bool relink_next (void) { check_type(STRM_tixel); if (str_tixel->NextSibling()) { str_tixel = str_tixel->NextSibling(); return true; } else return false; }
158  bool relink_prev (void) { check_type(STRM_tixel); if (str_tixel->PreviousSibling()) { str_tixel = str_tixel->PreviousSibling(); return true; } else return false; }
159 
161  void skip_commnet (void) { check_type(STRM_tixel); while (true) if (str_tixel->ToComment() != NULL) str_tixel = str_tixel->NextSibling(); else break; }
162 
163  private:
164  void check_type (Stream_type tp) {
165  if (type != tp)
166  _errorr ("wrong type of Stream"); }
167  void checkin_type (Stream_type tp) { if (type == STRM_void) type = tp; else if (type != tp) _errorr ("wrong type of Stream"); }
168 };
169 
170 
171 
172 
176 bool ST_scan_number (Stream *src, int &dest);
177 bool ST_scan_number (Stream *src, long &dest);
178 bool ST_scan_number (Stream *src, double &dest);
179 //
180 bool ST_scan_array (Stream *src, int n, int *dest);
181 bool ST_scan_array (Stream *src, int n, long *dest);
182 bool ST_scan_array (Stream *src, int n, double *dest);
183 
184 
189 long GP_scan_line (Stream * stream, char *dest);
191 long GP_scan_word (Stream * stream, char *dest);
193 long GP_scan_line_alloc (Stream * stream, char *&dest);
194 
195 
196 //* ********************************************************************************************
197 //* *** *** *** *** docasne XML FCES *** *** *** ***
198 //* ********************************************************************************************
199 const XMLElement * XP_give_unique_expected_elem (const XMLNode *xelem, const char * name, bool uniq=true);
200 void XP_check_expected_attribute (const XMLNode *xelem, const char *name, const char *value);
201 const char * XP_giveDAtext (const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc=NULL);
202 
203 
204 } // namespace midaspace
205 
206 #endif // MIDAS_TIXY_H
Stream_type give_type(void)
Definition: tixy2.h:148
bool relink_next(void)
Definition: tixy2.h:157
long GP_scan_line(Stream *stream, char *dest)
... line; return value is length of the line
Definition: tixy2.cpp:76
Stream(FILE *stream)
CONSTRUCTOR.
Definition: tixy2.h:63
bool isString(void)
Definition: tixy2.h:152
void redefine(XMLNode *stream)
Definition: tixy2.h:135
bool isTixel(void)
Definition: tixy2.h:151
const XMLElement * XP_give_unique_expected_elem(const XMLNode *xelem, const char *name, bool uniq)
Definition: tixy2.cpp:117
General functions.
#define _openFileN(_1, _2, _3)
Definition: gelib.h:173
bool relink_downF(void)
Definition: tixy2.h:154
FILE * file(void)
*** GET ***
Definition: tixy2.h:139
void XP_check_expected_attribute(const XMLNode *xelem, const char *name, const char *value)
Definition: tixy2.cpp:126
Stream(Stream_type tp)
CONSTRUCTOR.
Definition: tixy2.h:61
const char * XP_giveDAtext(const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc)
Definition: tixy2.cpp:137
The element is a container class.
Definition: tinyxml2.h:1116
const char * str_string
Definition: tixy2.h:55
Stream(const char *stream)
Definition: tixy2.h:65
const char * string(void)
Definition: tixy2.h:145
bool relink_up(void)
Definition: tixy2.h:156
#define errol
Definition: gelib.h:142
#define _errorr2(_1, _2)
Definition: gelib.h:145
A Document binds together all the functionality.
Definition: tinyxml2.h:1445
void redefine(FILE *stream)
Definition: tixy2.h:134
bool isFile(void)
Definition: tixy2.h:150
Stream_type type
Definition: tixy2.h:50
XMLDocument * openTXdcPNSS(const char *path, const char *name, const char *suff, const char *suff2)
bool relink_prev(void)
Definition: tixy2.h:158
Stream(void)
CONSTRUCTOR.
Definition: tixy2.h:59
long GP_scan_line_alloc(Stream *stream, char *&dest)
... line; return value is length of the line; dest is NULL and allocated here
Definition: tixy2.cpp:87
void skip_commnet(void)
if this XMLnode is XMLComment, skip to next noncomment
Definition: tixy2.h:161
XMLNode is a base class for every object that is in the XML Document Object Model (DOM)...
Definition: tinyxml2.h:579
XMLDocument * tix_doc(void)
Definition: tixy2.h:143
void redefine(const char *stream)
Definition: tixy2.h:136
bool ST_scan_number(Stream *src, int &dest)
*** *** *** *** TINYXML FCE *** *** *** ***
Definition: tixy2.cpp:36
XMLElement * tixel(void)
Definition: tixy2.h:141
virtual ~Stream()
DESTRUCTOR.
Definition: tixy2.h:67
Stream_type
*** *** *** *** CLASS STREAM *** *** *** ***
Definition: tixy2.h:43
void open(Stream_type t, const char *rw, const char *&fn, XMLNode *node=NULL)
*** SET ***
Definition: tixy2.h:74
#define _errorr(_1)
Definition: gelib.h:151
void close(void)
Definition: tixy2.h:112
const char * filename
Definition: tixy2.h:51
bool ST_scan_array(Stream *src, int n, int *dest)
Definition: tixy2.cpp:55
void checkin_type(Stream_type tp)
Definition: tixy2.h:167
const char ** pstring(void)
Definition: tixy2.h:146
void check_type(Stream_type tp)
Definition: tixy2.h:164
Stream(XMLNode *stream)
Definition: tixy2.h:64
FILE * str_file
Definition: tixy2.h:53
XMLNode * tixnod(void)
Definition: tixy2.h:140
XMLDocument * openTXdcPN(const char *path, const char *name)
*** *** *** *** TINYXML FCE *** *** *** ***
long GP_scan_word(Stream *stream, char *dest)
... word; return value is length of the word
Definition: tixy2.cpp:104
XMLNode * str_tixel
Definition: tixy2.h:54
bool relink_downL(void)
Definition: tixy2.h:155