C++11: N2672 Initializer lists

- Modified code to use the more compact and readable initializer lists.
This commit is contained in:
Paul Beckingham 2015-05-24 12:47:36 -04:00
parent 49f7612704
commit 7bbc794d3a
25 changed files with 136 additions and 231 deletions

View file

@ -534,13 +534,8 @@ bool Context::verbose (const std::string& token)
verbosity[0] != "sync" && //
verbosity[0] != "filter") //
{
verbosity.clear ();
// This list emulates rc.verbose=off in version 1.9.4.
verbosity.push_back ("blank");
verbosity.push_back ("label");
verbosity.push_back ("new-id");
verbosity.push_back ("edit");
verbosity = {"blank", "label", "new-id", "edit"};
}
}
@ -765,8 +760,7 @@ void Context::updateVerbosity ()
if (command != "" &&
command[0] == '_')
{
verbosity.clear ();
verbosity.push_back ("nothing");
verbosity = {"nothing"};
}
}

View file

@ -52,16 +52,12 @@ DOM::~DOM ()
////////////////////////////////////////////////////////////////////////////////
const std::vector <std::string> DOM::get_references () const
{
std::vector <std::string> refs;
refs.push_back ("context.program");
refs.push_back ("context.args");
refs.push_back ("context.width");
refs.push_back ("context.height");
refs.push_back ("system.version");
refs.push_back ("system.os");
return refs;
return {"context.program",
"context.args",
"context.width",
"context.height",
"system.version",
"system.os"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -43,23 +43,23 @@ ColumnDate::ColumnDate ()
_style = "formatted";
_label = "";
_styles.push_back ("formatted");
_styles.push_back ("julian");
_styles.push_back ("epoch");
_styles.push_back ("iso");
_styles.push_back ("age");
_styles.push_back ("remaining");
_styles.push_back ("countdown");
_styles = {"formatted",
"julian",
"epoch",
"iso",
"age",
"remaining",
"countdown"};
Date now;
now -= 125; // So that "age" is non-zero.
_examples.push_back (now.toString (context.config.get ("dateformat")));
_examples.push_back (format (now.toJulian (), 13, 12));
_examples.push_back (now.toEpochString ());
_examples.push_back (now.toISO ());
_examples.push_back (Duration (Date () - now).formatCompact ());
_examples.push_back ("");
_examples.push_back (Duration (Date () - now).format ());
_examples = {now.toString (context.config.get ("dateformat")),
format (now.toJulian (), 13, 12),
now.toEpochString (),
now.toISO (),
Duration (Date () - now).formatCompact (),
"",
Duration (Date () - now).format ()};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -43,13 +43,13 @@ ColumnDepends::ColumnDepends ()
_style = "list";
_label = STRING_COLUMN_LABEL_DEP;
_styles.push_back ("list");
_styles.push_back ("count");
_styles.push_back ("indicator");
_styles = {"list",
"count",
"indicator"};
_examples.push_back ("1 2 10");
_examples.push_back ("[3]");
_examples.push_back (context.config.get ("dependency.indicator"));
_examples = {"1 2 10",
"[3]",
context.config.get ("dependency.indicator")};
_hyphenate = context.config.getBoolean ("hyphenate");
}

View file

@ -44,12 +44,12 @@ ColumnDescription::ColumnDescription ()
_style = "combined";
_label = STRING_COLUMN_LABEL_DESC;
_styles.push_back ("combined");
_styles.push_back ("desc");
_styles.push_back ("oneline");
_styles.push_back ("truncated");
_styles.push_back ("count");
_styles.push_back ("truncated_count");
_styles = {"combined",
"desc",
"oneline",
"truncated",
"count",
"truncated_count"};
_dateformat = context.config.get ("dateformat.annotation");
if (_dateformat == "")
@ -62,20 +62,18 @@ ColumnDescription::ColumnDescription ()
std::string a3 = STRING_COLUMN_EXAMPLES_ANNO3;
std::string a4 = STRING_COLUMN_EXAMPLES_ANNO4;
_examples.push_back (d
+ "\n " + t + " " + a1
+ "\n " + t + " " + a2
+ "\n " + t + " " + a3
+ "\n " + t + " " + a4);
_examples.push_back (d);
_examples.push_back (d
+ " " + t + " " + a1
+ " " + t + " " + a2
+ " " + t + " " + a3
+ " " + t + " " + a4);
_examples.push_back (d.substr (0, 20) + "...");
_examples.push_back (d + " [4]");
_examples.push_back (d.substr (0, 20) + "... [4]");
_examples = {d + "\n " + t + " " + a1
+ "\n " + t + " " + a2
+ "\n " + t + " " + a3
+ "\n " + t + " " + a4,
d,
d + " " + t + " " + a1
+ " " + t + " " + a2
+ " " + t + " " + a3
+ " " + t + " " + a4,
d.substr (0, 20) + "...",
d + " [4]",
d.substr (0, 20) + "... [4]"};
_hyphenate = context.config.getBoolean ("hyphenate");

View file

@ -43,7 +43,7 @@ ColumnDue::ColumnDue ()
Date now;
now += 125;
_examples.push_back (Duration (now - Date ()).formatCompact ());
_examples = {Duration (now - Date ()).formatCompact ()};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,10 +41,8 @@ ColumnID::ColumnID ()
_style = "number";
_label = STRING_COLUMN_LABEL_ID;
_modifiable = false;
_styles.push_back ("number");
_examples.push_back ("123");
_styles = {"number"};
_examples = {"123"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,10 +41,8 @@ ColumnIMask::ColumnIMask ()
_style = "number";
_label = STRING_COLUMN_LABEL_MASK_IDX;
_modifiable = false;
_styles.push_back ("number");
_examples.push_back ("12");
_styles = {"number"};
_examples = {"12"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,10 +41,8 @@ ColumnMask::ColumnMask ()
_style = "default";
_label = STRING_COLUMN_LABEL_MASK;
_modifiable = false;
_styles.push_back ("default");
_examples.push_back ("++++---");
_styles = {"default"};
_examples = {"++++---"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,12 +41,8 @@ ColumnParent::ColumnParent ()
_style = "long";
_label = STRING_COLUMN_LABEL_PARENT;
_modifiable = false;
_styles.push_back ("long");
_styles.push_back ("short");
_examples.push_back ("f30cb9c3-3fc0-483f-bfb2-3bf134f00694");
_examples.push_back ("34f00694");
_styles = {"long", "short"};
_examples = {"f30cb9c3-3fc0-483f-bfb2-3bf134f00694", "34f00694"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -37,19 +37,14 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnProject::ColumnProject ()
{
_name = "project";
_type = "string";
_style = "full";
_label = STRING_COLUMN_LABEL_PROJECT;
_styles.push_back ("full");
_styles.push_back ("parent");
_styles.push_back ("indented");
_examples.push_back (STRING_COLUMN_EXAMPLES_PROJ);
_examples.push_back (STRING_COLUMN_EXAMPLES_PAR);
_examples.push_back (STRING_COLUMN_EXAMPLES_IND);
_name = "project";
_type = "string";
_style = "full";
_label = STRING_COLUMN_LABEL_PROJECT;
_styles = {"full", "parent", "indented"};
_examples = {STRING_COLUMN_EXAMPLES_PROJ,
STRING_COLUMN_EXAMPLES_PAR,
STRING_COLUMN_EXAMPLES_IND};
_hyphenate = context.config.getBoolean ("hyphenate");
}

View file

@ -37,20 +37,16 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnRecur::ColumnRecur ()
{
_name = "recur";
_name = "recur";
// This is 'string', and not 'duration' to force the value to be stored as a
// raw duration, so that it can be reevaluated every time.
_type = "string";
_type = "string";
_style = "duration";
_label = STRING_COLUMN_LABEL_RECUR;
_styles.push_back ("duration");
_styles.push_back ("indicator");
_examples.push_back ("weekly");
_examples.push_back (context.config.get ("recurrence.indicator"));
_style = "duration";
_label = STRING_COLUMN_LABEL_RECUR;
_styles = {"duration", "indicator"};
_examples = {"weekly", context.config.get ("recurrence.indicator")};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -38,14 +38,13 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnScheduled::ColumnScheduled ()
{
_name = "scheduled";
_label = STRING_COLUMN_LABEL_SCHED;
_styles.push_back ("countdown");
_name = "scheduled";
_label = STRING_COLUMN_LABEL_SCHED;
_styles = {"countdown"};
Date now;
now += 125;
_examples.push_back (Duration (now - Date ()).formatCompact ());
_examples = {Duration (now - Date ()).formatCompact ()};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -36,12 +36,10 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnStart::ColumnStart ()
{
_name = "start";
_label = STRING_COLUMN_LABEL_STARTED;
_styles.push_back ("active");
_examples.push_back (context.config.get ("active.indicator"));
_name = "start";
_label = STRING_COLUMN_LABEL_STARTED;
_styles = {"active"};
_examples = {context.config.get ("active.indicator")};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -36,16 +36,13 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnStatus::ColumnStatus ()
{
_name = "status";
_type = "string";
_style = "long";
_label = STRING_COLUMN_LABEL_STATUS;
_styles.push_back ("long");
_styles.push_back ("short");
_examples.push_back (STRING_COLUMN_LABEL_STAT_PE);
_examples.push_back (STRING_COLUMN_LABEL_STAT_P);
_name = "status";
_type = "string";
_style = "long";
_label = STRING_COLUMN_LABEL_STATUS;
_styles = {"long", "short"};
_examples = {STRING_COLUMN_LABEL_STAT_PE,
STRING_COLUMN_LABEL_STAT_P};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -35,21 +35,18 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnString::ColumnString ()
{
_name = "string";
_type = "string";
_style = "left";
_label = "";
_styles.push_back ("left");
_styles.push_back ("right");
_styles.push_back ("left_fixed");
_styles.push_back ("right_fixed");
_styles.push_back ("Hello (wrapped) ");
_styles.push_back (" Hello (wrapped)");
_styles.push_back ("Hello (no-wrap) ");
_styles.push_back (" Hello (no-wrap)");
_name = "string";
_type = "string";
_style = "left";
_label = "";
_styles = {"left",
"right",
"left_fixed",
"right_fixed"};
_examples = {"Hello (wrapped) ",
" Hello (wrapped)",
"Hello (no-wrap) ",
" Hello (no-wrap)"};
_hyphenate = context.config.getBoolean ("hyphenate");
}

View file

@ -37,19 +37,14 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnTags::ColumnTags ()
{
_name = "tags";
_type = "string";
_style = "list";
_label = STRING_COLUMN_LABEL_TAGS;
_styles.push_back ("list");
_styles.push_back ("indicator");
_styles.push_back ("count");
_examples.push_back (STRING_COLUMN_EXAMPLES_TAGS);
_examples.push_back (context.config.get ("tag.indicator"));
_examples.push_back ("[2]");
_name = "tags";
_type = "string";
_style = "list";
_label = STRING_COLUMN_LABEL_TAGS;
_styles = {"list", "indicator", "count"};
_examples = {STRING_COLUMN_EXAMPLES_TAGS,
context.config.get ("tag.indicator"),
"[2]"};
_hyphenate = context.config.getBoolean ("hyphenate");
}

View file

@ -39,16 +39,13 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnUDA::ColumnUDA ()
{
_name = "<uda>";
_type = "string";
_style = "default";
_label = "";
_uda = true;
_name = "<uda>";
_type = "string";
_style = "default";
_label = "";
_uda = true;
_hyphenate = (_type == "string") ? true : false;
_styles.push_back (_style);
_styles.push_back ("indicator");
_styles = {_style, "indicator"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -41,12 +41,8 @@ ColumnUUID::ColumnUUID ()
_style = "long";
_label = STRING_COLUMN_LABEL_UUID;
_modifiable = false;
_styles.push_back ("long");
_styles.push_back ("short");
_examples.push_back ("f30cb9c3-3fc0-483f-bfb2-3bf134f00694");
_examples.push_back ("f30cb9c3");
_styles = {"long", "short"};
_examples = {"f30cb9c3-3fc0-483f-bfb2-3bf134f00694", "f30cb9c3"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -35,16 +35,12 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
ColumnUrgency::ColumnUrgency ()
{
_name = "urgency";
_type = "numeric";
_style = "real";
_label = STRING_COLUMN_LABEL_URGENCY;
_styles.push_back ("real");
_styles.push_back ("integer");
_examples.push_back ("4.6");
_examples.push_back ("4");
_name = "urgency";
_type = "numeric";
_style = "real";
_label = STRING_COLUMN_LABEL_URGENCY;
_styles = {"real", "integer"};
_examples = {"4.6", "4"};
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -65,9 +65,8 @@ extern Context context;
// std::getline, the newline can be detected, and the prompt re-written.
bool confirm (const std::string& question)
{
std::vector <std::string> options;
options.push_back (STRING_UTIL_CONFIRM_YES);
options.push_back (STRING_UTIL_CONFIRM_NO);
std::vector <std::string> options {STRING_UTIL_CONFIRM_YES,
STRING_UTIL_CONFIRM_NO};
std::string answer;
std::vector <std::string> matches;
@ -94,13 +93,12 @@ bool confirm (const std::string& question)
// 3 = quit
int confirm4 (const std::string& question)
{
std::vector <std::string> options;
options.push_back (STRING_UTIL_CONFIRM_YES_U);
options.push_back (STRING_UTIL_CONFIRM_YES);
options.push_back (STRING_UTIL_CONFIRM_NO);
options.push_back (STRING_UTIL_CONFIRM_ALL_U);
options.push_back (STRING_UTIL_CONFIRM_ALL);
options.push_back (STRING_UTIL_CONFIRM_QUIT);
std::vector <std::string> options {STRING_UTIL_CONFIRM_YES_U,
STRING_UTIL_CONFIRM_YES,
STRING_UTIL_CONFIRM_NO,
STRING_UTIL_CONFIRM_ALL_U,
STRING_UTIL_CONFIRM_ALL,
STRING_UTIL_CONFIRM_QUIT};
std::string answer;
std::vector <std::string> matches;