istreamwrapper.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_ISTREAMWRAPPER_H_
20 #define RAPIDJSON_ISTREAMWRAPPER_H_
21 
22 #include <ios>
23 #include <iosfwd>
24 #include "stream.h"
25 
26 #ifdef __clang__
27 RAPIDJSON_DIAG_PUSH
28 RAPIDJSON_DIAG_OFF(padded)
29 #elif defined(_MSC_VER)
30 RAPIDJSON_DIAG_PUSH
31 RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be
32  // default initialized
33 #endif
34 
36 
38 
53 template <typename StreamType>
55  public:
56  typedef typename StreamType::char_type Ch;
57 
59 
63  : stream_(stream),
65  bufferSize_(4),
66  bufferLast_(0),
68  readCount_(0),
69  count_(0),
70  eof_(false) {
71  Read();
72  }
73 
75 
80  BasicIStreamWrapper(StreamType &stream, char *buffer, size_t bufferSize)
81  : stream_(stream),
82  buffer_(buffer),
83  bufferSize_(bufferSize),
84  bufferLast_(0),
86  readCount_(0),
87  count_(0),
88  eof_(false) {
89  RAPIDJSON_ASSERT(bufferSize >= 4);
90  Read();
91  }
92 
93  Ch Peek() const { return *current_; }
94  Ch Take() {
95  Ch c = *current_;
96  Read();
97  return c;
98  }
99  size_t Tell() const {
100  return count_ + static_cast<size_t>(current_ - buffer_);
101  }
102 
103  // Not implemented
104  void Put(Ch) { RAPIDJSON_ASSERT(false); }
105  void Flush() { RAPIDJSON_ASSERT(false); }
106  Ch *PutBegin() {
107  RAPIDJSON_ASSERT(false);
108  return 0;
109  }
110  size_t PutEnd(Ch *) {
111  RAPIDJSON_ASSERT(false);
112  return 0;
113  }
114 
115  // For encoding detection only.
116  const Ch *Peek4() const {
117  return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0;
118  }
119 
120  private:
124 
125  void Read() {
126  if (current_ < bufferLast_)
127  ++current_;
128  else if (!eof_) {
129  count_ += readCount_;
132  current_ = buffer_;
133 
134  if (!stream_.read(buffer_, static_cast<std::streamsize>(bufferSize_))) {
135  readCount_ = static_cast<size_t>(stream_.gcount());
136  *(bufferLast_ = buffer_ + readCount_) = '\0';
137  eof_ = true;
138  }
139  }
140  }
141 
144  size_t bufferSize_;
146  Ch *current_;
147  size_t readCount_;
148  size_t count_;
149  bool eof_;
150 };
151 
154 
155 #if defined(__clang__) || defined(_MSC_VER)
156 RAPIDJSON_DIAG_POP
157 #endif
158 
160 
161 #endif // RAPIDJSON_ISTREAMWRAPPER_H_
BasicIStreamWrapper< std::istream > IStreamWrapper
size_t count_
Number of characters read.
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
StreamType & stream_
BasicIStreamWrapper(StreamType &stream, char *buffer, size_t bufferSize)
Constructor.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
BasicIStreamWrapper(StreamType &stream)
Constructor.
size_t Tell() const
BasicIStreamWrapper< std::wistream > WIStreamWrapper
StreamType
Wrapper of std::basic_istream into RapidJSON&#39;s Stream concept.
const Ch * Peek4() const
BasicIStreamWrapper & operator=(const BasicIStreamWrapper &)
StreamType::char_type Ch


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46