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