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, 2015 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>
32
33template<class TYPE> class VarHashEntry;
34
36template<class TYPE>
37class Scope : public XERCES_CPP_NAMESPACE_QUALIFIER XMemory
38{
39public:
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
64private:
65 typename Scope<TYPE>::Type _type;
66 VarHash _map;
67 XPath2MemoryManager* _memMgr;
68 Scope<TYPE>* _next;
69};
70
71template<class TYPE>
73 _map(17, true, memMgr)
74{
75 _memMgr=memMgr;
76 _type = type;
77 _next = NULL;
78}
79
80template<class TYPE>
82{
83 _map.removeAll();
84}
85
86template<class TYPE>
88{
89 return _type;
90}
91
92template<class TYPE>
93VarHashEntry<TYPE>* Scope<TYPE>::get(unsigned int nsID, const XMLCh* name)
94{
95 return _map.get(name,nsID);
96}
97
98template<class TYPE>
99void Scope<TYPE>::put(unsigned int nsID, const XMLCh* name, VarHashEntry<TYPE>* value)
100{
101 _map.put((void*)_memMgr->getPooledString(name),nsID,value);
102}
103
104template<class TYPE>
105void Scope<TYPE>::remove(unsigned int nsID, const XMLCh* name)
106{
107 _map.removeKey(name,nsID);
108}
109
110template<class TYPE>
111std::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
125template<class TYPE>
127{
128 _map.removeAll();
129}
130
131template<class TYPE>
133{
134 return _next;
135}
136
137template<class TYPE>
139{
140 _next=next;
141}
142
143#endif // _SCOPE_HPP
used inside VariableStore to implement variable scoping
Definition Scope.hpp:38
void setNext(Scope *next)
Definition Scope.hpp:138
Scope(XPath2MemoryManager *memMgr, Type type)
constructor.
Definition Scope.hpp:72
~Scope()
Definition Scope.hpp:126
VarHashEntry< TYPE > * get(unsigned int nsID, const XMLCh *name)
Definition Scope.hpp:93
Type
enum for classifying type of scope
Definition Scope.hpp:41
@ LOCAL_SCOPE
Definition Scope.hpp:43
@ GLOBAL_SCOPE
Definition Scope.hpp:42
@ LOGICAL_BLOCK_SCOPE
Definition Scope.hpp:44
void remove(unsigned int nsID, const XMLCh *name)
Definition Scope.hpp:105
std::vector< std::pair< unsigned int, const XMLCh * > > getVars() const
Definition Scope.hpp:111
Type getType() const
Definition Scope.hpp:87
void clear()
Definition Scope.hpp:81
void put(unsigned int nsID, const XMLCh *name, VarHashEntry< TYPE > *value)
Definition Scope.hpp:99
xercesc::RefHash2KeysTableOf< VarHashEntry< TYPE > > VarHash
Definition Scope.hpp:47
Scope * getNext()
Definition Scope.hpp:132
The class that stores the values of the variables.
Definition VarHashEntry.hpp:29
Definition XPath2MemoryManager.hpp:46