Logo Search packages:      
Sourcecode: icu version File versions

UCalendarDateFields Calendar::resolveFields ( const UFieldResolutionTable precedenceTable  )  [protected, inherited]

Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if none is found.

The precedence table is a 3-dimensional array of integers. It may be thought of as an array of groups. Each group is an array of lines. Each line is an array of field numbers. Within a line, if all fields are set, then the time stamp of the line is taken to be the stamp of the most recently set field. If any field of a line is unset, then the line fails to match. Within a group, the line with the newest time stamp is selected. The first field of the line is returned to indicate which line matched.

In some cases, it may be desirable to map a line to field that whose stamp is NOT examined. For example, if the best field is DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In order to do this, insert the value kResolveRemap | F at the start of the line, where F is the desired return field value. This field will NOT be examined; it only determines the return value if the other fields in the line are the newest.

If all lines of a group contain at least one unset field, then no line will match, and the group as a whole will fail to match. In that case, the next group will be processed. If all groups fail to match, then UCAL_FIELD_COUNT is returned.

For internal use only.

Definition at line 2329 of file calendar.cpp.

References Calendar::fStamp, and Calendar::kResolveRemap.

Referenced by Calendar::computeJulianDay(), Calendar::getLocalDOW(), Calendar::handleComputeJulianDay(), GregorianCalendar::handleGetExtendedYear(), and Calendar::handleGetExtendedYearFromWeekFields().

                                                                                        {
    int32_t bestField = UCAL_FIELD_COUNT;
    for (int32_t g=0; precedenceTable[g][0][0] != -1 && (bestField == UCAL_FIELD_COUNT); ++g) {
        int32_t bestStamp = kUnset;
        for (int32_t l=0; precedenceTable[g][l][0] != -1; ++l) {
            int32_t lineStamp = kUnset;
            // Skip over first entry if it is negative
            for (int32_t i=((precedenceTable[g][l][0]>=kResolveRemap)?1:0); precedenceTable[g][l][i]!=-1; ++i) {
                int32_t s = fStamp[precedenceTable[g][l][i]];
                // If any field is unset then don't use this line
                if (s == kUnset) {
                    goto linesInGroup;
                } else if(s > lineStamp) {
                    lineStamp = s;
                }
            }
            // Record new maximum stamp & field no.
            if (lineStamp > bestStamp) {
                bestStamp = lineStamp;
                bestField = precedenceTable[g][l][0]; // First field refers to entire line
            }
linesInGroup:
            ;
        }
    }
    return (UCalendarDateFields)( (bestField>=kResolveRemap)?(bestField&(kResolveRemap-1)):bestField  );
}


Generated by  Doxygen 1.6.0   Back to index