Cleanup
[carla.git] / source / modules / ysfx / sources / ysfx_reader.hpp
bloba24c1d807dde8c7b626e0e59dc5b66e1a1e56633
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #pragma once
19 #include <string>
20 #include <cstdio>
21 #include <cstddef>
23 namespace ysfx {
25 class text_reader
27 public:
28 virtual ~text_reader() = default;
29 virtual char read_next_char() = 0;
30 virtual char peek_next_char() = 0;
31 bool read_next_line(std::string &line);
34 //------------------------------------------------------------------------------
35 class string_text_reader : public text_reader
37 public:
38 explicit string_text_reader(const char *text) : m_char_ptr(text) {}
39 char read_next_char() override;
40 char peek_next_char() override;
41 private:
42 const char *m_char_ptr = nullptr;
45 //------------------------------------------------------------------------------
46 class stdio_text_reader : public text_reader
48 public:
49 explicit stdio_text_reader(FILE *stream) : m_stream(stream) {}
50 char read_next_char() override;
51 char peek_next_char() override;
52 private:
53 FILE *m_stream = nullptr;
56 } // namespace ysfx