Skip to content

Commit

Permalink
WIP step 9
Browse files Browse the repository at this point in the history
Nettoyage des DDD
  • Loading branch information
marcboulle committed Nov 28, 2023
1 parent 0ca1a25 commit b255072
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 268 deletions.
86 changes: 9 additions & 77 deletions src/Learning/KWData/KWDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,34 +150,6 @@ class Date : public SystemObject

// Utilisation d'une union DateTime pour acceder au champs Date, dans une structure commune aux type temporels
union DateTime dateValue;

/*DDD
// Stockage optimise d'une Date sous forme d'un entier
// On utilise un champ de bits pour stocker a la fois les information de Date et de time zone, utilises
// potentiellement dans les cas des TimestampTZ
// Bits 1 a 12: annee (entre 0 et 4000)
// Bits 13 a 16: mois (entre 1 et 12)
// Bits 17 a 21: jour (entre 1 et 31, ou 0 si invalide)
// Bit 22: signe de la timezone (0 si negatif, 1 si positif)
// Bits 23 a 26: heure de la timezone (entre 0 et 14)
// Bits 27 a 32: minute de la timezone (entre 0 et 59)
// Une time est invalide si elle vaut 0 (heure a 0; validite de 1 a 24), et interdite si elle vaut 0xFFFFFFFF
// La partie time zone est invalide si elle vaut 0 (une time zone -00:00 est codee +00:00 pour etre valide).
union DateValue
{
unsigned long long int nDate;
struct DateFields
{
unsigned int nYear : 12;
unsigned int nMonth : 4;
unsigned int nDay : 5;
unsigned int nTimeZoneSign : 1;
unsigned int nTimeZoneHour : 4;
unsigned int nTimeZoneMinute : 6;
unsigned int nFillerTime : 32;
} dateFields;
} dateValue;
*/
};

// Ecriture dans un stream
Expand Down Expand Up @@ -300,63 +272,40 @@ class KWDateFormat : public Object
inline void Date::Reset()
{
dateValue.lBytes = 0;
/*DDD
dateValue.dateFields.nYear = 0;
dateValue.dateFields.nMonth = 0;
dateValue.dateFields.nDay = 0;
dateValue.dateFields.nTimeZoneSign = 0;
dateValue.dateFields.nTimeZoneHour = 0;
dateValue.dateFields.nTimeZoneMinute = 0;
*/
//DDD dateValue.nDate = 0;
}

inline boolean Date::operator==(const Date& dtValue) const
{
return (dateValue.lBytes == dtValue.dateValue.lBytes);
//DDD return (dateValue.parts.nDate == dtValue.dateValue.parts.nDate);
//DDD return (dateValue.nDate == dtValue.dateValue.nDate);
}

inline boolean Date::operator!=(const Date& dtValue) const
{
return (dateValue.lBytes != dtValue.dateValue.lBytes);
//DDD return (dateValue.parts.nDate != dtValue.dateValue.parts.nDate);
//DDD return (dateValue.nDate != dtValue.dateValue.nDate);
}

inline boolean Date::Check() const
{
require(not IsForbiddenValue());
return dateValue.lBytes != 0;
//DDD return dateValue.parts.nDate != 0;
/*DDD
return dateValue.dateFields.nYear != 0 or dateValue.dateFields.nMonth != 0 or dateValue.dateFields.nDay != 0 or
dateValue.dateFields.nTimeZoneSign != 0 or dateValue.dateFields.nTimeZoneHour != 0 or
dateValue.dateFields.nTimeZoneMinute != 0;
*/
//DDD return dateValue.nDate != 0;
}

inline int Date::GetYear() const
{
require(Check());
return dateValue.fields.nYear;
//DDD return dateValue.dateFields.nYear;
}

inline int Date::GetMonth() const
{
require(Check());
return dateValue.fields.nMonth;
//DDD return dateValue.dateFields.nMonth;
}

inline int Date::GetDay() const
{
require(Check());
return dateValue.fields.nDay;
//DDD return dateValue.dateFields.nDay;
}

inline int Date::Diff(const Date dtOtherDate) const
Expand Down Expand Up @@ -388,33 +337,28 @@ inline void Date::SetYear(int nValue)
{
require(1 <= nValue and nValue <= DateTime::nMaxYear);
dateValue.fields.nYear = nValue;
//DDD dateValue.dateFields.nYear = nValue;
}

inline void Date::SetMonth(int nValue)
{
require(1 <= nValue and nValue <= 12);
dateValue.fields.nMonth = nValue;
//DDD dateValue.dateFields.nMonth = nValue;
}

inline void Date::SetDay(int nValue)
{
require(1 <= nValue and nValue <= 31);
dateValue.fields.nDay = nValue;
//DDD dateValue.dateFields.nDay = nValue;
}

inline void Date::SetForbiddenValue()
{
dateValue.lBytes = DateTime::lForbiddenValue;
//DDD dateValue.nDate = 0xFFFFFFFF;
}

inline boolean Date::IsForbiddenValue() const
{
return (dateValue.lBytes == DateTime::lForbiddenValue);
//DDD return (dateValue.nDate == 0xFFFFFFFF);
}

