/src/trafficserver/lib/yamlcpp/src/stream.h
Line | Count | Source |
1 | | #ifndef STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |
2 | | #define STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |
3 | | |
4 | | #if defined(_MSC_VER) || \ |
5 | | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ |
6 | | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 |
7 | | #pragma once |
8 | | #endif |
9 | | |
10 | | #include "yaml-cpp/mark.h" |
11 | | #include <cstddef> |
12 | | #include <deque> |
13 | | #include <ios> |
14 | | #include <iostream> |
15 | | #include <set> |
16 | | #include <string> |
17 | | |
18 | | namespace YAML { |
19 | | |
20 | | class StreamCharSource; |
21 | | |
22 | | class Stream { |
23 | | public: |
24 | | friend class StreamCharSource; |
25 | | |
26 | | Stream(std::istream& input); |
27 | | Stream(const Stream&) = delete; |
28 | | Stream(Stream&&) = delete; |
29 | | Stream& operator=(const Stream&) = delete; |
30 | | Stream& operator=(Stream&&) = delete; |
31 | | ~Stream(); |
32 | | |
33 | | operator bool() const; |
34 | 778k | bool operator!() const { return !static_cast<bool>(*this); } |
35 | | |
36 | | char peek() const; |
37 | | char get(); |
38 | | std::string get(int n); |
39 | | void eat(int n = 1); |
40 | | |
41 | 342k | static char eof() { return 0x04; } |
42 | | |
43 | 1.01M | const Mark mark() const { return m_mark; } |
44 | 22.5k | int pos() const { return m_mark.pos; } |
45 | 23.4k | int line() const { return m_mark.line; } |
46 | 1.54M | int column() const { return m_mark.column; } |
47 | 8.26k | void ResetColumn() { m_mark.column = 0; } |
48 | | |
49 | | private: |
50 | | enum CharacterSet { utf8, utf16le, utf16be, utf32le, utf32be }; |
51 | | |
52 | | std::istream& m_input; |
53 | | Mark m_mark; |
54 | | |
55 | | CharacterSet m_charSet; |
56 | | mutable std::deque<char> m_readahead; |
57 | | unsigned char* const m_pPrefetched; |
58 | | mutable size_t m_nPrefetchedAvailable; |
59 | | mutable size_t m_nPrefetchedUsed; |
60 | | |
61 | | void AdvanceCurrent(); |
62 | | char CharAt(size_t i) const; |
63 | | bool ReadAheadTo(size_t i) const; |
64 | | bool _ReadAheadTo(size_t i) const; |
65 | | void StreamInUtf8() const; |
66 | | void StreamInUtf16() const; |
67 | | void StreamInUtf32() const; |
68 | | unsigned char GetNextByte() const; |
69 | | }; |
70 | | |
71 | | // CharAt |
72 | | // . Unchecked access |
73 | 9.96M | inline char Stream::CharAt(size_t i) const { return m_readahead[i]; } |
74 | | |
75 | 6.83M | inline bool Stream::ReadAheadTo(size_t i) const { |
76 | 6.83M | if (m_readahead.size() > i) |
77 | 5.87M | return true; |
78 | 956k | return _ReadAheadTo(i); |
79 | 6.83M | } |
80 | | } // namespace YAML |
81 | | |
82 | | #endif // STREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66 |