SourceForge.net Logo

Scope.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2007
00003  *     DecisionSoft Limited. All rights reserved.
00004  * Copyright (c) 2004-2007
00005  *     Oracle. All rights reserved.
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  * $Id: Scope.hpp,v 1.11 2007/11/28 13:13:20 jpcs Exp $
00020  */
00021 
00022 /*
00023   Scope
00024 */
00025 
00026 #ifndef _SCOPE_HPP
00027 #define _SCOPE_HPP
00028 
00029 #include <xqilla/framework/XQillaExport.hpp>
00030 #include <xqilla/context/VarHashEntry.hpp>
00031 #include <vector>
00032 #include <xercesc/util/RefHash2KeysTableOf.hpp>
00033 #include <xercesc/util/XMemory.hpp>
00034 
00035 template<class TYPE> class VarHashEntry;
00036 
00038 template<class TYPE>
00039 class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
00040 {
00041 public:
00043   typedef enum {
00044     GLOBAL_SCOPE,
00045     LOCAL_SCOPE,
00046     LOGICAL_BLOCK_SCOPE
00047   } Type;
00048 
00049   typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOf< VarHashEntry<TYPE> > VarHash;
00050 
00052   Scope(XPath2MemoryManager* memMgr, Type type);
00053   ~Scope();
00054 
00055   void clear();
00056 
00057   Type getType() const;
00058   VarHashEntry<TYPE>* get(unsigned int nsID, const XMLCh* name);
00059   void put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value);
00060   void remove(unsigned int nsID, const XMLCh* name);
00061   std::vector< std::pair<unsigned int, const XMLCh*> > getVars() const;
00062 
00063   Scope* getNext();
00064   void setNext(Scope* next);
00065   
00066 private:
00067   typename Scope<TYPE>::Type _type;
00068   VarHash _map;
00069   XPath2MemoryManager* _memMgr;
00070   Scope<TYPE>* _next;
00071 };
00072 
00073 template<class TYPE>
00074 Scope<TYPE>::Scope(XPath2MemoryManager* memMgr, Type type) :
00075     _map(17, true, memMgr)
00076 {
00077   _memMgr=memMgr;
00078   _type = type;
00079   _next = NULL;
00080 }
00081 
00082 template<class TYPE>
00083 void Scope<TYPE>::clear()
00084 {
00085   _map.removeAll();
00086 }
00087 
00088 template<class TYPE>
00089 typename Scope<TYPE>::Type Scope<TYPE>::getType() const
00090 {
00091   return _type;
00092 }
00093 
00094 template<class TYPE>
00095 VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
00096 {
00097         return _map.get(name,nsID);
00098 }
00099 
00100 template<class TYPE>
00101 void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
00102 {
00103         _map.put((void*)_memMgr->getPooledString(name),nsID,value);
00104 }
00105 
00106 template<class TYPE>
00107 void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
00108 {
00109         _map.removeKey(name,nsID);
00110 }
00111 
00112 template<class TYPE>
00113 std::vector< std::pair<unsigned int, const XMLCh*> > Scope<TYPE>::getVars() const
00114 {
00115     std::vector< std::pair<unsigned int, const XMLCh*> > result;
00116     XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOfEnumerator< VarHashEntry<TYPE> > iterator(const_cast<VarHash*>(&_map));
00117     while(iterator.hasMoreElements())
00118         {
00119                 XMLCh* name;
00120                 int nsID;
00121                 iterator.nextElementKey((void*&)name, nsID);
00122         result.push_back(std::pair<unsigned int, const XMLCh*>(nsID,name));
00123         }
00124         return result;
00125 }
00126 
00127 template<class TYPE>
00128 Scope<TYPE>::~Scope()
00129 {
00130   _map.removeAll();
00131 }
00132 
00133 template<class TYPE>
00134 Scope<TYPE>* Scope<TYPE>::getNext()
00135 {
00136     return _next;
00137 }
00138 
00139 template<class TYPE>
00140 void Scope<TYPE>::setNext(Scope<TYPE>* next)
00141 {
00142     _next=next;
00143 }
00144 
00145 #endif // _SCOPE_HPP

Generated on Wed Dec 12 20:16:43 2007 for XQilla Simple API by  doxygen 1.5.1