| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef CEREAL_RAPIDJSON_CURSORSTREAMWRAPPER_H_ |
| 16 |
#define CEREAL_RAPIDJSON_CURSORSTREAMWRAPPER_H_ |
| 17 |
|
| 18 |
#include "stream.h" |
| 19 |
|
| 20 |
#if defined(__GNUC__) |
| 21 |
CEREAL_RAPIDJSON_DIAG_PUSH |
| 22 |
CEREAL_RAPIDJSON_DIAG_OFF(effc++) |
| 23 |
#endif |
| 24 |
|
| 25 |
#if defined(_MSC_VER) && _MSC_VER <= 1800 |
| 26 |
CEREAL_RAPIDJSON_DIAG_PUSH |
| 27 |
CEREAL_RAPIDJSON_DIAG_OFF(4702) |
| 28 |
CEREAL_RAPIDJSON_DIAG_OFF(4512) |
| 29 |
#endif |
| 30 |
|
| 31 |
CEREAL_RAPIDJSON_NAMESPACE_BEGIN |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
template <typename InputStream, typename Encoding = UTF8<> > |
| 39 |
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> { |
| 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 |
Ch Take() { |
| 48 |
Ch ch = this->is_.Take(); |
| 49 |
if(ch == '\n') { |
| 50 |
line_ ++; |
| 51 |
col_ = 0; |
| 52 |
} else { |
| 53 |
col_ ++; |
| 54 |
} |
| 55 |
return ch; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
size_t GetLine() const { return line_; } |
| 60 |
|
| 61 |
size_t GetColumn() const { return col_; } |
| 62 |
|
| 63 |
private: |
| 64 |
size_t line_; |
| 65 |
size_t col_; |
| 66 |
}; |
| 67 |
|
| 68 |
#if defined(_MSC_VER) && _MSC_VER <= 1800 |
| 69 |
CEREAL_RAPIDJSON_DIAG_POP |
| 70 |
#endif |
| 71 |
|
| 72 |
#if defined(__GNUC__) |
| 73 |
CEREAL_RAPIDJSON_DIAG_POP |
| 74 |
#endif |
| 75 |
|
| 76 |
CEREAL_RAPIDJSON_NAMESPACE_END |
| 77 |
|
| 78 |
#endif |