sl@0
|
1 |
/*
|
sl@0
|
2 |
**********************************************************************
|
sl@0
|
3 |
* Copyright (c) 2004, International Business Machines
|
sl@0
|
4 |
* Corporation and others. All Rights Reserved.
|
sl@0
|
5 |
**********************************************************************
|
sl@0
|
6 |
* Author: Alan Liu
|
sl@0
|
7 |
* Created: January 16 2004
|
sl@0
|
8 |
* Since: ICU 2.8
|
sl@0
|
9 |
**********************************************************************
|
sl@0
|
10 |
*/
|
sl@0
|
11 |
#ifndef LOCBASED_H
|
sl@0
|
12 |
#define LOCBASED_H
|
sl@0
|
13 |
|
sl@0
|
14 |
#include "unicode/locid.h"
|
sl@0
|
15 |
#include "unicode/uobject.h"
|
sl@0
|
16 |
|
sl@0
|
17 |
/**
|
sl@0
|
18 |
* Macro to declare a locale LocaleBased wrapper object for the given
|
sl@0
|
19 |
* object, which must have two members named `validLocale' and
|
sl@0
|
20 |
* `actualLocale'.
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
#define U_LOCALE_BASED(varname, objname) \
|
sl@0
|
23 |
LocaleBased varname((objname).validLocale, (objname).actualLocale);
|
sl@0
|
24 |
|
sl@0
|
25 |
U_NAMESPACE_BEGIN
|
sl@0
|
26 |
|
sl@0
|
27 |
/**
|
sl@0
|
28 |
* A utility class that unifies the implementation of getLocale() by
|
sl@0
|
29 |
* various ICU services. This class is likely to be removed in the
|
sl@0
|
30 |
* ICU 3.0 time frame in favor of an integrated approach with the
|
sl@0
|
31 |
* services framework.
|
sl@0
|
32 |
* @since ICU 2.8
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
class U_COMMON_API LocaleBased : public UMemory {
|
sl@0
|
35 |
|
sl@0
|
36 |
public:
|
sl@0
|
37 |
|
sl@0
|
38 |
/**
|
sl@0
|
39 |
* Construct a LocaleBased wrapper around the two pointers. These
|
sl@0
|
40 |
* will be aliased for the lifetime of this object.
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
inline LocaleBased(char* validAlias, char* actualAlias);
|
sl@0
|
43 |
|
sl@0
|
44 |
/**
|
sl@0
|
45 |
* Construct a LocaleBased wrapper around the two const pointers.
|
sl@0
|
46 |
* These will be aliased for the lifetime of this object.
|
sl@0
|
47 |
*/
|
sl@0
|
48 |
inline LocaleBased(const char* validAlias, const char* actualAlias);
|
sl@0
|
49 |
|
sl@0
|
50 |
/**
|
sl@0
|
51 |
* Return locale meta-data for the service object wrapped by this
|
sl@0
|
52 |
* object. Either the valid or the actual locale may be
|
sl@0
|
53 |
* retrieved.
|
sl@0
|
54 |
* @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
|
sl@0
|
55 |
* @param status input-output error code
|
sl@0
|
56 |
* @return the indicated locale
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
|
sl@0
|
59 |
|
sl@0
|
60 |
/**
|
sl@0
|
61 |
* Return the locale ID for the service object wrapped by this
|
sl@0
|
62 |
* object. Either the valid or the actual locale may be
|
sl@0
|
63 |
* retrieved.
|
sl@0
|
64 |
* @param type either ULOC_VALID_LOCALE or ULOC_ACTUAL_LOCALE
|
sl@0
|
65 |
* @param status input-output error code
|
sl@0
|
66 |
* @return the indicated locale ID
|
sl@0
|
67 |
*/
|
sl@0
|
68 |
const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
|
sl@0
|
69 |
|
sl@0
|
70 |
/**
|
sl@0
|
71 |
* Set the locale meta-data for the service object wrapped by this
|
sl@0
|
72 |
* object. If either parameter is zero, it is ignored.
|
sl@0
|
73 |
* @param valid the ID of the valid locale
|
sl@0
|
74 |
* @param actual the ID of the actual locale
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
void setLocaleIDs(const char* valid, const char* actual);
|
sl@0
|
77 |
|
sl@0
|
78 |
private:
|
sl@0
|
79 |
|
sl@0
|
80 |
char* valid;
|
sl@0
|
81 |
|
sl@0
|
82 |
char* actual;
|
sl@0
|
83 |
};
|
sl@0
|
84 |
|
sl@0
|
85 |
inline LocaleBased::LocaleBased(char* validAlias, char* actualAlias) :
|
sl@0
|
86 |
valid(validAlias), actual(actualAlias) {
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
inline LocaleBased::LocaleBased(const char* validAlias,
|
sl@0
|
90 |
const char* actualAlias) :
|
sl@0
|
91 |
// ugh: cast away const
|
sl@0
|
92 |
valid((char*)validAlias), actual((char*)actualAlias) {
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
U_NAMESPACE_END
|
sl@0
|
96 |
|
sl@0
|
97 |
#endif
|