Code Cleanup

- Merging Record and Task objects, step 2.
This commit is contained in:
Paul Beckingham 2011-08-07 16:28:40 -04:00
parent 6d00337db3
commit 33cfdec5a6
4 changed files with 105 additions and 104 deletions

View file

@ -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);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -43,16 +43,6 @@ public:
void parse (const std::string&); 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 #endif

View file

@ -160,6 +160,100 @@ void Task::setStart ()
recalc_urgency = true; 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 Task::status Task::getStatus () const
{ {

View file

@ -63,6 +63,17 @@ public:
void setEnd (); void setEnd ();
void setStart (); 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; status getStatus () const;
void setStatus (status); void setStatus (status);