Enhancement - Record::has

- Implemented Record::has which guarantees no autovivification of
  attributes.
This commit is contained in:
Paul Beckingham 2009-06-11 20:29:53 -04:00
parent 1ff3e73ebc
commit 754b79afb2
3 changed files with 16 additions and 1 deletions

View file

@ -116,6 +116,16 @@ void Record::parse (const std::string& input)
"Record not recognized as format 4"); "Record not recognized as format 4");
} }
////////////////////////////////////////////////////////////////////////////////
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> Record::all ()
{ {

View file

@ -43,6 +43,7 @@ public:
std::string composeCSV (); std::string composeCSV ();
void parse (const std::string&); void parse (const std::string&);
bool has (const std::string&) const;
std::vector <Att> all (); std::vector <Att> all ();
const std::string get (const std::string&) const; const std::string get (const std::string&) const;
int get_int (const std::string&) const; int get_int (const std::string&) const;

View file

@ -35,7 +35,7 @@ Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv) int main (int argc, char** argv)
{ {
UnitTest t (17); UnitTest t (19);
// (blank) // (blank)
bool good = true; bool good = true;
@ -85,6 +85,10 @@ int main (int argc, char** argv)
record.set ("name", "value"); record.set ("name", "value");
t.is (record.composeF4 (), "[name:\"value\"]\n", "Record::set"); t.is (record.composeF4 (), "[name:\"value\"]\n", "Record::set");
// Record::has
t.ok (record.has ("name"), "Record::has");
t.notok (record.has ("woof"), "Record::has not");
// Record::get_int // Record::get_int
record.set ("one", 1); record.set ("one", 1);
t.is (record.composeF4 (), "[name:\"value\" one:\"1\"]\n", "Record::set"); t.is (record.composeF4 (), "[name:\"value\" one:\"1\"]\n", "Record::set");