]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/fldset.h
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / test / intltest / fldset.h
CommitLineData
46f4442e
A
1/*
2************************************************************************
3* Copyright (c) 2007, International Business Machines
4* Corporation and others. All Rights Reserved.
5************************************************************************
6*/
7#ifndef FLDSET_H_
8#define FLDSET_H_
9
10#include "unicode/utypes.h"
11
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"
19
20#define U_FIELDS_SET_MAX 64
21
22class FieldsSet {
23 protected:
24 /**
25 * subclass interface
26 * @param whichEnum which enumaration value goes with this set. Will be used to calculate str values and also enum size.
27 */
28 FieldsSet(UDebugEnumType whichEnum);
29
30 /**
31 * subclass interface - no enum tie-in
32 * @param fieldCount how many fields this can hold.
33 */
34 FieldsSet(int32_t fieldsCount);
35
36 public:
37 /**
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.
42 */
43 UnicodeString diffFrom(const FieldsSet& other, UErrorCode &status) const;
44
45 public:
46 /**
47 * @param str string to parse
48 * @param status formatted string for status
49 */
50 int32_t parseFrom(const UnicodeString& str, UErrorCode& status) { return parseFrom(str,NULL,status); }
51
52 public:
53 int32_t parseFrom(const UnicodeString& str, const FieldsSet& inheritFrom, UErrorCode& status) { return parseFrom(str, &inheritFrom, status); }
54
55 int32_t parseFrom(const UnicodeString& str, const
56 FieldsSet* inheritFrom, UErrorCode& status);
57
58 protected:
59 /**
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.
64 *
65 * If there is a special directive, the implementer can catch it here and return -1 after special processing completes.
66 *
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.
72 */
73 virtual int32_t handleParseName(const FieldsSet* inheritFrom, const UnicodeString& name, const UnicodeString& substr, UErrorCode& status);
74
75 /**
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
83 */
84 virtual void handleParseValue(const FieldsSet* inheritFrom, int32_t field, const UnicodeString& substr, UErrorCode& status);
85
86 /**
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
91 */
92 void parseValueDefault(const FieldsSet* inheritFrom, int32_t field, const UnicodeString& substr, UErrorCode& status);
93
94
95 /**
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
100 */
101 void parseValueEnum(UDebugEnumType type, const FieldsSet* inheritFrom, int32_t field, const UnicodeString& substr, UErrorCode& status);
102
103 private:
104 FieldsSet();
105
106 void construct(UDebugEnumType whichEnum, int32_t fieldCount);
107
108 public:
109 virtual ~FieldsSet();
110
111 void clear();
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;
116
117 UBool isSameType(const FieldsSet& other) const;
118 int32_t fieldCount() const;
119
120
121 protected:
122 int32_t fValue[U_FIELDS_SET_MAX];
123 UBool fIsSet[U_FIELDS_SET_MAX];
124 protected:
125 int32_t fFieldCount;
126 UDebugEnumType fEnum;
127};
128
129/** ------- Calendar Fields Set -------- **/
130class CalendarFieldsSet : public FieldsSet {
131 public:
132 CalendarFieldsSet();
133 virtual ~CalendarFieldsSet();
134
135// void clear(UCalendarDateFields field) { clear((int32_t)field); }
136// void set(UCalendarDateFields field, int32_t amount) { set ((int32_t)field, amount); }
137
138// UBool isSet(UCalendarDateFields field) const { return isSet((int32_t)field); }
139// int32_t get(UCalendarDateFields field) const { return get((int32_t)field); }
140
141 /**
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.
144 */
145 UBool matches(Calendar *cal, CalendarFieldsSet &diffSet,
146 UErrorCode& status) const;
147
148 /**
149 * set the specified fields on this calendar. Doesn't clear first. Returns any errors the cale
150 */
151 void setOnCalendar(Calendar *cal, UErrorCode& status) const;
152
153
154 protected:
155 void handleParseValue(const FieldsSet* inheritFrom, int32_t field, const UnicodeString& substr, UErrorCode& status);
156};
157
158/**
159 * This class simply implements a set of date and time styles
160 * such as DATE=SHORT or TIME=SHORT,DATE=LONG
161 */
162class DateTimeStyleSet : public FieldsSet {
163 public:
164 DateTimeStyleSet();
165 virtual ~DateTimeStyleSet();
166
167
168 /**
169 * @return the date style, or UDAT_NONE if not set
170 */
171 UDateFormatStyle getDateStyle() const;
172
173 /**
174 * @return the time style, or UDAT_NONE if not set
175 */
176 UDateFormatStyle getTimeStyle() const;
177
178
179 protected:
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);
182};
183
184
185#endif /*!UCONFIG_NO_FORMAT*/
186#endif /*FLDSET_H_*/