inline boolean Date::InitTimeZone(int nSign, int nHour, int nMinute)
Expand Down Expand Up @@ -446,19 +390,23 @@ inline boolean Date::InitTimeZone(int nSign, int nHour, int nMinute)

inline boolean Date::SetTimeZoneTotalMinutes(int nValue)
{
int nSign;
int nHour;
int nMinute;

// Initialisation de la timezone a invalide
ResetTimeZone();

// Initialisation si time zone valide
if (-12 * 60 <= nValue and nValue <= 14 * 60)
{
if (nValue >= 0)
SetTimeZoneSign(1);
nSign = 1;
else
SetTimeZoneSign(-1);
SetTimeZoneHour(abs(nValue) / 60);
SetTimeZoneMinute(abs(nValue) % 60);
return true;
nSign = -1;
nHour = abs(nValue) / 60;
nMinute = abs(nValue) % 60;
return InitTimeZone(nSign, nHour, nMinute);
}
return false;
}
Expand All @@ -473,63 +421,47 @@ inline void Date::SetTimeZoneSign(int nValue)
{
require(nValue == -1 or nValue == 1);
dateValue.fields.nTimeZoneSign = (nValue + 1) / 2;
//DDD dateValue.dateFields.nTimeZoneSign = (nValue + 1) / 2;
}

inline int Date::GetTimeZoneSign() const
{
require(CheckTimeZone());
return (dateValue.fields.nTimeZoneSign * 2) - 1;
//DDD return (dateValue.dateFields.nTimeZoneSign * 2) - 1;
}

inline void Date::SetTimeZoneHour(int nValue)
{
require(0 <= nValue and nValue <= 14);
dateValue.fields.nTimeZoneHour = nValue;
//DDD dateValue.dateFields.nTimeZoneHour = nValue;
}

inline int Date::GetTimeZoneHour() const
{
require(CheckTimeZone());
return dateValue.fields.nTimeZoneHour;
//DDD return dateValue.dateFields.nTimeZoneHour;
}

inline void Date::SetTimeZoneMinute(int nValue)
{
require(0 <= nValue and nValue <= 59);
dateValue.SetTimeZoneMinute(nValue);
//DDD dateValue.dateFields.nTimeZoneMinute = nValue;
}

inline int Date::GetTimeZoneMinute() const
{
require(CheckTimeZone());
return dateValue.GetTimeZoneMinute();
//DDD return dateValue.dateFields.nTimeZoneMinute;
}

inline void Date::ResetTimeZone()
{
//DDD
dateValue.SetTimeZone(0);
/*DDD
dateValue.dateFields.nTimeZoneSign = 0;
dateValue.dateFields.nTimeZoneHour = 0;
dateValue.dateFields.nTimeZoneMinute = 0;
*/
}

inline boolean Date::CheckTimeZone() const
{
require(not IsForbiddenValue());
return dateValue.GetTimeZone() != 0;
/*DDD
return dateValue.dateFields.nTimeZoneSign != 0 or dateValue.dateFields.nTimeZoneHour != 0 or
dateValue.dateFields.nTimeZoneMinute != 0;
*/
}

