本文整理汇总了C++中Duration::valid方法的典型用法代码示例。如果您正苦于以下问题:C++ Duration::valid方法的具体用法?C++ Duration::valid怎么用?C++ Duration::valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duration
的用法示例。
在下文中一共展示了Duration::valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseTask
void CmdEdit::parseTask (Task& task, const std::string& after, const std::string& dateformat)
{
// project
std::string value = findValue (after, "\n Project:");
if (task.get ("project") != value)
{
if (value != "")
{
context.footnote (STRING_EDIT_PROJECT_MOD);
task.set ("project", value);
}
else
{
context.footnote (STRING_EDIT_PROJECT_DEL);
task.remove ("project");
}
}
// priority
value = findValue (after, "\n Priority:");
if (task.get ("priority") != value)
{
if (value != "")
{
if (context.columns["priority"]->validate (value))
{
context.footnote (STRING_EDIT_PRIORITY_MOD);
task.set ("priority", value);
}
}
else
{
context.footnote (STRING_EDIT_PRIORITY_DEL);
task.remove ("priority");
}
}
// tags
value = findValue (after, "\n Tags:");
std::vector <std::string> tags;
split (tags, value, ' ');
task.remove ("tags");
task.addTags (tags);
// description.
value = findValue (after, "\n Description:");
if (task.get ("description") != value)
{
if (value != "")
{
context.footnote (STRING_EDIT_DESC_MOD);
task.set ("description", value);
}
else
throw std::string (STRING_EDIT_DESC_REMOVE_ERR);
}
// entry
value = findValue (after, "\n Created:");
if (value != "")
{
std::string formatted = formatDate (task, "entry", dateformat);
if (formatted != value)
{
context.footnote (STRING_EDIT_ENTRY_MOD);
task.set ("entry", Date(value, dateformat).toEpochString ());
}
}
else
throw std::string (STRING_EDIT_ENTRY_REMOVE_ERR);
// start
value = findValue (after, "\n Started:");
if (value != "")
{
if (task.get ("start") != "")
{
std::string formatted = formatDate (task, "start", dateformat);
if (formatted != value)
{
context.footnote (STRING_EDIT_START_MOD);
task.set ("start", Date(value, dateformat).toEpochString ());
}
}
else
{
context.footnote (STRING_EDIT_START_MOD);
task.set ("start", Date(value, dateformat).toEpochString ());
}
}
else
{
if (task.get ("start") != "")
{
context.footnote (STRING_EDIT_START_DEL);
task.remove ("start");
}
}
//.........这里部分代码省略.........
示例2: validate
////////////////////////////////////////////////////////////////////////////////
// The purpose of Task::validate is three-fold:
// 1) To provide missing attributes where possible
// 2) To provide suitable warnings about odd states
// 3) To generate errors when the inconsistencies are not fixable
//
void Task::validate (bool applyDefault /* = true */)
{
Task::status status = getStatus ();
// 1) Provide missing attributes where possible
// Provide a UUID if necessary.
if (! has ("uuid"))
set ("uuid", uuid ());
// Recurring tasks get a special status.
if (status == Task::pending &&
has ("due") &&
has ("recur") &&
! has ("parent"))
status = Task::recurring;
// Tasks with a wait: date get a special status.
else if (status == Task::pending &&
has ("wait"))
status = Task::waiting;
// By default, tasks are pending.
else if (! has ("status"))
status = Task::pending;
// Store the derived status.
setStatus (status);
// Provide an entry date unless user already specified one.
if (!has ("entry"))
setEntry ();
// Completed tasks need an end date, so inherit the entry date.
if (! has ("end") &&
(getStatus () == Task::completed ||
getStatus () == Task::deleted))
setEnd ();
// Override with default.project, if not specified.
if (applyDefault && ! has ("project"))
{
std::string defaultProject = context.config.get ("default.project");
if (defaultProject != "" &&
context.columns["project"]->validate (defaultProject))
set ("project", defaultProject);
}
// Override with default.priority, if not specified.
if (applyDefault && get ("priority") == "")
{
std::string defaultPriority = context.config.get ("default.priority");
if (defaultPriority != "" &&
context.columns["priority"]->validate (defaultPriority))
set ("priority", defaultPriority);
}
// Override with default.due, if not specified.
if (applyDefault && get ("due") == "")
{
std::string defaultDue = context.config.get ("default.due");
if (defaultDue != "" &&
context.columns["due"]->validate (defaultDue))
set ("due", Date (defaultDue).toEpoch ());
}
// 2) To provide suitable warnings about odd states
// Date relationships.
validate_before ("wait", "due");
validate_before ("entry", "start");
validate_before ("entry", "end");
validate_before ("wait", "scheduled");
validate_before ("scheduled", "start");
validate_before ("scheduled", "due");
validate_before ("scheduled", "end");
// 3) To generate errors when the inconsistencies are not fixable
// There is no fixing a missing description.
if (!has ("description"))
throw std::string (STRING_TASK_VALID_DESC);
else if (get ("description") == "")
throw std::string (STRING_TASK_VALID_BLANK);
// Cannot have a recur frequency with no due date - when would it recur?
if (! has ("due") && has ("recur"))
throw std::string (STRING_TASK_VALID_REC_DUE);
// Recur durations must be valid.
if (has ("recur"))
{
Duration d;
if (! d.valid (get ("recur")))
throw std::string (format (STRING_TASK_VALID_RECUR, get ("recur")));
//.........这里部分代码省略.........