muMECH  1.0
tixy2.cpp
Go to the documentation of this file.
1 #include "tixy2.h"
2 
3 #include "librw.h"
4 
5 
6 namespace gelibspace {
7 
11 
12 
13 //XMLDocument* openTXdcPNSS (const char *path, const char *name, const char *suff, const char *suff2)
14 //{
15 // char file[255];
16 // if (path) sprintf (file, "%s%s%s%s", path, name, suff, suff2);
17 // else sprintf (file, "%s%s%s", name, suff, suff2);
18 //
19 // return new XMLDocument(file);
20 //}
21 
22 //XMLDocument* openTXdcPN (const char *path, const char *name)
23 //{
24 // char file[255];
25 // if (path) sprintf (file, "%s%s", path, name);
26 // else sprintf (file, "%s", name);
27 //
28 // return new XMLDocument(file);
29 //}
30 
31 
32 
36 bool ST_scan_number (Stream *src, int &dest)
37 {
38  if (src->isFile ()) return ( fscanf (src->file(), "%d", &dest) == 1 );
39  if (src->isString()) return SP_scan_number (*src->pstring(), dest);
40  errol; return false;
41 }
42 bool ST_scan_number (Stream *src, long &dest)
43 {
44  if (src->isFile ()) return ( fscanf (src->file(), "%ld", &dest) == 1 );
45  if (src->isString()) return SP_scan_number (*src->pstring(), dest);
46  errol; return false;
47 }
48 bool ST_scan_number (Stream *src, double &dest)
49 {
50  if (src->isFile ()) return ( fscanf (src->file(), "%lf", &dest) == 1 );
51  if (src->isString()) return SP_scan_number (*src->pstring(), dest);
52  errol; return false;
53 }
54 
55 bool ST_scan_array (Stream *src, int n, int *dest)
56 {
57  if (src->isFile ()) return FP_scan_array (src->file(), n, dest);
58  if (src->isString()) return SP_scan_array (*src->pstring(), n, dest);
59  errol; return false;
60 }
61 bool ST_scan_array (Stream *src, int n, long *dest)
62 {
63  if (src->isFile ()) return FP_scan_array (src->file(), n, dest);
64  if (src->isString()) return SP_scan_array (*src->pstring(), n, dest);
65  errol; return false;
66 }
67 bool ST_scan_array (Stream *src, int n, double *dest)
68 {
69  if (src->isFile ()) return FP_scan_array (src->file(), n, dest);
70  if (src->isString()) return SP_scan_array (*src->pstring(), n, dest);
71  errol; return false;
72 }
73 
75 bool ST_scan_expected_number (Stream *src, long expctd)
76 {
77  long aux;
78  return (ST_scan_number(src, aux) && aux == expctd);
79 }
80 
81 
82 
84 long GP_scan_line (Stream * stream, char *dest)
85 {
86  if (stream->isFile())
87  return FP_scan_line (stream->file(), dest);
88  else {
89  const char *a = stream->tixel()->GetText();
90  return SP_scan_line (a, dest);
91  }
92 }
93 
95 long GP_scan_line_alloc (Stream * stream, char *&dest)
96 {
97  if (stream->isFile())
98  return FP_scan_line_alloc (stream->file(), dest);
99  else {
100  const char *a = stream->tixel()->GetText();
101  return SP_scan_line_alloc (a, dest);
102  }
103 }
104 long GP_scan_line_alloc_skip_commented (Stream * stream, char *&dest)
105 {
106  if (stream->isFile()) FP_skip_line_commented (stream->file());
107 
108  return GP_scan_line_alloc (stream, dest);
109 }
110 
112 long GP_scan_word (Stream * stream, char *dest)
113 {
114  if (stream->isFile())
115  return FP_scan_word (stream->file(), dest);
116  else {
117  const char *a = stream->tixel()->GetText();
118  return SP_scan_word (a, dest);
119  }
120 }
121 
122 //* ********************************************************************************************
123 //* *** *** *** *** docasne XML FCES *** *** *** ***
124 //* ********************************************************************************************
125 const XMLElement * XP_give_unique_expected_elem (const XMLNode *xelem, const char * name, bool uniq)
126 {
127  const XMLElement * answer = xelem->FirstChild()->ToElement();
128  if (!answer) _errorr ("no child");
129  if (uniq && answer->NextSibling() != NULL) _errorr ("is not unique");
130  if ( strcmp(answer->Value(), name) != 0 ) _errorr2 ("name of xelement is not \"%s\"", name);
131 
132  return answer;
133 }
134 void XP_check_expected_attribute (const XMLNode *xelem, const char *name, const char *value)
135 {
136  if ( strcmp(xelem->ToElement()->Attribute(name), value) != 0 ) _errorr2 ("no attribute \"%s\"", value);
137 }
138 
139 //int XP_give_attribute_int (const XMLElement *xelem, const char *name)
140 //{
141 // int answer;
142 // if (xelem->QueryIntAttribute(name, &answer) != TIXML_SUCCESS) _errorr ("no attribute \"%s\"", name);
143 // return answer;
144 //}
145 const char * XP_giveDAtext (const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc)
146 {
147  const XMLNode *da = NULL;
148  if (n == 0) da = xelem;
149  else if (n == 1) da = xelem->FirstChild();
150  else if (n == 2) da = xelem->FirstChild()->NextSibling();
151  else if (n == 3) da = xelem->FirstChild()->NextSibling()->NextSibling();
152  else _errorr ("error");
153 
154  if (!da) _errorr ("no data array");
155  if (last && da->NextSibling() != NULL) _errorr ("is not last");
156  if ( strcmp(da->Value(), "DataArray") != 0 ) _errorr ("name of xelement is not DataArray");
157 
158  ; XP_check_expected_attribute (da, "format", format);
159  ; XP_check_expected_attribute (da, "type", type);
160  if (name) XP_check_expected_attribute (da, "Name", name);
161  if (noc) {
162  const char *no = da->ToElement()->Attribute("NumberOfComponents");
163  int n;
164  if (no) n = atol(no);
165  else n = 1;
166  if (*noc && *noc != n) _errorr3 ("in DataArray, NumberOfComponents is not \"%s\" but %s", *noc, n);
167  else *noc = n;
168  }
169 
170  const char * text = da->ToElement()->GetText();
171  if (text == NULL)
172  _errorr("no text in DataArray");
173 
174  return text;
175 }
176 
177 
178 } // namespace gelibspace
void FP_skip_line_commented(FILE *stream)
move file descriptor to the start of the new noncommented line, without checking of EOF ...
Definition: librw.cpp:156
void XP_check_expected_attribute(const XMLNode *xelem, const char *name, const char *value)
Definition: tixy2.cpp:134
long GP_scan_line(Stream *stream, char *dest)
... line; return value is length of the line
Definition: tixy2.cpp:84
Input / output function.
const XMLElement * XP_give_unique_expected_elem(const XMLNode *xelem, const char *name, bool uniq)
Definition: tixy2.cpp:125
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:95
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:671
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:647
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:253
XMLElement * tixel(void)
Definition: tixy2.h:142
long GP_scan_line_alloc_skip_commented(Stream *stream, char *&dest)
Definition: tixy2.cpp:104
The element is a container class.
Definition: tinyxml2.h:1116
bool ST_scan_expected_number(Stream *src, long expctd)
... number and compare with expected one
Definition: tixy2.cpp:75
#define errol
Definition: gelib.h:151
bool FP_scan_array(FILE *stream, int n, int *dest)
scan/copy array of numbers from src to dest, src pointer is shifted over the field ...
Definition: librw.cpp:313
#define _errorr2(_1, _2)
Definition: gelib.h:154
FILE * file(void)
*** GET ***
Definition: tixy2.h:140
bool isString(void)
Definition: tixy2.h:153
bool ST_scan_number(Stream *src, int &dest)
*** *** *** *** TINYXML FCE *** *** *** ***
Definition: tixy2.cpp:36
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without ' ' from stream
Definition: librw.cpp:420
long FP_scan_line_alloc(FILE *stream, char *&dest)
scan/copy line == string without ' ' from stream; dest is NULL and allocated here ...
Definition: librw.cpp:439
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:714
XMLNode is a base class for every object that is in the XML Document Object Model (DOM)...
Definition: tinyxml2.h:579
const char * Value() const
The meaning of 'value' changes for the specific type.
Definition: tinyxml2.h:647
const char * Attribute(const char *name, const char *value=0) const
Given an attribute name, Attribute() returns the value for the attribute of that name, or null if none exists.
Definition: tinyxml2.cpp:1226
TinyXML functions.
const char * GetText() const
Convenience function for easy access to the text inside an element.
Definition: tinyxml2.cpp:1239
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
Definition: librw.cpp:663
long SP_scan_line_alloc(const char *&src, char *&dest)
... line; return value is length of the line; dest is NULL and allocated here
Definition: librw.cpp:678
#define _errorr(_1)
Definition: gelib.h:160
#define _errorr3(_1, _2, _3)
Definition: gelib.h:155
long GP_scan_word(Stream *stream, char *dest)
... word; return value is length of the word
Definition: tixy2.cpp:112
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:145
bool isFile(void)
Definition: tixy2.h:151
bool ST_scan_array(Stream *src, int n, int *dest)
scan/copy array of numbers from src to dest, src pointer is shifted over the field ...
Definition: tixy2.cpp:55
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:455
const char ** pstring(void)
Definition: tixy2.h:147
virtual XMLElement * ToElement()
Safely cast to an Element, or null.
Definition: tinyxml2.h:595
const XMLNode * NextSibling() const
Get the next (right) sibling node of this node.
Definition: tinyxml2.h:723