diff options
| author | deva <deva> | 2008-05-16 15:00:12 +0000 | 
|---|---|---|
| committer | deva <deva> | 2008-05-16 15:00:12 +0000 | 
| commit | d22c5966c130ef7768bac7914cb4dafa74088036 (patch) | |
| tree | 9e0cffb41f582cdf01f592257dd6c85677241f2e /server/src/templateparser.cc | |
| parent | 3f2a5d6e373a79260594382c67d693d4b97c4ffa (diff) | |
Worked on the connection of the various elements of the server.
Diffstat (limited to 'server/src/templateparser.cc')
| -rw-r--r-- | server/src/templateparser.cc | 87 | 
1 files changed, 73 insertions, 14 deletions
| diff --git a/server/src/templateparser.cc b/server/src/templateparser.cc index 1e6ddc7..956a0e8 100644 --- a/server/src/templateparser.cc +++ b/server/src/templateparser.cc @@ -67,9 +67,14 @@ TemplateParser::~TemplateParser()    if(fd != -1) close(fd);  } +void TemplateParser::characterData(std::string &data) +{ +  if(state == MAP) current_macro->maps.back().attributes["lua"].append(data); +} +  void TemplateParser::startTag(std::string name, std::map< std::string, std::string> attributes)  { -  // Create template and enable parsing of macrosequences +  // Create template and enable parsing of courses    if(name == "template") {      if(state != UNDEFINED) error("template found not in outer level.");      state = TEMPLATE; @@ -83,35 +88,35 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri    }    // Enable macro parsing -  if(name == "macrosequence") { -    if(state != TEMPLATE) error("macrosequence found outside template."); -    state = MACROSEQUENCE; +  if(name == "course") { +    if(state != TEMPLATE) error("course found outside template."); +    state = COURSE; -    assert(t); // A Template has not yet been allocated, cannot create macrosequence! +    assert(t); // A Template has not yet been allocated, cannot create course! -    t->macrosequence.attributes = attributes; +    t->course.attributes = attributes;      return;    }    // Create macro and enable parsing of queries, maps and window    if(name == "macro") { -    if(state != MACROSEQUENCE) error("macro found outside macrosequence."); +    if(state != COURSE) error("macro found outside course.");      state = MACRO;      assert(t); // A Template has not yet been allocated, cannot create macro!      Macro m;      m.attributes = attributes; -    t->macrosequence.macroes.push_back(m); -    current_macro = &(t->macrosequence.macroes.back()); +    t->course.macroes.push_back(m); +    current_macro = &(t->course.macroes.back());      return;    }    // Enable Query parsing    if(name == "queries") { -    if(state != TEMPLATE) error("queries found outside template."); +    if(state != MACRO) error("queries found outside macro.");      state = QUERIES;      assert(current_macro); // No macro is currently available, cannot create queries! @@ -135,7 +140,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri    // Enable Map parsing    if(name == "maps") { -    if(state != TEMPLATE) error("maps found outside template."); +    if(state != MACRO) error("maps found outside macro.");      state = MAPS;      assert(current_macro); // No macro is currently available, cannot create maps! @@ -159,7 +164,7 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri    // Enable widget parsing    if(name == "window") { -    if(state != TEMPLATE) error("window found outside template."); +    if(state != MACRO) error("window found outside macro.");      state = WINDOW;      assert(current_macro); // No macro is currently available, cannot create window! @@ -196,8 +201,8 @@ void TemplateParser::startTag(std::string name, std::map< std::string, std::stri  void TemplateParser::endTag(std::string name)  {    if(name == "template") state = UNDEFINED; -  if(name == "macrosequence") state = TEMPLATE; -  if(name == "macro") state = MACROSEQUENCE; +  if(name == "course") state = TEMPLATE; +  if(name == "macro") state = COURSE;    if(name == "queries") state = MACRO;    if(name == "query") state = QUERIES;    if(name == "maps") state = MACRO; @@ -221,3 +226,57 @@ Template *TemplateParser::getTemplate()  {    return t;  } + +#ifdef TEST_TEMPLATEPARSER + +void print_attributes(std::string prefix, +                      std::map< std::string, std::string > &att) +{ +  std::map< std::string, std::string >::iterator i = att.begin(); +  while(i != att.end()) { +    printf("%s %s = \"%s\"\n", prefix.c_str(), (*i).first.c_str(), (*i).second.c_str()); +    i++; +  } +} + +int main() +{ +  TemplateParser parser("../xml/example2.xml"); +  parser.parse(); + +  Template *t = parser.getTemplate(); + +  printf("[Template]:\n"); +  print_attributes("\t-", t->attributes); + +  printf("\t[Course]:\n"); +  print_attributes("\t\t-", t->course.attributes); +   +  printf("\t\t[Macroes]:\n"); +  std::vector< Macro >::iterator i = t->course.macroes.begin(); + +  while(i != t->course.macroes.end()) { +    printf("\t\t\t[Macro]:\n"); +    print_attributes("\t\t\t\t-", (*i).attributes); +     +    std::vector< Query >::iterator qi = (*i).queries.begin(); +    while(qi != (*i).queries.end()) { +      printf("\t\t\t\t[Query]:\n"); +      print_attributes("\t\t\t\t\t-", (*qi).attributes); +      qi++; +    } + +    std::vector< Map >::iterator mi = (*i).maps.begin(); +    while(mi != (*i).maps.end()) { +      printf("\t\t\t\t[Map]:\n"); +      print_attributes("\t\t\t\t\t-", (*mi).attributes); +      mi++; +    } + +    i++; +  } + +  return 0; +} + +#endif/*TEST_TEMPLATEPARSER*/ | 
