cursorstreamwrapper.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_CURSORSTREAMWRAPPER_H_
20 #define RAPIDJSON_CURSORSTREAMWRAPPER_H_
21 
22 #include "stream.h"
23 
24 #if defined(__GNUC__)
25 RAPIDJSON_DIAG_PUSH
26 RAPIDJSON_DIAG_OFF(effc++)
27 #endif
28 
29 #if defined(_MSC_VER) && _MSC_VER <= 1800
30 RAPIDJSON_DIAG_PUSH
31 RAPIDJSON_DIAG_OFF(4702) // unreachable code
32 RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
33 #endif
34 
36 
38 
41 template <typename InputStream, typename Encoding = UTF8<>>
42 class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
43  public:
44  typedef typename Encoding::Ch Ch;
45 
46  CursorStreamWrapper(InputStream &is)
47  : GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}
48 
49  // counting line and column number
50  Ch Take() {
51  Ch ch = this->is_.Take();
52  if (ch == '\n') {
53  line_++;
54  col_ = 0;
55  } else {
56  col_++;
57  }
58  return ch;
59  }
60 
62  size_t GetLine() const { return line_; }
64  size_t GetColumn() const { return col_; }
65 
66  private:
67  size_t line_;
68  size_t col_;
69 };
70 
71 #if defined(_MSC_VER) && _MSC_VER <= 1800
72 RAPIDJSON_DIAG_POP
73 #endif
74 
75 #if defined(__GNUC__)
76 RAPIDJSON_DIAG_POP
77 #endif
78 
80 
81 #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_
Cursor stream wrapper for counting line and column number if error exists.
CursorStreamWrapper(InputStream &is)
size_t line_
Current Line.
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
size_t GetLine() const
Get the error line number, if error exists.
A Stream Wrapper.
Definition: stream.h:125
size_t GetColumn() const
Get the error column number, if error exists.
InputStream & is_
Definition: stream.h:146
size_t col_
Current Column.


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