]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/unicode/resbund.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / common / unicode / resbund.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
3*
4* Copyright (C) 1996-2003, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7******************************************************************************
8*
9* File resbund.h
10*
11* CREATED BY
12* Richard Gillam
13*
14* Modification History:
15*
16* Date Name Description
17* 2/5/97 aliu Added scanForLocaleInFile. Added
18* constructor which attempts to read resource bundle
19* from a specific file, without searching other files.
20* 2/11/97 aliu Added UErrorCode return values to constructors. Fixed
21* infinite loops in scanForFile and scanForLocale.
22* Modified getRawResourceData to not delete storage
23* in localeData and resourceData which it doesn't own.
24* Added Mac compatibility #ifdefs for tellp() and
25* ios::nocreate.
26* 2/18/97 helena Updated with 100% documentation coverage.
27* 3/13/97 aliu Rewrote to load in entire resource bundle and store
28* it as a Hashtable of ResourceBundleData objects.
29* Added state table to govern parsing of files.
30* Modified to load locale index out of new file
31* distinct from default.txt.
32* 3/25/97 aliu Modified to support 2-d arrays, needed for timezone
33* data. Added support for custom file suffixes. Again,
34* needed to support timezone data.
35* 4/7/97 aliu Cleaned up.
36* 03/02/99 stephen Removed dependency on FILE*.
37* 03/29/99 helena Merged Bertrand and Stephen's changes.
38* 06/11/99 stephen Removed parsing of .txt files.
39* Reworked to use new binary format.
40* Cleaned up.
41* 06/14/99 stephen Removed methods taking a filename suffix.
42* 11/09/99 weiv Added getLocale(), fRealLocale, removed fRealLocaleID
43******************************************************************************
44*/
45
46#ifndef RESBUND_H
47#define RESBUND_H
48
49#include "unicode/utypes.h"
50#include "unicode/uobject.h"
51#include "unicode/ures.h"
52#include "unicode/unistr.h"
53#include "unicode/locid.h"
54
55U_NAMESPACE_BEGIN
56
57/**
58 * A class representing a collection of resource information pertaining to a given
59 * locale. A resource bundle provides a way of accessing locale- specfic information in
60 * a data file. You create a resource bundle that manages the resources for a given
61 * locale and then ask it for individual resources.
62 * <P>
63 * Resource bundles in ICU4C are currently defined using text files which conform to the following
64 * <a href="http://oss.software.ibm.com/cvs/icu/~checkout~/icuhtml/design/bnf_rb.txt">BNF definition</a>.
65 * More on resource bundle concepts and syntax can be found in the
66 * <a href="http://oss.software.ibm.com/icu/userguide/ResourceManagement.html">Users Guide</a>.
67 * <P>
68 *
69 * The ResourceBundle class is not suitable for subclassing.
70 *
71 * @stable ICU 2.0
72 */
73class U_COMMON_API ResourceBundle : public UObject {
74public:
75 /**
76 * Constructor
77 *
78 * @param path This is a full pathname in the platform-specific format for the
79 * directory containing the resource data files we want to load
80 * resources from. We use locale IDs to generate filenames, and the
81 * filenames have this string prepended to them before being passed
82 * to the C++ I/O functions. Therefore, this string must always end
83 * with a directory delimiter (whatever that is for the target OS)
84 * for this class to work correctly.
85 * @param locale This is the locale this resource bundle is for. To get resources
86 * for the French locale, for example, you would create a
87 * ResourceBundle passing Locale::FRENCH for the "locale" parameter,
88 * and all subsequent calls to that resource bundle will return
89 * resources that pertain to the French locale. If the caller doesn't
90 * pass a locale parameter, the default locale for the system (as
91 * returned by Locale::getDefault()) will be used.
92 * @param err The Error Code.
93 * The UErrorCode& err parameter is used to return status information to the user. To
94 * check whether the construction succeeded or not, you should check the value of
95 * U_SUCCESS(err). If you wish more detailed information, you can check for
96 * informational error results which still indicate success. U_USING_FALLBACK_WARNING
97 * indicates that a fall back locale was used. For example, 'de_CH' was requested,
98 * but nothing was found there, so 'de' was used. U_USING_DEFAULT_WARNING indicates that
99 * the default locale data was used; neither the requested locale nor any of its
100 * fall back locales could be found.
101 * @stable ICU 2.0
102 */
103 ResourceBundle(const UnicodeString& path,
104 const Locale& locale,
105 UErrorCode& err);
106
107 /**
108 * Construct a resource bundle for the root bundle in the specified path.
109 *
110 * @param path A path/basename for the data file(s) containing the bundle.
111 * @param err A UErrorCode value
112 * @stable ICU 2.0
113 */
114 ResourceBundle(const UnicodeString& path,
115 UErrorCode& err);
116
117 /**
118 * Construct a resource bundle for the ICU root bundle.
119 *
120 * @param err A UErrorCode value
121 * @stable ICU 2.0
122 */
123 ResourceBundle(UErrorCode &err);
124
125 /**
126 * Standard constructor, onstructs a resource bundle for the locale-specific
127 * bundle in the specified path.
128 *
129 * @param path A path/basename for the data file(s) containing the bundle.
130 * NULL is used for ICU data.
131 * @param locale The locale for which to open a resource bundle.
132 * @param err A UErrorCode value
133 * @stable ICU 2.0
134 */
135 ResourceBundle(const char* path,
136 const Locale& locale,
137 UErrorCode& err);
138
139 /**
140 * Copy constructor.
141 *
142 * @param original The resource bundle to copy.
143 * @stable ICU 2.0
144 */
145 ResourceBundle(const ResourceBundle &original);
146
147 /**
148 * Constructor from a C UResourceBundle.
149 *
150 * @param res A pointer to the C resource bundle.
151 * @param status A UErrorCode value.
152 * @stable ICU 2.0
153 */
154 ResourceBundle(UResourceBundle *res,
155 UErrorCode &status);
156
157 /**
158 * Assignment operator.
159 *
160 * @param other The resource bundle to copy.
161 * @stable ICU 2.0
162 */
163 ResourceBundle&
164 operator=(const ResourceBundle& other);
165
166 /** Destructor.
167 * @stable ICU 2.0
168 */
169 ~ResourceBundle();
170
171 /**
172 * Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is
173 * the number of child resources.
174 *
175 * @return number of resources in a given resource.
176 * @stable ICU 2.0
177 */
178 int32_t
179 getSize(void) const;
180
181 /**
182 * returns a string from a string resource type
183 *
184 * @param status fills in the outgoing error code
185 * could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
186 * could be a warning
187 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
188 * @return a pointer to a zero-terminated UChar array which lives in a memory mapped/DLL file.
189 * @stable ICU 2.0
190 */
191 UnicodeString
192 getString(UErrorCode& status) const;
193
194 /**
195 * returns a binary data from a resource. Can be used at most primitive resource types (binaries,
196 * strings, ints)
197 *
198 * @param len fills in the length of resulting byte chunk
199 * @param status fills in the outgoing error code
200 * could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
201 * could be a warning
202 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
203 * @return a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
204 * @stable ICU 2.0
205 */
206 const uint8_t*
207 getBinary(int32_t& len, UErrorCode& status) const;
208
209
210 /**
211 * returns an integer vector from a resource.
212 *
213 * @param len fills in the length of resulting integer vector
214 * @param status fills in the outgoing error code
215 * could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
216 * could be a warning
217 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
218 * @return a pointer to a vector of integers that lives in a memory mapped/DLL file.
219 * @stable ICU 2.0
220 */
221 const int32_t*
222 getIntVector(int32_t& len, UErrorCode& status) const;
223
224 /**
225 * returns an unsigned integer from a resource.
226 * This integer is originally 28 bits.
227 *
228 * @param status fills in the outgoing error code
229 * could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
230 * could be a warning
231 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
232 * @return an unsigned integer value
233 * @stable ICU 2.0
234 */
235 uint32_t
236 getUInt(UErrorCode& status) const;
237
238 /**
239 * returns a signed integer from a resource.
240 * This integer is originally 28 bit and the sign gets propagated.
241 *
242 * @param status fills in the outgoing error code
243 * could be <TT>U_MISSING_RESOURCE_ERROR</T> if the key is not found
244 * could be a warning
245 * e.g.: <TT>U_USING_FALLBACK_WARNING</TT>,<TT>U_USING_DEFAULT_WARNING </TT>
246 * @return a signed integer value
247 * @stable ICU 2.0
248 */
249 int32_t
250 getInt(UErrorCode& status) const;
251
252 /**
253 * Checks whether the resource has another element to iterate over.
254 *
255 * @return TRUE if there are more elements, FALSE if there is no more elements
256 * @stable ICU 2.0
257 */
258 UBool
259 hasNext(void) const;
260
261 /**
262 * Resets the internal context of a resource so that iteration starts from the first element.
263 *
264 * @stable ICU 2.0
265 */
266 void
267 resetIterator(void);
268
269 /**
270 * Returns the key associated with this resource. Not all the resources have a key - only
271 * those that are members of a table.
272 *
273 * @return a key associated to this resource, or NULL if it doesn't have a key
274 * @stable ICU 2.0
275 */
276 const char*
277 getKey(void);
278
279 /**
280 * Gets the locale ID of the resource bundle as a string.
281 * Same as getLocale().getName() .
282 *
283 * @return the locale ID of the resource bundle as a string
284 * @stable ICU 2.0
285 */
286 const char*
287 getName(void);
288
289
290 /**
291 * Returns the type of a resource. Available types are defined in enum UResType
292 *
293 * @return type of the given resource.
294 * @stable ICU 2.0
295 */
296 UResType
297 getType(void);
298
299 /**
300 * Returns the next resource in a given resource or NULL if there are no more resources
301 *
302 * @param status fills in the outgoing error code
303 * @return ResourceBundle object.
304 * @stable ICU 2.0
305 */
306 ResourceBundle
307 getNext(UErrorCode& status);
308
309 /**
310 * Returns the next string in a resource or NULL if there are no more resources
311 * to iterate over.
312 *
313 * @param status fills in the outgoing error code
314 * @return an UnicodeString object.
315 * @stable ICU 2.0
316 */
317 UnicodeString
318 getNextString(UErrorCode& status);
319
320 /**
321 * Returns the next string in a resource or NULL if there are no more resources
322 * to iterate over.
323 *
324 * @param key fill in for key associated with this string
325 * @param status fills in the outgoing error code
326 * @return an UnicodeString object.
327 * @stable ICU 2.0
328 */
329 UnicodeString
330 getNextString(const char ** key,
331 UErrorCode& status);
332
333 /**
334 * Returns the resource in a resource at the specified index.
335 *
336 * @param index an index to the wanted resource.
337 * @param status fills in the outgoing error code
338 * @return ResourceBundle object. If there is an error, resource is invalid.
339 * @stable ICU 2.0
340 */
341 ResourceBundle
342 get(int32_t index,
343 UErrorCode& status) const;
344
345 /**
346 * Returns the string in a given resource at the specified index.
347 *
348 * @param index an index to the wanted string.
349 * @param status fills in the outgoing error code
350 * @return an UnicodeString object. If there is an error, string is bogus
351 * @stable ICU 2.0
352 */
353 UnicodeString
354 getStringEx(int32_t index,
355 UErrorCode& status) const;
356
357 /**
358 * Returns a resource in a resource that has a given key. This procedure works only with table
359 * resources.
360 *
361 * @param key a key associated with the wanted resource
362 * @param status fills in the outgoing error code.
363 * @return ResourceBundle object. If there is an error, resource is invalid.
364 * @stable ICU 2.0
365 */
366 ResourceBundle
367 get(const char* key,
368 UErrorCode& status) const;
369
370 /**
371 * Returns a string in a resource that has a given key. This procedure works only with table
372 * resources.
373 *
374 * @param key a key associated with the wanted string
375 * @param status fills in the outgoing error code
376 * @return an UnicodeString object. If there is an error, string is bogus
377 * @stable ICU 2.0
378 */
379 UnicodeString
380 getStringEx(const char* key,
381 UErrorCode& status) const;
382
383 /**
384 * Return the version number associated with this ResourceBundle as a string. Please
385 * use getVersion, as this method is going to be deprecated.
386 *
387 * @return A version number string as specified in the resource bundle or its parent.
388 * The caller does not own this string.
389 * @see getVersion
390 * @stable ICU 2.0
391 */
392 const char*
393 getVersionNumber(void) const;
394
395 /**
396 * Return the version number associated with this ResourceBundle as a UVersionInfo array.
397 *
398 * @param versionInfo A UVersionInfo array that is filled with the version number
399 * as specified in the resource bundle or its parent.
400 * @stable ICU 2.0
401 */
402 void
403 getVersion(UVersionInfo versionInfo) const;
404
405 /**
406 * Return the Locale associated with this ResourceBundle.
407 *
408 * @return a Locale object
409 * @stable ICU 2.0
410 */
411 const Locale&
412 getLocale(void) const;
413
414 /**
415 * ICU "poor man's RTTI", returns a UClassID for the actual class.
416 *
417 * @draft ICU 2.2
418 */
419 virtual inline UClassID getDynamicClassID() const;
420
421 /**
422 * ICU "poor man's RTTI", returns a UClassID for this class.
423 *
424 * @draft ICU 2.2
425 */
426 static inline UClassID getStaticClassID();
427
428private:
429 ResourceBundle(); // default constructor not implemented
430
431 UResourceBundle *resource;
432 void constructForLocale(const UnicodeString& path, const Locale& locale, UErrorCode& error);
433 Locale *locName;
434
435 /**
436 * The address of this static class variable serves as this class's ID
437 * for ICU "poor man's RTTI".
438 */
439 static const char fgClassID;
440};
441
442inline UClassID
443ResourceBundle::getStaticClassID()
444{ return (UClassID)&fgClassID; }
445
446inline UClassID
447ResourceBundle::getDynamicClassID() const
448{ return ResourceBundle::getStaticClassID(); }
449
450U_NAMESPACE_END
451#endif