QName.hpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:10k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 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) 2001, 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.  * $Log: QName.hpp,v $
  58.  * Revision 1.8  2003/05/16 21:36:59  knoaman
  59.  * Memory manager implementation: Modify constructors to pass in the memory manager.
  60.  *
  61.  * Revision 1.7  2003/05/16 06:01:52  knoaman
  62.  * Partial implementation of the configurable memory manager.
  63.  *
  64.  * Revision 1.6  2003/05/15 19:04:35  knoaman
  65.  * Partial implementation of the configurable memory manager.
  66.  *
  67.  * Revision 1.5  2002/11/04 15:22:04  tng
  68.  * C++ Namespace Support.
  69.  *
  70.  * Revision 1.4  2002/10/30 21:52:00  tng
  71.  * [Bug 13641] compiler-generated copy-constructor for QName doesn't do the right thing.
  72.  *
  73.  * Revision 1.3  2002/09/05 16:06:41  tng
  74.  * [Bug 12232] Make operator to be constant.
  75.  *
  76.  * Revision 1.2  2002/08/20 16:54:25  tng
  77.  * [Bug 6251] Info during compilation.
  78.  *
  79.  * Revision 1.1.1.1  2002/02/01 22:22:11  peiyongz
  80.  * sane_include
  81.  *
  82.  * Revision 1.8  2001/12/06 17:48:36  tng
  83.  * Performance Enhancement.  Added setNPrefix and setNLocalPart methods that allow code to take advantage of the fact that it knows the length of the prefix and local name, when possible.  That can avoid a copy of the prefix into a null-terminated temporary variable before copying into the fPrefix.
  84.  * Also changed the getRawName method so that it would simply return the local part when there is no prefix, instead of allocating another buffer to copy the local part into the fRawName.
  85.  * When there is a prefix, changed the getRawName to copy the prefix and local part into the fRawName using XMLString::moveChars instead of using XMLString::copyString and XMLString::catString.  The catString method has to loop past the prefix portion of the fRawName, which seems like a waste.
  86.  * By Henry Zongaro.
  87.  *
  88.  * Revision 1.7  2001/07/24 18:31:47  knoaman
  89.  * Added support for <group> + extra constraint checking for complexType
  90.  *
  91.  * Revision 1.6  2001/05/11 13:26:28  tng
  92.  * Copyright update.
  93.  *
  94.  * Revision 1.5  2001/04/19 18:17:10  tng
  95.  * Schema: SchemaValidator update, and use QName in Content Model
  96.  *
  97.  * Revision 1.4  2001/03/21 21:56:12  tng
  98.  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  99.  *
  100.  * Revision 1.3  2001/02/27 14:48:39  tng
  101.  * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
  102.  *
  103.  * Revision 1.2  2001/02/26 21:56:16  tng
  104.  * Schema: QName can also be constructed with rawName.
  105.  *
  106.  * Revision 1.1  2001/02/26 19:44:25  tng
  107.  * Schema: add utility class QName, by Pei Yong Zhang.
  108.  *
  109.  */
  110. #if !defined(QNAME_HPP)
  111. #define QNAME_HPP
  112. #include <xercesc/util/XMLString.hpp>
  113. #include <xercesc/util/XMLUniDefs.hpp>
  114. #include <xercesc/util/XMemory.hpp>
  115. #include <xercesc/util/PlatformUtils.hpp>
  116. XERCES_CPP_NAMESPACE_BEGIN
  117. class XMLUTIL_EXPORT QName : public XMemory
  118. {
  119. public :
  120.     // -----------------------------------------------------------------------
  121.     //  Contructors and Destructor
  122.     // -----------------------------------------------------------------------
  123.     /** Default constructor. */
  124.     QName(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
  125.     /** Constructs a specified qname using prefix, and localpart. */
  126.     QName
  127.     (
  128.           const XMLCh* const   prefix
  129.         , const XMLCh* const   localPart
  130.     , const unsigned int   uriId
  131.         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
  132.     );
  133.     /** Constructs a specified qname using rawName. */
  134.     QName
  135.     (
  136.           const XMLCh* const   rawName
  137.     , const unsigned int   uriId
  138.         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
  139.     );
  140.     /** Copy constructor. */
  141.     QName(const QName& qname);
  142.     ~QName();
  143.     // -----------------------------------------------------------------------
  144.     //  Getters
  145.     // -----------------------------------------------------------------------
  146.     const XMLCh* getPrefix() const;
  147.     XMLCh* getPrefix();
  148.     const XMLCh* getLocalPart() const;
  149.     XMLCh* getLocalPart();
  150.     unsigned int getURI() const;
  151.     const XMLCh* getRawName() const;
  152.     XMLCh* getRawName();
  153.     MemoryManager* getMemoryManager() const;
  154.     // -----------------------------------------------------------------------
  155.     //  Setters
  156.     // -----------------------------------------------------------------------
  157.     void setName
  158.     (
  159.         const XMLCh* const        prefix
  160.       , const XMLCh* const        localPart
  161.    , const unsigned int        uriId
  162.     );
  163.     void setName
  164.     (
  165.         const XMLCh* const        rawName
  166.    , const unsigned int        uriId
  167.     );
  168.     void setPrefix(const XMLCh*) ;
  169.     void setLocalPart(const XMLCh*) ;
  170.     void setNPrefix(const XMLCh*, const unsigned int) ;
  171.     void setNLocalPart(const XMLCh*, const unsigned int) ;
  172.     void setURI(const unsigned int) ;
  173.     void setValues(const QName& qname);
  174.     // -----------------------------------------------------------------------
  175.     //  comparison
  176.     // -----------------------------------------------------------------------
  177.     bool operator==(const QName&) const;
  178.     // -----------------------------------------------------------------------
  179.     //  Misc
  180.     // -----------------------------------------------------------------------
  181.     void cleanUp();
  182. private :
  183.     // -----------------------------------------------------------------------
  184.     //  Private instance variables
  185.     //
  186.     //  We copy the followings from XMLAttr.hpp, but stick to Java version's
  187.     //  naming convention
  188.     //
  189.     //  fPrefix
  190.     //  fPrefixBufSz
  191.     //      The prefix that was applied to this attribute's name, and the
  192.     //      current size of the buffer (minus one for the null.) Prefixes
  193.     //      really don't matter technically but it might be required for
  194.     //      pratical reasons, to recreate the original document for instance.
  195.     //
  196.     //  fLocalPart
  197.     //  fLocalPartBufSz
  198.     //      The base part of the name of the attribute, and the current size
  199.     //      of the buffer (minus one, where the null is.)
  200.     //
  201.     //  fRawName
  202.     //  fRawNameBufSz
  203.     //      This is the QName form of the name, which is faulted in (from the
  204.     //      prefix and name) upon request. The size field indicates the
  205.     //      current size of the buffer (minus one for the null.) It will be
  206.     //      zero until fauled in.
  207.     //
  208.     //  fURIId
  209.     //      The id of the URI that this attribute belongs to.
  210.     // -----------------------------------------------------------------------
  211.     MemoryManager*      fMemoryManager;
  212.     XMLCh*              fPrefix;
  213.     unsigned int        fPrefixBufSz;
  214.     XMLCh*              fLocalPart;
  215.     unsigned int        fLocalPartBufSz;
  216.     XMLCh*              fRawName;
  217.     unsigned int        fRawNameBufSz;
  218.     unsigned int        fURIId;
  219. };
  220. // ---------------------------------------------------------------------------
  221. //  QName: Getter methods
  222. // ---------------------------------------------------------------------------
  223. inline const XMLCh* QName::getPrefix() const
  224. {
  225. return fPrefix;
  226. }
  227. inline XMLCh* QName::getPrefix()
  228. {
  229. return fPrefix;
  230. }
  231. inline const XMLCh* QName::getLocalPart() const
  232. {
  233. return fLocalPart;
  234. }
  235. inline XMLCh* QName::getLocalPart()
  236. {
  237. return fLocalPart;
  238. }
  239. inline unsigned int QName::getURI() const
  240. {
  241. return fURIId;
  242. }
  243. inline MemoryManager* QName::getMemoryManager() const
  244. {
  245.     return fMemoryManager;
  246. }
  247. // ---------------------------------------------------------------------------
  248. //  QName: Setter methods
  249. // ---------------------------------------------------------------------------
  250. inline void QName::setURI(const unsigned int uriId)
  251. {
  252.     fURIId = uriId;
  253. }
  254. XERCES_CPP_NAMESPACE_END
  255. #endif