File indexing completed on 2025-02-21 10:13:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
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)
0028 RAPIDJSON_DIAG_OFF(4512)
0029 #endif
0030
0031 RAPIDJSON_NAMESPACE_BEGIN
0032
0033
0034
0035
0036
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
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
0059 size_t GetLine() const { return line_; }
0060
0061 size_t GetColumn() const { return col_; }
0062
0063 private:
0064 size_t line_;
0065 size_t col_;
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