cursorstreamwrapper.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON available.
2 //
3 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4 //
5 // Licensed under the MIT License (the "License"); you may not use this file except
6 // in compliance with the License. You may obtain a copy of the License at
7 //
8 // http://opensource.org/licenses/MIT
9 //
10 // Unless required by applicable law or agreed to in writing, software distributed
11 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13 // specific language governing permissions and limitations under the License.
14 
15 #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_
16 #define RAPIDJSON_CURSORSTREAMWRAPPER_H_
17 
18 #include "stream.h"
19 
20 #if defined(__GNUC__)
21 RAPIDJSON_DIAG_PUSH
22 RAPIDJSON_DIAG_OFF(effc++)
23 #endif
24 
25 #if defined(_MSC_VER) && _MSC_VER <= 1800
26 RAPIDJSON_DIAG_PUSH
27 RAPIDJSON_DIAG_OFF(4702) // unreachable code
28 RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
29 #endif
30 
32 
34 
37 template <typename InputStream, typename Encoding = UTF8<> >
38 class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding>
39 {
40 public:
41  typedef typename Encoding::Ch Ch;
42 
43  CursorStreamWrapper(InputStream& is) : GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0)
44  {
45  }
46 
47  // counting line and column number
48  Ch Take()
49  {
50  Ch ch = this->is_.Take();
51  if (ch == '\n')
52  {
53  line_++;
54  col_ = 0;
55  }
56  else
57  {
58  col_++;
59  }
60  return ch;
61  }
62 
64  size_t GetLine() const
65  {
66  return line_;
67  }
69  size_t GetColumn() const
70  {
71  return col_;
72  }
73 
74 private:
75  size_t line_;
76  size_t col_;
77 };
78 
79 #if defined(_MSC_VER) && _MSC_VER <= 1800
80 RAPIDJSON_DIAG_POP
81 #endif
82 
83 #if defined(__GNUC__)
84 RAPIDJSON_DIAG_POP
85 #endif
86 
88 
89 #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:126
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
size_t GetLine() const
Get the error line number, if error exists.
A Stream Wrapper.
Definition: stream.h:126
size_t GetColumn() const
Get the error column number, if error exists.
InputStream & is_
Definition: stream.h:180
size_t col_
Current Column.


xbot_talker
Author(s): wangxiaoyun
autogenerated on Sat Oct 10 2020 03:27:53