fw4spl
CsvIO.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwGdcmIO/helper/CsvIO.hpp"
8 
9 #include <fwCore/spyLog.hpp>
10 
11 #include <boost/tokenizer.hpp>
12 
13 #include <fstream>
14 #include <string>
15 
16 namespace fwGdcmIO
17 {
18 
19 namespace helper
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 CsvIO::CsvIO(std::istream& csvStream) :
25  m_stream(csvStream)
26 {
27 }
28 
29 //------------------------------------------------------------------------------
30 
32 {
33 }
34 
35 //------------------------------------------------------------------------------
36 
37 typedef ::boost::char_separator<char> CharSeparatorType;
38 typedef ::boost::tokenizer< CharSeparatorType > TokenizerType;
39 
40 //------------------------------------------------------------------------------
41 
42 CsvIO::TokenContainerType CsvIO::getLine(const std::string& separator)
43 {
44  std::string line;
45  TokenContainerType tokens;
46  const CharSeparatorType sep(separator.c_str(), "", ::boost::keep_empty_tokens);
47 
48  if(std::getline(m_stream, line))
49  {
50  TokenizerType tokenizer(line, sep);
51  tokens.assign(tokenizer.begin(), tokenizer.end());
52  }
53 
54  return tokens;
55 }
56 
57 //------------------------------------------------------------------------------
58 
59 } // namespace helper
60 } // namespace fwGdcmIO
61 
FWGDCMIO_API TokenContainerType getLine(const std::string &separator=",")
Returns tokens on next line to read, using comma separator.
Definition: CsvIO.cpp:42
FWGDCMIO_API CsvIO(std::istream &csvStream)
Constructor.
Definition: CsvIO.cpp:24
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
virtual FWGDCMIO_API ~CsvIO()
Desctructor.
Definition: CsvIO.cpp:31
std::vector< std::string > TokenContainerType
Containers to store parsed tokens.
Definition: CsvIO.hpp:42
This file defines SpyLog macros. These macros are used to log messages to a file or to the console du...