My Byte of Code Blog. Tips and observations on creating software with Objective-C, C/C++, Python, Cocoa and Boost on Mac.

Showing posts with label bimap. Show all posts
Showing posts with label bimap. Show all posts

Wednesday, February 24, 2010

Parse CSV File With Boost Tokenizer In C++

Often data required by application are available in CSV formatted files. In c++ it is easy to read file line by line. All that is left is to extract fields from each line and insert them into datastructure stored in memory. Boost Tokenizer is a package that provides a way to easilly break a string or sequence of characters into sequence of tokens, and provides standard iterator interface to traverse the tokens. I will show simple way of using Boost Tokenizer to parse data from CSV file.

Monday, February 08, 2010

Representing bidirectional relationship with boost::bimap

In C++, std maps and hash-maps are perfect choice for storing key-value pairs of elements. We use key to lookup related value(s). Quite often I manipulate key-value relationships where both keys and values are unique and usually there is a one-to-one relationships between keys and values. Example of this is a translation tables between two sets of symbols (strings).

I ended up coding my own class with two internal maps, or hash-maps, plus getters and setters to populate and access values for two way lookups.

A while ago I stumbled upon boost's bimap. Here is an example how to use it.