Skip to content

Commit

Permalink
Move bytes.hpp into core
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMax committed Dec 26, 2023
1 parent 7ff2270 commit a864ae8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 55 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ project(lexio LANGUAGES C CXX)

set(LEXIO_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/include/lexio/bufreader.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lexio/bytes.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lexio/core.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lexio/lexio.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/lexio/ref.hpp"
Expand Down
50 changes: 0 additions & 50 deletions include/lexio/bytes.hpp

This file was deleted.

20 changes: 20 additions & 0 deletions include/lexio/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ inline size_t Read(uint8_t (&outArray)[N], READER &reader)
return reader.LexRead(&outArray[0], N);
}

template <typename READER, typename IT, typename = std::enable_if_t<IsReaderV<READER>>>
inline size_t Read(IT outStart, IT outEnd, READER &reader)
{
const size_t count = std::distance(outStart, outEnd);
return reader.LexRead(&(*outStart), count, reader);
}

/**
* @brief Fill the internal buffer of data to the requested size without
* advancing the offset. If EOF is encountered, the rest of the
Expand Down Expand Up @@ -387,6 +394,19 @@ inline size_t Write(WRITER &writer, const uint8_t *src, const size_t count)
return writer.LexWrite(src, count);
}

template <typename WRITER, size_t N, typename = std::enable_if_t<IsWriterV<WRITER>>>
inline size_t Write(WRITER &writer, uint8_t (&array)[N])
{
return writer.LexWrite(&array[0], N);
}

template <typename WRITER, typename IT, typename = std::enable_if_t<IsWriterV<WRITER>>>
inline size_t Write(WRITER &writer, IT start, IT end)
{
const size_t count = std::distance(start, end);
return Write<WRITER>(writer, &(*start), count);
}

/**
* @brief Flushes data to underlying storage. Can be a no-op.
*
Expand Down
1 change: 0 additions & 1 deletion include/lexio/lexio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "./core.hpp"

#include "./bufreader.hpp"
#include "./bytes.hpp"
#include "./ref.hpp"
#include "./serialize.hpp"
#include "./stream.hpp"
2 changes: 0 additions & 2 deletions include/lexio/stream/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

#include "../core.hpp"

#include <vector> // Used by StdBufReader

namespace LexIO
{

Expand Down
2 changes: 1 addition & 1 deletion tests/test_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST_CASE("Test file opened in read mode")

// Test writing.
uint8_t writeBuffer[32] = {0x00};
REQUIRE_THROWS(LexIO::WriteBytes(file, writeBuffer));
REQUIRE_THROWS(LexIO::Write(file, writeBuffer));

// Test seeking.
size_t pos = LexIO::Seek(file, 2, LexIO::Whence::start);
Expand Down

0 comments on commit a864ae8

Please sign in to comment.