NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkCSVRow.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkCSVRow_h
16 #define niftkCSVRow_h
17 
18 #include <NifTKConfigure.h>
20 
21 #include <iterator>
22 #include <iostream>
23 #include <fstream>
24 #include <sstream>
25 #include <vector>
26 #include <string>
27 
28 namespace niftk
29 {
30 
51 {
52 public:
53 
55  CSVRow();
56 
58  ~CSVRow();
59 
61  std::string const& operator[]( std::size_t index ) const
62  {
63  return (*m_Data)[index];
64  }
65 
67  std::size_t Size() const
68  {
69  return m_Data->size();
70  }
71 
73  void ReadNextRow( std::istream& inStream );
74 
75 private:
76 
77  std::vector<std::string> *m_Data;
78 };
79 
80 
82 std::istream& operator>>( std::istream& str, CSVRow &data )
83 {
84  data.ReadNextRow( str );
85  return str;
86 }
87 
89 std::ostream& operator<<( std::ostream &os, const CSVRow &data )
90 {
91  for (unsigned int i=0; i < data.Size(); i++)
92  {
93  os << data[i];
94 
95  if ( i < data.Size() - 1 )
96  {
97  os << ",";
98  }
99  }
100 
101  return os;
102 }
103 
104 } // end namespace
105 
106 #endif // niftkCSVRow_h
void ReadNextRow(std::istream &inStream)
Definition: niftkCSVRow.cxx:35
std::istream & operator>>(std::istream &str, CSVRow &data)
Definition: niftkCSVRow.h:82
std::vcl_size_t Size() const
Definition: niftkCSVRow.h:67
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1363
std::ostream & operator<<(std::ostream &os, const CSVRow &data)
Definition: niftkCSVRow.h:89
#define NIFTKCOMMON_WINEXPORT
Definition: niftkCommonWin32ExportHeader.h:28
GLuint index
Definition: glew.h:1798
std::string const & operator[](std::vcl_size_t index) const
Definition: niftkCSVRow.h:61
Comma separated value (CSV) row class used to parse rows from an input stream and split them into a v...
Definition: niftkCSVRow.h:50
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194