source: NonGTP/Xerces/xercesc/util/KVStringPair.hpp @ 188

Revision 188, 8.7 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
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: KVStringPair.hpp,v $
59 * Revision 1.7  2004/01/29 11:48:46  cargilld
60 * Code cleanup changes to get rid of various compiler diagnostic messages.
61 *
62 * Revision 1.6  2003/09/25 22:23:25  peiyongz
63 * Implementation of Serialization/Deserialization
64 *
65 * Revision 1.5  2003/05/18 14:02:05  knoaman
66 * Memory manager implementation: pass per instance manager.
67 *
68 * Revision 1.4  2003/05/16 06:01:52  knoaman
69 * Partial implementation of the configurable memory manager.
70 *
71 * Revision 1.3  2003/05/15 19:04:35  knoaman
72 * Partial implementation of the configurable memory manager.
73 *
74 * Revision 1.2  2002/11/04 15:22:04  tng
75 * C++ Namespace Support.
76 *
77 * Revision 1.1.1.1  2002/02/01 22:22:11  peiyongz
78 * sane_include
79 *
80 * Revision 1.6  2001/05/11 13:26:27  tng
81 * Copyright update.
82 *
83 * Revision 1.5  2001/01/15 21:26:34  tng
84 * Performance Patches by David Bertoni.
85 *
86 * Details: (see xerces-c-dev mailing Jan 14)
87 * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
88 * was going through this function numerous times.  As a result, the top hot-spot
89 * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
90 * functions are unbelievably slow.  For things like encodings, it might be
91 * better to use a special comparison function that only considers a-z and
92 * A-Z as characters with case.  This works since the character set for
93 * encodings is limit to printable ASCII characters.
94 *
95 *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
96 * They are also much faster.  The other tweak is to only make a copy of an attribute
97 * string if it needs to be split.  And then, the strategy is to try to use a
98 * stack-based buffer, rather than a dynamically-allocated one.
99 *
100 * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
101 *
102 * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
103 * likely be re-used many times, cutting down on dynamic memory allocations.
104 *
105 * XMLString.hpp: a more efficient implementation of stringLen().
106 *
107 * DTDValidator.cpp: another case of using a stack-based buffer when possible
108 *
109 * These patches made a big difference in parse time in some of our test
110 * files, especially the ones are very attribute-heavy.
111 *
112 * Revision 1.4  2000/03/02 19:54:40  roddey
113 * This checkin includes many changes done while waiting for the
114 * 1.1.0 code to be finished. I can't list them all here, but a list is
115 * available elsewhere.
116 *
117 * Revision 1.3  2000/02/24 20:05:24  abagchi
118 * Swat for removing Log from API docs
119 *
120 * Revision 1.2  2000/02/06 07:48:02  rahulj
121 * Year 2K copyright swat.
122 *
123 * Revision 1.1.1.1  1999/11/09 01:04:37  twl
124 * Initial checkin
125 *
126 * Revision 1.2  1999/11/08 20:45:08  rahul
127 * Swat for adding in Product name and CVS comment log variable.
128 *
129 */
130
131#if !defined(KVSTRINGPAIR_HPP)
132#define KVSTRINGPAIR_HPP
133
134#include <xercesc/util/XMemory.hpp>
135#include <xercesc/util/PlatformUtils.hpp>
136
137#include <xercesc/internal/XSerializable.hpp>
138
139XERCES_CPP_NAMESPACE_BEGIN
140
141//
142//  This class provides a commonly used data structure, which is that of
143//  a pair of strings which represent a 'key=value' type mapping. It works
144//  only in terms of XMLCh type raw strings.
145//
146class XMLUTIL_EXPORT KVStringPair : public XSerializable, public XMemory
147{
148public:
149    // -----------------------------------------------------------------------
150    //  Constructors and Destructor
151    // -----------------------------------------------------------------------
152    KVStringPair(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
153    KVStringPair
154    (
155        const XMLCh* const key
156        , const XMLCh* const value
157        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
158    );
159    KVStringPair(const KVStringPair& toCopy);
160    ~KVStringPair();
161
162
163    // -----------------------------------------------------------------------
164    //  Getters
165    //
166    //  We support the
167    // -----------------------------------------------------------------------
168    const XMLCh* getKey() const;
169    XMLCh* getKey();
170    const XMLCh* getValue() const;
171    XMLCh* getValue();
172
173
174    // -----------------------------------------------------------------------
175    //  Setters
176    // -----------------------------------------------------------------------
177    void setKey(const XMLCh* const newKey);
178    void setValue(const XMLCh* const newValue);
179    void set
180    (
181        const   XMLCh* const    newKey
182        , const XMLCh* const    newValue
183    );
184
185
186    /***
187     * Support for Serialization/De-serialization
188     ***/
189    DECL_XSERIALIZABLE(KVStringPair)
190
191private :
192    // unimplemented:
193       
194    KVStringPair& operator=(const KVStringPair&);
195    // -----------------------------------------------------------------------
196    //  Private data members
197    //
198    //  fKey
199    //      The string that represents the key field of this object.
200    //
201    //  fKeyAllocSize
202    //      The amount of memory allocated for fKey.
203    //
204    //  fValue
205    //      The string that represents the value of this pair object.
206    //
207    //  fValueAllocSize
208    //      The amount of memory allocated for fValue.
209    //
210    // -----------------------------------------------------------------------
211    MemoryManager* fMemoryManager;
212    XMLCh*         fKey;
213    unsigned long  fKeyAllocSize;
214    XMLCh*         fValue;
215    unsigned long  fValueAllocSize;
216};
217
218// ---------------------------------------------------------------------------
219//  KVStringPair: Getters
220// ---------------------------------------------------------------------------
221inline const XMLCh* KVStringPair::getKey() const
222{
223    return fKey;
224}
225
226inline XMLCh* KVStringPair::getKey()
227{
228    return fKey;
229}
230
231inline const XMLCh* KVStringPair::getValue() const
232{
233    return fValue;
234}
235
236inline XMLCh* KVStringPair::getValue()
237{
238    return fValue;
239}
240
241XERCES_CPP_NAMESPACE_END
242
243#endif
Note: See TracBrowser for help on using the repository browser.