Orcus
stream.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef INCLUDED_ORCUS_STREAM_HPP
9 #define INCLUDED_ORCUS_STREAM_HPP
10 
11 #include "env.hpp"
12 #include "orcus/pstring.hpp"
13 
14 #include <memory>
15 
16 namespace orcus {
17 
23 class ORCUS_PSR_DLLPUBLIC file_content
24 {
25  struct impl;
26  std::unique_ptr<impl> mp_impl;
27 public:
28  file_content(const file_content&) = delete;
29  file_content& operator= (const file_content&) = delete;
30 
31  file_content();
32  file_content(file_content&& other);
33  file_content(const char* filepath);
34  ~file_content();
35 
36  const char* data() const;
37  size_t size() const;
38  bool empty() const;
39 
40  void swap(file_content& other);
41 
48  void load(const char* filepath);
49 
56 
57  pstring str() const;
58 };
59 
67 class ORCUS_PSR_DLLPUBLIC memory_content
68 {
69  struct impl;
70  std::unique_ptr<impl> mp_impl;
71 public:
72  memory_content(const file_content&) = delete;
73  memory_content& operator= (const file_content&) = delete;
74 
76  memory_content(const char* p, size_t n);
78  ~memory_content();
79 
80  const char* data() const;
81  size_t size() const;
82  bool empty() const;
83 
84  void swap(memory_content& other);
85 
92 
93  pstring str() const;
94 };
95 
96 struct ORCUS_PSR_DLLPUBLIC line_with_offset
97 {
98  std::string line;
99  size_t line_number;
100  size_t offset_on_line;
101 
102  line_with_offset(std::string _line, size_t _line_number, size_t _offset_on_line);
103  line_with_offset(const line_with_offset& other);
105  ~line_with_offset();
106 };
107 
117 ORCUS_PSR_DLLPUBLIC std::string create_parse_error_output(
118  const pstring& strm, std::ptrdiff_t offset);
119 
130 ORCUS_PSR_DLLPUBLIC line_with_offset locate_line_with_offset(const pstring& strm, std::ptrdiff_t offset);
131 
143 ORCUS_PSR_DLLPUBLIC size_t locate_first_different_char(
144  const pstring& left, const pstring& right);
145 
146 } // namespace orcus
147 
148 #endif
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: stream.hpp:24
void load(const char *filepath)
Definition: stream.hpp:68
Definition: pstring.hpp:28
Definition: stream.hpp:97