[188] | 1 | /*
|
---|
| 2 | * The Apache Software License, Version 1.1
|
---|
| 3 | *
|
---|
| 4 | * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
|
---|
| 5 | * reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | *
|
---|
| 14 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 15 | * notice, this list of conditions and the following disclaimer in
|
---|
| 16 | * the documentation and/or other materials provided with the
|
---|
| 17 | * distribution.
|
---|
| 18 | *
|
---|
| 19 | * 3. The end-user documentation included with the redistribution,
|
---|
| 20 | * if any, must include the following acknowledgment:
|
---|
| 21 | * "This product includes software developed by the
|
---|
| 22 | * Apache Software Foundation (http://www.apache.org/)."
|
---|
| 23 | * Alternately, this acknowledgment may appear in the software itself,
|
---|
| 24 | * if and wherever such third-party acknowledgments normally appear.
|
---|
| 25 | *
|
---|
| 26 | * 4. The names "Xerces" and "Apache Software Foundation" must
|
---|
| 27 | * not be used to endorse or promote products derived from this
|
---|
| 28 | * software without prior written permission. For written
|
---|
| 29 | * permission, please contact apache\@apache.org.
|
---|
| 30 | *
|
---|
| 31 | * 5. Products derived from this software may not be called "Apache",
|
---|
| 32 | * nor may "Apache" appear in their name, without prior written
|
---|
| 33 | * permission of the Apache Software Foundation.
|
---|
| 34 | *
|
---|
| 35 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
---|
| 36 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 37 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
| 38 | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
---|
| 39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
---|
| 42 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
| 43 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
| 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
---|
| 45 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 46 | * SUCH DAMAGE.
|
---|
| 47 | * ====================================================================
|
---|
| 48 | *
|
---|
| 49 | * This software consists of voluntary contributions made by many
|
---|
| 50 | * individuals on behalf of the Apache Software Foundation, and was
|
---|
| 51 | * originally based on software copyright (c) 1999, International
|
---|
| 52 | * Business Machines, Inc., http://www.ibm.com . For more information
|
---|
| 53 | * on the Apache Software Foundation, please see
|
---|
| 54 | * <http://www.apache.org/>.
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * $Log: XMLRefInfo.hpp,v $
|
---|
| 59 | * Revision 1.8 2003/09/30 18:14:34 peiyongz
|
---|
| 60 | * Implementation of Serialization/Deserialization
|
---|
| 61 | *
|
---|
| 62 | * Revision 1.7 2003/05/16 21:36:55 knoaman
|
---|
| 63 | * Memory manager implementation: Modify constructors to pass in the memory manager.
|
---|
| 64 | *
|
---|
| 65 | * Revision 1.6 2003/05/15 18:26:07 knoaman
|
---|
| 66 | * Partial implementation of the configurable memory manager.
|
---|
| 67 | *
|
---|
| 68 | * Revision 1.5 2003/04/21 20:46:01 knoaman
|
---|
| 69 | * Use XMLString::release to prepare for configurable memory manager.
|
---|
| 70 | *
|
---|
| 71 | * Revision 1.4 2003/03/07 18:08:10 tng
|
---|
| 72 | * Return a reference instead of void for operator=
|
---|
| 73 | *
|
---|
| 74 | * Revision 1.3 2002/12/04 02:32:43 knoaman
|
---|
| 75 | * #include cleanup.
|
---|
| 76 | *
|
---|
| 77 | * Revision 1.2 2002/11/04 15:00:21 tng
|
---|
| 78 | * C++ Namespace Support.
|
---|
| 79 | *
|
---|
| 80 | * Revision 1.1.1.1 2002/02/01 22:21:52 peiyongz
|
---|
| 81 | * sane_include
|
---|
| 82 | *
|
---|
| 83 | * Revision 1.5 2000/07/07 22:23:38 jpolast
|
---|
| 84 | * remove useless getKey() functions.
|
---|
| 85 | *
|
---|
| 86 | * Revision 1.4 2000/02/24 20:00:23 abagchi
|
---|
| 87 | * Swat for removing Log from API docs
|
---|
| 88 | *
|
---|
| 89 | * Revision 1.3 2000/02/15 01:21:31 roddey
|
---|
| 90 | * Some initial documentation improvements. More to come...
|
---|
| 91 | *
|
---|
| 92 | * Revision 1.2 2000/02/06 07:47:49 rahulj
|
---|
| 93 | * Year 2K copyright swat.
|
---|
| 94 | *
|
---|
| 95 | * Revision 1.1.1.1 1999/11/09 01:08:37 twl
|
---|
| 96 | * Initial checkin
|
---|
| 97 | *
|
---|
| 98 | * Revision 1.2 1999/11/08 20:44:40 rahul
|
---|
| 99 | * Swat for adding in Product name and CVS comment log variable.
|
---|
| 100 | *
|
---|
| 101 | */
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | #if !defined(XMLIDREFINFO_HPP)
|
---|
| 105 | #define XMLIDREFINFO_HPP
|
---|
| 106 |
|
---|
| 107 | #include <xercesc/util/XMemory.hpp>
|
---|
| 108 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
| 109 | #include <xercesc/util/XMLString.hpp>
|
---|
| 110 |
|
---|
| 111 | #include <xercesc/internal/XSerializable.hpp>
|
---|
| 112 |
|
---|
| 113 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 114 |
|
---|
| 115 | /**
|
---|
| 116 | * This class provides a simple means to track ID Ref usage. Since id/idref
|
---|
| 117 | * semamatics are part of XML 1.0, any validator will likely to be able to
|
---|
| 118 | * track them. Instances of this class represent a reference and two markers,
|
---|
| 119 | * one for its being declared and another for its being used. When the
|
---|
| 120 | * document is done, one can look at each instance and, if used but not
|
---|
| 121 | * declared, its an error.
|
---|
| 122 | *
|
---|
| 123 | * The getKey() method allows it to support keyed collection semantics. It
|
---|
| 124 | * returns the referenced name, so these objects will be stored via the hash
|
---|
| 125 | * of the name. This name will either be a standard QName if namespaces are
|
---|
| 126 | * not enabled/supported by the validator, or it will be in the form
|
---|
| 127 | * {url}name if namespace processing is enabled.
|
---|
| 128 | */
|
---|
| 129 | class XMLPARSER_EXPORT XMLRefInfo : public XSerializable, public XMemory
|
---|
| 130 | {
|
---|
| 131 | public :
|
---|
| 132 | // -----------------------------------------------------------------------
|
---|
| 133 | // Constructors and Destructor
|
---|
| 134 | // -----------------------------------------------------------------------
|
---|
| 135 |
|
---|
| 136 | /** @name Constructor */
|
---|
| 137 | //@{
|
---|
| 138 | XMLRefInfo
|
---|
| 139 | (
|
---|
| 140 | const XMLCh* const refName
|
---|
| 141 | , const bool fDeclared = false
|
---|
| 142 | , const bool fUsed = false
|
---|
| 143 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 144 | );
|
---|
| 145 | //@}
|
---|
| 146 |
|
---|
| 147 | /** @name Destructor */
|
---|
| 148 | //@{
|
---|
| 149 | ~XMLRefInfo();
|
---|
| 150 | //@}
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | // -----------------------------------------------------------------------
|
---|
| 154 | // Getter methods
|
---|
| 155 | // -----------------------------------------------------------------------
|
---|
| 156 | bool getDeclared() const;
|
---|
| 157 | const XMLCh* getRefName() const;
|
---|
| 158 | bool getUsed() const;
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | // -----------------------------------------------------------------------
|
---|
| 162 | // Setter methods
|
---|
| 163 | // -----------------------------------------------------------------------
|
---|
| 164 | void setDeclared(const bool newValue);
|
---|
| 165 | void setUsed(const bool newValue);
|
---|
| 166 |
|
---|
| 167 | /***
|
---|
| 168 | * Support for Serialization/De-serialization
|
---|
| 169 | ***/
|
---|
| 170 | DECL_XSERIALIZABLE(XMLRefInfo)
|
---|
| 171 |
|
---|
| 172 | XMLRefInfo
|
---|
| 173 | (
|
---|
| 174 | MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
| 175 | );
|
---|
| 176 |
|
---|
| 177 | private :
|
---|
| 178 | // -----------------------------------------------------------------------
|
---|
| 179 | // Unimplemented constructors and operators
|
---|
| 180 | // -----------------------------------------------------------------------
|
---|
| 181 | XMLRefInfo(const XMLRefInfo&);
|
---|
| 182 | XMLRefInfo& operator=(XMLRefInfo&);
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | // -----------------------------------------------------------------------
|
---|
| 186 | // Private data members
|
---|
| 187 | //
|
---|
| 188 | // fDeclared
|
---|
| 189 | // The name was declared somewhere as an ID attribute.
|
---|
| 190 | //
|
---|
| 191 | // fRefName
|
---|
| 192 | // The name of the ref that this object represents. This is not a
|
---|
| 193 | // name of the attribute, but of the value of an ID or IDREF attr
|
---|
| 194 | // in content.
|
---|
| 195 | //
|
---|
| 196 | // fUsed
|
---|
| 197 | // The name was used somewhere in an IDREF/IDREFS attribute. If this
|
---|
| 198 | // is true, but fDeclared is false, then the ref does not refer to
|
---|
| 199 | // a declared ID.
|
---|
| 200 | // -----------------------------------------------------------------------
|
---|
| 201 | bool fDeclared;
|
---|
| 202 | bool fUsed;
|
---|
| 203 | XMLCh* fRefName;
|
---|
| 204 | MemoryManager* fMemoryManager;
|
---|
| 205 | };
|
---|
| 206 |
|
---|
| 207 |
|
---|
| 208 | // ---------------------------------------------------------------------------
|
---|
| 209 | // XMLRefInfo: Constructors and Destructor
|
---|
| 210 | // ---------------------------------------------------------------------------
|
---|
| 211 | inline XMLRefInfo::XMLRefInfo( const XMLCh* const refName
|
---|
| 212 | , const bool declared
|
---|
| 213 | , const bool used
|
---|
| 214 | , MemoryManager* const manager) :
|
---|
| 215 | fDeclared(declared)
|
---|
| 216 | , fUsed(used)
|
---|
| 217 | , fRefName(0)
|
---|
| 218 | , fMemoryManager(manager)
|
---|
| 219 | {
|
---|
| 220 | fRefName = XMLString::replicate(refName, fMemoryManager);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | inline XMLRefInfo::~XMLRefInfo()
|
---|
| 224 | {
|
---|
| 225 | fMemoryManager->deallocate(fRefName);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | // ---------------------------------------------------------------------------
|
---|
| 230 | // XMLRefInfo: Getter methods
|
---|
| 231 | // ---------------------------------------------------------------------------
|
---|
| 232 | inline bool XMLRefInfo::getDeclared() const
|
---|
| 233 | {
|
---|
| 234 | return fDeclared;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | inline const XMLCh* XMLRefInfo::getRefName() const
|
---|
| 238 | {
|
---|
| 239 | return fRefName;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | inline bool XMLRefInfo::getUsed() const
|
---|
| 243 | {
|
---|
| 244 | return fUsed;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 |
|
---|
| 248 | // ---------------------------------------------------------------------------
|
---|
| 249 | // XMLRefInfo: Setter methods
|
---|
| 250 | // ---------------------------------------------------------------------------
|
---|
| 251 | inline void XMLRefInfo::setDeclared(const bool newValue)
|
---|
| 252 | {
|
---|
| 253 | fDeclared = newValue;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | inline void XMLRefInfo::setUsed(const bool newValue)
|
---|
| 257 | {
|
---|
| 258 | fUsed = newValue;
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | XERCES_CPP_NAMESPACE_END
|
---|
| 262 |
|
---|
| 263 | #endif
|
---|