From 858972dfa61b60499445131ec5e37ccdceb3abb5 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 15 Nov 2012 21:55:41 +0000 Subject: [PATCH] ICU-9748 MSVC2010 issues, move EnumSet<> to separate header X-SVN-Rev: 32838 --- .gitattributes | 1 + icu4c/source/common/common.vcxproj | 5 +- icu4c/source/common/common.vcxproj.filters | 5 +- icu4c/source/common/unicode/enumset.h | 55 ++++++++++++++++++++++ icu4c/source/common/wintz.c | 2 +- icu4c/source/data/makedata.mak | 4 +- icu4c/source/i18n/digitlst.cpp | 7 --- icu4c/source/i18n/digitlst.h | 9 +++- icu4c/source/i18n/unicode/decimfmt.h | 40 +++------------- 9 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 icu4c/source/common/unicode/enumset.h diff --git a/.gitattributes b/.gitattributes index 96d18042c3..51f2508d06 100644 --- a/.gitattributes +++ b/.gitattributes @@ -52,6 +52,7 @@ icu4c/icu4c.css -text icu4c/source/allinone/icucheck.bat -text icu4c/source/common/common.vcxproj -text icu4c/source/common/common.vcxproj.filters -text +icu4c/source/common/unicode/enumset.h -text icu4c/source/data/curr/pool.res -text icu4c/source/data/in/coll/invuca.icu -text icu4c/source/data/in/coll/ucadata.icu -text diff --git a/icu4c/source/common/common.vcxproj b/icu4c/source/common/common.vcxproj index 8487169354..6c8567e884 100644 --- a/icu4c/source/common/common.vcxproj +++ b/icu4c/source/common/common.vcxproj @@ -1,4 +1,4 @@ - + @@ -580,6 +580,7 @@ + @@ -1707,4 +1708,4 @@ - + \ No newline at end of file diff --git a/icu4c/source/common/common.vcxproj.filters b/icu4c/source/common/common.vcxproj.filters index 01b23c4e3b..492b053300 100644 --- a/icu4c/source/common/common.vcxproj.filters +++ b/icu4c/source/common/common.vcxproj.filters @@ -808,6 +808,9 @@ properties & sets + + data & memory + @@ -1045,4 +1048,4 @@ - + \ No newline at end of file diff --git a/icu4c/source/common/unicode/enumset.h b/icu4c/source/common/unicode/enumset.h new file mode 100644 index 0000000000..8961145451 --- /dev/null +++ b/icu4c/source/common/unicode/enumset.h @@ -0,0 +1,55 @@ +/* +****************************************************************************** +* +* Copyright (C) 2012, International Business Machines +* Corporation and others. All Rights Reserved. +* +****************************************************************************** +*/ + +/** + * \file + * \brief C++: internal template EnumSet<> + */ + +#ifndef ENUMSET_H +#define ENUMSET_H + +#include "unicode/utypes.h" + + +/** + * enum bitset for boolean fields. Similar to Java EnumSet<>. + * Needs to range check. + * @internal + */ +template +class EnumSet { +public: + inline EnumSet() : fBools(0) {} + inline EnumSet(const EnumSet& other) : fBools(other.fBools) {} + inline ~EnumSet() {} + inline void clear() { fBools=0; } + inline void add(T toAdd) { set(toAdd, 1); } + inline void remove(T toRemove) { set(toRemove, 0); } + inline int32_t contains(T toCheck) const { return get(toCheck); } + inline void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); } + inline int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } + inline UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck& operator=(const EnumSet& other) { + fBools = other.fBools; + return *this; + } + + inline uint32_t getAll() const { + return fBools; + } + +private: + inline uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } +private: + uint32_t fBools; +}; + +#endif diff --git a/icu4c/source/common/wintz.c b/icu4c/source/common/wintz.c index a1da126a0d..addf76ba88 100644 --- a/icu4c/source/common/wintz.c +++ b/icu4c/source/common/wintz.c @@ -339,7 +339,7 @@ uprv_detectWindowsTimeZone() { /* if icuTZ has more than one city, take only the first (i.e. terminate icuTZ at first space) */ int index=0; while (! (*icuTZ == '\0' || *icuTZ ==' ')) { - tmpid[index++]=*icuTZ++; + tmpid[index++]=(char)(*icuTZ++); /* safe to assume 'char' is ASCII compatible on windows */ } tmpid[index]='\0'; } diff --git a/icu4c/source/data/makedata.mak b/icu4c/source/data/makedata.mak index f9df0324c9..097dbbec05 100644 --- a/icu4c/source/data/makedata.mak +++ b/icu4c/source/data/makedata.mak @@ -750,13 +750,13 @@ $(ICUBRK)\khmerdict.dict: !IFNDEF ICUDATA_SOURCE_ARCHIVE # Rule for creating converters $(CNV_FILES): $(UCM_SOURCE) - @echo Making Charset Conversion tables + @echo Building Charset Conversion table $(@B) @"$(ICUTOOLS)\makeconv\$(CFG)\makeconv" -c -d"$(ICUBLD_PKG)" $(ICUSRCDATA_RELATIVE_PATH)\$(ICUUCM)\$(@B).ucm !ENDIF !IFDEF BUILD_SPECIAL_CNV_FILES $(CNV_FILES_SPECIAL): $(UCM_SOURCE_SPECIAL) - @echo Making Special Charset Conversion tables + @echo Building Special Charset Conversion table $(@B) @"$(ICUTOOLS)\makeconv\$(CFG)\makeconv" -c --ignore-siso-check -d"$(ICUBLD_PKG)" $(ICUSRCDATA_RELATIVE_PATH)\$(ICUUCM)\$(@B).ucm !ENDIF diff --git a/icu4c/source/i18n/digitlst.cpp b/icu4c/source/i18n/digitlst.cpp index 592b228259..50aa7a85eb 100644 --- a/icu4c/source/i18n/digitlst.cpp +++ b/icu4c/source/i18n/digitlst.cpp @@ -946,13 +946,6 @@ DigitList::isZero() const return decNumberIsZero(fDecNumber); } - - -void * U_EXPORT2 DigitList::operator new(size_t /*size*/, void *stack, EStackMode /*mode*/) U_NO_THROW { - return stack; -} - - U_NAMESPACE_END #endif // #if !UCONFIG_NO_FORMATTING diff --git a/icu4c/source/i18n/digitlst.h b/icu4c/source/i18n/digitlst.h index aa29a14593..077df24fe3 100644 --- a/icu4c/source/i18n/digitlst.h +++ b/icu4c/source/i18n/digitlst.h @@ -414,12 +414,19 @@ private: public: using UMemory::operator new; + using UMemory::operator delete; /** * Placement new for stack usage * @internal */ - static void * U_EXPORT2 operator new(size_t size, void *onStack, EStackMode mode) U_NO_THROW; + static inline void * U_EXPORT2 operator new(size_t size, void *onStack, EStackMode mode) U_NO_THROW { return onStack; } + + /** + * Placement delete for stack usage + * @internal + */ + static inline void U_EXPORT2 operator delete(void *ptr, void *onStack, EStackMode mode) U_NO_THROW {} private: inline void internalSetDouble(double d) { diff --git a/icu4c/source/i18n/unicode/decimfmt.h b/icu4c/source/i18n/unicode/decimfmt.h index 0c55bfedd4..5f66720104 100644 --- a/icu4c/source/i18n/unicode/decimfmt.h +++ b/icu4c/source/i18n/unicode/decimfmt.h @@ -38,6 +38,7 @@ #include "unicode/fpositer.h" #include "unicode/stringpiece.h" #include "unicode/curramt.h" +#include "unicode/enumset.h" /** * \def UNUM_DECIMALFORMAT_INTERNAL_SIZE @@ -56,39 +57,12 @@ class Hashtable; class UnicodeSet; class FieldPositionHandler; -/** - * enum bitset for boolean fields. Similar to Java EnumSet<>. - * Needs to range check. Not specific to decimal format. - * @internal - */ -template -class EnumSet { -public: - EnumSet() : fBools(0) {} - EnumSet(const EnumSet& other) : fBools(other.fBools) {} - ~EnumSet() {} - void clear() { fBools=0; } - void add(T toAdd) { set(toAdd, 1); } - void remove(T toRemove) { set(toRemove, 0); } - int32_t contains(T toCheck) const { return get(toCheck); } - void set(T toSet, int32_t v) { fBools=(fBools&(~flag(toSet)))|(v?(flag(toSet)):0); } - int32_t get(T toCheck) const { return (fBools & flag(toCheck))?1:0; } - UBool isValidEnum(T toCheck) const { return (toCheck>=minValue&&toCheck& operator=(const EnumSet& other) { - fBools = other.fBools; - return *this; - } - - uint32_t getAll() const { - return fBools; - } - -private: - uint32_t flag(T toCheck) const { return (1<<(toCheck-minValue)); } -private: - uint32_t fBools; -}; +// explicit template instantiation. see digitlst.h +#if !U_PLATFORM_IS_DARWIN_BASED +template class U_I18N_API EnumSet; +#endif /** * DecimalFormat is a concrete subclass of NumberFormat that formats decimal