mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-28 22:47:20 +02:00
Code Cleanup
- Removed 9 useless methods by making members public. Accessors are nice sometimes, but also an unnecessary layer.
This commit is contained in:
parent
50d4b37519
commit
ac1497ff1a
4 changed files with 54 additions and 124 deletions
|
@ -104,16 +104,15 @@ bool A3t::canonicalize (
|
|||
// autoCompletes to a valid command/report.
|
||||
void A3t::findBinary ()
|
||||
{
|
||||
if (_tree->branches () >= 1)
|
||||
if (_tree->_branches.size () >= 1)
|
||||
{
|
||||
_tree->operator[](0)->tag ("BINARY");
|
||||
|
||||
std::string binary = _tree->operator[](0)->attribute ("raw");
|
||||
_tree->_branches[0]->tag ("BINARY");
|
||||
std::string binary = _tree->_branches[0]->attribute ("raw");
|
||||
std::string::size_type slash = binary.rfind ('/');
|
||||
if (slash != std::string::npos)
|
||||
binary = binary.substr (slash + 1);
|
||||
|
||||
_tree->operator[](0)->attribute ("basename", binary);
|
||||
_tree->_branches[0]->attribute ("basename", "binary");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,12 +121,12 @@ void A3t::findBinary ()
|
|||
// all args in the raw state.
|
||||
void A3t::findTerminator ()
|
||||
{
|
||||
std::string command;
|
||||
for (int i = 0; i < _tree->branches (); ++i)
|
||||
std::vector <Tree*>::iterator i;
|
||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
||||
{
|
||||
if (_tree->operator[](i)->attribute ("raw") == "--")
|
||||
if ((*i)->attribute ("raw") == "--")
|
||||
{
|
||||
_tree->operator[](i)->tag ("TERMINATOR");
|
||||
(*i)->tag ("TERMINATOR");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -139,38 +138,39 @@ void A3t::findTerminator ()
|
|||
void A3t::findCommand ()
|
||||
{
|
||||
std::string command;
|
||||
for (int i = 0; i < _tree->branches (); ++i)
|
||||
std::vector <Tree*>::iterator i;
|
||||
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
||||
{
|
||||
// Parser override operator.
|
||||
if (_tree->operator[](i)->attribute ("raw") == "--")
|
||||
if ((*i)->attribute ("raw") == "--")
|
||||
break;
|
||||
|
||||
if (canonicalize (command, "report", _tree->operator[](i)->attribute ("raw")))
|
||||
if (canonicalize (command, "report", (*i)->attribute ("raw")))
|
||||
{
|
||||
_tree->operator[](i)->attribute ("canonical", command);
|
||||
_tree->operator[](i)->tag ("REPORT");
|
||||
_tree->operator[](i)->tag ("CMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
(*i)->tag ("REPORT");
|
||||
(*i)->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "readcmd", _tree->operator[](i)->attribute ("raw")))
|
||||
else if (canonicalize (command, "readcmd", (*i)->attribute ("raw")))
|
||||
{
|
||||
_tree->operator[](i)->attribute ("canonical", command);
|
||||
_tree->operator[](i)->tag ("READCMD");
|
||||
_tree->operator[](i)->tag ("CMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
(*i)->tag ("READCMD");
|
||||
(*i)->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "writecmd", _tree->operator[](i)->attribute ("raw")))
|
||||
else if (canonicalize (command, "writecmd", (*i)->attribute ("raw")))
|
||||
{
|
||||
_tree->operator[](i)->attribute ("canonical", command);
|
||||
_tree->operator[](i)->tag ("WRITECMD");
|
||||
_tree->operator[](i)->tag ("CMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
(*i)->tag ("WRITECMD");
|
||||
(*i)->tag ("CMD");
|
||||
}
|
||||
|
||||
else if (canonicalize (command, "specialcmd", _tree->operator[](i)->attribute ("raw")))
|
||||
else if (canonicalize (command, "specialcmd", (*i)->attribute ("raw")))
|
||||
{
|
||||
_tree->operator[](i)->attribute ("canonical", command);
|
||||
_tree->operator[](i)->tag ("SPECIALCMD");
|
||||
_tree->operator[](i)->tag ("CMD");
|
||||
(*i)->attribute ("canonical", command);
|
||||
(*i)->tag ("SPECIALCMD");
|
||||
(*i)->tag ("CMD");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,16 +65,6 @@ Tree& Tree::operator= (const Tree& other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Tree* Tree::operator[] (const int branch)
|
||||
{
|
||||
if (branch < 0 ||
|
||||
branch > (int) _branches.size () - 1)
|
||||
throw "Tree::operator[] out of range";
|
||||
|
||||
return _branches[branch];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Tree* Tree::addBranch (Tree* branch)
|
||||
{
|
||||
|
@ -115,24 +105,6 @@ void Tree::replaceBranch (Tree* from, Tree* to)
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Tree::branches ()
|
||||
{
|
||||
return _branches.size ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Tree::name (const std::string& name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Tree::name () const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Accessor for attributes.
|
||||
void Tree::attribute (const std::string& name, const std::string& value)
|
||||
|
@ -173,28 +145,11 @@ void Tree::removeAttribute (const std::string& name)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Tree::attributes () const
|
||||
{
|
||||
return _attributes.size ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <std::string> Tree::allAttributes () const
|
||||
{
|
||||
std::vector <std::string> names;
|
||||
std::map <std::string, std::string>::const_iterator it;
|
||||
for (it = _attributes.begin (); it != _attributes.end (); ++it)
|
||||
names.push_back (it->first);
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Recursively completes a list of Tree* objects, left to right, depth first.
|
||||
// The reason for the depth-first enumeration is that a client may wish to
|
||||
// traverse the tree and delete nodes. With a depth-first iteration, this is a
|
||||
// safe mechanism, and a node pointer will never be dereferenced after it has
|
||||
// been deleted.
|
||||
// Recursively builds a list of Tree* objects, left to right, depth first. The
|
||||
// reason for the depth-first enumeration is that a client may wish to traverse
|
||||
// the tree and delete nodes. With a depth-first iteration, this is a safe
|
||||
// mechanism, and a node pointer will never be dereferenced after it has been
|
||||
// deleted.
|
||||
void Tree::enumerate (std::vector <Tree*>& all) const
|
||||
{
|
||||
for (std::vector <Tree*>::const_iterator i = _branches.begin ();
|
||||
|
@ -206,12 +161,6 @@ void Tree::enumerate (std::vector <Tree*>& all) const
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Tree* Tree::parent () const
|
||||
{
|
||||
return _trunk;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Tree::hasTag (const std::string& tag) const
|
||||
{
|
||||
|
@ -228,18 +177,6 @@ void Tree::tag (const std::string& tag)
|
|||
_tags.push_back (tag);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Tree::tags () const
|
||||
{
|
||||
return _tags.size ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <std::string> Tree::allTags () const
|
||||
{
|
||||
return _tags;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Tree::count () const
|
||||
{
|
||||
|
@ -265,7 +202,7 @@ Tree* Tree::find (const std::string& path)
|
|||
// Must start at the trunk.
|
||||
Tree* cursor = this;
|
||||
std::vector <std::string>::iterator it = elements.begin ();
|
||||
if (cursor->name () != *it)
|
||||
if (cursor->_name != *it)
|
||||
return NULL;
|
||||
|
||||
// Perhaps the trunk is what is needed?
|
||||
|
@ -278,11 +215,12 @@ Tree* Tree::find (const std::string& path)
|
|||
bool found = false;
|
||||
|
||||
// If the cursor has a branch that matches *it, proceed.
|
||||
for (int i = 0; i < cursor->branches (); ++i)
|
||||
std::vector <Tree*>::iterator i;
|
||||
for (i = cursor->_branches.begin (); i != cursor->_branches.end (); ++i)
|
||||
{
|
||||
if ((*cursor)[i]->name () == *it)
|
||||
if ((*i)->_name == *it)
|
||||
{
|
||||
cursor = (*cursor)[i];
|
||||
cursor = *i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -302,18 +240,18 @@ void Tree::dumpNode (Tree* t, int depth)
|
|||
for (int i = 0; i < depth; ++i)
|
||||
std::cout << " ";
|
||||
|
||||
std::cout << t << " \033[1m" << t->name () << "\033[0m";
|
||||
std::cout << t << " \033[1m" << t->_name << "\033[0m";
|
||||
|
||||
// Dump attributes.
|
||||
std::string atts;
|
||||
std::vector <std::string> attributes = t->allAttributes ();
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = attributes.begin (); it != attributes.end (); ++it)
|
||||
|
||||
std::map <std::string, std::string>::iterator a;
|
||||
for (a = t->_attributes.begin (); a != t->_attributes.end (); ++a)
|
||||
{
|
||||
if (it != attributes.begin ())
|
||||
if (a != t->_attributes.begin ())
|
||||
atts += " ";
|
||||
|
||||
atts += *it + "='\033[33m" + t->attribute (*it) + "\033[0m'";
|
||||
atts += a->first + "='\033[33m" + a->second + "\033[0m'";
|
||||
}
|
||||
|
||||
if (atts.length ())
|
||||
|
@ -321,9 +259,9 @@ void Tree::dumpNode (Tree* t, int depth)
|
|||
|
||||
// Dump tags.
|
||||
std::string tags;
|
||||
std::vector <std::string> allTags = t->allTags ();
|
||||
for (it = allTags.begin (); it != allTags.end (); ++it)
|
||||
tags += (tags.length () ? " " : "") + *it;
|
||||
std::vector <std::string>::iterator tag;
|
||||
for (tag = t->_tags.begin (); tag != t->_tags.end (); ++tag)
|
||||
tags += (tags.length () ? " " : "") + *tag;
|
||||
|
||||
if (tags.length ())
|
||||
std::cout << " \033[32m" << tags << "\033[0m";
|
||||
|
@ -331,8 +269,9 @@ void Tree::dumpNode (Tree* t, int depth)
|
|||
std::cout << "\n";
|
||||
|
||||
// Recurse for branches.
|
||||
for (int i = 0; i < t->branches (); ++i)
|
||||
dumpNode ((*t)[i], depth + 1);
|
||||
std::vector <Tree*>::iterator b;
|
||||
for (b = t->_branches.begin (); b != t->_branches.end (); ++b)
|
||||
dumpNode (*b, depth + 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -40,30 +40,21 @@ public:
|
|||
~Tree ();
|
||||
Tree (const Tree&);
|
||||
Tree& operator= (const Tree&);
|
||||
Tree* operator[] (const int);
|
||||
|
||||
Tree* addBranch (Tree*);
|
||||
void removeBranch (Tree*);
|
||||
void replaceBranch (Tree*, Tree*);
|
||||
int branches ();
|
||||
|
||||
void name (const std::string&);
|
||||
std::string name () const;
|
||||
void attribute (const std::string&, const std::string&);
|
||||
void attribute (const std::string&, const int);
|
||||
void attribute (const std::string&, const double);
|
||||
std::string attribute (const std::string&);
|
||||
void removeAttribute (const std::string&);
|
||||
int attributes () const;
|
||||
std::vector <std::string> allAttributes () const;
|
||||
|
||||
void enumerate (std::vector <Tree*>& all) const;
|
||||
|
||||
bool hasTag (const std::string&) const;
|
||||
void tag (const std::string&);
|
||||
int tags () const;
|
||||
std::vector <std::string> allTags () const;
|
||||
|
||||
void enumerate (std::vector <Tree*>& all) const;
|
||||
Tree* parent () const;
|
||||
|
||||
int count () const;
|
||||
|
||||
|
@ -74,7 +65,7 @@ public:
|
|||
private:
|
||||
void dumpNode (Tree*, int);
|
||||
|
||||
private:
|
||||
public:
|
||||
Tree* _trunk; // Parent.
|
||||
std::string _name; // Name.
|
||||
std::vector <Tree*> _branches; // Children.
|
||||
|
|
|
@ -9,5 +9,5 @@
|
|||
#echo; ./args rc:x rc.debug:1 a.b\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d
|
||||
|
||||
echo; ./args 123 mod pro:'P 1' +home /from/to/g
|
||||
echo; ./args add -- modify
|
||||
echo; ./args add -- modify +tag /from/to/g name:value
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue