The Artima Developer Community
Sponsored Link

Java Buzz Forum
Boost Multi-index Container

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
Boost Multi-index Container Posted: Mar 28, 2006 1:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: Boost Multi-index Container
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

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 Boost multi-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);

Read: Boost Multi-index Container

Topic: Sko-gar [Flickr] Previous Topic   Next Topic Topic: JavaUK06

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use