1 | /*
|
---|
2 | * Copyright 1999-2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Log: XMLRefInfo.hpp,v $
|
---|
19 | * Revision 1.9 2004/09/08 13:55:59 peiyongz
|
---|
20 | * Apache License Version 2.0
|
---|
21 | *
|
---|
22 | * Revision 1.8 2003/09/30 18:14:34 peiyongz
|
---|
23 | * Implementation of Serialization/Deserialization
|
---|
24 | *
|
---|
25 | * Revision 1.7 2003/05/16 21:36:55 knoaman
|
---|
26 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
27 | *
|
---|
28 | * Revision 1.6 2003/05/15 18:26:07 knoaman
|
---|
29 | * Partial implementation of the configurable memory manager.
|
---|
30 | *
|
---|
31 | * Revision 1.5 2003/04/21 20:46:01 knoaman
|
---|
32 | * Use XMLString::release to prepare for configurable memory manager.
|
---|
33 | *
|
---|
34 | * Revision 1.4 2003/03/07 18:08:10 tng
|
---|
35 | * Return a reference instead of void for operator=
|
---|
36 | *
|
---|
37 | * Revision 1.3 2002/12/04 02:32:43 knoaman
|
---|
38 | * #include cleanup.
|
---|
39 | *
|
---|
40 | * Revision 1.2 2002/11/04 15:00:21 tng
|
---|
41 | * C++ Namespace Support.
|
---|
42 | *
|
---|
43 | * Revision 1.1.1.1 2002/02/01 22:21:52 peiyongz
|
---|
44 | * sane_include
|
---|
45 | *
|
---|
46 | * Revision 1.5 2000/07/07 22:23:38 jpolast
|
---|
47 | * remove useless getKey() functions.
|
---|
48 | *
|
---|
49 | * Revision 1.4 2000/02/24 20:00:23 abagchi
|
---|
50 | * Swat for removing Log from API docs
|
---|
51 | *
|
---|
52 | * Revision 1.3 2000/02/15 01:21:31 roddey
|
---|
53 | * Some initial documentation improvements. More to come...
|
---|
54 | *
|
---|
55 | * Revision 1.2 2000/02/06 07:47:49 rahulj
|
---|
56 | * Year 2K copyright swat.
|
---|
57 | *
|
---|
58 | * Revision 1.1.1.1 1999/11/09 01:08:37 twl
|
---|
59 | * Initial checkin
|
---|
60 | *
|
---|
61 | * Revision 1.2 1999/11/08 20:44:40 rahul
|
---|
62 | * Swat for adding in Product name and CVS comment log variable.
|
---|
63 | *
|
---|
64 | */
|
---|
65 |
|
---|
66 |
|
---|
67 | #if !defined(XMLIDREFINFO_HPP)
|
---|
68 | #define XMLIDREFINFO_HPP
|
---|
69 |
|
---|
70 | #include <xercesc/util/XMemory.hpp>
|
---|
71 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
72 | #include <xercesc/util/XMLString.hpp>
|
---|
73 |
|
---|
74 | #include <xercesc/internal/XSerializable.hpp>
|
---|
75 |
|
---|
76 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * This class provides a simple means to track ID Ref usage. Since id/idref
|
---|
80 | * semamatics are part of XML 1.0, any validator will likely to be able to
|
---|
81 | * track them. Instances of this class represent a reference and two markers,
|
---|
82 | * one for its being declared and another for its being used. When the
|
---|
83 | * document is done, one can look at each instance and, if used but not
|
---|
84 | * declared, its an error.
|
---|
85 | *
|
---|
86 | * The getKey() method allows it to support keyed collection semantics. It
|
---|
87 | * returns the referenced name, so these objects will be stored via the hash
|
---|
88 | * of the name. This name will either be a standard QName if namespaces are
|
---|
89 | * not enabled/supported by the validator, or it will be in the form
|
---|
90 | * {url}name if namespace processing is enabled.
|
---|
91 | */
|
---|
92 | class XMLPARSER_EXPORT XMLRefInfo : public XSerializable, public XMemory
|
---|
93 | {
|
---|
94 | public :
|
---|
95 | // -----------------------------------------------------------------------
|
---|
96 | // Constructors and Destructor
|
---|
97 | // -----------------------------------------------------------------------
|
---|
98 |
|
---|
99 | /** @name Constructor */
|
---|
100 | //@{
|
---|
101 | XMLRefInfo
|
---|
102 | (
|
---|
103 | const XMLCh* const refName
|
---|
104 | , const bool fDeclared = false
|
---|
105 | , const bool fUsed = false
|
---|
106 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
107 | );
|
---|
108 | //@}
|
---|
109 |
|
---|
110 | /** @name Destructor */
|
---|
111 | //@{
|
---|
112 | ~XMLRefInfo();
|
---|
113 | //@}
|
---|
114 |
|
---|
115 |
|
---|
116 | // -----------------------------------------------------------------------
|
---|
117 | // Getter methods
|
---|
118 | // -----------------------------------------------------------------------
|
---|
119 | bool getDeclared() const;
|
---|
120 | const XMLCh* getRefName() const;
|
---|
121 | bool getUsed() const;
|
---|
122 |
|
---|
123 |
|
---|
124 | // -----------------------------------------------------------------------
|
---|
125 | // Setter methods
|
---|
126 | // -----------------------------------------------------------------------
|
---|
127 | void setDeclared(const bool newValue);
|
---|
128 | void setUsed(const bool newValue);
|
---|
129 |
|
---|
130 | /***
|
---|
131 | * Support for Serialization/De-serialization
|
---|
132 | ***/
|
---|
133 | DECL_XSERIALIZABLE(XMLRefInfo)
|
---|
134 |
|
---|
135 | XMLRefInfo
|
---|
136 | (
|
---|
137 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
138 | );
|
---|
139 |
|
---|
140 | private :
|
---|
141 | // -----------------------------------------------------------------------
|
---|
142 | // Unimplemented constructors and operators
|
---|
143 | // -----------------------------------------------------------------------
|
---|
144 | XMLRefInfo(const XMLRefInfo&);
|
---|
145 | XMLRefInfo& operator=(XMLRefInfo&);
|
---|
146 |
|
---|
147 |
|
---|
148 | // -----------------------------------------------------------------------
|
---|
149 | // Private data members
|
---|
150 | //
|
---|
151 | // fDeclared
|
---|
152 | // The name was declared somewhere as an ID attribute.
|
---|
153 | //
|
---|
154 | // fRefName
|
---|
155 | // The name of the ref that this object represents. This is not a
|
---|
156 | // name of the attribute, but of the value of an ID or IDREF attr
|
---|
157 | // in content.
|
---|
158 | //
|
---|
159 | // fUsed
|
---|
160 | // The name was used somewhere in an IDREF/IDREFS attribute. If this
|
---|
161 | // is true, but fDeclared is false, then the ref does not refer to
|
---|
162 | // a declared ID.
|
---|
163 | // -----------------------------------------------------------------------
|
---|
164 | bool fDeclared;
|
---|
165 | bool fUsed;
|
---|
166 | XMLCh* fRefName;
|
---|
167 | MemoryManager* fMemoryManager;
|
---|
168 | };
|
---|
169 |
|
---|
170 |
|
---|
171 | // ---------------------------------------------------------------------------
|
---|
172 | // XMLRefInfo: Constructors and Destructor
|
---|
173 | // ---------------------------------------------------------------------------
|
---|
174 | inline XMLRefInfo::XMLRefInfo( const XMLCh* const refName
|
---|
175 | , const bool declared
|
---|
176 | , const bool used
|
---|
177 | , MemoryManager* const manager) :
|
---|
178 | fDeclared(declared)
|
---|
179 | , fUsed(used)
|
---|
180 | , fRefName(0)
|
---|
181 | , fMemoryManager(manager)
|
---|
182 | {
|
---|
183 | fRefName = XMLString::replicate(refName, fMemoryManager);
|
---|
184 | }
|
---|
185 |
|
---|
186 | inline XMLRefInfo::~XMLRefInfo()
|
---|
187 | {
|
---|
188 | fMemoryManager->deallocate(fRefName);
|
---|
189 | }
|
---|
190 |
|
---|
191 |
|
---|
192 | // ---------------------------------------------------------------------------
|
---|
193 | // XMLRefInfo: Getter methods
|
---|
194 | // ---------------------------------------------------------------------------
|
---|
195 | inline bool XMLRefInfo::getDeclared() const
|
---|
196 | {
|
---|
197 | return fDeclared;
|
---|
198 | }
|
---|
199 |
|
---|
200 | inline const XMLCh* XMLRefInfo::getRefName() const
|
---|
201 | {
|
---|
202 | return fRefName;
|
---|
203 | }
|
---|
204 |
|
---|
205 | inline bool XMLRefInfo::getUsed() const
|
---|
206 | {
|
---|
207 | return fUsed;
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 | // ---------------------------------------------------------------------------
|
---|
212 | // XMLRefInfo: Setter methods
|
---|
213 | // ---------------------------------------------------------------------------
|
---|
214 | inline void XMLRefInfo::setDeclared(const bool newValue)
|
---|
215 | {
|
---|
216 | fDeclared = newValue;
|
---|
217 | }
|
---|
218 |
|
---|
219 | inline void XMLRefInfo::setUsed(const bool newValue)
|
---|
220 | {
|
---|
221 | fUsed = newValue;
|
---|
222 | }
|
---|
223 |
|
---|
224 | XERCES_CPP_NAMESPACE_END
|
---|
225 |
|
---|
226 | #endif
|
---|