cursorstreamwrapper.h
Engine/source/persistence/rapidjson/cursorstreamwrapper.h
Classes:
class
Cursor stream wrapper for counting line and column number if error exists.
Detailed Description
1 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 32RAPIDJSON_NAMESPACE_BEGIN 33 34 35//! Cursor stream wrapper for counting line and column number if error exists. 36/*! 37 \tparam InputStream Any stream that implements Stream Concept 38*/ 39template <typename InputStream, typename Encoding = UTF8<> > 40class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> { 41public: 42 typedef typename Encoding::Ch Ch; 43 44 CursorStreamWrapper(InputStream& is): 45 GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {} 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 59 //! Get the error line number, if error exists. 60 size_t GetLine() const { return line_; } 61 //! Get the error column number, if error exists. 62 size_t GetColumn() const { return col_; } 63 64private: 65 size_t line_; //!< Current Line 66 size_t col_; //!< Current Column 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 77RAPIDJSON_NAMESPACE_END 78 79#endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 80