cxmlelement.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CXMLELEMENT_H
00020 #define __CXMLELEMENT_H
00021
00022 #include <string>
00023 #include <map>
00024 #include <vector>
00025 #include "simkerneldefs.h"
00026 #include "cenvir.h"
00027
00028 NAMESPACE_BEGIN
00029
00030 class cXMLElement;
00031 class cModule;
00032
00036 typedef std::vector<cXMLElement*> cXMLElementList;
00037
00041 typedef std::map<std::string,std::string> cXMLAttributeMap;
00042
00043
00075 class SIM_API cXMLElement
00076 {
00077 public:
00082 class SIM_API ParamResolver
00083 {
00084 public:
00090 virtual bool resolve(const char *paramname, std::string& value) = 0;
00091 virtual ~ParamResolver() {}
00092 };
00093
00094 private:
00095 std::string ename;
00096 std::string srcloc;
00097 std::string value;
00098 cXMLAttributeMap attrs;
00099 cXMLElement *parent;
00100 cXMLElement *firstchild;
00101 cXMLElement *lastchild;
00102 cXMLElement *prevsibling;
00103 cXMLElement *nextsibling;
00104
00105 private:
00106 void doGetElementsByTagName(const char *tagname, cXMLElementList& list) const;
00107
00108 public:
00109
00110 cXMLElement(const char *tagname, const char *srcloc, cXMLElement *parent);
00111
00112
00113 virtual void setNodeValue(const char *s, int len);
00114
00115
00116 virtual void appendNodeValue(const char *s, int len);
00117
00118
00119 virtual ~cXMLElement();
00120
00121
00122 virtual void setAttribute(const char *attr, const char *value);
00123
00124
00125 virtual void appendChild(cXMLElement *node);
00126
00127
00128
00129 virtual void insertChildBefore(cXMLElement *where, cXMLElement *newnode);
00130
00131
00132
00133 virtual cXMLElement *removeChild(cXMLElement *node);
00134
00135
00136 static cXMLElement *getDocumentElementByPath(cXMLElement *documentnode, const char *pathexpr, ParamResolver *resolver=NULL);
00137
00138
00139 std::string tostr(int level) const;
00140
00143
00147 virtual const char *getTagName() const;
00148
00153 virtual const char *getSourceLocation() const;
00154
00159 virtual const char *getNodeValue() const;
00160
00165 virtual const char *getAttribute(const char *attr) const;
00166
00170 virtual bool hasAttributes() const;
00171
00175 virtual const cXMLAttributeMap& getAttributes() const;
00177
00183 virtual cXMLElement *getParentNode() const;
00184
00188 virtual bool hasChildren() const;
00189
00194 virtual cXMLElement *getFirstChild() const;
00195
00200 virtual cXMLElement *getLastChild() const;
00201
00217 virtual cXMLElement *getNextSibling() const;
00218
00224 virtual cXMLElement *getPreviousSibling() const;
00225
00230 virtual cXMLElement *getFirstChildWithTag(const char *tagname) const;
00231
00246 virtual cXMLElement *getNextSiblingWithTag(const char *tagname) const;
00247
00251 virtual cXMLElementList getChildren() const;
00252
00256 virtual cXMLElementList getChildrenByTagName(const char *tagname) const;
00257
00262 virtual cXMLElementList getElementsByTagName(const char *tagname) const;
00264
00273 cXMLElement *getFirstChildWithAttribute(const char *tagname, const char *attr, const char *attrvalue=NULL) const;
00274
00280 cXMLElement *getElementById(const char *idattrvalue) const;
00281
00311 cXMLElement *getElementByPath(const char *pathexpression, cXMLElement *root=NULL, ParamResolver *resolver=NULL) const;
00312
00316 void debugDump() const;
00317
00324 virtual std::string detailedInfo() const;
00326 };
00327
00335 class SIM_API ModNameParamResolver : public cXMLElement::ParamResolver
00336 {
00337 protected:
00338 cModule *mod;
00339 public:
00340 ModNameParamResolver(cModule *mod) {this->mod = mod;}
00341 virtual bool resolve(const char *paramname, std::string& value);
00342 };
00343
00349 class SIM_API StringMapParamResolver : public cXMLElement::ParamResolver
00350 {
00351 public:
00352 typedef std::map<std::string,std::string> StringMap;
00353 protected:
00354 StringMap params;
00355 public:
00356 StringMapParamResolver(const StringMap& m) {params = m;}
00357 virtual bool resolve(const char *paramname, std::string& value);
00358 };
00359
00360 NAMESPACE_END
00361
00362
00363 #endif
00364