Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:13:00

0001 // Tencent is pleased to support the open source community by making RapidJSON available.
0002 //
0003 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
0004 //
0005 // Licensed under the MIT License (the "License"); you may not use this file except
0006 // in compliance with the License. You may obtain a copy of the License at
0007 //
0008 // http://opensource.org/licenses/MIT
0009 //
0010 // Unless required by applicable law or agreed to in writing, software distributed
0011 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
0012 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
0013 // specific language governing permissions and limitations under the License.
0014 
0015 #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_
0016 #define RAPIDJSON_CURSORSTREAMWRAPPER_H_
0017 
0018 #include "stream.h"
0019 
0020 #if defined(__GNUC__)
0021 RAPIDJSON_DIAG_PUSH
0022 RAPIDJSON_DIAG_OFF(effc++)
0023 #endif
0024 
0025 #if defined(_MSC_VER) && _MSC_VER <= 1800
0026 RAPIDJSON_DIAG_PUSH
0027 RAPIDJSON_DIAG_OFF(4702)  // unreachable code
0028 RAPIDJSON_DIAG_OFF(4512)  // assignment operator could not be generated
0029 #endif
0030 
0031 RAPIDJSON_NAMESPACE_BEGIN
0032 
0033 
0034 //! Cursor stream wrapper for counting line and column number if error exists.
0035 /*!
0036     \tparam InputStream     Any stream that implements Stream Concept
0037 */
0038 template <typename InputStream, typename Encoding = UTF8<> >
0039 class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
0040 public:
0041     typedef typename Encoding::Ch Ch;
0042 
0043     CursorStreamWrapper(InputStream& is):
0044         GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}
0045 
0046     // counting line and column number
0047     Ch Take() {
0048         Ch ch = this->is_.Take();
0049         if(ch == '\n') {
0050             line_ ++;
0051             col_ = 0;
0052         } else {
0053             col_ ++;
0054         }
0055         return ch;
0056     }
0057 
0058     //! Get the error line number, if error exists.
0059     size_t GetLine() const { return line_; }
0060     //! Get the error column number, if error exists.
0061     size_t GetColumn() const { return col_; }
0062 
0063 private:
0064     size_t line_;   //!< Current Line
0065     size_t col_;    //!< Current Column
0066 };
0067 
0068 #if defined(_MSC_VER) && _MSC_VER <= 1800
0069 RAPIDJSON_DIAG_POP
0070 #endif
0071 
0072 #if defined(__GNUC__)
0073 RAPIDJSON_DIAG_POP
0074 #endif
0075 
0076 RAPIDJSON_NAMESPACE_END
0077 
0078 #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_