# XQilla Simple API Documentation

- Main Page
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

# Scope.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2001, 2008,
    00003  *     DecisionSoft Limited. All rights reserved.
    00004  * Copyright (c) 2004, 2015 Oracle and/or its affiliates. All rights reserved.
    00005  *
    00006  *
    00007  * Licensed under the Apache License, Version 2.0 (the "License");
    00008  * you may not use this file except in compliance with the License.
    00009  * You may obtain a copy of the License at
    00010  *
    00011  *     http://www.apache.org/licenses/LICENSE-2.0
    00012  *
    00013  * Unless required by applicable law or agreed to in writing, software
    00014  * distributed under the License is distributed on an "AS IS" BASIS,
    00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00016  * See the License for the specific language governing permissions and
    00017  * limitations under the License.
    00018  */
    00019
    00020 /*
    00021   Scope
    00022 */
    00023
    00024 #ifndef _SCOPE_HPP
    00025 #define _SCOPE_HPP
    00026
    00027 #include <xqilla/framework/XQillaExport.hpp>
    00028 #include <xqilla/context/VarHashEntry.hpp>
    00029 #include <vector>
    00030 #include <xercesc/util/RefHash2KeysTableOf.hpp>
    00031 #include <xercesc/util/XMemory.hpp>
    00032
    00033 template<class TYPE> class VarHashEntry;
    00034
    00036 template<class TYPE>
    00037 class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
    00038 {
    00039 public:
    00041   typedef enum {
    00042     GLOBAL_SCOPE,
    00043     LOCAL_SCOPE,
    00044     LOGICAL_BLOCK_SCOPE
    00045   } Type;
    00046
    00047   typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOf< VarHashEntry<TYPE> > VarHash;
    00048
    00050   Scope(XPath2MemoryManager* memMgr, Type type);
    00051   ~Scope();
    00052
    00053   void clear();
    00054
    00055   Type getType() const;
    00056   VarHashEntry<TYPE>* get(unsigned int nsID, const XMLCh* name);
    00057   void put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value);
    00058   void remove(unsigned int nsID, const XMLCh* name);
    00059   std::vector< std::pair<unsigned int, const XMLCh*> > getVars() const;
    00060
    00061   Scope* getNext();
    00062   void setNext(Scope* next);
    00063
    00064 private:
    00065   typename Scope<TYPE>::Type _type;
    00066   VarHash _map;
    00067   XPath2MemoryManager* _memMgr;
    00068   Scope<TYPE>* _next;
    00069 };
    00070
    00071 template<class TYPE>
    00072 Scope<TYPE>::Scope(XPath2MemoryManager* memMgr, Type type) :
    00073     _map(17, true, memMgr)
    00074 {
    00075   _memMgr=memMgr;
    00076   _type = type;
    00077   _next = NULL;
    00078 }
    00079
    00080 template<class TYPE>
    00081 void Scope<TYPE>::clear()
    00082 {
    00083   _map.removeAll();
    00084 }
    00085
    00086 template<class TYPE>
    00087 typename Scope<TYPE>::Type Scope<TYPE>::getType() const
    00088 {
    00089   return _type;
    00090 }
    00091
    00092 template<class TYPE>
    00093 VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
    00094 {
    00095         return _map.get(name,nsID);
    00096 }
    00097
    00098 template<class TYPE>
    00099 void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
    00100 {
    00101         _map.put((void*)_memMgr->getPooledString(name),nsID,value);
    00102 }
    00103
    00104 template<class TYPE>
    00105 void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
    00106 {
    00107         _map.removeKey(name,nsID);
    00108 }
    00109
    00110 template<class TYPE>
    00111 std::vector< std::pair<unsigned int, const XMLCh*> > Scope<TYPE>::getVars() const
    00112 {
    00113     std::vector< std::pair<unsigned int, const XMLCh*> > result;
    00114     XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOfEnumerator< VarHashEntry<TYPE> > iterator(const_cast<VarHash*>(&_map));
    00115     while(iterator.hasMoreElements())
    00116         {
    00117                 XMLCh* name;
    00118                 int nsID;
    00119                 iterator.nextElementKey((void*&)name, nsID);
    00120         result.push_back(std::pair<unsigned int, const XMLCh*>(nsID,name));
    00121         }
    00122         return result;
    00123 }
    00124
    00125 template<class TYPE>
    00126 Scope<TYPE>::~Scope()
    00127 {
    00128   _map.removeAll();
    00129 }
    00130
    00131 template<class TYPE>
    00132 Scope<TYPE>* Scope<TYPE>::getNext()
    00133 {
    00134     return _next;
    00135 }
    00136
    00137 template<class TYPE>
    00138 void Scope<TYPE>::setNext(Scope<TYPE>* next)
    00139 {
    00140     _next=next;
    00141 }
    00142
    00143 #endif // _SCOPE_HPP