cursorstreamwrapper.h Source File

cursorstreamwrapper.h Source File#

Composable Kernel: cursorstreamwrapper.h Source File
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.
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__)
21RAPIDJSON_DIAG_PUSH
22RAPIDJSON_DIAG_OFF(effc++)
23#endif
24
25#if defined(_MSC_VER) && _MSC_VER <= 1800
26RAPIDJSON_DIAG_PUSH
27RAPIDJSON_DIAG_OFF(4702) // unreachable code
28RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
29#endif
30
32
34
37template <typename InputStream, typename Encoding = UTF8<>>
38class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding>
39{
40 public:
41 typedef typename Encoding::Ch Ch;
42
43 CursorStreamWrapper(InputStream& is)
44 : GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0)
45 {
46 }
47
48 // counting line and column number
50 {
51 Ch ch = this->is_.Take();
52 if(ch == '\n')
53 {
54 line_++;
55 col_ = 0;
56 }
57 else
58 {
59 col_++;
60 }
61 return ch;
62 }
63
65 size_t GetLine() const { return line_; }
67 size_t GetColumn() const { return col_; }
68
69 private:
70 size_t line_;
71 size_t col_;
72};
73
74#if defined(_MSC_VER) && _MSC_VER <= 1800
75RAPIDJSON_DIAG_POP
76#endif
77
78#if defined(__GNUC__)
79RAPIDJSON_DIAG_POP
80#endif
81
83
84#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_
Encoding::Ch Ch
Definition cursorstreamwrapper.h:41
CursorStreamWrapper(InputStream &is)
Definition cursorstreamwrapper.h:43
size_t GetLine() const
Get the error line number, if error exists.
Definition cursorstreamwrapper.h:65
Ch Take()
Definition cursorstreamwrapper.h:49
size_t GetColumn() const
Get the error column number, if error exists.
Definition cursorstreamwrapper.h:67
InputStream & is_
Definition stream.h:148
GenericStreamWrapper(InputStream &is)
Definition stream.h:130
Concept for encoding of Unicode characters.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:121
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:124