mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 10:07:19 +02:00
Enhancement - Record accessors
- Implemented a variety of get/set routines for Record.
This commit is contained in:
parent
0eff6fa2b1
commit
2e5e20e3e5
4 changed files with 63 additions and 24 deletions
|
@ -25,6 +25,8 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <sstream>
|
||||
#include "util.h"
|
||||
#include "Record.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -63,3 +65,56 @@ void Record::parse (const std::string& input)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <Att> Record::all ()
|
||||
{
|
||||
std::vector <Att> all;
|
||||
foreach (a, mAtts)
|
||||
all.push_back (a->second);
|
||||
|
||||
return all;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string Record::get (const std::string& name)
|
||||
{
|
||||
if (mAtts.find (name) != mAtts.end ())
|
||||
return mAtts[name].value ();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Record::getInt (const std::string& name)
|
||||
{
|
||||
if (mAtts.find (name) != mAtts.end ())
|
||||
return ::atoi (mAtts[name].value ().c_str ());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::set (const std::string& name, const std::string& value)
|
||||
{
|
||||
mAtts[name] = Att (name, value);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::set (const std::string& name, int value)
|
||||
{
|
||||
std::stringstream svalue;
|
||||
svalue << value;
|
||||
|
||||
mAtts[name] = Att (name, svalue.str ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::remove (const std::string& name)
|
||||
{
|
||||
std::map <std::string, Att> copy = mAtts;
|
||||
mAtts.clear ();
|
||||
foreach (i, copy)
|
||||
if (i->first != name)
|
||||
mAtts[i->first] = i->second;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue