Commit 7890a1b1 authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

StreamLocalCopy: move to reader.h

Eventually move to internal header `internal/streamcopy.h`?

Based on 088e8173.
parent f6903f79
......@@ -209,31 +209,6 @@ struct StreamTraits {
enum { copyOptimization = 0 };
};
template<typename Stream, bool = StreamTraits<Stream>::copyOptimization>
class StreamLocalCopy;
template<typename Stream>
class StreamLocalCopy<Stream, 1> {
public:
StreamLocalCopy(Stream& original) : s(original), original_(original) {}
~StreamLocalCopy() { original_ = s; }
Stream s; //!< copy
private:
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
Stream& original_;
};
template<typename Stream>
class StreamLocalCopy<Stream, 0> {
public:
StreamLocalCopy(Stream& original) : s(original) {}
Stream& s; //!< reference
private:
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
};
//! Put N copies of a character to a stream.
template<typename Stream, typename Ch>
inline void PutN(Stream& stream, Ch c, size_t n) {
......
......@@ -126,6 +126,43 @@ struct BaseReaderHandler {
void EndArray(SizeType) { Default(); }
};
///////////////////////////////////////////////////////////////////////////////
// StreamLocalCopy
namespace internal {
template<typename Stream, int = StreamTraits<Stream>::copyOptimization>
class StreamLocalCopy;
//! Do copy optimziation.
template<typename Stream>
class StreamLocalCopy<Stream, 1> {
public:
StreamLocalCopy(Stream& original) : s(original), original_(original) {}
~StreamLocalCopy() { original_ = s; }
Stream s;
private:
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
Stream& original_;
};
//! Keep reference.
template<typename Stream>
class StreamLocalCopy<Stream, 0> {
public:
StreamLocalCopy(Stream& original) : s(original) {}
Stream& s;
private:
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
};
} // namespace internal
///////////////////////////////////////////////////////////////////////////////
// SkipWhitespace
......@@ -135,7 +172,7 @@ struct BaseReaderHandler {
*/
template<typename InputStream>
void SkipWhitespace(InputStream& is) {
StreamLocalCopy<InputStream> copy(is);
internal::StreamLocalCopy<InputStream> copy(is);
InputStream& s(copy.s);
while (s.Peek() == ' ' || s.Peek() == '\n' || s.Peek() == '\r' || s.Peek() == '\t')
......@@ -450,7 +487,7 @@ private:
// Parse string and generate String event. Different code paths for kParseInsituFlag.
template<unsigned parseFlags, typename InputStream, typename Handler>
void ParseString(InputStream& is, Handler& handler) {
StreamLocalCopy<InputStream> copy(is);
internal::StreamLocalCopy<InputStream> copy(is);
InputStream& s(copy.s);
if (parseFlags & kParseInsituFlag) {
......@@ -531,7 +568,7 @@ private:
template<unsigned parseFlags, typename InputStream, typename Handler>
void ParseNumber(InputStream& is, Handler& handler) {
StreamLocalCopy<InputStream> copy(is);
internal::StreamLocalCopy<InputStream> copy(is);
InputStream& s(copy.s);
// Parse minus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment