예제 #1
0
bool Settings::useEggs()
{
    if(!enableEggs || !isTime())
         return false;

    return true;
}
QTime Soprano::LiteralValue::toTime() const
{
    if ( isTime() ) {
        // QVariant::toTime does use the simple ISO format
        return d->value.toTime();
    }
    else {
        return DateTime::fromTimeString( toString() );
    }
}
double CSSPrimitiveValue::computeSeconds()
{
    ASSERT(isTime() || (isCalculated() && cssCalcValue()->category() == CalcTime));
    UnitType currentType = isCalculated() ? cssCalcValue()->expressionNode()->typeWithCalcResolved() : type();
    if (currentType == UnitType::Seconds)
        return getDoubleValue();
    if (currentType == UnitType::Milliseconds)
        return getDoubleValue() / 1000;
    ASSERT_NOT_REACHED();
    return 0;
}
예제 #4
0
Time::Time(int hr, int min, int sec) {
	if (!isTime(hr, min, sec))
	{
		cout<<"WARNING TIME IS NOT VALID"<<endl;
	}

	hour = hr;
	minute = min;
	second = sec;

}
예제 #5
0
void FileActionPerformer::writeData(const QList<int> &data)
{
	if (!mIsStartSave) {
		return;
	}

	if (!mIsTime) {
		return;
	}

	mIsTime = false;
	QTimer::singleShot(mFreq, this, SLOT(isTime()));

	mSaver->writeData(data);
}
예제 #6
0
int Interval::go()
{
  int returnme;
  unsigned long now;

  returnme = 0;
  now = millis();

  if( isTime( now ) )
  {
    update();
    returnme = 1;
  }

  return returnme;

}
예제 #7
0
파일: CInterval.cpp 프로젝트: colinw7/CUtil
double
CInterval::
interval(int i) const
{
  if       (isDate()) {
    if      (timeType_ == TimeType::YEARS) {
      return yearsToTime(startTime_.year + i*calcIncrement());
    }
    else if (timeType_ == TimeType::MONTHS) {
      return monthsToTime(startTime_, startTime_.month + i*calcIncrement());
    }
    else if (timeType_ == TimeType::DAYS) {
      return daysToTime(startTime_, startTime_.day + i*calcIncrement());
    }
    else {
      return 0;
    }
  }
  else if (isTime()) {
    if      (timeType_ == TimeType::HOURS) {
      return hoursToTime(startTime_, startTime_.hour + i*calcIncrement());
    }
    else if (timeType_ == TimeType::MINUTES) {
      return minutesToTime(startTime_, startTime_.minute + i*calcIncrement());
    }
    else if (timeType_ == TimeType::SECONDS) {
      return secondsToTime(startTime_, startTime_.second + i*calcIncrement());
    }
    else {
      return 0;
    }
  }
  else {
    return valueStart() + i*calcIncrement();
  }
}
// here we use DataTime instead of QT's built-in time conversion
// since the latter does not properly handle fractions of seconds
// in the ISO8601 specification.
QString Soprano::LiteralValue::toString() const
{
    if ( d ) {
        if ( !d->stringCacheValid ) {
            if( isInt() )
                d->stringCache = QString::number( toInt() );
            else if( isInt64() )
                d->stringCache = QString::number( toInt64() );
            else if( isUnsignedInt() )
                d->stringCache = QString::number( toUnsignedInt() );
            else if( isUnsignedInt64() )
                d->stringCache = QString::number( toUnsignedInt64() );
            else if( isBool() )
                d->stringCache = ( toBool() ? QString("true") : QString("false" ) );
            else if( isDouble() ) // FIXME: decide on a proper double encoding or check if there is one in xml schema
                d->stringCache = QString::number( toDouble(), 'e', 10 );
            else if( isDate() )
                d->stringCache = DateTime::toString( toDate() );
            else if( isTime() )
                d->stringCache = DateTime::toString( toTime() );
            else if( isDateTime() )
                d->stringCache = DateTime::toString( toDateTime() );
            else if ( isByteArray() )
                d->stringCache = QString::fromAscii( toByteArray().toBase64() );
            else
                d->stringCache = d->value.toString();

            d->stringCacheValid = true;
        }

        return d->stringCache;
    }
    else {
        return QString();
    }
}
예제 #9
0
파일: CInterval.cpp 프로젝트: colinw7/CUtil
void
CInterval::
init()
{
  bool integral = isIntegral();

  timeType_ = TimeType::SECONDS;

  startTime_.year   = 0;
  startTime_.month  = 0;
  startTime_.day    = 0;
  startTime_.hour   = 0;
  startTime_.minute = 0;
  startTime_.second = 0;

  // Ensure min/max are in the correct order
  double min = std::min(data_.start, data_.end);
  double max = std::max(data_.start, data_.end);

  if      (isIntegral()) {
    min = std::floor(min);
    max = std::ceil (max);
  }
  else if (isDate()) {
    int y = timeLengthToYears  (min, max);
    int m = timeLengthToMonths (min, max);
    int d = timeLengthToDays   (min, max);

    startTime_.year  = timeToYear   (min);
    startTime_.month = timeToMonths (min);
    startTime_.day   = timeToDays   (min);

    min = 0;

    if      (y >= 5) {
      //std::cout << "years\n";
      timeType_ = TimeType::YEARS;
      max       = y;
    }
    else if (m >= 3) {
      //std::cout << "months\n";
      timeType_ = TimeType::MONTHS;
      max       = m;
    }
    else if (d >= 4) {
      //std::cout << "days\n";
      timeType_ = TimeType::DAYS;
      max       = d;
    }

    integral = true;
  }
  else if (isTime()) {
    int h = timeLengthToHours  (min, max);
    int m = timeLengthToMinutes(min, max);
    int s = timeLengthToSeconds(min, max);

    startTime_.hour   = timeToHours  (min);
    startTime_.minute = timeToMinutes(min);
    startTime_.second = timeToSeconds(min);

    min = 0;

    if      (h >= 12) {
      //std::cout << "hours\n";
      timeType_ = TimeType::HOURS;
      max       = h;
    }
    else if (m >= 10) {
      //std::cout << "minutes\n";
      timeType_ = TimeType::MINUTES;
      max       = m;
    }
    else {
      //std::cout << "seconds\n";
      timeType_ = TimeType::SECONDS;
      max       = s;
    }

    integral = true;
  }

  //---

  // use fixed increment
  double majorIncrement = this->majorIncrement();

  if (majorIncrement > 0.0 && (! isDate() && ! isTime())) {
    calcData_.start     = min;
    calcData_.end       = max;
    calcData_.increment = majorIncrement;

    calcData_.numMajor =
      CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment);
    calcData_.numMinor = 5;

    return;
  }

  //---

  if (data_.numMajor > 0) {
    goodTicks_.opt = data_.numMajor;
    goodTicks_.min = std::max(goodTicks_.opt/10, 1);
    goodTicks_.max = goodTicks_.opt*10;
  }
  else {
    goodTicks_ = GoodTicks();
  }

  //---

  calcData_.numMajor = -1;
  calcData_.numMinor = 5;

  //---

  calcData_.increment = data_.increment;

  if (calcData_.increment <= 0.0) {
    calcData_.increment = initIncrement(min, max, integral);

    //---

    // Calculate other test increments
    for (int i = 0; i < numIncrementTests; i++) {
      // disable non-integral increments for integral
      if (integral && ! isInteger(incrementTests[i].factor)) {
        incrementTests[i].incFactor = 0.0;
        continue;
      }

      // disable non-log increments for log
      if (isLog() && ! incrementTests[i].isLog) {
        incrementTests[i].incFactor = 0.0;
        continue;
      }

      incrementTests[i].incFactor = calcData_.increment*incrementTests[i].factor;
    }

    //---

    // Test each increment in turn (Set default start/end to force update)
    int tickIncrement = this->tickIncrement();

    GapData axisGapData;

    for (int i = 0; i < numIncrementTests; i++) {
      // skip disable tests
      if (incrementTests[i].incFactor <= 0.0)
        continue;

      // if tick increment set then skip if not multiple of increment
      if (tickIncrement > 0) {
        if (! isInteger(incrementTests[i].incFactor))
          continue;

        int incFactor1 = int(incrementTests[i].incFactor);

        if (incFactor1 % tickIncrement != 0)
          continue;
      }

      // test factor, ticks and update best
      if (testAxisGaps(min, max,
                       incrementTests[i].incFactor,
                       incrementTests[i].numTicks,
                       axisGapData)) {
        //axisGapData.print("  Best) ");
      }
    }

    //---

    calcData_.start     = axisGapData.start;
    calcData_.end       = axisGapData.end;
    calcData_.increment = axisGapData.increment;
    calcData_.numMinor  = (! isLog() ? axisGapData.numMinor : 10);
  }
  else {
    calcData_.start    = min;
    calcData_.end      = max;
    calcData_.numMinor = 5;
  }

  calcData_.numMajor =
    CMathRound::RoundNearest((calcData_.end - calcData_.start)/calcData_.increment);

  if      (isDate()) {
    if      (timeType_ == TimeType::YEARS) {
      calcData_.numMinor = 12;
    }
    else if (timeType_ == TimeType::MONTHS) {
      calcData_.numMinor = 4;
    }
    else if (timeType_ == TimeType::DAYS) {
      calcData_.numMinor = 4;
    }
  }
  else if (isTime()) {
    if      (timeType_ == TimeType::HOURS) {
      calcData_.numMinor = 6;
    }
    else if (timeType_ == TimeType::MINUTES) {
      calcData_.numMinor = 12;
    }
    else if (timeType_ == TimeType::SECONDS) {
      calcData_.numMinor = 12;
    }
  }
}
예제 #10
0
파일: GamePlay.cpp 프로젝트: acid30m/OOP
void GamePlay::play()
{
	srand(time(0));
	char tmp2;
	cout << "New game - enter \'n\'" << endl;
	cout << "Resume game - enter \'r\'" << endl;
	cin >> tmp2;
	int score, lives;
	if(tmp2 == 'n')
		map.ReadFromFile("map.txt",score,lives);
	if(tmp2 == 'r')
	{
		map.ReadFromFile("saved.txt",score,lives);
		patagonist.setScore(score);
		patagonist.setLives(lives);
	}
	map.Show(hConsole);
	COORD tmp;
	char chr;
	do{
		do{
			if(isEnd())
			{
				char choice;
				cout << "Want to play again? (y/n)" << endl;
				cin >> choice;
				if(choice == 'n')
				{
					cout << "Bye!" << endl;
					exit(EXIT_SUCCESS);
				}
				else if(choice == 'y')
				{
					Sleep(800);
					reset();
				}
			}
			Blinky.move(map,patagonist.getPos());
			Pinky.move(map,patagonist.getPos());
			Inky.move(map,patagonist.getPos());
			Clyde.move(map,patagonist.getPos());
			if(patagonist.move(map))
			{
				patagonist.Show(hConsole);
			}
			isTime();
			isGhost();
			isEnergy(map, patagonist.getPos());
			Blinky.Show(map);
			Pinky.Show(map);
			Inky.Show(map);
			Clyde.Show(map);
			patagonist.Show(hConsole);
			tmp.X = 1;
			tmp.Y = 22;
			SetConsoleCursorPosition(hConsole,tmp);
			cout << "Score : " << patagonist.getScore() << endl;
			tmp.Y++;
			SetConsoleCursorPosition(hConsole,tmp);
			cout << "Lives : " <<  patagonist.getLives() << endl;
		} while ( !kbhit() );
		chr = getch();
		if( chr == -32 )
			chr = getch();

		switch(chr)
		{
		case SCROLL_UP:
			patagonist.setDir('u');			
			break;
		case SCROLL_DOWN:
			patagonist.setDir('d');
			break;
		case SCROLL_RIGHT:
			patagonist.setDir('r');
			break;
		case SCROLL_LEFT:
			patagonist.setDir('l');
			break;
		case 'p':
			{
				system("cls");
				cout << "Paused" << endl;
				cout << "Resume - press \'r\'" << endl;
				cout << "Save state and exit - press \'s\'" << endl;
				cin >> tmp2;
				if(tmp2 == 's')
				{
					map.WriteToFile("saved.txt",patagonist.getScore(),patagonist.getLives());
					exit(0);
				}
				map.Show(hConsole);
			}
			break;
		}




	}while ( chr != 27 );
	map.Show(hConsole);
}