Expression Refactor

- Refactoring complete.  Arg objects now uses enumerations for _type
  and _category, which should help with performance.
This commit is contained in:
Paul Beckingham 2011-08-21 01:06:50 -04:00
parent 9086f51d29
commit 7aa4efef8d
6 changed files with 331 additions and 247 deletions

View file

@ -34,8 +34,8 @@ extern Context context;
Arg::Arg ()
: _value ("")
, _raw ("")
, _type ("")
, _category ("")
, _type (type_none)
, _category (cat_none)
{
}
@ -43,31 +43,31 @@ Arg::Arg ()
Arg::Arg (const std::string& raw)
: _value ("")
, _raw (raw)
, _type ("")
, _category ("")
, _type (type_none)
, _category (cat_none)
{
}
////////////////////////////////////////////////////////////////////////////////
Arg::Arg (
const std::string& raw,
const std::string& category)
const category c)
: _value ("")
, _raw (raw)
, _type ("")
, _category (category)
, _type (type_none)
, _category (c)
{
}
////////////////////////////////////////////////////////////////////////////////
Arg::Arg (
const std::string& raw,
const std::string& type,
const std::string& category)
const type t,
const category c)
: _value ("")
, _raw (raw)
, _type (type)
, _category (category)
, _type (t)
, _category (c)
{
}
@ -104,4 +104,83 @@ bool Arg::operator== (const Arg& other) const
}
////////////////////////////////////////////////////////////////////////////////
const Arg::type Arg::type_id (const std::string& input)
{
if (input == "bool") return Arg::type_bool;
else if (input == "string") return Arg::type_string;
else if (input == "date") return Arg::type_date;
else if (input == "duration") return Arg::type_duration;
else if (input == "number") return Arg::type_number;
else if (input == "pseudo") return Arg::type_pseudo;
return Arg::type_none;
}
////////////////////////////////////////////////////////////////////////////////
const std::string Arg::type_name (Arg::type t)
{
switch (t)
{
case Arg::type_none: return "none";
case Arg::type_pseudo: return "pseudo";
case Arg::type_bool: return "bool";
case Arg::type_string: return "string";
case Arg::type_date: return "date";
case Arg::type_duration: return "duration";
case Arg::type_number: return "number";
}
return "none";
}
////////////////////////////////////////////////////////////////////////////////
const Arg::category Arg::category_id (const std::string& input)
{
if (input == "terminator") return Arg::cat_terminator;
else if (input == "program") return Arg::cat_program;
else if (input == "command") return Arg::cat_command;
else if (input == "rc") return Arg::cat_rc;
else if (input == "rx") return Arg::cat_rx;
else if (input == "override") return Arg::cat_override;
else if (input == "attr") return Arg::cat_attr;
else if (input == "attmod") return Arg::cat_attmod;
else if (input == "id") return Arg::cat_id;
else if (input == "uuid") return Arg::cat_uuid;
else if (input == "subst") return Arg::cat_subst;
else if (input == "pattern") return Arg::cat_pattern;
else if (input == "tag") return Arg::cat_tag;
else if (input == "dom") return Arg::cat_dom;
else if (input == "op") return Arg::cat_op;
else if (input == "literal") return Arg::cat_literal;
return Arg::cat_none;
}
////////////////////////////////////////////////////////////////////////////////
const std::string Arg::category_name (Arg::category c)
{
switch (c)
{
case Arg::cat_none: return "none";
case Arg::cat_terminator: return "terminator";
case Arg::cat_program: return "program";
case Arg::cat_command: return "command";
case Arg::cat_rc: return "rc";
case Arg::cat_rx: return "rx";
case Arg::cat_override: return "override";
case Arg::cat_attr: return "attr";
case Arg::cat_attmod: return "attmod";
case Arg::cat_id: return "id";
case Arg::cat_uuid: return "uuid";
case Arg::cat_subst: return "subst";
case Arg::cat_pattern: return "pattern";
case Arg::cat_tag: return "tag";
case Arg::cat_dom: return "dom";
case Arg::cat_op: return "op";
case Arg::cat_literal: return "literal";
}
return "none";
}
///////////////////////////////////////////////////////////////////////////////