ICU-2203 no public hashtable, replace with const list of UnicodeString

X-SVN-Rev: 11179
This commit is contained in:
Doug Felt 2003-02-27 20:14:51 +00:00
parent 46fb4dc7c3
commit 7456e00aee
2 changed files with 67 additions and 51 deletions

View File

@ -31,6 +31,7 @@
#include "unicode/resbund.h"
#include "unicode/dcfmtsym.h"
#include "unicode/decimfmt.h"
#include "uhash.h"
#include "iculserv.h"
#include <float.h>
@ -323,47 +324,62 @@ protected:
class NFFactory : public LocaleKeyFactory {
private:
NumberFormatFactory* _delegate;
NumberFormatFactory* _delegate;
Hashtable* _ids;
public:
NFFactory(NumberFormatFactory* delegate)
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
, _delegate(delegate)
{
}
virtual ~NFFactory()
{
delete _delegate;
}
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
{
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
Locale loc;
lkey.canonicalLocale(loc);
int32_t kind = lkey.kind();
UObject* result = _delegate->createFormat(loc, (UNumberFormatStyle)(kind+1));
if (result == NULL) {
result = service->getKey((ICUServiceKey&)key /* cast away const */, NULL, this, status);
}
return result;
}
return NULL;
NFFactory(NumberFormatFactory* delegate)
: LocaleKeyFactory(delegate->visible() ? VISIBLE : INVISIBLE)
, _delegate(delegate)
, _ids(NULL)
{
}
virtual ~NFFactory()
{
delete _delegate;
}
virtual UObject* create(const ICUServiceKey& key, const ICUService* service, UErrorCode& status) const
{
if (handlesKey(key, status)) {
const LocaleKey& lkey = (const LocaleKey&)key;
Locale loc;
lkey.canonicalLocale(loc);
int32_t kind = lkey.kind();
UObject* result = _delegate->createFormat(loc, (UNumberFormatStyle)(kind+1));
if (result == NULL) {
result = service->getKey((ICUServiceKey&)key /* cast away const */, NULL, this, status);
}
return result;
}
return NULL;
}
protected:
/**
* Return the set of ids that this factory supports (visible or
* otherwise). This can be called often and might need to be
* cached if it is expensive to create.
*/
virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
{
return _delegate->getSupportedIDs(status);
/**
* Return the set of ids that this factory supports (visible or
* otherwise). This can be called often and might need to be
* cached if it is expensive to create.
*/
virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
{
if (U_SUCCESS(status)) {
if (!_ids) {
int32_t count = 0;
const UnicodeString * const idlist = _delegate->getSupportedIDs(count, status);
((NFFactory*)this)->_ids = new Hashtable(status); /* cast away const */
if (_ids) {
for (int i = 0; i < count; ++i) {
_ids->put(idlist[i], (void*)this, status);
}
}
}
return _ids;
}
return NULL;
}
};
class ICUNumberFormatService : public ICULocaleService {

View File

@ -27,7 +27,6 @@
#include "unicode/unistr.h"
#include "unicode/format.h"
#include "unicode/unum.h" // UNumberFormatStyle
#include "hash.h"
#include "unicode/locid.h"
U_NAMESPACE_BEGIN
@ -678,10 +677,10 @@ public:
virtual UBool visible(void) const = 0;
/**
* Return an unmodifiable collection of the locale names directly
* supported by this factory.
* Return the locale names directly supported by this factory. The number of names
* is returned in count;
*/
virtual const Hashtable* getSupportedIDs(UErrorCode& status) const = 0;
virtual const UnicodeString * const getSupportedIDs(int32_t &count, UErrorCode& status) const = 0;
/**
* Return a number format of the appropriate type. If the locale
@ -699,27 +698,28 @@ public:
class U_I18N_API SimpleNumberFormatFactory : public NumberFormatFactory {
protected:
const UBool _visible;
Hashtable _ids;
UnicodeString _id;
public:
SimpleNumberFormatFactory(const Locale& locale, UBool visible = TRUE)
: _visible(visible)
{
UErrorCode status = U_ZERO_ERROR;
_ids.put(locale.getName(), this, status); // um, ignore error code...
: _visible(visible)
, _id(locale.getName())
{
}
virtual UBool visible(void) const {
return _visible;
}
virtual const Hashtable* getSupportedIDs(UErrorCode& status) const
{
if (U_SUCCESS(status)) {
return &_ids;
}
return NULL;
}
virtual const UnicodeString * const getSupportedIDs(int32_t &count, UErrorCode& status) const
{
if (U_SUCCESS(status)) {
count = 1;
return &_id;
}
count = 0;
return NULL;
}
};