tabularfile.hpp
Go to the documentation of this file.
1// $Id: tabularfile.hpp 1078 2012-09-25 11:13:53Z veralh $
2
3// Copyright (c) 2011, Norwegian Computing Center
4// All rights reserved.
5// Redistribution and use in source and binary forms, with or without modification,
6// are permitted provided that the following conditions are met:
7// • Redistributions of source code must retain the above copyright notice, this
8// list of conditions and the following disclaimer.
9// • Redistributions in binary form must reproduce the above copyright notice, this list of
10// conditions and the following disclaimer in the documentation and/or other materials
11// provided with the distribution.
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
13// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
15// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
17// OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
20// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
22#ifndef NRLIB_IOTOOLS_TABULARFILE_HPP
23#define NRLIB_IOTOOLS_TABULARFILE_HPP
24
25#include <cassert>
26#include <string>
27#include <vector>
28
29namespace NRLib {
30
34{
35public:
36 explicit TabularFile(const std::string& filename);
37 TabularFile(const std::string& filename, size_t first_data_line, size_t n_columns, bool read_last_line = true);
38
41 static bool CheckFile(const std::string& filename,
42 size_t& first_data_line,
43 size_t& n_columns,
44 bool& read_last_line,
45 std::string& last_line);
46
47 void ReadFromFile(const std::string& filename,
48 size_t first_data_line,
49 size_t n_columns,
50 bool read_last_line = true);
51
52 size_t GetNColumns() const { return columns_.size(); }
53
54 inline const std::vector<double>& GetColumn(size_t i) const;
55
56private:
57 std::vector<std::vector<double> > columns_;
58};
59
60// ========== INLINE FUNCTIONS =========
61
62const std::vector<double>& TabularFile::GetColumn(size_t i) const
63{
64 assert(i < columns_.size());
65 return columns_[i];
66}
67
68} // namespace NRLib
69
70#endif // NRLIB_IOTOOLS_TABULARFILE_HPP
const char *const string
Definition: cJSON.h:170
Definition: tabularfile.hpp:34
static bool CheckFile(const std::string &filename, size_t &first_data_line, size_t &n_columns, bool &read_last_line, std::string &last_line)
TabularFile(const std::string &filename, size_t first_data_line, size_t n_columns, bool read_last_line=true)
TabularFile(const std::string &filename)
size_t GetNColumns() const
Definition: tabularfile.hpp:52
const std::vector< double > & GetColumn(size_t i) const
Definition: tabularfile.hpp:62
void ReadFromFile(const std::string &filename, size_t first_data_line, size_t n_columns, bool read_last_line=true)
Definition: exception.hpp:31