mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Merging Record and Task objects, step 2.
This commit is contained in:
parent
6d00337db3
commit
33cfdec5a6
4 changed files with 105 additions and 104 deletions
|
@ -94,97 +94,3 @@ void Record::parse (const std::string& input)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Record::has (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <Att> Record::all ()
|
||||
{
|
||||
std::vector <Att> all;
|
||||
std::map <std::string, Att>::iterator i;
|
||||
for (i = this->begin (); i != this->end (); ++i)
|
||||
all.push_back (i->second);
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string Record::get (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return i->second.value ();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Record::get_int (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return atoi (i->second.value ().c_str ());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned long Record::get_ulong (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Record::get_date (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return (time_t) strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Record::get_duration (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return (time_t) strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::set (const std::string& name, const std::string& value)
|
||||
{
|
||||
(*this)[name] = Att (name, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::set (const std::string& name, int value)
|
||||
{
|
||||
std::stringstream svalue;
|
||||
svalue << value;
|
||||
|
||||
(*this)[name] = Att (name, svalue.str ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::remove (const std::string& name)
|
||||
{
|
||||
Record::iterator it;
|
||||
if ((it = this->find (name)) != this->end ())
|
||||
this->erase (it);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
10
src/Record.h
10
src/Record.h
|
@ -43,16 +43,6 @@ public:
|
|||
|
||||
void parse (const std::string&);
|
||||
|
||||
bool has (const std::string&) const;
|
||||
std::vector <Att> all ();
|
||||
const std::string get (const std::string&) const;
|
||||
int get_int (const std::string&) const;
|
||||
unsigned long get_ulong (const std::string&) const;
|
||||
time_t get_date (const std::string&) const;
|
||||
time_t get_duration (const std::string&) const;
|
||||
void set (const std::string&, const std::string&);
|
||||
void set (const std::string&, int);
|
||||
void remove (const std::string&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
94
src/Task.cpp
94
src/Task.cpp
|
@ -160,6 +160,100 @@ void Task::setStart ()
|
|||
recalc_urgency = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Task::has (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <Att> Task::all ()
|
||||
{
|
||||
std::vector <Att> all;
|
||||
std::map <std::string, Att>::iterator i;
|
||||
for (i = this->begin (); i != this->end (); ++i)
|
||||
all.push_back (i->second);
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string Task::get (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return i->second.value ();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Task::get_int (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return atoi (i->second.value ().c_str ());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unsigned long Task::get_ulong (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Task::get_date (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return (time_t) strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Task::get_duration (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return (time_t) strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::set (const std::string& name, const std::string& value)
|
||||
{
|
||||
(*this)[name] = Att (name, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::set (const std::string& name, int value)
|
||||
{
|
||||
std::stringstream svalue;
|
||||
svalue << value;
|
||||
|
||||
(*this)[name] = Att (name, svalue.str ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::remove (const std::string& name)
|
||||
{
|
||||
Task::iterator it;
|
||||
if ((it = this->find (name)) != this->end ())
|
||||
this->erase (it);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Task::status Task::getStatus () const
|
||||
{
|
||||
|
|
11
src/Task.h
11
src/Task.h
|
@ -63,6 +63,17 @@ public:
|
|||
void setEnd ();
|
||||
void setStart ();
|
||||
|
||||
bool has (const std::string&) const;
|
||||
std::vector <Att> all ();
|
||||
const std::string get (const std::string&) const;
|
||||
int get_int (const std::string&) const;
|
||||
unsigned long get_ulong (const std::string&) const;
|
||||
time_t get_date (const std::string&) const;
|
||||
time_t get_duration (const std::string&) const;
|
||||
void set (const std::string&, const std::string&);
|
||||
void set (const std::string&, int);
|
||||
void remove (const std::string&);
|
||||
|
||||
status getStatus () const;
|
||||
void setStatus (status);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue