ocarina/lib/database.cpp

65 lines
1016 B
C++
Raw Normal View History

/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <database.h>
IndexEntry :: IndexEntry()
{
}
IndexEntry :: IndexEntry(const std::string &k, unsigned int v)
: key(k)
{
insert(v);
}
IndexEntry :: ~IndexEntry()
{
}
const std::string &IndexEntry :: primary_key()
{
return key;
}
void IndexEntry :: write(File &f)
{
std::set<unsigned int>::iterator it;
f << key << std::endl << values.size() << " ";
for (it = values.begin(); it != values.end(); it++)
f << *it << " ";
}
void IndexEntry :: read(File &f)
{
unsigned int num, val;
f >> key >> num;
for (unsigned int i = 0; i < num; i++) {
f >> val;
values.insert(val);
}
}
void IndexEntry :: print()
{
std::set<unsigned int>::iterator it;
:: print("{");
for (it = values.begin(); it != values.end(); it++) {
if (it != values.begin())
:: print(" ");
:: print("%d", *it);
}
:: print("}");
}
void IndexEntry :: insert(unsigned int val)
{
values.insert(val);
}
void IndexEntry :: remove(unsigned int val)
{
values.erase(val);
}