// KWDateFormat
Expand Down
3 changes: 0 additions & 3 deletions src/Learning/KWData/KWTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,17 @@ const char* const Time::ToString() const
else
{
nSecondFrac = timeValue.fields.nFrac;
//DDD nSecondFrac = timeValue.timeFields.nFrac;

// Cas ou il n'y a pas de fraction de secondes
if (nSecondFrac == 0)
snprintf(sTime, BUFFER_LENGTH, "%02d:%02d:%02d", GetHour(), GetMinute(),
(int)timeValue.fields.nSecond);
//DDD (int)timeValue.timeFields.nSecond);
// Cas avec fraction de secondes
else
{
nLength =
snprintf(sTime, BUFFER_LENGTH, "%02d:%02d:%02d.%0*d", GetHour(), GetMinute(),
(int)timeValue.fields.nSecond, DateTime::nFracSecondsDigitNumber, nSecondFrac);
//DDD (int)timeValue.timeFields.nSecond, nSecondFrac);

// Supression des zero en fin pour ne garder que la partie utile des decimales de secondes
for (i = 0; i < DateTime::nFracSecondsDigitNumber; i++)
Expand Down
46 changes: 0 additions & 46 deletions src/Learning/KWData/KWTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,6 @@ class Time : public SystemObject

// Utilisation d'une union DateTime pour acceder au champs Time, dans une structure commune aux type temporels
union DateTime timeValue;
/*DDD
// Stockage optimise d'une Time sous forme d'un entier
// Bits 1 a 5: heure de 0 a 23, plus 1
// Bits 6 a 11: minutes de 0 a 59
// Bits 12 a 17: secondes de 0 a 59
// Bits 20 a 32: partie decimale des secondes; de 0 a 999 (en 1/1000 de seconde)
// Une time est invalide si elle vaut 0 (heure a 0; validite de 1 a 24), et interdite si elle vaut 0xFFFFFFFF
union TimeValue
{
unsigned long long int nTime;
struct TimeFields
{
unsigned int nFillerDate : 32;
unsigned int nHour : 5;
unsigned int nMinute : 6;
unsigned int nSecond : 6;
unsigned int nFrac : 15;
} timeFields;
} timeValue;
*/
};

// Ecriture dans un stream
Expand Down Expand Up @@ -259,60 +239,40 @@ class KWTimeFormat : public Object
inline void Time::Reset()
{
timeValue.lBytes = 0;
/*DDD
timeValue.timeFields.nHour = 0;
timeValue.timeFields.nMinute = 0;
timeValue.timeFields.nSecond = 0;
timeValue.timeFields.nFrac = 0;
*/
//DDD timeValue.nTime = 0;
}

inline boolean Time::operator==(const Time& tmValue) const
{
return (timeValue.lBytes == tmValue.timeValue.lBytes);
//DDD return (timeValue.parts.nTime == tmValue.timeValue.parts.nTime);
//DDD return (timeValue.nTime == tmValue.timeValue.nTime);
}

inline boolean Time::operator!=(const Time& tmValue) const
{
return (timeValue.lBytes != tmValue.timeValue.lBytes);
//DDD return (timeValue.parts.nTime != tmValue.timeValue.parts.nTime);
//DDD return (timeValue.nTime != tmValue.timeValue.nTime);
}

inline boolean Time::Check() const
{
require(not IsForbiddenValue());
return timeValue.lBytes != 0;
//DDD return timeValue.parts.nTime != 0;
/*DDD
return timeValue.timeFields.nHour != 0 or timeValue.timeFields.nMinute != 0 or
timeValue.timeFields.nSecond != 0 or timeValue.timeFields.nFrac != 0;
*/
//DDD return timeValue.nTime != 0;
}

inline int Time::GetHour() const
{
require(Check());
return timeValue.fields.nHour - 1;
//DDD return timeValue.timeFields.nHour - 1;
}

inline int Time::GetMinute() const
{
require(Check());
return timeValue.fields.nMinute;
//DDD return timeValue.timeFields.nMinute;
}

inline double Time::GetSecond() const
{
require(Check());
return timeValue.fields.nSecond + timeValue.fields.nFrac / (double)DateTime::nMaxFracSeconds;
// return timeValue.timeFields.nSecond + timeValue.timeFields.nFrac / 10000.0;
}

inline double Time::GetDaySecond() const
Expand Down Expand Up @@ -371,14 +331,12 @@ inline void Time::SetHour(int nValue)
{
require(0 <= nValue and nValue < 24);
timeValue.fields.nHour = nValue + 1;
//DDD timeValue.timeFields.nHour = nValue + 1;
}

inline void Time::SetMinute(int nValue)
{
require(0 <= nValue and nValue < 60);
timeValue.fields.nMinute = nValue;
//DDD timeValue.timeFields.nMinute = nValue;
}

inline void Time::SetSecond(double dValue)
Expand All @@ -395,20 +353,16 @@ inline void Time::SetSecond(double dValue)
nSecondFrac--;
timeValue.fields.nSecond = nSecond;
timeValue.fields.nFrac = nSecondFrac;
//DDD timeValue.timeFields.nSecond = nSecond;
//DDD timeValue.timeFields.nFrac = nSecondFrac;
}

inline void Time::SetForbiddenValue()
{
timeValue.lBytes = DateTime::lForbiddenValue;
//DDD timeValue.nTime = 0xFFFFFFFF;
}

inline boolean Time::IsForbiddenValue() const
{
return (timeValue.lBytes == DateTime::lForbiddenValue);
//DDD return (timeValue.nTime == 0xFFFFFFFF);
}

// KWTimeFormat
Expand Down
6 changes: 0 additions & 6 deletions src/Learning/KWData/KWTimestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ boolean Timestamp::AddSeconds(double dSeconds)
GetInternalTime().SetHour(nHour);
GetInternalTime().SetMinute(nMinute);
GetInternalTime().SetSecond(dDaySeconds);
//DDD GetInternalTime().Init(nHour, nMinute, dDaySeconds);
}

// Reinitialistation si non valide
Expand All @@ -119,10 +118,6 @@ void Timestamp::SetCurrentTimestamp()
tmValue.SetCurrentTime();
SetDate(dtValue);
SetTime(tmValue);
/*DDD
GetInternalDate().SetCurrentDate();
GetInternalTime().SetCurrentTime();
*/
}

const char* const Timestamp::ToString() const
Expand Down Expand Up @@ -200,7 +195,6 @@ void Timestamp::Test()
int nTotalSecondNumber;

cout << "sizeof(Timestamp): " << sizeof(Timestamp) << endl;
//DDD assert(sizeof(Timestamp) == sizeof(Date) + sizeof(Time));
assert(sizeof(Timestamp) == sizeof(longint));
tsCurrent.SetCurrentTimestamp();
cout << "SYSTEM\tCurrent Timestamp\t" << tsCurrent << "\t" << tsCurrent.GetDate().GetWeekDay() << endl;
Expand Down
Loading

0 comments on commit b255072

Please sign in to comment.