Example #1
0
 uint_t GetScore() const
 {
   return Song.size()
        + Game.size()
        + Dumper.size()
        + Comments.size()
        + DumpDate.size() * IsValidDate(DumpDate)
        + 100 * IsValidTime(FadeTime)
        + 100 * IsValidTime(FadeDuration)
   ;
 }
Example #2
0
mitk::Geometry3D* mitk::TimeSlicedGeometry::GetGeometry3D(int t) const
{
  mitk::Geometry3D::Pointer geometry3d = NULL;
  if(IsValidTime(t))
  {
    geometry3d = m_Geometry3Ds[t];
    //if (a) we don't have a Geometry3D stored for the requested time,
    //(b) m_EvenlyTimed is activated and (c) the first geometry (t=0)
    //is set, then we clone the geometry and set the m_TimeBounds accordingly.
    if((m_EvenlyTimed) && (geometry3d.IsNull()))
    {
      const Geometry3D* firstgeometry=m_Geometry3Ds[0].GetPointer();

      assert(firstgeometry != NULL);

      mitk::Geometry3D::Pointer requestedgeometry;
      requestedgeometry = dynamic_cast<Geometry3D*>(firstgeometry->Clone().GetPointer());
      if ( requestedgeometry.IsNull() ) itkExceptionMacro("Geometry is NULL!");

      TimeBounds timebounds = requestedgeometry->GetTimeBounds();
      if(timebounds[1]<ScalarTypeNumericTraits::max())
      {
        mitk::ScalarType later = (timebounds[1]-timebounds[0])*t;
        timebounds[0]+=later; timebounds[1]+=later;
        requestedgeometry->SetTimeBounds(timebounds);
      }

      geometry3d = requestedgeometry;
      m_Geometry3Ds[t] = geometry3d;
    }
  }
  else
    return NULL;
  return geometry3d;
}
Example #3
0
bool mitk::TimeSlicedGeometry::SetGeometry3D(mitk::Geometry3D* geometry3D, int t)
{
  if(IsValidTime(t))
  {
    m_Geometry3Ds[t]=geometry3D;
    return true;
  }
  return false;
}
Example #4
0
//------------------------------------------------------------------------------
//  Date(Integer year, Integer dayOfYear, Integer hour, Integer minute,
//       Real second)
//------------------------------------------------------------------------------
Date::Date(Integer year, Integer dayOfYear, Integer hour, Integer minute,
           Real second)
{
   yearD = year;
   ToMonthDayFromYearDOY(year, dayOfYear, monthD, dayD);

   // check time
   if(!IsValidTime(yearD, monthD, dayD, hour, minute, second))
   {
      throw TimeRangeError();
   }
   secondsOfDayD = ToSecondsOfDayFromHMS(hour, minute, second);
}
Example #5
0
//------------------------------------------------------------------------------
//  Date(Integer year, Integer month, Integer day, Integer hour,
//       Integer minute, Real second)
//------------------------------------------------------------------------------
Date::Date(Integer year, Integer month, Integer day, Integer hour,
           Integer minute, Real second)
{
   // check time
   if(!IsValidTime(year, month, day, hour, minute, second))
   {
      throw TimeRangeError();
   }

   yearD = year;
   monthD = month;
   dayD = day;
   secondsOfDayD = ToSecondsOfDayFromHMS(hour, minute, second);
}
Example #6
0
//------------------------------------------------------------------------------
//  Date(Integer year, Integer month, Integer day, Real secondsOfDay)
//------------------------------------------------------------------------------
Date::Date(Integer year, Integer month, Integer day, Real secondsOfDay)
{
   Real    seconds;
   Integer hour, minute;

   yearD = year;
   monthD = month;
   dayD = day;
   secondsOfDayD = secondsOfDay;

   // check time
   ToHMSFromSecondsOfDay(secondsOfDay, hour, minute, seconds);
   if(!IsValidTime(yearD, monthD, dayD, hour, minute, seconds))
   {
      throw TimeRangeError();
   }
}
Example #7
0
mitk::ScalarType mitk::TimeSlicedGeometry::TimeStepToMS(int timestep) const
{
  if(IsValidTime(timestep)==false)
    return ScalarTypeNumericTraits::max();
  if(m_EvenlyTimed)
  {
    if ( timestep == 0 )
      return m_TimeBounds[0];
    else
    {
      assert( ! (m_TimeBounds[0] == ScalarTypeNumericTraits::NonpositiveMin() && m_TimeBounds[1] == ScalarTypeNumericTraits::max() ) );
      return ((mitk::ScalarType)timestep)/m_TimeSteps*(m_TimeBounds[1]-m_TimeBounds[0])+m_TimeBounds[0];
    }
  }
  else
  {
    return GetGeometry3D(timestep)->GetTimeBounds()[0];
  }
}
Example #8
0
//---------------------------------------------------------------------------
void GregorianDate::ParseOut(const wxString &str) 
{
   #if DEBUG_GREGORIAN_VALIDATE
   //MessageInterface::ShowMessage(wxT("==> GregorianDate::ParseOut() str=%s\n"), str.c_str());
   #endif
   
   // Check if non-empty string then parse out; otherwise, nothing. 
   if (str != wxT(""))
   {
      StringTokenizer dateToken(str, wxT(" "));

      if (dateToken.CountTokens() == 4)
      {
         wxString issString = (dateToken.GetToken(0));
         wxStringInputStream issStringStream(issString);
         wxTextInputStream iss(issStringStream);
         Integer dayNum, yearNum;

         // Get the number
         iss >> dayNum;

         // Get the year
         yearNum = ToInteger(dateToken.GetToken(2)); 

         // Check validity for year
         if (dateToken.GetToken(2).length() != 4 || yearNum < 1950)
            return;
//            throw GregorianDateException();

         // Check validity for month 
//          std::vector<wxString>::iterator pos;
//          pos = find(monthName.begin(),monthName.end(),
//                     dateToken.GetToken(1));

//          if (pos == monthName.end())
//             return;
// //            throw GregorianDateException();

         bool monthFound = false;
         Integer monthNum = 0;
         for (int i=0; i<12; i++)
         {
            if (GmatTimeConstants::MONTH_NAME_TEXT[i] == dateToken.GetToken(1))
            {
               monthFound = true;
               monthNum = i+1;
               break;
            }
         }
         
         if (!monthFound)
            return;

//          Integer monthNum;
//          monthNum = (Integer) distance(monthName.begin(),pos) + 1;

         wxString tempYMD;
         tempYMD = dateToken.GetToken(2) + NumToString(monthNum); 
         if (dateToken.GetToken(0).length() == 1)
            tempYMD += wxT("0");
         tempYMD += dateToken.GetToken(0) + wxT("."); 

         // Start with time
         StringTokenizer timeToken(dateToken.GetToken(3),wxT(":"));  

         if (timeToken.CountTokens() == 3)
         {
//            // Check length of time format
//            if (timeToken.GetToken(0).length() != 2 ||
//                timeToken.GetToken(1).length() != 2 ||
//                timeToken.GetToken(2).length() != 6)
//            {
//               MessageInterface::ShowMessage(
//                  wxT("\nWarning: invalid Gregorian format with time")); 
//               return;
//            }

            // Check length of the hour format
            if (timeToken.GetToken(0).length() != 2)
            {
               MessageInterface::ShowMessage(
                  wxT("\nWarning: invalid Gregorian time for hours format(HH)\n")); 
               return;
            }
            // Check length of the minute format
            if (timeToken.GetToken(1).length() != 2)
            {
               MessageInterface::ShowMessage(
                  wxT("\nWarning: invalid Gregorian time for minutes format(MM)\n")); 
               return;
            }
            if (timeToken.GetToken(2).length() != 6)
            {
               MessageInterface::ShowMessage(
                  wxT("\nWarning: invalid Gregorian time for seconds format(SS.mmm)\n")); 
               return;
            }

            // Get hour and minute
            Integer hour, minute;
            hour = ToInteger(timeToken.GetToken(0)); 
            minute = ToInteger(timeToken.GetToken(1)); 
           
            tempYMD += timeToken.GetToken(0) + timeToken.GetToken(1);

            // Finally start with seconds
            wxString strSeconds = timeToken.GetToken(2);
            timeToken.Set(strSeconds,wxT(".")); 

            // Check time format in second
            if (timeToken.CountTokens() != 2 || 
                timeToken.GetToken(0).length() != 2 ||
                timeToken.GetToken(1).length() != 3)
            {
               MessageInterface::ShowMessage(
                  wxT("\nWarning: invalid Gregorian format with seconds")); 
               return;
            }
            
            tempYMD += timeToken.GetToken(0) + timeToken.GetToken(1);

            // Get real number in seconds
            Real second = ToReal(strSeconds); 
   #if DEBUG_GREGORIAN_VALIDATE
            //MessageInterface::ShowMessage
            //   (wxT("==> GregorianDate::ParseOut() second=%.10f\n"), second);
            #endif
            
            // Finally check validity for the date  
            if (!IsValidTime(yearNum,monthNum,dayNum,hour,minute,second))
            {
               MessageInterface::ShowMessage(
                  wxT("\nWarning: invalid Gregorian format from DateUtil")); 
               return;
            } 
            
            stringYMDHMS = tempYMD;
            //MessageInterface::ShowMessage
            //   (wxT("==> GregorianDate::ParseOut() stringYMDHMS=%s\n"),
            //    stringYMDHMS.c_str());
         }                    
         isValid = true;
      }
Example #9
0
//------------------------------------------------------------------------------
// bool IsValid() const
//------------------------------------------------------------------------------
bool Date::IsValid() const
{
   return(IsValidTime(yearD,monthD,dayD,GetHour(),GetMinute(),GetSecond()));
}
Example #10
0
int GetTimeStamp(REC_INFO* pRec, void* pVal)
{
    REC_INFO* pCurRec = pRec;
    int recNum = 0;
    int temp = 0;
    unsigned int tempu = 0;
    TIME_INFO timeInfo = {0};
    if(sscanf(pCurRec->pContent, "%hu.%hu.%hu",&(timeInfo.year), &(timeInfo.month), &(timeInfo.day)) != 3)
    {
        return -1;
    }

    /* 删除空格 */
    ++recNum;
    pCurRec = goaheadRec(pCurRec, 1);
    temp = ignoreSpaces(pCurRec);
    if(temp <= 0)
    {
        return -1;
    }
    recNum += temp;
    pCurRec = goaheadRec(pCurRec, temp);

    /* 向前走4个,确保没有空指针 */
    if(goaheadRec(pCurRec,4) == NULL)
    {
        return -1;
    }

    /*  获取hour */
    if(GetNumberFromRec(pCurRec, &tempu) != 0)
    {
        return -1;
    }
    timeInfo.hour = (unsigned short)tempu;

    /* 获取minite */
    ++recNum;
    pCurRec = goaheadRec(pCurRec, 1);
    if(matchSep(pCurRec, SEP_COLON) != 0)
    {
        return -1;
    }
    ++recNum;
    pCurRec = goaheadRec(pCurRec, 1);
    if(GetNumberFromRec(pCurRec, &tempu) != 0)
    {
        return -1;
    }
    timeInfo.min = (unsigned short)tempu;

    /* 获取second */
    ++recNum;
    pCurRec = goaheadRec(pCurRec, 1);
    if(matchSep(pCurRec, SEP_COLON) != 0)
    {
        return -1;
    }
    ++recNum;
    pCurRec = goaheadRec(pCurRec, 1);
    if(GetNumberFromRec(pCurRec, &tempu) != 0)
    {
        return -1;
    }
    timeInfo.sec = tempu;

    if(!IsValidTime(&timeInfo))
    {
        return -2;
    }

    memcpy(pVal, &timeInfo, sizeof(timeInfo));
    ++recNum;

    return recNum;
}
Example #11
0
/*
 * Create range object from one or two arguments.
 * All not-digit characters in the argument(s) are ignored.
 * Both arg1 and arg2 must be valid pointer.
 */
static void
parse_range(pgBackupRange *range, const char *arg1, const char *arg2)
{
	size_t		len = strlen(arg1) + strlen(arg2) + 1;
	char	   *tmp;
	int			num;
	struct tm	tm;

	tmp = pgut_malloc(len);
	tmp[0] = '\0';
	if (arg1 != NULL)
		remove_not_digit(tmp, len, arg1);
	if (arg2 != NULL)
		remove_not_digit(tmp + strlen(tmp), len - strlen(tmp), arg2);

	memset(&tm, 0, sizeof(tm));
	tm.tm_year = 0;		/* tm_year is year - 1900 */
	tm.tm_mon = 0;		/* tm_mon is 0 - 11 */
	tm.tm_mday = 1;		/* tm_mday is 1 - 31 */
	tm.tm_hour = 0;
	tm.tm_min = 0;
	tm.tm_sec = 0;
	num = sscanf(tmp, "%04d %02d %02d %02d %02d %02d",
		&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
		&tm.tm_hour, &tm.tm_min, &tm.tm_sec);

	if (num < 1)
	{
		if (strcmp(tmp,"") != 0)
			elog(ERROR, "supplied id(%s) is invalid", tmp);
		else
			elog(ERROR, "arguments are invalid. near \"%s\"", arg1);
	}

	free(tmp);

	/* adjust year and month to convert to time_t */
	tm.tm_year -= 1900;
	if (num > 1)
		tm.tm_mon -= 1;
	tm.tm_isdst = -1;

	if (!IsValidTime(tm))
		elog(ERROR, "supplied time(%s) is invalid.", arg1);

	range->begin = mktime(&tm);

	switch (num)
	{
		case 1:
			tm.tm_year++;
			break;
		case 2:
			tm.tm_mon++;
			break;
		case 3:
			tm.tm_mday++;
			break;
		case 4:
			tm.tm_hour++;
			break;
		case 5:
			tm.tm_min++;
			break;
		case 6:
			tm.tm_sec++;
			break;
	}
	range->end = mktime(&tm);
	range->end--;
}