Inheritance diagram for XMLDrawFile:
Public Methods | |
XMLDrawFile (string fn, istream &is, ostream &es) | |
Drawing * | read_drawing () |
Private Methods | |
Object * | read_object () |
void | handle_attribute (Object *, string fname, string value) |
void | read_object_feature (Object *, string fname) |
Private Attributes | |
XMLTokenizer | t |
ostream & | err |
|
|
|
00136 { 00137 bool b; 00138 float f; 00139 string s; 00140 Position p; 00141 00142 try { 00143 if (Utilities::from_string(value,b)) { 00144 //cout << value << " is a bool!" << endl; 00145 e->add_feature(fname,b); 00146 } else if (Utilities::from_string(value,f)) { 00147 //cout << value << " is a float!" << endl; 00148 e->add_feature(fname,f); 00149 } else if (Utilities::from_string(value,p)) { 00150 //cout << value << " is a position!" << endl; 00151 e->add_feature(fname,p); 00152 } else { 00153 //cout << value << " is a string!" << endl; 00154 e->add_feature(fname,value); 00155 } 00156 } catch (unknown_feature&) { 00157 throw load_exception("Unknown feature: " + fname + " = " + value); 00158 } 00159 } |
|
Implements DrawFile.
00060 { 00061 if (t.next_token() != XMLTokenizer::OPEN || 00062 t.curr_name != "Drawing") { 00063 err << "draw file does not start with <Drawing> tag." << endl; 00064 return 0; 00065 } 00066 00067 Drawing* drawing = 0; 00068 00069 try { 00070 drawing = dynamic_cast<Drawing*>(read_object()); 00071 if (drawing == 0) throw load_exception("Internal error"); 00072 } catch (exception& e) { 00073 cerr << filename << ":" << t.get_line_number() << ":" 00074 << e.what() << ". Stopped reading draw file." << endl; 00075 return 0; 00076 } 00077 00078 if (t.next_token() != XMLTokenizer::END) { 00079 cerr << filename << ":" << t.get_line_number() << ":" 00080 << "Unexpected text after </Drawing> tag. Stopped reading draw file." 00081 << endl; 00082 } 00083 00084 return drawing; 00085 } |
|
00088 { 00089 string ename = t.curr_name; 00090 Object *o = Object::Factory::create(ename); 00091 00092 // read attributes: 00093 while (t.next_token() == XMLTokenizer::ATTR) { 00094 handle_attribute(o,t.curr_name,t.curr_text); 00095 } 00096 00097 if (t.curr_token == XMLTokenizer::ECLOSE) return o; // done! 00098 if (t.curr_token != XMLTokenizer::CLOSE) { 00099 if (t.curr_token == XMLTokenizer::ERROR) 00100 throw load_exception(t.curr_text); 00101 throw load_exception("Expected '>' after attributes"); 00102 } 00103 00104 string text; // built up bit by bit. 00105 00106 for (;;) { 00107 switch (t.next_token()) { 00108 default: 00109 throw load_exception("Internal error"); 00110 case XMLTokenizer::END: 00111 throw load_exception("Unexpected EOF"); 00112 case XMLTokenizer::ERROR: 00113 throw load_exception(t.curr_text); 00114 case XMLTokenizer::ETAG: 00115 if (t.curr_name != ename) { 00116 throw load_exception("<" + ename + "> ended by </" + 00117 t.curr_name + ">."); 00118 } 00119 // remove final spaces 00120 if (!text.empty()) { 00121 text.erase(text.find_last_not_of(" \t\n")+1); 00122 if (!text.empty()) o->add_feature("text",text); 00123 } 00124 return o; 00125 case XMLTokenizer::OPEN: 00126 read_object_feature(o,t.curr_name); 00127 break; 00128 case XMLTokenizer::TEXT: 00129 text += t.curr_text; 00130 break; 00131 } 00132 } 00133 } |
|
00162 { 00163 if (t.next_token() != XMLTokenizer::CLOSE) { 00164 if (t.curr_token == XMLTokenizer::ERROR) 00165 throw load_exception(t.curr_text); 00166 else 00167 throw load_exception("Feature open tags should be of form <feature>"); 00168 } 00169 00170 if (t.next_token() == XMLTokenizer::TEXT) { 00171 handle_attribute(o,fname,t.curr_text); 00172 } else { 00173 while (t.curr_token == XMLTokenizer::OPEN) { 00174 o->add_feature(fname,read_object()); 00175 (void)t.next_token(); 00176 } 00177 t.save_token(); 00178 } 00179 00180 if (t.next_token() != XMLTokenizer::ETAG || 00181 t.curr_name != fname) { 00182 if (t.curr_token == XMLTokenizer::ERROR) 00183 throw load_exception(t.curr_text); 00184 else 00185 throw load_exception("<" + fname + "> not closed after string"); 00186 } 00187 } |
|
|
|
|