|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: ValueArrayOf.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 |
|
39 #if !defined(VALUEARRAY_HPP) |
|
40 #define VALUEARRAY_HPP |
|
41 |
|
42 #include <xercesc/util/XMLEnumerator.hpp> |
|
43 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp> |
|
44 #include <xercesc/util/IllegalArgumentException.hpp> |
|
45 #include <xercesc/util/PlatformUtils.hpp> |
|
46 #include <xercesc/framework/MemoryManager.hpp> |
|
47 |
|
48 XERCES_CPP_NAMESPACE_BEGIN |
|
49 |
|
50 template <class TElem> class ValueArrayOf : public XMemory |
|
51 { |
|
52 public : |
|
53 // ----------------------------------------------------------------------- |
|
54 // Contructors and Destructor |
|
55 // ----------------------------------------------------------------------- |
|
56 ValueArrayOf |
|
57 ( |
|
58 const unsigned int size |
|
59 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
60 ); |
|
61 ValueArrayOf |
|
62 ( |
|
63 const TElem* values |
|
64 , const unsigned int size |
|
65 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
66 ); |
|
67 ValueArrayOf(const ValueArrayOf<TElem>& source); |
|
68 ~ValueArrayOf(); |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------- |
|
72 // Public operators |
|
73 // ----------------------------------------------------------------------- |
|
74 TElem& operator[](const unsigned int index); |
|
75 const TElem& operator[](const unsigned int index) const; |
|
76 ValueArrayOf<TElem>& operator=(const ValueArrayOf<TElem>& toAssign); |
|
77 bool operator==(const ValueArrayOf<TElem>& toCompare) const; |
|
78 bool operator!=(const ValueArrayOf<TElem>& toCompare) const; |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------- |
|
82 // Copy operations |
|
83 // ----------------------------------------------------------------------- |
|
84 unsigned int copyFrom(const ValueArrayOf<TElem>& srcArray); |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------- |
|
88 // Getter methods |
|
89 // ----------------------------------------------------------------------- |
|
90 unsigned int length() const; |
|
91 TElem* rawData() const; |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------- |
|
95 // Miscellaneous methods |
|
96 // ----------------------------------------------------------------------- |
|
97 void resize(const unsigned int newSize); |
|
98 |
|
99 |
|
100 private : |
|
101 // ----------------------------------------------------------------------- |
|
102 // Data members |
|
103 // ----------------------------------------------------------------------- |
|
104 unsigned int fSize; |
|
105 TElem* fArray; |
|
106 MemoryManager* fMemoryManager; |
|
107 }; |
|
108 |
|
109 |
|
110 // |
|
111 // An enumerator for a value array. It derives from the basic enumerator |
|
112 // class, so that value vectors can be generically enumerated. |
|
113 // |
|
114 template <class TElem> class ValueArrayEnumerator : public XMLEnumerator<TElem>, public XMemory |
|
115 { |
|
116 public : |
|
117 // ----------------------------------------------------------------------- |
|
118 // Constructors and Destructor |
|
119 // ----------------------------------------------------------------------- |
|
120 ValueArrayEnumerator |
|
121 ( |
|
122 ValueArrayOf<TElem>* const toEnum |
|
123 , const bool adopt = false |
|
124 ); |
|
125 virtual ~ValueArrayEnumerator(); |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------- |
|
129 // Enum interface |
|
130 // ----------------------------------------------------------------------- |
|
131 bool hasMoreElements() const; |
|
132 TElem& nextElement(); |
|
133 void Reset(); |
|
134 |
|
135 |
|
136 private : |
|
137 // ----------------------------------------------------------------------- |
|
138 // Unimplemented constructors and operators |
|
139 // ----------------------------------------------------------------------- |
|
140 ValueArrayEnumerator(const ValueArrayEnumerator<TElem>&); |
|
141 ValueArrayEnumerator<TElem>& operator=(const ValueArrayEnumerator<TElem>&); |
|
142 |
|
143 // ----------------------------------------------------------------------- |
|
144 // Data Members |
|
145 // |
|
146 // fAdopted |
|
147 // Indicates whether we have adopted the passed vector. If so then |
|
148 // we delete the vector when we are destroyed. |
|
149 // |
|
150 // fCurIndex |
|
151 // This is the current index into the vector. |
|
152 // |
|
153 // fToEnum |
|
154 // The value array being enumerated. |
|
155 // ----------------------------------------------------------------------- |
|
156 bool fAdopted; |
|
157 unsigned int fCurIndex; |
|
158 ValueArrayOf<TElem>* fToEnum; |
|
159 }; |
|
160 |
|
161 XERCES_CPP_NAMESPACE_END |
|
162 |
|
163 #if !defined(XERCES_TMPLSINC) |
|
164 #include <xercesc/util/ValueArrayOf.c> |
|
165 #endif |
|
166 |
|
167 #endif |