OpenWalnut  1.5.0dev
hierarchicalClustering/hierchClustDisplay/WFileParser.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 //---------------------------------------------------------------------------
26 //
27 // Project: hClustering
28 //
29 // Whole-Brain Connectivity-Based Hierarchical Parcellation Project
30 // David Moreno-Dominguez
31 // d.mor.dom@gmail.com
32 // moreno@cbs.mpg.de
33 // www.cbs.mpg.de/~moreno//
34 // This file is also part of OpenWalnut ( http://www.openwalnut.org ).
35 //
36 // hClustering is free software: you can redistribute it and/or modify
37 // it under the terms of the GNU Lesser General Public License as published by
38 // the Free Software Foundation, either version 3 of the License, or
39 // (at your option) any later version.
40 // http://creativecommons.org/licenses/by-nc/3.0
41 //
42 // hClustering is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU Lesser General Public License for more details.
46 //
47 //---------------------------------------------------------------------------
48 
49 #ifndef WFILEPARSER_H
50 #define WFILEPARSER_H
51 
52 // std library
53 #include <fstream>
54 #include <string>
55 #include <vector>
56 
57 // boost library
58 // Use filesystem version 2 for compatibility with newer boost versions.
59 #if 0
60 #ifndef BOOST_FILESYSTEM_VERSION
61  #define BOOST_FILESYSTEM_VERSION 2
62 #endif
63 #endif
64 
65 #include <boost/filesystem.hpp>
66 #include <boost/regex.hpp>
67 
68 
69 /**
70  * this class implements text file loading and several convinience methods to access the recovered text
71  */
72 class WFileParser
73 {
74 public:
75  /**
76  * constructor
77  * \param fileName
78  */
79  explicit WFileParser( const std::string fileName );
80 
81  /**
82  * destructor
83  */
85 
86  /**
87  * helper function to read a text file
88  * \return string containing the file
89  */
90  bool readFile();
91 
92  /**
93  * getter
94  * \return the content of the loaded as vector of strings for each line
95  */
96  std::vector<std::string>getRawLines();
97 
98  /**
99  * getter
100  * \param tag tag marking a certain type of content
101  * \return vector of strings for each line for the tag
102  */
103  std::vector<std::string>getLinesForTag( std::string tag );
104 
105  /**
106  * getter
107  * \param tag tag marking a certain type of content
108  * \return same as getLinesForTag but each line represented as vector of strings
109  */
110  std::vector< std::vector<std::string> >getLinesForTagSeparated( std::string tag );
111 
112 protected:
113 private:
114  std::string m_fileName; //!< the file name of the file to parse
115 
116  std::vector<std::string>m_rawLines; //!< vector of every line in the file
117 
118  std::string m_tagIndicator; //!< string marking a line as tag
119 
120  std::string m_endIndicator; //!< string marking the end of a tagged area
121 
122  std::string m_delimiter; //!< delimiter for entries in a line
123 };
124 
125 inline std::vector<std::string> WFileParser::getRawLines()
126 {
127  return m_rawLines;
128 }
129 
130 #endif // WFILEPARSER_H
class implements text file loading and several convinience methods to access
std::string m_fileName
the file name of the file to parse
std::vector< std::string > m_rawLines
vector of every line in the file
std::vector< std::string > getRawLines()
getter
std::vector< std::string > getRawLines()
getter
WFileParser(const std::string fileName)
constructor
std::string m_delimiter
delimiter for entries in a line
bool readFile()
helper function to read a text file
std::vector< std::vector< std::string > > getLinesForTagSeparated(std::string tag)
getter
~WFileParser()
destructor
std::string m_endIndicator
string marking the end of a tagged area
std::vector< std::string > getLinesForTag(std::string tag)
getter
std::string m_tagIndicator
string marking a line as tag