]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/fldset.h
2 ************************************************************************
3 * Copyright (c) 2007, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ************************************************************************
10 #include "unicode/utypes.h"
12 #if !UCONFIG_NO_FORMATTING
13 #include "unicode/calendar.h"
14 #include "unicode/ucal.h"
15 #include "unicode/udat.h"
16 #include "unicode/udbgutil.h"
17 #include "unicode/dbgutil.h"
18 #include "unicode/unistr.h"
20 #define U_FIELDS_SET_MAX 64
26 * @param whichEnum which enumaration value goes with this set. Will be used to calculate str values and also enum size.
28 FieldsSet(UDebugEnumType whichEnum
);
31 * subclass interface - no enum tie-in
32 * @param fieldCount how many fields this can hold.
34 FieldsSet(int32_t fieldsCount
);
38 * @param other "expected" set to match against
39 * @param status - will return invalid argument if sets are not the same size
40 * @return a formatted string listing which fields are set in
41 * this, with the comparison made agaainst those fields in other.
43 UnicodeString
diffFrom(const FieldsSet
& other
, UErrorCode
&status
) const;
47 * @param str string to parse
48 * @param status formatted string for status
50 int32_t parseFrom(const UnicodeString
& str
, UErrorCode
& status
) { return parseFrom(str
,NULL
,status
); }
53 int32_t parseFrom(const UnicodeString
& str
, const FieldsSet
& inheritFrom
, UErrorCode
& status
) { return parseFrom(str
, &inheritFrom
, status
); }
55 int32_t parseFrom(const UnicodeString
& str
, const
56 FieldsSet
* inheritFrom
, UErrorCode
& status
);
60 * Callback interface for subclass.
61 * This function is called when parsing a field name, such as "MONTH" in "MONTH=4".
62 * Base implementation is to lookup the enum value using udbg_* utilities, or else as an integer if
63 * enum is not available.
65 * If there is a special directive, the implementer can catch it here and return -1 after special processing completes.
67 * @param inheritFrom the set inheriting from - may be null.
68 * @param name the field name (key side)
69 * @param substr the string in question (value side)
70 * @param status error status - set to error for failure.
71 * @return field number, or negative if field should be skipped.
73 virtual int32_t handleParseName(const FieldsSet
* inheritFrom
, const UnicodeString
& name
, const UnicodeString
& substr
, UErrorCode
& status
);
76 * Callback interface for subclass.
77 * Base implementation is to call parseValueDefault(...)
78 * @param inheritFrom the set inheriting from - may be null.
79 * @param field which field is being parsed
80 * @param substr the string in question (value side)
81 * @param status error status - set to error for failure.
82 * @see parseValueDefault
84 virtual void handleParseValue(const FieldsSet
* inheritFrom
, int32_t field
, const UnicodeString
& substr
, UErrorCode
& status
);
87 * the default implementation for handleParseValue.
88 * Base implementation is to parse a decimal integer value, or inherit from inheritFrom if the string is 0-length.
89 * Implementations of this function should call set(field,...) on successful parse.
90 * @see handleParseValue
92 void parseValueDefault(const FieldsSet
* inheritFrom
, int32_t field
, const UnicodeString
& substr
, UErrorCode
& status
);
96 * convenience implementation for handleParseValue
97 * attempt to load a value from an enum value using udbg_enumByString()
98 * if fails, will call parseValueDefault()
99 * @see handleParseValue
101 void parseValueEnum(UDebugEnumType type
, const FieldsSet
* inheritFrom
, int32_t field
, const UnicodeString
& substr
, UErrorCode
& status
);
106 void construct(UDebugEnumType whichEnum
, int32_t fieldCount
);
109 virtual ~FieldsSet();
112 void clear(int32_t field
);
113 void set(int32_t field
, int32_t amount
);
114 UBool
isSet(int32_t field
) const;
115 int32_t get(int32_t field
) const;
117 UBool
isSameType(const FieldsSet
& other
) const;
118 int32_t fieldCount() const;
122 int32_t fValue
[U_FIELDS_SET_MAX
];
123 UBool fIsSet
[U_FIELDS_SET_MAX
];
126 UDebugEnumType fEnum
;
129 /** ------- Calendar Fields Set -------- **/
130 class CalendarFieldsSet
: public FieldsSet
{
133 virtual ~CalendarFieldsSet();
135 // void clear(UCalendarDateFields field) { clear((int32_t)field); }
136 // void set(UCalendarDateFields field, int32_t amount) { set ((int32_t)field, amount); }
138 // UBool isSet(UCalendarDateFields field) const { return isSet((int32_t)field); }
139 // int32_t get(UCalendarDateFields field) const { return get((int32_t)field); }
142 * @param matches fillin to hold any fields different. Will have the calendar's value set on them.
143 * @return true if the calendar matches in these fields.
145 UBool
matches(Calendar
*cal
, CalendarFieldsSet
&diffSet
,
146 UErrorCode
& status
) const;
149 * set the specified fields on this calendar. Doesn't clear first. Returns any errors the cale
151 void setOnCalendar(Calendar
*cal
, UErrorCode
& status
) const;
155 void handleParseValue(const FieldsSet
* inheritFrom
, int32_t field
, const UnicodeString
& substr
, UErrorCode
& status
);
159 * This class simply implements a set of date and time styles
160 * such as DATE=SHORT or TIME=SHORT,DATE=LONG
162 class DateTimeStyleSet
: public FieldsSet
{
165 virtual ~DateTimeStyleSet();
169 * @return the date style, or UDAT_NONE if not set
171 UDateFormatStyle
getDateStyle() const;
174 * @return the time style, or UDAT_NONE if not set
176 UDateFormatStyle
getTimeStyle() const;
180 void handleParseValue(const FieldsSet
* inheritFrom
, int32_t field
, const UnicodeString
& substr
, UErrorCode
& status
);
181 int32_t handleParseName(const FieldsSet
* inheritFrom
, const UnicodeString
& name
, const UnicodeString
& substr
, UErrorCode
& status
);
185 #endif /*!UCONFIG_NO_FORMAT*/