Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:53

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLREFINFO_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLREFINFO_HPP
0024 
0025 #include <xercesc/util/XMemory.hpp>
0026 #include <xercesc/util/PlatformUtils.hpp>
0027 #include <xercesc/util/XMLString.hpp>
0028 
0029 #include <xercesc/internal/XSerializable.hpp>
0030 
0031 XERCES_CPP_NAMESPACE_BEGIN
0032 
0033 /**
0034  *  This class provides a simple means to track ID Ref usage. Since id/idref
0035  *  semantics are part of XML 1.0, any validator will likely to be able to
0036  *  track them. Instances of this class represent a reference and two markers,
0037  *  one for its being declared and another for its being used. When the
0038  *  document is done, one can look at each instance and, if used but not
0039  *  declared, its an error.
0040  *
0041  *  The getKey() method allows it to support keyed collection semantics. It
0042  *  returns the referenced name, so these objects will be stored via the hash
0043  *  of the name. This name will either be a standard QName if namespaces are
0044  *  not enabled/supported by the validator, or it will be in the form
0045  *  {url}name if namespace processing is enabled.
0046  */
0047 class XMLPARSER_EXPORT XMLRefInfo : public XSerializable, public XMemory
0048 {
0049 public :
0050     // -----------------------------------------------------------------------
0051     //  Constructors and Destructor
0052     // -----------------------------------------------------------------------
0053 
0054     /** @name Constructor */
0055     //@{
0056     XMLRefInfo
0057     (
0058         const   XMLCh* const   refName
0059         , const bool           fDeclared = false
0060         , const bool           fUsed = false
0061         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0062     );
0063     //@}
0064 
0065     /** @name Destructor */
0066     //@{
0067     ~XMLRefInfo();
0068     //@}
0069 
0070 
0071     // -----------------------------------------------------------------------
0072     //  Getter methods
0073     // -----------------------------------------------------------------------
0074     bool getDeclared() const;
0075     const XMLCh* getRefName() const;
0076     bool getUsed() const;
0077 
0078 
0079     // -----------------------------------------------------------------------
0080     //  Setter methods
0081     // -----------------------------------------------------------------------
0082     void setDeclared(const bool newValue);
0083     void setUsed(const bool newValue);
0084 
0085     /***
0086      * Support for Serialization/De-serialization
0087      ***/
0088     DECL_XSERIALIZABLE(XMLRefInfo)
0089 
0090     XMLRefInfo
0091     (
0092       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0093     );
0094 
0095 private :
0096     // -----------------------------------------------------------------------
0097     //  Unimplemented constructors and operators
0098     // -----------------------------------------------------------------------
0099     XMLRefInfo(const XMLRefInfo&);
0100     XMLRefInfo& operator=(XMLRefInfo&);
0101 
0102 
0103     // -----------------------------------------------------------------------
0104     //  Private data members
0105     //
0106     //  fDeclared
0107     //      The name was declared somewhere as an ID attribute.
0108     //
0109     //  fRefName
0110     //      The name of the ref that this object represents. This is not a
0111     //      name of the attribute, but of the value of an ID or IDREF attr
0112     //      in content.
0113     //
0114     //  fUsed
0115     //      The name was used somewhere in an IDREF/IDREFS attribute. If this
0116     //      is true, but fDeclared is false, then the ref does not refer to
0117     //      a declared ID.
0118     // -----------------------------------------------------------------------
0119     bool        fDeclared;
0120     bool        fUsed;
0121     XMLCh*      fRefName;
0122     MemoryManager* fMemoryManager;
0123 };
0124 
0125 
0126 // ---------------------------------------------------------------------------
0127 //  XMLRefInfo: Constructors and Destructor
0128 // ---------------------------------------------------------------------------
0129 inline XMLRefInfo::XMLRefInfo( const XMLCh* const   refName
0130                              , const bool           declared
0131                              , const bool           used
0132                              , MemoryManager* const manager) :
0133     fDeclared(declared)
0134     , fUsed(used)
0135     , fRefName(0)
0136     , fMemoryManager(manager)
0137 {
0138     fRefName = XMLString::replicate(refName, fMemoryManager);
0139 }
0140 
0141 inline XMLRefInfo::~XMLRefInfo()
0142 {
0143     fMemoryManager->deallocate(fRefName);
0144 }
0145 
0146 
0147 // ---------------------------------------------------------------------------
0148 //  XMLRefInfo: Getter methods
0149 // ---------------------------------------------------------------------------
0150 inline bool XMLRefInfo::getDeclared() const
0151 {
0152     return fDeclared;
0153 }
0154 
0155 inline const XMLCh* XMLRefInfo::getRefName() const
0156 {
0157     return fRefName;
0158 }
0159 
0160 inline bool XMLRefInfo::getUsed() const
0161 {
0162     return fUsed;
0163 }
0164 
0165 
0166 // ---------------------------------------------------------------------------
0167 //  XMLRefInfo: Setter methods
0168 // ---------------------------------------------------------------------------
0169 inline void XMLRefInfo::setDeclared(const bool newValue)
0170 {
0171     fDeclared = newValue;
0172 }
0173 
0174 inline void XMLRefInfo::setUsed(const bool newValue)
0175 {
0176     fUsed = newValue;
0177 }
0178 
0179 XERCES_CPP_NAMESPACE_END
0180 
0181 #endif