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 
55  void convert_to_utf8();
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 
91  void convert_to_utf8();
92 
93  pstring str() const;
94 };
95 
105 ORCUS_PSR_DLLPUBLIC std::string create_parse_error_output(
106  const pstring& strm, std::ptrdiff_t offset);
107 
119 ORCUS_PSR_DLLPUBLIC size_t locate_first_different_char(
120  const pstring& left, const pstring& right);
121 
122 } // namespace orcus
123 
124 #endif
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
orcus::file_content
Definition: stream.hpp:23
orcus::pstring
Definition: pstring.hpp:27
orcus::memory_content
Definition: stream.hpp:67