SourceForge.net Logo
Scope.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001, 2008,
3  * DecisionSoft Limited. All rights reserved.
4  * Copyright (c) 2004, 2018 Oracle and/or its affiliates. All rights reserved.
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 /*
21  Scope
22 */
23 
24 #ifndef _SCOPE_HPP
25 #define _SCOPE_HPP
26 
27 #include <xqilla/framework/XQillaExport.hpp>
29 #include <vector>
30 #include <xercesc/util/RefHash2KeysTableOf.hpp>
31 #include <xercesc/util/XMemory.hpp>
32 
33 template<class TYPE> class VarHashEntry;
34 
36 template<class TYPE>
37 class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
38 {
39 public:
41  typedef enum {
45  } Type;
46 
47  typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOf< VarHashEntry<TYPE> > VarHash;
48 
50  Scope(XPath2MemoryManager* memMgr, Type type);
51  ~Scope();
52 
53  void clear();
54 
55  Type getType() const;
56  VarHashEntry<TYPE>* get(unsigned int nsID, const XMLCh* name);
57  void put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value);
58  void remove(unsigned int nsID, const XMLCh* name);
59  std::vector< std::pair<unsigned int, const XMLCh*> > getVars() const;
60 
61  Scope* getNext();
62  void setNext(Scope* next);
63 
64 private:
65  typename Scope<TYPE>::Type _type;
66  VarHash _map;
67  XPath2MemoryManager* _memMgr;
68  Scope<TYPE>* _next;
69 };
70 
71 template<class TYPE>
73  _map(17, true, memMgr)
74 {
75  _memMgr=memMgr;
76  _type = type;
77  _next = NULL;
78 }
79 
80 template<class TYPE>
82 {
83  _map.removeAll();
84 }
85 
86 template<class TYPE>
88 {
89  return _type;
90 }
91 
92 template<class TYPE>
93 VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
94 {
95  return _map.get(name,nsID);
96 }
97 
98 template<class TYPE>
99 void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
100 {
101  _map.put((void*)_memMgr->getPooledString(name),nsID,value);
102 }
103 
104 template<class TYPE>
105 void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
106 {
107  _map.removeKey(name,nsID);
108 }
109 
110 template<class TYPE>
111 std::vector< std::pair<unsigned int, const XMLCh*> > Scope<TYPE>::getVars() const
112 {
113  std::vector< std::pair<unsigned int, const XMLCh*> > result;
114  XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOfEnumerator< VarHashEntry<TYPE> > iterator(const_cast<VarHash*>(&_map));
115  while(iterator.hasMoreElements())
116  {
117  XMLCh* name;
118  int nsID;
119  iterator.nextElementKey((void*&)name, nsID);
120  result.push_back(std::pair<unsigned int, const XMLCh*>(nsID,name));
121  }
122  return result;
123 }
124 
125 template<class TYPE>
127 {
128  _map.removeAll();
129 }
130 
131 template<class TYPE>
133 {
134  return _next;
135 }
136 
137 template<class TYPE>
139 {
140  _next=next;
141 }
142 
143 #endif // _SCOPE_HPP
Definition: Scope.hpp:43
Type
enum for classifying type of scope
Definition: Scope.hpp:41
Definition: XPath2MemoryManager.hpp:45
void clear()
Definition: Scope.hpp:81
Scope * getNext()
Definition: Scope.hpp:132
void remove(unsigned int nsID, const XMLCh *name)
Definition: Scope.hpp:105
void put(unsigned int nsID, const XMLCh *name, VarHashEntry< TYPE > *value)
Definition: Scope.hpp:99
xercesc::RefHash2KeysTableOf< VarHashEntry< TYPE > > VarHash
Definition: Scope.hpp:47
XMemory()
Protected default constructor.
Definition: XMemory.hpp:130
Scope(XPath2MemoryManager *memMgr, Type type)
constructor.
Definition: Scope.hpp:72
VarHashEntry< TYPE > * get(unsigned int nsID, const XMLCh *name)
Definition: Scope.hpp:93
The class that stores the values of the variables.
Definition: Scope.hpp:33
void setNext(Scope *next)
Definition: Scope.hpp:138
~Scope()
Definition: Scope.hpp:126
Definition: Scope.hpp:42
Definition: Scope.hpp:44
std::vector< std::pair< unsigned int, const XMLCh * > > getVars() const
Definition: Scope.hpp:111
used inside VariableStore to implement variable scoping
Definition: Scope.hpp:37
Type getType() const
Definition: Scope.hpp:87