source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/framework/XMLRefInfo.hpp @ 2674

Revision 2674, 5.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XMLRefInfo.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22
23#if !defined(XMLIDREFINFO_HPP)
24#define XMLIDREFINFO_HPP
25
26#include <xercesc/util/XMemory.hpp>
27#include <xercesc/util/PlatformUtils.hpp>
28#include <xercesc/util/XMLString.hpp>
29
30#include <xercesc/internal/XSerializable.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34/**
35 *  This class provides a simple means to track ID Ref usage. Since id/idref
36 *  semamatics are part of XML 1.0, any validator will likely to be able to
37 *  track them. Instances of this class represent a reference and two markers,
38 *  one for its being declared and another for its being used. When the
39 *  document is done, one can look at each instance and, if used but not
40 *  declared, its an error.
41 *
42 *  The getKey() method allows it to support keyed collection semantics. It
43 *  returns the referenced name, so these objects will be stored via the hash
44 *  of the name. This name will either be a standard QName if namespaces are
45 *  not enabled/supported by the validator, or it will be in the form
46 *  {url}name if namespace processing is enabled.
47 */
48class XMLPARSER_EXPORT XMLRefInfo : public XSerializable, public XMemory
49{
50public :
51    // -----------------------------------------------------------------------
52    //  Constructors and Destructor
53    // -----------------------------------------------------------------------
54
55    /** @name Constructor */
56    //@{
57    XMLRefInfo
58    (
59        const   XMLCh* const   refName
60        , const bool           fDeclared = false
61        , const bool           fUsed = false
62        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
63    );
64    //@}
65
66    /** @name Destructor */
67    //@{
68    ~XMLRefInfo();
69    //@}
70
71
72    // -----------------------------------------------------------------------
73    //  Getter methods
74    // -----------------------------------------------------------------------
75    bool getDeclared() const;
76    const XMLCh* getRefName() const;
77    bool getUsed() const;
78
79
80    // -----------------------------------------------------------------------
81    //  Setter methods
82    // -----------------------------------------------------------------------
83    void setDeclared(const bool newValue);
84    void setUsed(const bool newValue);
85
86    /***
87     * Support for Serialization/De-serialization
88     ***/
89    DECL_XSERIALIZABLE(XMLRefInfo)
90
91    XMLRefInfo
92    (
93      MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
94    );
95
96private :
97    // -----------------------------------------------------------------------
98    //  Unimplemented constructors and operators
99    // -----------------------------------------------------------------------
100    XMLRefInfo(const XMLRefInfo&);
101    XMLRefInfo& operator=(XMLRefInfo&);
102
103
104    // -----------------------------------------------------------------------
105    //  Private data members
106    //
107    //  fDeclared
108    //      The name was declared somewhere as an ID attribute.
109    //
110    //  fRefName
111    //      The name of the ref that this object represents. This is not a
112    //      name of the attribute, but of the value of an ID or IDREF attr
113    //      in content.
114    //
115    //  fUsed
116    //      The name was used somewhere in an IDREF/IDREFS attribute. If this
117    //      is true, but fDeclared is false, then the ref does not refer to
118    //      a declared ID.
119    // -----------------------------------------------------------------------
120    bool        fDeclared;
121    bool        fUsed;
122    XMLCh*      fRefName;
123    MemoryManager* fMemoryManager;
124};
125
126
127// ---------------------------------------------------------------------------
128//  XMLRefInfo: Constructors and Destructor
129// ---------------------------------------------------------------------------
130inline XMLRefInfo::XMLRefInfo( const XMLCh* const   refName
131                             , const bool           declared
132                             , const bool           used
133                             , MemoryManager* const manager) :
134    fDeclared(declared)
135    , fUsed(used)
136    , fRefName(0)
137    , fMemoryManager(manager)
138{
139    fRefName = XMLString::replicate(refName, fMemoryManager);
140}
141
142inline XMLRefInfo::~XMLRefInfo()
143{
144    fMemoryManager->deallocate(fRefName);
145}
146
147
148// ---------------------------------------------------------------------------
149//  XMLRefInfo: Getter methods
150// ---------------------------------------------------------------------------
151inline bool XMLRefInfo::getDeclared() const
152{
153    return fDeclared;
154}
155
156inline const XMLCh* XMLRefInfo::getRefName() const
157{
158    return fRefName;
159}
160
161inline bool XMLRefInfo::getUsed() const
162{
163    return fUsed;
164}
165
166
167// ---------------------------------------------------------------------------
168//  XMLRefInfo: Setter methods
169// ---------------------------------------------------------------------------
170inline void XMLRefInfo::setDeclared(const bool newValue)
171{
172    fDeclared = newValue;
173}
174
175inline void XMLRefInfo::setUsed(const bool newValue)
176{
177    fUsed = newValue;
178}
179
180XERCES_CPP_NAMESPACE_END
181
182#endif
Note: See TracBrowser for help on using the repository browser.