Enhancement - Record accessors

- Implemented a variety of get/set routines for Record.
This commit is contained in:
Paul Beckingham 2009-05-23 18:51:37 -04:00
parent 0eff6fa2b1
commit 2e5e20e3e5
4 changed files with 63 additions and 24 deletions

View file

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