Skip to content

C++ csv parser with iterator, using iterator_facade

Notifications You must be signed in to change notification settings

mincongzhang/CppCsvParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

FileParser

C++ tool to parse file like:

FIELD1,FIELD2,FIELD3,FIELD4,
VAL__1,VAL__X,VAL__Y,VAL__Z,
VAL__1,VAL__X,VAL__Y,VAL__Z,    (duplicates)
VAL__2,VAL__X,VAL__Y,VAL__Z,
VAL__3,VAL__X,VAL__Y,VAL__Z,

with config

FIELDS = FIELD1,FIELD2,FIELD3,FIELD4
DELIM  = ","

to achieve:

Parser parser;
parser.load("path/to/file", "path/to/cfg");

for (Parser::const_iterator it=parser.begin(); it!=parser.end(); ++it){
	string val;
	if(it->get("FIELD2",val)){
		//update something
	}
}

actual code:

Parser parser;
parser.load(/*filename, cfg*/);
for (parser_iterator it=parser.begin(); it!=parser.end(); it++){
    //it.print();
    string val;
    if(it.get(parser.getFieldIdx("A"), val)){
        cout<<val<<endl;
    } else {
        cout<<"unable to get val"<<endl;
    }
}

reference:

1.Wrap STL vector and change behavior of its iterator
https://stackoverflow.com/questions/7824097/wrap-stl-vector-and-change-behavior-of-its-iterator

2.Using boost::iterator_facade<>
https://stackoverflow.com/questions/3514457/using-boostiterator-facade
http://www.boost.org/doc/libs/1_62_0/libs/iterator/doc/iterator_facade.html

3.Iterator Adaptor?

About

C++ csv parser with iterator, using iterator_facade

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages