OMNeT++ NEDXML  5.4.1
NedResourceCache Class Reference

#include <nedresourcecache.h>

Description

Stores loaded NED files, and keeps track of components in them.

This class can be turned into a cache (discarding and reloading NED files on demand) if such need arises.

Classes

class  CachedTypeNames
 
class  INedTypeNames
 
struct  PendingNedType
 

Public Member Functions

 NedResourceCache ()
 
virtual ~NedResourceCache ()
 
virtual int loadNedSourceFolder (const char *foldername)
 
virtual void loadNedFile (const char *nedfname, const char *expectedPackage, bool isXML)
 
virtual void loadNedText (const char *name, const char *nedtext, const char *expectedPackage, bool isXML)
 
virtual void doneLoadingNedFiles ()
 
virtual bool addFile (const char *fname, ASTNode *node)
 
virtual ASTNodegetFile (const char *fname) const
 
virtual NedFileElement * getParentPackageNedFile (NedFileElement *nedfile) const
 
virtual NedTypeInfolookup (const char *qname) const
 
virtual NedTypeInfogetDecl (const char *qname) const
 
virtual std::string resolveNedType (const NedLookupContext &context, const char *nedtypename, INedTypeNames *qnames)
 
virtual std::string resolveNedType (const NedLookupContext &context, const char *nedtypename)
 
virtual const std::vector< std::string > & getTypeNames () const
 
virtual std::string getNedPackageForFolder (const char *folder) const
 

Static Public Member Functions

static NedLookupContext getParentContextOf (const char *qname, ASTNode *node)
 

Protected Types

typedef std::map< std::string, ASTNode * > NedFileMap
 
typedef std::map< std::string, NedTypeInfo * > NedTypeInfoMap
 
typedef std::map< std::string, std::string > StringMap
 

Protected Member Functions

virtual void registerBuiltinDeclarations ()
 
virtual int doLoadNedSourceFolder (const char *foldername, const char *expectedPackage)
 
virtual void doLoadNedFileOrText (const char *nedfname, const char *nedtext, const char *expectedPackage, bool isXML)
 
virtual ASTNodeparseAndValidateNedFileOrText (const char *nedfname, const char *nedtext, bool isXML)
 
virtual std::string determineRootPackageName (const char *nedSourceFolderName)
 
virtual std::string getNedSourceFolderForFolder (const char *folder) const
 
virtual void collectNedTypesFrom (ASTNode *node, const std::string &packagePrefix, bool areInnerTypes)
 
virtual void collectNedType (const char *qname, bool isInnerType, ASTNode *node)
 
virtual bool areDependenciesResolved (const char *qname, ASTNode *node)
 
virtual void registerPendingNedTypes ()
 
virtual void registerNedType (const char *qname, bool isInnerType, ASTNode *node)
 
virtual std::string getFirstError (ErrorStore *errors, const char *prefix=nullptr)
 

Protected Attributes

NedFileMap files
 
NedTypeInfoMap nedTypes
 
std::vector< std::string > nedTypeNames
 
StringMap folderPackages
 
std::vector< PendingNedTypependingList
 

Member Typedef Documentation

typedef std::map<std::string, ASTNode *> NedFileMap
protected
typedef std::map<std::string, NedTypeInfo *> NedTypeInfoMap
protected
typedef std::map<std::string,std::string> StringMap
protected

Constructor & Destructor Documentation

Constructor

virtual ~NedResourceCache ( )
virtual

Destructor

Member Function Documentation

