summaryrefslogtreecommitdiff
path: root/ACE/ACEXML/common/AttributesImpl.h
blob: f6ee26e77851746bea6a8af152a52b601c2b9b17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// -*- C++ -*-

//=============================================================================
/**
 *  @file    AttributesImpl.h
 *
 *  $Id$
 *
 *  @author Nanbor Wang <nanbor@cs.wustl.edu>
 */
//=============================================================================


#ifndef ACEXML_ATTRIBUTESIMPL_H
#define ACEXML_ATTRIBUTESIMPL_H

#include /**/ "ace/pre.h"
#include "ACEXML/common/ACEXML_Export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ACEXML/common/Attributes.h"
#include "ace/Containers_T.h"

#if !defined ACEXML_AttributesImpl_Default_Size
#define ACEXML_AttributesImpl_Default_Size 20
#endif /* ACEXML_AttributesImpl_Default_Size */

class ACEXML_AttributesImpl;

/**
 * @class ACEXML_Attribute AttributesImpl.h "ACEXML/common/AttributesImpl.h"
 *
 * @brief ACEXML_Attribute defines the data structure of an attribute
 *
 * @sa ACEXML_AttributesImpl
 */
class ACEXML_Export ACEXML_Attribute
{
public:
  friend class ACEXML_AttributesImpl;

  /// Default constructor.
  ACEXML_Attribute (void);

  /// Copy constructor.
  ACEXML_Attribute (const ACEXML_Attribute &attr);

  /// Initialize all constructor.
  ACEXML_Attribute (const ACEXML_Char *uri,
                    const ACEXML_Char *localName,
                    const ACEXML_Char *qName,
                    const ACEXML_Char *type,
                    const ACEXML_Char *value);

  /// Destructor.
  ~ACEXML_Attribute (void);

  /// Set all members.
  void setAttribute (const ACEXML_Char *uri,
                     const ACEXML_Char *localName,
                     const ACEXML_Char *qName,
                     const ACEXML_Char *type,
                     const ACEXML_Char *value);

  /// Get \a uri_.
  const ACEXML_Char *uri (void) const;

  /// Set \a uri_.
  void uri (const ACEXML_Char *uri);

  /// Get \a localName_.
  const ACEXML_Char *localName (void) const;

  /// Set \a localName_.
  void localName (const ACEXML_Char *localName);

  /// Get \a qName_.
  const ACEXML_Char *qName (void) const;

  /// Set \a qName_.
  void qName (const ACEXML_Char *qName);

  /// Get \a type_.
  const ACEXML_Char *type (void) const;

  /// Set \a type_.
  void type (const ACEXML_Char *type);

  /// Get \a value_.
  const ACEXML_Char *value (void) const;

  /// Set \a value_.
  void value (const ACEXML_Char *value);

  /// Assignment operator.
  ACEXML_Attribute &operator= (const ACEXML_Attribute &rhs);

  /// Comparison operator.
  bool operator!= (const ACEXML_Attribute&rhs) const;

private:
  /// Namespace URI of an attribute
  ACEXML_Char *uri_;

  ACEXML_Char *localName_;
  ACEXML_Char *qName_;
  ACEXML_Char *type_;
  ACEXML_Char *value_;
};

/**
 * @typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array
 */
typedef ACE_Array<ACEXML_Attribute> ACEXML_Attribute_Array;

/**
 * @class ACEXML_AttributesImpl AttributesImpl.h "ACEXML/common/AttributesImpl.h"
 *
 * @brief ACEXML_AttributesImpl provides the default implementation
 * of interface ACEXML_Attributes.
 *
 * This class provides a default implementation of the SAX2 Attributes
 * interface, with the addition of manipulators so that the list can
 * be modified or reused.
 *
 * There are two typical uses of this class:
 *
 * - to take a persistent snapshot of an Attributes object in a
 *   startElement event; or
 * - to construct or modify an Attributes object in a SAX2 driver or filter.
 *
 * This class replaces the now-deprecated SAX1 AttributeListImpl
 * class; in addition to supporting the updated Attributes interface
 * rather than the deprecated AttributeList interface, it also
 * includes a much more efficient implementation using a single array
 * rather than a set of Vectors.
 *
 * @sa ACEXML_Attributes
 */
