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-2008
5  * Oracle. All rights reserved.
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  * $Id$
20  */
21 
22 /*
23  Scope
24 */
25 
26 #ifndef _SCOPE_HPP
27 #define _SCOPE_HPP
28 
29 #include <xqilla/framework/XQillaExport.hpp>
31 #include <vector>
32 #include <xercesc/util/RefHash2KeysTableOf.hpp>
33 #include <xercesc/util/XMemory.hpp>
34 
35 template<class TYPE> class VarHashEntry;
36 
38 template<class TYPE>
39 class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
40 {
41 public:
43  typedef enum {
47  } Type;
48 
49  typedef XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOf< VarHashEntry<TYPE> > VarHash;
50 
52  Scope(XPath2MemoryManager* memMgr, Type type);
53  ~Scope();
54 
55  void clear();
56 
57  Type getType() const;
58  VarHashEntry<TYPE>* get(unsigned int nsID, const XMLCh* name);
59  void put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value);
60  void remove(unsigned int nsID, const XMLCh* name);
61  std::vector< std::pair<unsigned int, const XMLCh*> > getVars() const;
62 
63  Scope* getNext();
64  void setNext(Scope* next);
65 
66 private:
67  typename Scope<TYPE>::Type _type;
68  VarHash _map;
69  XPath2MemoryManager* _memMgr;
70  Scope<TYPE>* _next;
71 };
72 
73 template<class TYPE>
75  _map(17, true, memMgr)
76 {
77  _memMgr=memMgr;
78  _type = type;
79  _next = NULL;
80 }
81 
82 template<class TYPE>
84 {
85  _map.removeAll();
86 }
87 
88 template<class TYPE>
90 {
91  return _type;
92 }
93 
94 template<class TYPE>
95 VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
96 {
97  return _map.get(name,nsID);
98 }
99 
100 template<class TYPE>
101 void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
102 {
103  _map.put((void*)_memMgr->getPooledString(name),nsID,value);
104 }
105 
106 template<class TYPE>
107 void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
108 {
109  _map.removeKey(name,nsID);
110 }
111 
112 template<class TYPE>
113 std::vector< std::pair<unsigned int, const XMLCh*> > Scope<TYPE>::getVars() const
114 {
115  std::vector< std::pair<unsigned int, const XMLCh*> > result;
116  XERCES_CPP_NAMESPACE_QUALIFIER RefHash2KeysTableOfEnumerator< VarHashEntry<TYPE> > iterator(const_cast<VarHash*>(&_map));
117  while(iterator.hasMoreElements())
118  {
119  XMLCh* name;
120  int nsID;
121  iterator.nextElementKey((void*&)name, nsID);
122  result.push_back(std::pair<unsigned int, const XMLCh*>(nsID,name));
123  }
124  return result;
125 }
126 
127 template<class TYPE>
129 {
130  _map.removeAll();
131 }
132 
133 template<class TYPE>
135 {
136  return _next;
137 }
138 
139 template<class TYPE>
141 {
142  _next=next;
143 }
144 
145 #endif // _SCOPE_HPP
Definition: Scope.hpp:45
Type
enum for classifying type of scope
Definition: Scope.hpp:43
Definition: XPath2MemoryManager.hpp:47
void clear()
Definition: Scope.hpp:83
Scope * getNext()
Definition: Scope.hpp:134
void remove(unsigned int nsID, const XMLCh *name)
Definition: Scope.hpp:107
void put(unsigned int nsID, const XMLCh *name, VarHashEntry< TYPE > *value)
Definition: Scope.hpp:101
xercesc::RefHash2KeysTableOf< VarHashEntry< TYPE > > VarHash
Definition: Scope.hpp:49
XMemory()
Protected default constructor.
Definition: XMemory.hpp:130
Scope(XPath2MemoryManager *memMgr, Type type)
constructor.
Definition: Scope.hpp:74
VarHashEntry< TYPE > * get(unsigned int nsID, const XMLCh *name)
Definition: Scope.hpp:95
The class that stores the values of the variables.
Definition: Scope.hpp:35
void setNext(Scope *next)
Definition: Scope.hpp:140
~Scope()
Definition: Scope.hpp:128
Definition: Scope.hpp:44
Definition: Scope.hpp:46
std::vector< std::pair< unsigned int, const XMLCh * > > getVars() const
Definition: Scope.hpp:113
used inside VariableStore to implement variable scoping
Definition: Scope.hpp:39
Type getType() const
Definition: Scope.hpp:89