00001
00002
00003 #include <Parse.h>
00004 #include <Base64.h>
00005 #include "RobotXMLFile.h"
00006
00007
00008
00009
00010 RobotXMLFile::RobotXMLFile(const std::string& filename)
00011 :BaseXMLFile(filename, "", "robot")
00012 {
00013 }
00014
00015
00016 RobotXMLFile::~RobotXMLFile()
00017 {
00018 }
00019
00020
00021 xmlNodePtr RobotXMLFile::Find(xmlNodePtr base,const std::string& path)
00022 {
00023 Parse pa(path,"/");
00024 std::string ord = pa.getword();
00025 std::string str = pa.getrest();
00026 xmlNodePtr p = GetFirstElement(base,ord);
00027 if (p && str.size())
00028 {
00029 return Find(p,str);
00030 }
00031 return p;
00032 }
00033
00034
00035 std::string RobotXMLFile::GetString(const std::string& path,const std::string& property)
00036 {
00037 xmlNodePtr p = Find(GetRootElement(),path);
00038 if (p)
00039 {
00040 SetCurrent(p);
00041 std::string str = GetProperty(property);
00042 return str;
00043 }
00044 fprintf(stderr,"config path not found: %s\n",path.c_str());
00045 return "";
00046 }
00047
00048
00049 void RobotXMLFile::GetMethods(std::map<std::string,int>& mmap)
00050 {
00051 xmlNodePtr p = GetFirstElement("methods");
00052 if (p)
00053 {
00054 SetCurrent(p);
00055 p = GetChildrenNode();
00056 while (p)
00057 {
00058 std::string name = GetProperty("name");
00059 std::string entry = GetProperty("entry");
00060 if (name.size())
00061 mmap[name] = atoi(entry.c_str());
00062
00063 p = GetNextNode();
00064 }
00065 }
00066 }
00067
00068
00069 void RobotXMLFile::GetVariables(std::vector<VARIABLE *>& ref)
00070 {
00071 xmlNodePtr p = GetFirstElement("variables");
00072 if (p)
00073 {
00074 SetCurrent(p);
00075 p = GetChildrenNode();
00076 while (p)
00077 {
00078 std::string name = GetProperty("name");
00079 std::string type = GetProperty("type");
00080 std::string index = GetProperty("index");
00081 if (name.size())
00082 {
00083 VARIABLE *p = new VARIABLE(name, atoi(type.c_str()), atoi(index.c_str()));
00084 ref.push_back(p);
00085 }
00086
00087 p = GetNextNode();
00088 }
00089 }
00090 }
00091
00092