24 using namespace tinyxml2;
42 int parse(
const char *buf,
Parameters& params);
50 int store_vector_data(
const XMLElement *, vector<string>&);
52 void traverse(
const XMLElement *,
const string& indent =
"")
const;
64 if (!buf)
return EXIT_FAILURE;
87 vout.
crucial(m_vl,
"Error at %s: tag \"Parameters\" not found.\n", class_name.c_str());
94 int retv = store_map_data(e, params);
96 if (retv != EXIT_SUCCESS) {
97 vout.
crucial(m_vl,
"Error at %s: parse failed.\n", class_name.c_str());
109 if (!elem)
return EXIT_FAILURE;
112 if (!ee)
return EXIT_FAILURE;
117 if (strcmp(ee->
Name(),
"value") == 0) {
123 if (e->QueryIntAttribute(
"id", &
id) ==
XML_SUCCESS) {
130 fprintf(stderr,
"Error. inappropriate id\n");
134 if (
id > max_index) max_index = id;
136 mm[id] = e->GetText();
143 string tag = e->Name();
147 }
else if (tag ==
"y") {
149 }
else if (tag ==
"z") {
151 }
else if (tag ==
"t") {
153 }
else if (tag ==
"w") {
156 fprintf(stderr,
"unknown tag.\n");
160 if (
id > max_index) max_index = id;
162 mm[id] = e->GetText();
166 vector<string> vv(max_index + 1);
168 for (map<int, string>::const_iterator p = mm.begin(); p != mm.end(); ++p) {
169 vv[p->first] = p->second;
181 if (!elem)
return EXIT_FAILURE;
183 const char *elem_name = elem->
Name();
184 const char *elem_value = elem->
GetText();
186 if (elem_value != NULL) {
193 const char *elem_attr = elem->
Attribute(
"type");
195 if (elem_attr && (strcmp(elem_attr,
"sequence") == 0)) {
197 int retv = store_vector_data(elem, v);
199 if (retv == EXIT_SUCCESS) {
210 int retv = store_map_data(e, pp);
212 if (retv != EXIT_SUCCESS) {
229 const char *elem_name = elem->
Name();
230 const char *elem_value = elem->
GetText();
232 if (elem_value != NULL) {
233 vout.
general(m_vl,
"%sElementName = %s, value = %s\n", indent.c_str(), elem_name, elem_value);
236 vout.
general(m_vl,
"%sElementName = %s\n", indent.c_str(), elem_name);
238 const char *elem_attr = elem->
Attribute(
"type");
239 if (elem_attr && (strcmp(elem_attr,
"sequence") == 0)) {
240 vout.
general(m_vl,
"%s- is a sequence.\n", indent.c_str());
244 traverse(e, indent +
" ");
255 const int io_node = 0;
262 std::ifstream fin(params_file.c_str());
264 vout.
crucial(m_vl,
"Error at %s: unable to read parameter file: %s.\n", class_name.c_str(), params_file.c_str());
269 fin.seekg(0, std::ios::end);
270 filesize = fin.tellg();
271 fin.seekg(0, std::ios::beg);
273 int padding = 8 - (filesize % 8);
275 vout.
paranoiac(m_vl,
"%s::%s: filesize = %d, padding = %d\n", class_name.c_str(), __func__, filesize, padding);
281 buf =
new char [filesize];
282 memset(buf, 0, filesize);
284 fin.read(buf, filesize - padding);
292 buf =
new char [filesize];
293 memset(buf, 0, filesize);
void set_Parameters(const string &key, const Parameters &value)
static void abort()
terminate communicator
XMLError Parse(const char *xml, size_t nBytes=(size_t)(-1))
void general(const char *format,...)
int store_vector_data(const XMLElement *, vector< string > &)
static int broadcast(size_t size, void *data, int sender)
void traverse(const XMLElement *, const string &indent="") const
static const string class_name
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
void set_string(const string &key, const string &value)
Bridge::VerboseLevel m_vl
const XMLElement * FirstChildElement(const char *value=0) const
const char * Attribute(const char *name, const char *value=0) const
int parse(const char *buf, Parameters ¶ms)
const char * GetText() const
Common parameter class: provides parameters as singleton.
void paranoiac(const char *format,...)
static const std::string class_name
void crucial(const char *format,...)
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
int store_map_data(const XMLElement *, Parameters &)
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
void read_params(const std::string ¶ms_file, Parameters ¶ms)
read parameters from file.
static int nodeid()
alternative name for self().
const char * ErrorName() const
const char * Name() const
Get the name of an element (which is the Value() of the node.)
void set_string_vector(const string &key, const vector< string > &value)