diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/common/CharReader.cpp | 23 | ||||
-rw-r--r-- | src/core/common/CharReader.hpp | 9 | ||||
-rw-r--r-- | src/core/common/Exceptions.hpp | 2 | ||||
-rw-r--r-- | src/core/common/Logger.hpp | 14 |
4 files changed, 31 insertions, 17 deletions
diff --git a/src/core/common/CharReader.cpp b/src/core/common/CharReader.cpp index 3e95280..2a4383f 100644 --- a/src/core/common/CharReader.cpp +++ b/src/core/common/CharReader.cpp @@ -336,7 +336,7 @@ size_t Buffer::seekCursor(CursorId cursor, size_t offs) const ssize_t relativeOffs = offs - currentOffs; // Perform the actual seeking, move the peek cursor to the read cursor - const ssize_t reachedOffs = currentOffs + moveCursor(cursor, relativeOffs); + const ssize_t reachedOffs = currentOffs + moveCursor(cursor, relativeOffs); // Clamp to values larger or equal to zero return reachedOffs < 0 ? 0 : reachedOffs; @@ -402,6 +402,18 @@ CharReader::CharReader(std::shared_ptr<Buffer> buffer, SourceId sourceId, { } +CharReader::CharReader(CharReader &&other) noexcept + : buffer(std::move(other.buffer)), + readCursor(other.readCursor), + peekCursor(other.peekCursor), + coherent(other.coherent), + sourceId(other.sourceId), + offs(other.offs) +{ + other.readCursor = 0; + other.peekCursor = 0; +} + CharReader::CharReader(const std::string &str, SourceId sourceId, size_t offs) : CharReader(std::shared_ptr<Buffer>{new Buffer{str}}, sourceId, offs) { @@ -468,10 +480,7 @@ bool CharReader::read(char &c) return res; } -bool CharReader::fetch(char &c) -{ - return buffer->fetch(readCursor, c); -} +bool CharReader::fetch(char &c) { return buffer->fetch(readCursor, c); } bool CharReader::fetchPeek(char &c) { @@ -541,7 +550,7 @@ size_t CharReader::readRaw(char *buf, size_t size) size_t CharReader::seek(size_t requestedOffset) { - const size_t res = buffer->seekCursor(readCursor, requestedOffset); + const size_t res = buffer->seekCursor(readCursor, requestedOffset); buffer->copyCursor(readCursor, peekCursor); coherent = true; return res; @@ -549,7 +558,7 @@ size_t CharReader::seek(size_t requestedOffset) size_t CharReader::seekPeekCursor(size_t requestedOffset) { - const size_t res = buffer->seekCursor(peekCursor, requestedOffset); + const size_t res = buffer->seekCursor(peekCursor, requestedOffset); coherent = (res == getOffset()); return res; } diff --git a/src/core/common/CharReader.hpp b/src/core/common/CharReader.hpp index a90d337..0a220ee 100644 --- a/src/core/common/CharReader.hpp +++ b/src/core/common/CharReader.hpp @@ -462,10 +462,15 @@ public: ~CharReader(); // No copy - CharReader(const Buffer &) = delete; + CharReader(const CharReader &) = delete; // No assign - CharReader &operator=(const Buffer &) = delete; + CharReader &operator=(const CharReader &) = delete; + + /** + * Move constructor. + */ + CharReader(CharReader &&) noexcept; /** * Peeks a single character. If called multiple times, returns the diff --git a/src/core/common/Exceptions.hpp b/src/core/common/Exceptions.hpp index b63c32a..337480a 100644 --- a/src/core/common/Exceptions.hpp +++ b/src/core/common/Exceptions.hpp @@ -109,7 +109,7 @@ public: * @param loc is a reference to a variable with location data. */ template <class LocationType> - LoggableException(std::string msg, LocationType loc) + LoggableException(std::string msg, const LocationType &loc) : LoggableException(std::move(msg), SourceLocation::location(loc)) { } diff --git a/src/core/common/Logger.hpp b/src/core/common/Logger.hpp index c8b324c..d2d8e80 100644 --- a/src/core/common/Logger.hpp +++ b/src/core/common/Logger.hpp @@ -280,7 +280,7 @@ public: * @param mode specifies how the message should be displayed. */ template <class LocationType> - void log(const LoggableException &ex, LocationType loc, + void log(const LoggableException &ex, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(ex, SourceLocation::location(loc), mode); @@ -297,7 +297,7 @@ public: * @param mode specifies how the message should be displayed. */ template <class LocationType> - void log(Severity severity, const std::string &msg, LocationType loc, + void log(Severity severity, const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(severity, msg, SourceLocation::location(loc), mode); @@ -328,7 +328,7 @@ public: * information. */ template <class LocationType> - void debug(const std::string &msg, LocationType loc, + void debug(const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { #ifndef NDEBUG @@ -357,7 +357,7 @@ public: * information. */ template <class LocationType> - void note(const std::string &msg, LocationType loc, + void note(const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(Severity::NOTE, msg, loc, mode); @@ -384,7 +384,7 @@ public: * information. */ template <class LocationType> - void warning(const std::string &msg, LocationType loc, + void warning(const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(Severity::WARNING, msg, SourceLocation::location(loc), mode); @@ -411,7 +411,7 @@ public: * information. */ template <class LocationType> - void error(const std::string &msg, LocationType loc, + void error(const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(Severity::ERROR, msg, SourceLocation::location(loc), mode); @@ -438,7 +438,7 @@ public: * information. */ template <class LocationType> - void fatalError(const std::string &msg, LocationType loc, + void fatalError(const std::string &msg, const LocationType &loc, MessageMode mode = MessageMode::DEFAULT) { log(Severity::FATAL_ERROR, msg, SourceLocation::location(loc), mode); |