예제 #1
0
/** Set all weekdays in the month on which this rule is repeated.

@leave KErrNotSupported If it is called on a repeat rule which is not monthly or yearly.

@param aDays Array containing all days in the month that are to be set. Any days in the month
not included in this array will not be set. For a yearly rule, only the first item in the array 
will be used. Any invalid data will be ignored. 
@publishedAll
@released
@capability None
*/
EXPORT_C void TCalRRule::SetByDay(const RArray<TDayOfMonth>& aDays)
	{
	__ASSERT_ALWAYS(iType == EMonthly || iType == EYearly, User::Leave(KErrNotSupported));
		
	if (iType == EMonthly)
		{
		iBuffer = 0;
		TInt daysCount = aDays.Count();
		for (TInt i = 0; i < daysCount; ++i)
			{
			TDayOfMonth dayOfMonth = aDays[i];
			TDay weekDay = dayOfMonth.Day();
			if (weekDay >= EMonday && weekDay <= ESunday)
				{
				TInt byteToSet = dayOfMonth.WeekInMonth();
				// if this day and week are valid then set this bit
				if (byteToSet == -1 || (byteToSet >= 1 && byteToSet <= 4))
					{
					if (byteToSet == -1)
						{
						byteToSet = 0;
						}
					
					// first 7 bits represent which weekdays are set on the last week of the month - (week = -1)
					// next 7 bits represent which weekdays are set on the 1st week of the month - (week = 1)
					// next 7 bits represent which weekdays are set on the 2nd week of the month - (week = 2)
					// next 7 bits represent which weekdays are set on the 3rd week of the month - (week = 3)
					// next 7 bits represent which weekdays are set on the 4th week of the month - (week = 4)
					TUint bitToSet = weekDay + 7 * byteToSet;
					SetNthBit(bitToSet);
					}
				}
			}
		SetNthBit(KMonthlyByWeek);
		}
	else if (iType == EYearly)
		{
		if (!GetNthBit(KYearlyByWeek))
			{
			iBuffer = 0;
			SetNthBit(KYearlyByWeek);
			}
			
		if (aDays.Count() >= 1)
			{
			TDay theDay = aDays[0].Day();
			TInt8 theWeek = aDays[0].WeekInMonth();
			
			if (theDay >= EMonday && theDay <= ESunday && 
				(theWeek == -1 || (theWeek >= 1 && theWeek <= 4)) )
				{
				TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s
				// EMonday=0 so store it as 1, this allows us to tell if any days have been set
				bufferPtr[0] = (TUint8)theDay+1;
				bufferPtr[1] = (TUint8)theWeek;
				}
			}
		}
	}
예제 #2
0
/* Member function obitstream::writeBit
 * ----------------------------------
 * If bits remain to be written in curByte, add bit into byte and increment pos
 * Else if end of curByte (or some other write happened), then start a fresh
 * byte at position 0.
 * We write the byte out for each bit (backing up to overwrite as needed), rather
 * than waiting for 8 bits.	 This is because the client might make
 * 3 writeBit calls and then start using << so we can't wait til full-byte
 * boundary to flush any partial-byte bits.
 */
void obitstream::writeBit(int bit) {
    if (bit != 0 && bit != 1) {
        error(string("writeBit must be passed an integer argument of 0 or 1.  You passed the integer ")
              + toPrintable(bit) + " (" + integerToString(bit) + ").");
    }
    if (!is_open()) {
        error("Cannot writeBit to stream which is not open.");
    }

    // if just filled curByte or if data written to stream after last writeBit()
    if (lastTell != tellp() || pos == NUM_BITS_IN_BYTE) {
        curByte = 0;   // zero out byte for next writes
        pos = 0;	   // start writing to first bit of new byte
    }

    if (bit) {
        // only need to change if bit needs to be 1 (byte starts already zeroed)
        SetNthBit(pos, curByte);
    }

    if (pos == 0 || bit) {   // only write if first bit in byte or changing 0 to 1
        if (pos != 0) {
            seekp(-1, ios::cur);   // back up to overwite if pos > 0
        }
        put(curByte);
    }

    pos++; // advance to next bit position for next write
    lastTell = tellp();
}
예제 #3
0
/** Sets all dates of the month on which this rule is repeated.

@leave KErrNotSupported If it is not a monthly repeat rule.

@param aMonthDays Array containing all month dates that are to be set. Any month dates
not included in this array will not be set. Any out of range dates will be ignored. 
@publishedAll
@released
@capability None
*/
EXPORT_C void TCalRRule::SetByMonthDay(const RArray<TInt>& aMonthDays)
	{
	__ASSERT_ALWAYS(iType == EMonthly, User::Leave(KErrNotSupported));
	
	iBuffer = 0;
	TInt daysCount = aMonthDays.Count();
	for (TInt i = 0; i < daysCount; ++i)
		{
		TInt bit = aMonthDays[i];
		
		// check this date is valid
		if (bit >= 0 && bit <= 30)
			{
			SetNthBit(bit);
			}
		}
	}
예제 #4
0
/** Set all weekdays on which this rule is repeated.

@leave KErrNotSupported if not called on a weekly repeat rule.
@param aDays Array containing all weekdays that are to be set. Any weekdays not included 
in this array will not be set. Any weekdays not in the TDay enum will be ignored. 
@publishedAll
@released
@capability None
*/
EXPORT_C void TCalRRule::SetByDay(const RArray<TDay>& aDays)
	{
	__ASSERT_ALWAYS(iType == EWeekly, User::Leave(KErrNotSupported));
	
	iBuffer = 0;
	
	TInt daysCount = aDays.Count();
	for (TInt i = 0; i < daysCount; ++i)
		{
		TDay day(aDays[i]);
		if (day >= EMonday && day <= ESunday)
			{
			// if this day is valid then set this bit
			SetNthBit(static_cast<TUint>(day));
			}
		}
	}
예제 #5
0
/** Sets the month of the year for this repeat rule.

@leave KErrNotSupported If it is not on a yearly repeat rule 
@param aMonths Array of months on which to repeat. Only the first month in the array is used.
@publishedAll
@released
@capability None
*/
EXPORT_C void TCalRRule::SetByMonth(const RArray<TMonth> aMonths)
	{
	__ASSERT_ALWAYS(iType == EYearly, User::Leave(KErrNotSupported));
	
	if (aMonths.Count() >= 1)
		{
		TMonth month = aMonths[0];
		if (month >= EJanuary && month <= EDecember)
			{
			if (!GetNthBit(KYearlyByWeek))
				{
				iBuffer = 0;
				SetNthBit(KYearlyByWeek);
				}
			
			TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s
			// EJanuary=0 so store it as 1, this allows us to tell if any months have been set
			bufferPtr[2] = (TUint8)month+1;
			}
		}
	}