nedresourcecache.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __NEDRESOURCECACHE_H
00019 #define __NEDRESOURCECACHE_H
00020
00021 #include <map>
00022 #include <vector>
00023 #include <string>
00024 #include "nedelements.h"
00025 #include "nedtypeinfo.h"
00026
00027 NAMESPACE_BEGIN
00028
00029
00033 struct NEDLookupContext
00034 {
00035 NEDElement *element;
00036 std::string qname;
00037 NEDLookupContext(NEDElement *e, const char *q) {element=e;qname=q;}
00038 };
00039
00048 class NEDXML_API NEDResourceCache
00049 {
00050 public:
00052 class INEDTypeNames {
00053 public:
00055 virtual bool contains(const char *qname) const = 0;
00056
00058 virtual int size() const = 0;
00059
00061 virtual const char *get(int k) const = 0;
00062
00063 virtual ~INEDTypeNames() {}
00064 };
00065
00066 class CachedTypeNames : public INEDTypeNames {
00067 protected:
00068 NEDResourceCache *p;
00069 public:
00070 CachedTypeNames(NEDResourceCache *p) {this->p=p;}
00071 virtual bool contains(const char *qname) const {return p->lookup(qname)!=NULL;}
00072 virtual int size() const {return p->getTypeNames().size();}
00073 virtual const char *get(int k) const {return p->getTypeNames()[k].c_str();}
00074 };
00075
00076 protected:
00077 typedef std::map<std::string, NEDElement *> NEDFileMap;
00078 typedef std::map<std::string, NEDTypeInfo *> NEDTypeInfoMap;
00079
00080
00081 NEDFileMap files;
00082
00083
00084
00085 NEDTypeInfoMap nedTypes;
00086
00087
00088 mutable std::vector<std::string> nedTypeNames;
00089
00090
00091
00092 typedef std::map<std::string,std::string> StringMap;
00093 StringMap folderPackages;
00094
00095 struct PendingNedType {
00096 std::string qname;
00097 bool isInnerType;
00098 NEDElement *node;
00099 PendingNedType(const char *q, bool inner, NEDElement *e) {qname=q;isInnerType=inner;node=e;}
00100 };
00101
00102
00103 std::vector<PendingNedType> pendingList;
00104
00105 protected:
00106 virtual void registerBuiltinDeclarations();
00107 virtual int doLoadNedSourceFolder(const char *foldername, const char *expectedPackage);
00108 virtual void doLoadNedFileOrText(const char *nedfname, const char *nedtext, const char *expectedPackage, bool isXML);
00109 virtual NEDElement *parseAndValidateNedFileOrText(const char *nedfname, const char *nedtext, bool isXML);
00110 virtual std::string determineRootPackageName(const char *nedSourceFolderName);
00111 virtual std::string getNedSourceFolderForFolder(const char *folder) const;
00112 virtual void collectNedTypesFrom(NEDElement *node, const std::string& namespacePrefix, bool areInnerTypes);
00113 virtual void collectNedType(const char *qname, bool isInnerType, NEDElement *node);
00114 virtual bool areDependenciesResolved(const char *qname, NEDElement *node);
00115 virtual void registerPendingNedTypes();
00116 virtual void registerNedType(const char *qname, bool isInnerType, NEDElement *node);
00117
00118 public:
00120 NEDResourceCache();
00121
00123 virtual ~NEDResourceCache();
00124
00134 virtual int loadNedSourceFolder(const char *foldername);
00135
00143 virtual void loadNedFile(const char *nedfname, const char *expectedPackage, bool isXML);
00144
00155 virtual void loadNedText(const char *name, const char *nedtext, const char *expectedPackage, bool isXML);
00156
00162 virtual void doneLoadingNedFiles();
00163
00169 virtual bool addFile(const char *fname, NEDElement *node);
00170
00172 virtual NEDElement *getFile(const char *fname) const;
00173
00180 virtual NedFileElement *getParentPackageNedFile(NedFileElement *nedfile) const;
00181
00183 virtual NEDTypeInfo *lookup(const char *qname) const;
00184
00186 virtual NEDTypeInfo *getDecl(const char *qname) const;
00187
00189 virtual std::string resolveNedType(const NEDLookupContext& context, const char *nedtypename, INEDTypeNames *qnames);
00190
00192 virtual std::string resolveNedType(const NEDLookupContext& context, const char *nedtypename) {
00193 CachedTypeNames names(this);
00194 return resolveNedType(context, nedtypename, &names);
00195 }
00196
00198 virtual const std::vector<std::string>& getTypeNames() const;
00199
00204 virtual std::string getNedPackageForFolder(const char *folder) const;
00205
00209 static NEDLookupContext getParentContextOf(const char *qname, NEDElement *node);
00210
00211 };
00212
00213 NAMESPACE_END
00214
00215
00216 #endif
00217