include
xqilla
context
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>
28
#include <
xqilla/context/VarHashEntry.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
{
42
GLOBAL_SCOPE
,
43
LOCAL_SCOPE
,
44
LOGICAL_BLOCK_SCOPE
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>
72
Scope<TYPE>::Scope
(
XPath2MemoryManager
* memMgr,
Type
type) :
73
_map(17, true, memMgr)
74
{
75
_memMgr=memMgr;
76
_type = type;
77
_next = NULL;
78
}
79
80
template
<
class
TYPE>
81
void
Scope<TYPE>::clear
()
82
{
83
_map.removeAll();
84
}
85
86
template
<
class
TYPE>
87
typename
Scope<TYPE>::Type
Scope<TYPE>::getType
()
const
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>
126
Scope<TYPE>::~Scope
()
127
{
128
_map.removeAll();
129
}
130
131
template
<
class
TYPE>
132
Scope<TYPE>
*
Scope<TYPE>::getNext
()
133
{
134
return
_next;
135
}
136
137
template
<
class
TYPE>
138
void
Scope<TYPE>::setNext
(
Scope<TYPE>
* next)
139
{
140
_next=next;
141
}
142
143
#endif // _SCOPE_HPP
Scope::Type
Type
enum for classifying type of scope
Definition:
Scope.hpp:41
Scope::remove
void remove(unsigned int nsID, const XMLCh *name)
Definition:
Scope.hpp:105
Scope::LOGICAL_BLOCK_SCOPE
@ LOGICAL_BLOCK_SCOPE
Definition:
Scope.hpp:44
Scope::LOCAL_SCOPE
@ LOCAL_SCOPE
Definition:
Scope.hpp:43
Scope::getNext
Scope * getNext()
Definition:
Scope.hpp:132
Scope
used inside VariableStore to implement variable scoping
Definition:
Scope.hpp:38
Scope::put
void put(unsigned int nsID, const XMLCh *name, VarHashEntry< TYPE > *value)
Definition:
Scope.hpp:99
Scope::VarHash
xercesc::RefHash2KeysTableOf< VarHashEntry< TYPE > > VarHash
Definition:
Scope.hpp:47
VarHashEntry
The class that stores the values of the variables.
Definition:
Scope.hpp:33
Scope::Scope
Scope(XPath2MemoryManager *memMgr, Type type)
constructor.
Definition:
Scope.hpp:72
Scope::get
VarHashEntry< TYPE > * get(unsigned int nsID, const XMLCh *name)
Definition:
Scope.hpp:93
Scope::setNext
void setNext(Scope *next)
Definition:
Scope.hpp:138
XPath2MemoryManager
Definition:
XPath2MemoryManager.hpp:46
Scope::~Scope
~Scope()
Definition:
Scope.hpp:126
VarHashEntry.hpp
Scope::getVars
std::vector< std::pair< unsigned int, const XMLCh * > > getVars() const
Definition:
Scope.hpp:111
Scope::GLOBAL_SCOPE
@ GLOBAL_SCOPE
Definition:
Scope.hpp:42
Scope::clear
void clear()
Definition:
Scope.hpp:81
Scope::getType
Type getType() const
Definition:
Scope.hpp:87
xercesc::XMemory::XMemory
XMemory()
Protected default constructor.
Definition:
XMemory.hpp:130
XMemory.hpp
Generated by
1.8.18