# Scope.hpp

Go to the documentation of this file.

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