This is my second attempt at live blogging. I'm at the OCI internal C++ lunch presentation. Today's speaker is Jonathan Pollack and he's talking about the Boostmulti-index container, a C++ library that solves the "data" problem in certain situations:
You have a set of data, and you would like to find them by different sets of attributes. Find Customer by SSN, by name, etc.
I'll try something different this time. I'll try to write some code as I follow the presentation.
struct Customer {
std::string ssn_;
std::string name_;
};
struct SSN { /* tag for an index */ };
struct Name { /* tag for an index */ };
typedef boost::multi_index_container<
Customer,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::tag<SSN>,
boost::multi_index::member<Customer, std::string, &Customer::ssn_>
>,
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<Name>,
boost::multi_index::member<Customer, std::string, &Customer::name_>
>
MyCustomerDB;
typedef MyCustomerDB::index<SSN>::type SSNIndex;
typedef MyCustomerDB::index<Name>::type NameIndex;
typedef SSNIndex::iterator SSNIterator;
typedef NameIndex::iterator NameIterator;
MyCustomerDB db;
SSNIndex& ssnIndex = db.index<SSN>();
NameIndex& nameIndex = db.index<Name>();
Customer c1("333-44-5555", "John Smith");
Customer c2("666-77-8888", "Robert Brown");
db.insert(c1);
db.insert(c2);
SSNIterator ssnIter = ssnIndex.find("333-44-5555");
c1.ssn = "999-00-1111";
indexBy.replace(ssnIter, c1);