class ACEXML_Export ACEXML_AttributesImpl
  : public ACEXML_Attributes
{
public:
  /**
   * Initialize an AttributesImpl that holds <size> attributes.
   */
  ACEXML_AttributesImpl (int size = ACEXML_AttributesImpl_Default_Size);
  ACEXML_AttributesImpl (const ACEXML_AttributesImpl &attrs);
  virtual ~ACEXML_AttributesImpl (void);

  /**
   * Add a new attribute using the argument(s) supplied.
   * Return -1 if an attribute with the same name already exists.
   */
  virtual int addAttribute (const ACEXML_Char *uri,
                            const ACEXML_Char *localName,
                            const ACEXML_Char *qName,
                            const ACEXML_Char *type,
                            const ACEXML_Char *value);
  virtual int addAttribute (const ACEXML_Attribute &att);

  /**
   *  Check for duplicate attributes.
   */
  virtual int isDuplicate (const ACEXML_Char *uri,
                              const ACEXML_Char *localName,
                              const ACEXML_Char *qName);
  /**
   * Remove an attribute from the array.  Notice that this
   * operation can invalidate previously acquired <index>
   * value.  (It will repack the array.)
   */
  virtual int removeAttribute (size_t index);


  /**
   * Look up the index of an attribute by XML 1.0 qualified name.
   * Return -1 if we fail to find a match.
   */
  virtual int getIndex (const ACEXML_Char *qName);

  /**
   * Look up the index of an attribute by Namespace name.
   * Return -1 if we fail to find a match.
   */
  virtual int getIndex (const ACEXML_Char *uri,
                        const ACEXML_Char *localPart);

  /**
   * Return the number of attributes in the list.
   */
  virtual size_t getLength (void);

  /**
   * Look up an attribute's local name by index.
   * Return 0 if index is out of range.
   */
  virtual const ACEXML_Char *getLocalName (size_t index);

  /**
   * Look up an attribute's XML 1.0 qualified name by index.
   * Return 0 if index is out of range.
   */
  virtual const ACEXML_Char *getQName (size_t index);

  /**
   * Look up an attribute's type by index.
   * Return 0 if index is out of range.
   */
  virtual const ACEXML_Char *getType (size_t index);

  /**
   * Look up an attribute's type by XML 1.0 qualified name.
   * Return 0 if we fail to find a match.
   */
  virtual const ACEXML_Char *getType (const ACEXML_Char *qName);

  /**
   * Look up an attribute's type by Namespace name.
   * Return 0 if we fail to find a match.
   */
  virtual const ACEXML_Char *getType (const ACEXML_Char *uri,
                                      const ACEXML_Char *localPart);

  /**
   * Look up an attribute's Namespace URI by index.
   * Return 0 if index is out of range.
   */
  virtual const ACEXML_Char *getURI (size_t index);

  /**
   * Look up an attribute's value by index.
   * Return 0 if index is out of range.
   */
  virtual const ACEXML_Char *getValue (size_t index);

  /**
   * Look up an attribute's value by XML 1.0 qualified name.
   * Return 0 if we fail to find a match.
   */
  virtual const ACEXML_Char *getValue (const ACEXML_Char *qName);

  /**
   * Look up an attribute's value by Namespace name.
   * Return 0 if we fail to find a match.
   */
  virtual const ACEXML_Char *getValue (const ACEXML_Char *uri,
                                       const ACEXML_Char *localPart);

  /**
   * Set an attribute at index.  Return -1 if index is out of
   * range.
   */
  virtual int setAttribute (size_t index,
                            const ACEXML_Char *uri,
                            const ACEXML_Char *localName,
                            const ACEXML_Char *qName,
                            const ACEXML_Char *type,
                            const ACEXML_Char *value);

  /**
   * Set the localName of the attribute at <index>.
   * return -1 if <index> is out of range.
   */
  virtual int setLocalName (size_t index,
                            const ACEXML_Char *localName);

  /**
   * Set the qName of the attribute at <index>.
   * return -1 if <index> is out of range.
   */
  virtual int setQName (size_t index,
                        const ACEXML_Char *qName);

  /**
   * Set the URI of the attribute at <index>.
   * return -1 if <index> is out of range.
   */
  virtual int setURI (size_t index,
                      const ACEXML_Char *uri);

  /**
   * Set the type of the attribute at <index>.
   * return -1 if <index> is out of range.
   */
  virtual int setType (size_t index,
                       const ACEXML_Char *type);

  /**
   * Set the value of the attribute at <index>.
   * return -1 if <index> is out of range.
   */
  virtual int setValue (size_t index,
                        const ACEXML_Char *value);
private:
  /// Container for all attributes.
  ACEXML_Attribute_Array attrs_;
};

#if defined (__ACEXML_INLINE__)
# include "ACEXML/common/AttributesImpl.inl"
#endif /* __ACEXML_INLINE__ */

#include /**/ "ace/post.h"

#endif /* ACEXML_ATTRIBUTESIMPL_H */