mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Move strategies to cpp file
This commit is contained in:
parent
c8cd93d630
commit
7be87586c5
2 changed files with 176 additions and 175 deletions
|
@ -290,6 +290,50 @@ void CmdHistoryBase<HistoryStrategy>::outputTabular (std::string &output)
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////i
|
||||||
|
class MonthlyHistoryStrategy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Datetime getRelevantDate (const Datetime & dt)
|
||||||
|
{
|
||||||
|
return dt.startOfMonth ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupTableDates (Table & view)
|
||||||
|
{
|
||||||
|
view.add (STRING_CMD_HISTORY_YEAR);
|
||||||
|
view.add (STRING_CMD_HISTORY_MONTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void insertRowDate (
|
||||||
|
Table& view,
|
||||||
|
int row,
|
||||||
|
time_t rowTime,
|
||||||
|
time_t lastTime)
|
||||||
|
{
|
||||||
|
Datetime dt (rowTime);
|
||||||
|
int m, d, y;
|
||||||
|
dt.toYMD (y, m, d);
|
||||||
|
|
||||||
|
Datetime last_dt (lastTime);
|
||||||
|
int last_m, last_d, last_y;
|
||||||
|
last_dt.toYMD (last_y, last_m, last_d);
|
||||||
|
|
||||||
|
if (y != last_y)
|
||||||
|
{
|
||||||
|
view.set (row, 0, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
view.set (row, 1, Datetime::monthName (m));
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const char* keyword = "history.monthly";
|
||||||
|
static constexpr const char* usage = "task <filter> history.monthly";
|
||||||
|
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_M;
|
||||||
|
static constexpr unsigned int dateFieldCount = 2;
|
||||||
|
static constexpr bool graphical = false;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
template<class HistoryStrategy>
|
template<class HistoryStrategy>
|
||||||
int CmdHistoryBase<HistoryStrategy>::execute (std::string& output)
|
int CmdHistoryBase<HistoryStrategy>::execute (std::string& output)
|
||||||
|
@ -349,6 +393,132 @@ int CmdHistoryBase<HistoryStrategy>::execute (std::string& output)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////i
|
||||||
|
class MonthlyGHistoryStrategy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Datetime getRelevantDate (const Datetime & dt)
|
||||||
|
{
|
||||||
|
return dt.startOfMonth ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupTableDates (Table & view)
|
||||||
|
{
|
||||||
|
view.add (STRING_CMD_HISTORY_YEAR);
|
||||||
|
view.add (STRING_CMD_HISTORY_MONTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void insertRowDate (
|
||||||
|
Table& view,
|
||||||
|
int row,
|
||||||
|
time_t rowTime,
|
||||||
|
time_t lastTime)
|
||||||
|
{
|
||||||
|
Datetime dt (rowTime);
|
||||||
|
int m, d, y;
|
||||||
|
dt.toYMD (y, m, d);
|
||||||
|
|
||||||
|
Datetime last_dt (lastTime);
|
||||||
|
int last_m, last_d, last_y;
|
||||||
|
last_dt.toYMD (last_y, last_m, last_d);
|
||||||
|
|
||||||
|
if (y != last_y)
|
||||||
|
{
|
||||||
|
view.set (row, 0, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
view.set (row, 1, Datetime::monthName (m));
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const char* keyword = "ghistory.monthly";
|
||||||
|
static constexpr const char* usage = "task <filter> ghistory.monthly";
|
||||||
|
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_M;
|
||||||
|
static constexpr unsigned int dateFieldCount = 2;
|
||||||
|
static constexpr bool graphical = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////i
|
||||||
|
class AnnualGHistoryStrategy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Datetime getRelevantDate (const Datetime & dt)
|
||||||
|
{
|
||||||
|
return dt.startOfYear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupTableDates (Table & view)
|
||||||
|
{
|
||||||
|
view.add (STRING_CMD_HISTORY_YEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void insertRowDate (
|
||||||
|
Table& view,
|
||||||
|
int row,
|
||||||
|
time_t rowTime,
|
||||||
|
time_t lastTime)
|
||||||
|
{
|
||||||
|
Datetime dt (rowTime);
|
||||||
|
int m, d, y;
|
||||||
|
dt.toYMD (y, m, d);
|
||||||
|
|
||||||
|
Datetime last_dt (lastTime);
|
||||||
|
int last_m, last_d, last_y;
|
||||||
|
last_dt.toYMD (last_y, last_m, last_d);
|
||||||
|
|
||||||
|
if (y != last_y)
|
||||||
|
{
|
||||||
|
view.set (row, 0, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const char* keyword = "ghistory.annual";
|
||||||
|
static constexpr const char* usage = "task <filter> ghistory.annual";
|
||||||
|
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_A;
|
||||||
|
static constexpr unsigned int dateFieldCount = 1;
|
||||||
|
static constexpr bool graphical = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////i
|
||||||
|
class AnnualHistoryStrategy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Datetime getRelevantDate (const Datetime & dt)
|
||||||
|
{
|
||||||
|
return dt.startOfYear ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setupTableDates (Table & view)
|
||||||
|
{
|
||||||
|
view.add (STRING_CMD_HISTORY_YEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void insertRowDate (
|
||||||
|
Table& view,
|
||||||
|
int row,
|
||||||
|
time_t rowTime,
|
||||||
|
time_t lastTime)
|
||||||
|
{
|
||||||
|
Datetime dt (rowTime);
|
||||||
|
int m, d, y;
|
||||||
|
dt.toYMD (y, m, d);
|
||||||
|
|
||||||
|
Datetime last_dt (lastTime);
|
||||||
|
int last_m, last_d, last_y;
|
||||||
|
last_dt.toYMD (last_y, last_m, last_d);
|
||||||
|
|
||||||
|
if (y != last_y)
|
||||||
|
{
|
||||||
|
view.set (row, 0, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr const char* keyword = "history.annual";
|
||||||
|
static constexpr const char* usage = "task <filter> history.annual";
|
||||||
|
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_A;
|
||||||
|
static constexpr unsigned int dateFieldCount = 1;
|
||||||
|
static constexpr bool graphical = false;
|
||||||
|
};
|
||||||
|
|
||||||
// Explicit instantiations, avoiding cpp-inclusion or implementation in header
|
// Explicit instantiations, avoiding cpp-inclusion or implementation in header
|
||||||
template class CmdHistoryBase<MonthlyHistoryStrategy>;
|
template class CmdHistoryBase<MonthlyHistoryStrategy>;
|
||||||
template class CmdHistoryBase<AnnualHistoryStrategy>;
|
template class CmdHistoryBase<AnnualHistoryStrategy>;
|
||||||
|
|
|
@ -51,185 +51,16 @@ private:
|
||||||
void outputGraphical (std::string&);
|
void outputGraphical (std::string&);
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////i
|
// Forward-declare strategies implemented in CmdHistory.cpp
|
||||||
class MonthlyHistoryStrategy
|
class MonthlyHistoryStrategy;
|
||||||
{
|
class MonthlyGHistoryStrategy;
|
||||||
public:
|
class AnnualHistoryStrategy;
|
||||||
static Datetime getRelevantDate (const Datetime & dt)
|
class AnnualGHistoryStrategy;
|
||||||
{
|
|
||||||
return dt.startOfMonth ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setupTableDates (Table & view)
|
|
||||||
{
|
|
||||||
view.add (STRING_CMD_HISTORY_YEAR);
|
|
||||||
view.add (STRING_CMD_HISTORY_MONTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insertRowDate (
|
|
||||||
Table& view,
|
|
||||||
int row,
|
|
||||||
time_t rowTime,
|
|
||||||
time_t lastTime)
|
|
||||||
{
|
|
||||||
Datetime dt (rowTime);
|
|
||||||
int m, d, y;
|
|
||||||
dt.toYMD (y, m, d);
|
|
||||||
|
|
||||||
Datetime last_dt (lastTime);
|
|
||||||
int last_m, last_d, last_y;
|
|
||||||
last_dt.toYMD (last_y, last_m, last_d);
|
|
||||||
|
|
||||||
if (y != last_y)
|
|
||||||
{
|
|
||||||
view.set (row, 0, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
view.set (row, 1, Datetime::monthName (m));
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char* keyword = "history.monthly";
|
|
||||||
static constexpr const char* usage = "task <filter> history.monthly";
|
|
||||||
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_M;
|
|
||||||
static constexpr unsigned int dateFieldCount = 2;
|
|
||||||
static constexpr bool graphical = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// typedef the templates to nice names to be used outside this class
|
||||||
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
|
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////i
|
|
||||||
class MonthlyGHistoryStrategy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Datetime getRelevantDate (const Datetime & dt)
|
|
||||||
{
|
|
||||||
return dt.startOfMonth ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setupTableDates (Table & view)
|
|
||||||
{
|
|
||||||
view.add (STRING_CMD_HISTORY_YEAR);
|
|
||||||
view.add (STRING_CMD_HISTORY_MONTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insertRowDate (
|
|
||||||
Table& view,
|
|
||||||
int row,
|
|
||||||
time_t rowTime,
|
|
||||||
time_t lastTime)
|
|
||||||
{
|
|
||||||
Datetime dt (rowTime);
|
|
||||||
int m, d, y;
|
|
||||||
dt.toYMD (y, m, d);
|
|
||||||
|
|
||||||
Datetime last_dt (lastTime);
|
|
||||||
int last_m, last_d, last_y;
|
|
||||||
last_dt.toYMD (last_y, last_m, last_d);
|
|
||||||
|
|
||||||
if (y != last_y)
|
|
||||||
{
|
|
||||||
view.set (row, 0, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
view.set (row, 1, Datetime::monthName (m));
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char* keyword = "ghistory.monthly";
|
|
||||||
static constexpr const char* usage = "task <filter> ghistory.monthly";
|
|
||||||
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_M;
|
|
||||||
static constexpr unsigned int dateFieldCount = 2;
|
|
||||||
static constexpr bool graphical = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
|
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////i
|
|
||||||
class AnnualHistoryStrategy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Datetime getRelevantDate (const Datetime & dt)
|
|
||||||
{
|
|
||||||
return dt.startOfYear ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setupTableDates (Table & view)
|
|
||||||
{
|
|
||||||
view.add (STRING_CMD_HISTORY_YEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insertRowDate (
|
|
||||||
Table& view,
|
|
||||||
int row,
|
|
||||||
time_t rowTime,
|
|
||||||
time_t lastTime)
|
|
||||||
{
|
|
||||||
Datetime dt (rowTime);
|
|
||||||
int m, d, y;
|
|
||||||
dt.toYMD (y, m, d);
|
|
||||||
|
|
||||||
Datetime last_dt (lastTime);
|
|
||||||
int last_m, last_d, last_y;
|
|
||||||
last_dt.toYMD (last_y, last_m, last_d);
|
|
||||||
|
|
||||||
if (y != last_y)
|
|
||||||
{
|
|
||||||
view.set (row, 0, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char* keyword = "history.annual";
|
|
||||||
static constexpr const char* usage = "task <filter> history.annual";
|
|
||||||
static constexpr const char* description = STRING_CMD_HISTORY_USAGE_A;
|
|
||||||
static constexpr unsigned int dateFieldCount = 1;
|
|
||||||
static constexpr bool graphical = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;
|
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////i
|
|
||||||
class AnnualGHistoryStrategy
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static Datetime getRelevantDate (const Datetime & dt)
|
|
||||||
{
|
|
||||||
return dt.startOfYear ();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setupTableDates (Table & view)
|
|
||||||
{
|
|
||||||
view.add (STRING_CMD_HISTORY_YEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void insertRowDate (
|
|
||||||
Table& view,
|
|
||||||
int row,
|
|
||||||
time_t rowTime,
|
|
||||||
time_t lastTime)
|
|
||||||
{
|
|
||||||
Datetime dt (rowTime);
|
|
||||||
int m, d, y;
|
|
||||||
dt.toYMD (y, m, d);
|
|
||||||
|
|
||||||
Datetime last_dt (lastTime);
|
|
||||||
int last_m, last_d, last_y;
|
|
||||||
last_dt.toYMD (last_y, last_m, last_d);
|
|
||||||
|
|
||||||
if (y != last_y)
|
|
||||||
{
|
|
||||||
view.set (row, 0, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr const char* keyword = "ghistory.annual";
|
|
||||||
static constexpr const char* usage = "task <filter> ghistory.annual";
|
|
||||||
static constexpr const char* description = STRING_CMD_GHISTORY_USAGE_A;
|
|
||||||
static constexpr unsigned int dateFieldCount = 1;
|
|
||||||
static constexpr bool graphical = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual;
|
typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue