00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _SCOPE_HPP
00019 #define _SCOPE_HPP
00020
00021 #include <xqilla/framework/XQillaExport.hpp>
00022 #include <xqilla/context/VarHashEntry.hpp>
00023 #include <vector>
00024 #include <xercesc/util/RefHash2KeysTableOf.hpp>
00025 #include <xercesc/util/XMemory.hpp>
00026
00027 template<class TYPE> class VarHashEntry;
00028
00030 template<class TYPE>
00031 class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
00032 {
00033 public:
00035 typedef enum {
00036 GLOBAL_SCOPE,
00037 LOCAL_SCOPE,
00038 LOGICAL_BLOCK_SCOPE
00039 } Type;
00040
00041 typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOf< VarHashEntry<TYPE> > VarHash;
00042
00044 Scope(XPath2MemoryManager* memMgr, Type type);
00045 ~Scope();
00046
00047 void clear();
00048
00049 Type getType() const;
00050 VarHashEntry<TYPE>* get(unsigned int nsID, const XMLCh* name);
00051 void put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value);
00052 void remove(unsigned int nsID, const XMLCh* name);
00053 std::vector< std::pair<unsigned int, const XMLCh*> > getVars() const;
00054
00055 Scope* getNext();
00056 void setNext(Scope* next);
00057
00058 private:
00059 typename Scope<TYPE>::Type _type;
00060 VarHash _map;
00061 XPath2MemoryManager* _memMgr;
00062 Scope<TYPE>* _next;
00063 };
00064
00065 template<class TYPE>
00066 Scope<TYPE>::Scope(XPath2MemoryManager* memMgr, Type type) :
00067 _map(17, true, memMgr)
00068 {
00069 _memMgr=memMgr;
00070 _type = type;
00071 _next = NULL;
00072 }
00073
00074 template<class TYPE>
00075 void Scope<TYPE>::clear()
00076 {
00077 _map.removeAll();
00078 }
00079
00080 template<class TYPE>
00081 typename Scope<TYPE>::Type Scope<TYPE>::getType() const
00082 {
00083 return _type;
00084 }
00085
00086 template<class TYPE>
00087 VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
00088 {
00089 return _map.get(name,nsID);
00090 }
00091
00092 template<class TYPE>
00093 void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
00094 {
00095 _map.put((void*)_memMgr->getPooledString(name),nsID,value);
00096 }
00097
00098 template<class TYPE>
00099 void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
00100 {
00101 _map.removeKey(name,nsID);
00102 }
00103
00104 template<class TYPE>
00105 std::vector< std::pair<unsigned int, const XMLCh*> > Scope<TYPE>::getVars() const
00106 {
00107 std::vector< std::pair<unsigned int, const XMLCh*> > result;
00108 XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOfEnumerator< VarHashEntry<TYPE> > iterator(const_cast<VarHash*>(&_map));
00109 while(iterator.hasMoreElements())
00110 {
00111 XMLCh* name;
00112 int nsID;
00113 iterator.nextElementKey((void*&)name, nsID);
00114 result.push_back(std::pair<unsigned int, const XMLCh*>(nsID,name));
00115 }
00116 return result;
00117 }
00118
00119 template<class TYPE>
00120 Scope<TYPE>::~Scope()
00121 {
00122 _map.removeAll();
00123 }
00124
00125 template<class TYPE>
00126 Scope<TYPE>* Scope<TYPE>::getNext()
00127 {
00128 return _next;
00129 }
00130
00131 template<class TYPE>
00132 void Scope<TYPE>::setNext(Scope<TYPE>* next)
00133 {
00134 _next=next;
00135 }
00136
00137 #endif // _SCOPE_HPP