virtual void registerBuiltinDeclarations ( )
protectedvirtual
virtual int doLoadNedSourceFolder ( const char *  foldername,
const char *  expectedPackage 
)
protectedvirtual
virtual void doLoadNedFileOrText ( const char *  nedfname,
const char *  nedtext,
const char *  expectedPackage,
bool  isXML 
)
protectedvirtual
virtual ASTNode* parseAndValidateNedFileOrText ( const char *  nedfname,
const char *  nedtext,
bool  isXML 
)
protectedvirtual
virtual std::string determineRootPackageName ( const char *  nedSourceFolderName)
protectedvirtual
virtual std::string getNedSourceFolderForFolder ( const char *  folder) const
protectedvirtual
virtual void collectNedTypesFrom ( ASTNode node,
const std::string &  packagePrefix,
bool  areInnerTypes 
)
protectedvirtual
virtual void collectNedType ( const char *  qname,
bool  isInnerType,
ASTNode node 
)
protectedvirtual
virtual bool areDependenciesResolved ( const char *  qname,
ASTNode node 
)
protectedvirtual
virtual void registerPendingNedTypes ( )
protectedvirtual
virtual void registerNedType ( const char *  qname,
bool  isInnerType,
ASTNode node 
)
protectedvirtual
virtual std::string getFirstError ( ErrorStore errors,
const char *  prefix = nullptr 
)
protectedvirtual
virtual int loadNedSourceFolder ( const char *  foldername)
virtual

Load all NED files from a NED source folder. This involves visiting each subdirectory, and loading all "*.ned" files from there. The given folder is assumed to be the root of the NED package hierarchy. Returns the number of files loaded.

Note: doneLoadingNedFiles() must be called after the last loadNedSourceFolder()/loadNedFile()/loadNedText() call.

virtual void loadNedFile ( const char *  nedfname,
const char *  expectedPackage,
bool  isXML 
)
virtual

Load a single NED file. If the expected package is given (non-nullptr), it should match the package declaration inside the NED file.

Note: doneLoadingNedFiles() must be called after the last loadNedSourceFolder()/loadNedFile()/loadNedText() call.

virtual void loadNedText ( const char *  name,
const char *  nedtext,
const char *  expectedPackage,
bool  isXML 
)
virtual

Parses and loads the NED source code passed in the nedtext argument. The name argument will be used as filename in error messages, and and should be unique among the files loaded. If the expected package is given (non-nullptr), it should match the package declaration inside the NED file.

Note: doneLoadingNedFiles() must be called after the last loadNedSourceFolder()/loadNedFile()/loadNedText() call.

virtual void doneLoadingNedFiles ( )
virtual

To be called after all NED folders / files have been loaded. May be redefined to issue errors for components that could not be fully resolved because of missing base types or interfaces.

virtual bool addFile ( const char *  fname,
ASTNode node 
)
virtual

Add a file (parsed into an object tree) to the cache. If the file was already added, no processing takes place and the function returns false; otherwise it returns true.

virtual ASTNode* getFile ( const char *  fname) const
virtual

Get a file (represented as object tree) from the cache

virtual NedFileElement* getParentPackageNedFile ( NedFileElement *  nedfile) const
virtual

Given a NED file, returns the package.ned file from the same folder, or the nearest ancestor package.ned file. If the file is a package.ned file itself, returns the nearest ancestor package.ned file. Returns nullptr if there is no parent package.ned file.

virtual NedTypeInfo* lookup ( const char *  qname) const
virtual

Look up a fully qualified NED type name from the cache. Returns nullptr if not found.

Referenced by NedResourceCache::CachedTypeNames::contains().

virtual NedTypeInfo* getDecl ( const char *  qname) const
virtual

Like lookup(), but asserts non-nullptr return value

virtual std::string resolveNedType ( const NedLookupContext context,
const char *  nedtypename,
INedTypeNames qnames 
)
virtual

Resolves the given NED type name in the given context, among the given type names. Returns "" if not found.

virtual std::string resolveNedType ( const NedLookupContext context,
const char *  nedtypename 
)
inlinevirtual

Resolves NED type name, based on the NED files loaded

References NedLookupContext::qname.

virtual const std::vector<std::string>& getTypeNames ( ) const
virtual
virtual std::string getNedPackageForFolder ( const char *  folder) const
virtual

Returns the NED package that corresponds to the given folder. Returns "" for the default package, and "-" if the folder is outside all NED folders.

static NedLookupContext getParentContextOf ( const char *  qname,
ASTNode node 
)
static

Utility method, useful with resolveNedType()/resolveComponentType()

Member Data Documentation

NedFileMap files
protected
NedTypeInfoMap nedTypes
protected
std::vector<std::string> nedTypeNames
mutableprotected
StringMap folderPackages
protected
std::vector<PendingNedType> pendingList
protected

The documentation for this class was generated from the following file: