2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file TableReader.ih
19 * @author Bertrand Kerautret (\c kerautre@loria.fr )
20 * LORIA (CNRS, UMR 7503), University of Nancy, France
24 * Implementation of inline methods defined in TableReader.h
26 * This file is part of the DGtal library.
29///////////////////////////////////////////////////////////////////////////////
30// IMPLEMENTATION of inline methods.
31///////////////////////////////////////////////////////////////////////////////
33//////////////////////////////////////////////////////////////////////////////
37//////////////////////////////////////////////////////////////////////////////
41///////////////////////////////////////////////////////////////////////////////
42// Implementation of inline methods //
47template<typename TQuantity>
50DGtal::TableReader<TQuantity>::getColumnElementsFromFile (const std::string &aFilename, unsigned int aPosition)
53 infile.open (aFilename.c_str(), std::ifstream::in);
54 return TableReader<TQuantity>::getColumnElementsFromInputStream(infile, aPosition);
57template <typename TQuantity>
58inline std::vector<TQuantity>
59DGtal::TableReader<TQuantity>::getColumnElementsFromInputStream(
60std::istream & in, unsigned int aPosition )
62 std::vector<TQuantity> vectResult;
67 if ( ( str != "" ) && ( str[ 0 ] != '#' ) )
69 std::istringstream in_str( str );
74 while ( in_str.good() && !found )
76 std::operator>>( in_str, wordVal );
77 std::istringstream word_str( wordVal );
79 bool isOK = !word_str.fail();
80 if ( isOK && idx == aPosition )
83 vectResult.push_back( val );
93template <typename TQuantity>
94inline std::vector<std::vector<TQuantity>>
95DGtal::TableReader<TQuantity>::getLinesElementsFromFile(
96const std::string & aFilename )
99 infile.open( aFilename.c_str(), std::ifstream::in );
100 return DGtal::TableReader<TQuantity>::getLinesElementsFromInputStream(
104template <typename TQuantity>
105inline std::vector<std::vector<TQuantity>>
106DGtal::TableReader<TQuantity>::getLinesElementsFromInputStream(
109 std::vector<std::vector<TQuantity>> vectResult;
114 std::vector<TQuantity> aLine;
115 if ( ( str != "" ) && ( str[ 0 ] != '#' ) )
117 std::istringstream in_str( str );
120 while ( in_str.good() )
122 std::operator>>( in_str, wordVal );
123 std::istringstream word_str( wordVal );
125 if ( !word_str.fail() )
127 aLine.push_back( val );
130 vectResult.push_back( aLine );
138///////////////////////////////////////////////////////////////////////////////