MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
tixy2.cpp
Go to the documentation of this file.
1 #include "tixy2.h"
2 
3 #include "librw.h"
4 
5 
6 namespace midaspace {
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 
74 
76 long GP_scan_line (Stream * stream, char *dest)
77 {
78  if (stream->isFile())
79  return FP_scan_line (stream->file(), dest);
80  else {
81  const char *a = stream->tixel()->GetText();
82  return SP_scan_line (a, dest);
83  }
84 }
85 
87 long GP_scan_line_alloc (Stream * stream, char *&dest)
88 {
89  if (stream->isFile())
90  return FP_scan_line_alloc (stream->file(), dest);
91  else {
92  const char *a = stream->tixel()->GetText();
93  return SP_scan_line_alloc (a, dest);
94  }
95 }
96 long GP_scan_line_alloc_skip_commented (Stream * stream, char *&dest)
97 {
98  if (stream->isFile()) FP_skip_line_commented (stream->file());
99 
100  return GP_scan_line_alloc (stream, dest);
101 }
102 
104 long GP_scan_word (Stream * stream, char *dest)
105 {
106  if (stream->isFile())
107  return FP_scan_word (stream->file(), dest);
108  else {
109  const char *a = stream->tixel()->GetText();
110  return SP_scan_word (a, dest);
111  }
112 }
113 
114 //* ********************************************************************************************
115 //* *** *** *** *** docasne XML FCES *** *** *** ***
116 //* ********************************************************************************************
117 const XMLElement * XP_give_unique_expected_elem (const XMLNode *xelem, const char * name, bool uniq)
118 {
119  const XMLElement * answer = xelem->FirstChild()->ToElement();
120  if (!answer) _errorr ("no child");
121  if (uniq && answer->NextSibling() != NULL) _errorr ("is not unique");
122  if ( strcmp(answer->Value(), name) != 0 ) _errorr2 ("name of xelement is not \"%s\"", name);
123 
124  return answer;
125 }
126 void XP_check_expected_attribute (const XMLNode *xelem, const char *name, const char *value)
127 {
128  if ( strcmp(xelem->ToElement()->Attribute(name), value) != 0 ) _errorr2 ("no attribute \"%s\"", value);
129 }
130 
131 //int XP_give_attribute_int (const XMLElement *xelem, const char *name)
132 //{
133 // int answer;
134 // if (xelem->QueryIntAttribute(name, &answer) != TIXML_SUCCESS) _errorr ("no attribute \"%s\"", name);
135 // return answer;
136 //}
137 const char * XP_giveDAtext (const XMLNode *xelem, int n, bool last, const char *format, const char *type, const char *name, int *noc)
138 {
139  const XMLNode *da = NULL;
140  if (n == 0) da = xelem;
141  else if (n == 1) da = xelem->FirstChild();
142  else if (n == 2) da = xelem->FirstChild()->NextSibling();
143  else if (n == 3) da = xelem->FirstChild()->NextSibling()->NextSibling();
144  else _errorr ("error");
145 
146  if (!da) _errorr ("no data array");
147  if (last && da->NextSibling() != NULL) _errorr ("is not last");
148  if ( strcmp(da->Value(), "DataArray") != 0 ) _errorr ("name of xelement is not DataArray");
149 
150  ; XP_check_expected_attribute (da, "format", format);
151  ; XP_check_expected_attribute (da, "type", type);
152  if (name) XP_check_expected_attribute (da, "Name", name);
153  if (noc) {
154  const char *no = da->ToElement()->Attribute("NumberOfComponents");
155  int n;
156  if (no) n = atol(no);
157  else n = 1;
158  if (*noc && *noc != n) _errorr3 ("in DataArray, NumberOfComponents is not \"%s\" but %s", *noc, n);
159  else *noc = n;
160  }
161 
162  const char * text = da->ToElement()->GetText();
163  if (text == NULL)
164  _errorr("no text in DataArray");
165 
166  return text;
167 }
168 
169 
170 } // namespace midaspace
long GP_scan_line(Stream *stream, char *dest)
... line; return value is length of the line
Definition: tixy2.cpp:76
bool isString(void)
Definition: tixy2.h:152
int FP_scan_word(FILE *src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:356
const XMLElement * XP_give_unique_expected_elem(const XMLNode *xelem, const char *name, bool uniq)
Definition: tixy2.cpp:117
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:145
long SP_scan_word(const char *&src, char *dest)
... word; return value is length of the word
Definition: librw.cpp:528
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
Input / output function.
const XMLNode * FirstChild() const
Get the first child node, or null if none exists.
Definition: tinyxml2.h:671
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
#define errol
Definition: gelib.h:142
#define _errorr2(_1, _2)
Definition: gelib.h:145
bool isFile(void)
Definition: tixy2.h:150
long GP_scan_line_alloc_skip_commented(Stream *stream, char *&dest)
Definition: tixy2.cpp:96
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
long SP_scan_line(const char *&src, char *dest)
... line; return value is length of the line
Definition: librw.cpp:544
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:559
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.
bool ST_scan_number(Stream *src, int &dest)
*** *** *** *** TINYXML FCE *** *** *** ***
Definition: tixy2.cpp:36
const char * GetText() const
Convenience function for easy access to the text inside an element.
Definition: tinyxml2.cpp:1239
XMLElement * tixel(void)
Definition: tixy2.h:141
long FP_scan_line(FILE *stream, char *dest)
scan/copy line == string without ' ' from stream
Definition: librw.cpp:321
#define _errorr(_1)
Definition: gelib.h:151
#define _errorr3(_1, _2, _3)
Definition: gelib.h:146
bool ST_scan_array(Stream *src, int n, int *dest)
Definition: tixy2.cpp:55
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:233
bool SP_scan_number(const char *&src, int &dest)
... number of type int/long/double
Definition: librw.cpp:595
const char ** pstring(void)
Definition: tixy2.h:146
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:340
long GP_scan_word(Stream *stream, char *dest)
... word; return value is length of the word
Definition: tixy2.cpp:104
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
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:214