GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
file-info.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2017-2018 John W. Eaton
4 Copyright (C) 2001-2018 Ben Sapp
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if ! defined (octave_file_info_h)
25 #define octave_file_info_h 1
26 
27 #include "octave-config.h"
28 
29 #include <deque>
30 #include <map>
31 #include <string>
32 #include <vector>
33 
34 #include "oct-time.h"
35 
36 namespace octave
37 {
38  class file_info
39  {
40  public:
41 
42  file_info (void)
43  : m_file_buf (), m_offsets (), m_timestamp (static_cast<time_t> (0))
44  { }
45 
49  { }
50 
54  m_timestamp ()
55  { }
56 
57  file_info (const file_info&) = default;
58 
59  file_info& operator = (const file_info&) = default;
60 
61  ~file_info (void) = default;
62 
63  std::string get_line (size_t line) const;
64 
65  std::deque<std::string> get_lines (size_t line, size_t num_lines) const;
66 
67  size_t num_lines (void) const { return m_offsets.size (); }
68 
69  std::string text (void) const { return m_file_buf; }
70 
71  std::vector<size_t> line_offsets (void) const { return m_offsets; }
72 
73  sys::time timestamp (void) const { return m_timestamp; }
74 
75  size_t size (void) const { return m_file_buf.length (); }
76 
77  private:
78 
79  // File contents as a string.
81 
82  // Offsets to line beginnings.
83  std::vector<size_t> m_offsets;
84 
86 
87  // Read entire file called fname and return the contents as a string
88  static std::string snarf_file (const std::string& fname);
89 
90  static std::vector<size_t> get_line_offsets (const std::string& buf);
91  };
92 }
93 
94 #endif
std::vector< size_t > m_offsets
Definition: file-info.h:83
fname
Definition: load-save.cc:767
std::vector< size_t > line_offsets(void) const
Definition: file-info.h:71
~file_info(void)=default
static std::string snarf_file(const std::string &fname)
Definition: file-info.cc:73
static std::vector< size_t > get_line_offsets(const std::string &buf)
Definition: file-info.cc:103
std::string get_line(size_t line) const
Definition: file-info.cc:38
std::string text(void) const
Definition: file-info.h:69
std::deque< std::string > get_lines(size_t line, size_t num_lines) const
Definition: file-info.cc:61
file_info & operator=(const file_info &)=default
sys::time m_timestamp
Definition: file-info.h:85
file_info(const std::string &text, const sys::time &timestamp)
Definition: file-info.h:46
size_t num_lines(void) const
Definition: file-info.h:67
size_t size(void) const
Definition: file-info.h:75
std::string m_file_buf
Definition: file-info.h:80
sys::time timestamp(void) const
Definition: file-info.h:73
file_info(const std::string &fname)
Definition: file-info.h:51
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888