#include class COMPONENT_BASE: public ARRAY_OBJ{ protected: SSTRING name; SSTRING summary; SSTRING descrip; /*~PROTOBEG~ COMPONENT_BASE */ public: const char *getdescrip (void)const; const char *getname (void)const; const char *getsummary (void)const; /*~PROTOEND~ COMPONENT_BASE */ }; class PARAM: public COMPONENT_BASE{ SSTRING type; /*~PROTOBEG~ PARAM */ public: PARAM (const char *_type, const char *_name); PARAM (xmlNodePtr cur); const char *gettype (void)const; /*~PROTOEND~ PARAM */ }; class PARAMS: public ARRAY{ /*~PROTOBEG~ PARAMS */ public: PARAM *getitem (int no)const; /*~PROTOEND~ PARAMS */ }; class COMPONENT_FUNC: public COMPONENT_BASE{ protected: SSTRING rettype; PARAMS params; /*~PROTOBEG~ COMPONENT_FUNC */ public: int getnbparam (void)const; PARAM *getparam (int no)const; const char *getrettype (int no)const; const char *getrettype (void)const; protected: void init (xmlNodePtr cur); public: /*~PROTOEND~ COMPONENT_FUNC */ }; class FUNCTAG: public COMPONENT_FUNC{ bool opt; /*~PROTOBEG~ FUNCTAG */ public: FUNCTAG (xmlNodePtr cur); bool is_optional (void)const; /*~PROTOEND~ FUNCTAG */ }; class FUNCTAGS: public ARRAY{ /*~PROTOBEG~ FUNCTAGS */ public: FUNCTAG *getitem (int no)const; /*~PROTOEND~ FUNCTAGS */ }; class FHELPER: public COMPONENT_FUNC{ /*~PROTOBEG~ FHELPER */ public: FHELPER (xmlNodePtr cur); /*~PROTOEND~ FHELPER */ }; class FHELPERS: public ARRAY{ /*~PROTOBEG~ FHELPERS */ public: FHELPER *getitem (int no)const; /*~PROTOEND~ FHELPERS */ }; class PROTOTYPE: public ARRAY_OBJ{ SSTRING rettype; PARAMS params; /*~PROTOBEG~ PROTOTYPE */ public: PROTOTYPE (xmlNodePtr cur); /*~PROTOEND~ PROTOTYPE */ }; class PROTOTYPES: public ARRAY{ /*~PROTOBEG~ PROTOTYPES */ public: PROTOTYPE *getitem (int no)const; /*~PROTOEND~ PROTOTYPES */ }; class COMPONENT: public COMPONENT_BASE{ PROTOTYPES protos; FUNCTAGS functags; FHELPERS helpers; /*~PROTOBEG~ COMPONENT */ public: COMPONENT (xmlNodePtr cur); FHELPER *getfhelper (int no)const; FUNCTAG *getfunctag (int no)const; int getnbfhelper (void)const; int getnbfunctag (void)const; int getnbproto (void)const; PROTOTYPE *getproto (int no)const; const char *getrettype (void)const; bool isobject (void)const; /*~PROTOEND~ COMPONENT */ }; class SECTION: public COMPONENT_BASE{ /*~PROTOBEG~ SECTION */ public: SECTION (void); /*~PROTOEND~ SECTION */ }; class SECTIONS: public ARRAY{ /*~PROTOBEG~ SECTIONS */ public: SECTION *getitem (int no)const; /*~PROTOEND~ SECTIONS */ }; #if 0 static void component_set (SSTRING &s, const unsigned char *key, xmlNodePtr cur) { xmlChar *pt = xmlGetProp(cur,key); if (pt != NULL){ s.setfrom ((char*)pt); free (pt); }else{ s.setempty(); } } PUBLIC const char *COMPONENT_BASE::getname() const { return name.get(); } PUBLIC const char *COMPONENT_BASE::getsummary() const { return summary.get(); } PUBLIC const char *COMPONENT_BASE::getdescrip() const { return descrip.get(); } PUBLIC PARAM::PARAM (const char *_type, const char *_name) { type.setfrom(_type); name.setfrom(_name); } PUBLIC PARAM::PARAM (xmlNodePtr cur) { component_set (name,K_NAME,cur); component_set (type,K_TYPE,cur); xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL){ fprintf (stderr,"PARAM see %s\n",sub->name); if (xmlStrcmp(sub->name,K_SUMMARY)==0){ summary.setfrom ((char *)xmlNodeGetContent(sub)); }else if (xmlStrcmp(sub->name,K_DESCRIPTION)==0){ descrip.setfrom ((char *)xmlNodeGetContent(sub)); }else{ fprintf (stderr,"Unknown XML section in PARAM: %s\n",sub->name); } } } PUBLIC const char *PARAM::gettype () const { return type.get(); } PUBLIC PARAM *PARAMS::getitem(int no) const { return (PARAM*)ARRAY::getitem(no); } /* Return the return type of the functag */ PUBLIC const char *COMPONENT_FUNC::getrettype() const { return rettype.get(); } /* Return the number of parameter passed by this functag */ PUBLIC int COMPONENT_FUNC::getnbparam() const { return params.getnb(); } /* Return the type and name of one parameter */ PUBLIC const char *COMPONENT_FUNC::getrettype(int no) const { return rettype.get(); } /* Return the type and name of one parameter */ PUBLIC PARAM *COMPONENT_FUNC::getparam(int no) const { return params.getitem(no); } PROTECTED void COMPONENT_FUNC::init(xmlNodePtr cur) { component_set (name,K_NAME,cur); component_set (rettype,K_RETURN,cur); xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL){ fprintf (stderr,"COMPONENT_FUNC see %s\n",sub->name); if (xmlStrcmp(sub->name,K_SUMMARY)==0){ summary.setfrom ((char *)xmlNodeGetContent(sub)); }else if (xmlStrcmp(sub->name,K_DESCRIPTION)==0){ descrip.setfrom ((char *)xmlNodeGetContent(sub)); }else if (xmlStrcmp(sub->name,K_PARAM)==0){ params.add (new PARAM(sub)); }else{ fprintf (stderr,"Unknown XML section in functag: %s\n",sub->name); } sub = sub->next; } } PUBLIC FUNCTAG::FUNCTAG(xmlNodePtr cur) { SSTRING s; component_set (s,K_OPT,cur); opt = s.getval() != 0; init (cur); } PUBLIC bool FUNCTAG::is_optional() const { return opt; } PUBLIC FUNCTAG *FUNCTAGS::getitem(int no) const { return (FUNCTAG*)ARRAY::getitem(no); } PUBLIC FHELPER::FHELPER(xmlNodePtr cur) { init (cur); } PUBLIC FHELPER *FHELPERS::getitem (int no) const { return (FHELPER*)ARRAY::getitem(no); } PUBLIC PROTOTYPE::PROTOTYPE(xmlNodePtr cur) { component_set (rettype,K_RETURN,cur); xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL){ fprintf (stderr,"PROTOTYPE see %s\n",sub->name); if (xmlStrcmp(sub->name,K_PARAM)==0){ params.add (new PARAM(sub)); }else{ fprintf (stderr,"Unknown XML section in prototype: %s\n",sub->name); } sub = sub->next; } } PUBLIC PROTOTYPE *PROTOTYPES::getitem (int no) const { return (PROTOTYPE*)ARRAY::getitem(no); } PUBLIC COMPONENT::COMPONENT(xmlNodePtr cur) { component_set (name,K_NAME,cur); xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL){ fprintf (stderr,"COMPONENT see %s\n",sub->name); if (xmlStrcmp(sub->name,K_FUNCTAG)==0){ functags.add (new FUNCTAG(sub)); }else if (xmlStrcmp(sub->name,K_FHELPER)==0){ helpers.add (new FHELPER(sub)); }else if (xmlStrcmp(sub->name,K_SUMMARY)==0){ summary.setfrom ((char *)xmlNodeGetContent(sub)); }else if (xmlStrcmp(sub->name,K_DESCRIPTION)==0){ descrip.setfrom ((char *)xmlNodeGetContent(sub)); }else if (xmlStrcmp(sub->name,K_PROTOTYPE)==0){ protos.add (new PROTOTYPE(sub)); }else{ fprintf (stderr,"Unknown XML section in component: %s\n",sub->name); } sub = sub->next; } } PUBLIC const char *COMPONENT::getrettype() const { return ""; } /* Return the number of prototype for this function. Return "" for a class. */ PUBLIC int COMPONENT::getnbproto() const { return protos.getnb(); } PUBLIC PROTOTYPE *COMPONENT::getproto(int no) const { return protos.getitem(no); } /* Return the number of functags for this component */ PUBLIC int COMPONENT::getnbfunctag() const { return functags.getnb(); } PUBLIC FUNCTAG *COMPONENT::getfunctag (int no) const { return functags.getitem(no); } /* Return the number of fhelpers for this component */ PUBLIC int COMPONENT::getnbfhelper() const { return helpers.getnb(); } PUBLIC FHELPER *COMPONENT::getfhelper (int no) const { return helpers.getitem(no); } /* Tel if this component is a class or a function */ PUBLIC bool COMPONENT::isobject() const { return false; } static COMPONENT *component_locate(const char *filename, const char *name) { COMPONENT *ret = NULL; xmlDocPtr doc = xmlParseFile(filename); if (doc != NULL){ xmlNodePtr cur = xmlDocGetRootElement(doc); while (cur != NULL){ printf ("cur->name :%s:\n",cur->name); if (xmlStrcmp(cur->name,K_COMPONENT)==0){ xmlChar *cname = xmlGetProp(cur,K_NAME); printf ("name = :%s:\n",name); if (xmlStrcmp(cname,(unsigned char*)name)==0){ ret = new COMPONENT(cur); } free(cname); break; } cur = cur->next; } xmlFreeDoc(doc); } return ret; } /* Locate a component description. Return NULL if not found. */ COMPONENT *component_locate (const char *name) { COMPONENT *ret = NULL; ret = component_locate ("../framework/framework.comp",name); return ret; } PUBLIC SECTION::SECTION() { } PUBLIC SECTION *SECTIONS::getitem(int no) const { return (SECTION*)ARRAY::getitem(no); } #endif