Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ foreach (BOOST_CAPY_DEPENDENCY ${BOOST_CAPY_DEPENDENCIES})
endforeach ()
# Conditional dependencies
if (BOOST_CAPY_BUILD_TESTS)
set(BOOST_CAPY_UNIT_TEST_LIBRARIES url)
set(BOOST_CAPY_UNIT_TEST_LIBRARIES filesystem url)
endif ()
if (BOOST_CAPY_BUILD_EXAMPLES)
# set(BOOST_CAPY_EXAMPLE_LIBRARIES url)
Expand Down Expand Up @@ -140,6 +140,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_CAP
function(boost_capy_setup_properties target)
target_compile_features(${target} PUBLIC cxx_constexpr)
target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include")
target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}")
target_link_libraries(${target} PUBLIC ${BOOST_CAPY_DEPENDENCIES})
target_compile_definitions(${target} PUBLIC BOOST_CAPY_NO_LIB)
target_compile_definitions(${target} PRIVATE BOOST_CAPY_SOURCE)
Expand All @@ -161,6 +162,8 @@ if (BOOST_CAPY_MRDOCS_BUILD)
return()
endif()

# Complete dependency list

add_library(boost_capy include/boost/capy.hpp build/Jamfile ${BOOST_CAPY_HEADERS} ${BOOST_CAPY_SOURCES})
add_library(Boost::capy ALIAS boost_capy)
boost_capy_setup_properties(boost_capy)
Expand Down
28 changes: 26 additions & 2 deletions include/boost/capy/detail/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <boost/capy/detail/config.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/core/detail/string_view.hpp>
#include <boost/system/error_code.hpp>

namespace boost {
namespace capy {
Expand All @@ -21,12 +22,35 @@ namespace detail {
BOOST_CAPY_DECL void BOOST_NORETURN throw_bad_typeid(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_bad_alloc(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_invalid_argument(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_invalid_argument(
core::string_view s = "invalid argument",
char const* what,
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_length_error(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_length_error(
char const* what,
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_logic_error(
core::string_view s = "logic error",
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_out_of_range(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_runtime_error(
char const* what,
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_CAPY_DECL void BOOST_NORETURN throw_system_error(
system::error_code const& ec,
source_location const& loc = BOOST_CURRENT_LOCATION);

} // detail
Expand Down
116 changes: 116 additions & 0 deletions include/boost/capy/detail/file_posix.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//
// Copyright (c) 2022 Vinnie Falco ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/capy
//

#ifndef BOOST_CAPY_DETAIL_FILE_POSIX_HPP
#define BOOST_CAPY_DETAIL_FILE_POSIX_HPP

#include <boost/capy/detail/config.hpp>

#if ! defined(BOOST_CAPY_NO_POSIX_FILE)
# if ! defined(__APPLE__) && ! defined(__linux__) && ! defined(__FreeBSD__) && ! defined(__NetBSD__)
# define BOOST_CAPY_NO_POSIX_FILE
# endif
#endif

#if ! defined(BOOST_CAPY_USE_POSIX_FILE)
# if ! defined(BOOST_CAPY_NO_POSIX_FILE)
# define BOOST_CAPY_USE_POSIX_FILE 1
# else
# define BOOST_CAPY_USE_POSIX_FILE 0
# endif
#endif

#if BOOST_CAPY_USE_POSIX_FILE

#include <boost/capy/error.hpp>
#include <boost/capy/file_mode.hpp>
#include <boost/system/error_code.hpp>
#include <cstdint>

namespace boost {
namespace capy {
namespace detail {

// Implementation of File for POSIX systems.
class file_posix
{
int fd_ = -1;

BOOST_CAPY_DECL
static
int
native_close(int& fd);

public:
using native_handle_type = int;

BOOST_CAPY_DECL
~file_posix();

file_posix() = default;

BOOST_CAPY_DECL
file_posix(file_posix&& other) noexcept;

BOOST_CAPY_DECL
file_posix&
operator=(file_posix&& other) noexcept;

native_handle_type
native_handle() const
{
return fd_;
}

BOOST_CAPY_DECL
void
native_handle(native_handle_type fd);

bool
is_open() const
{
return fd_ != -1;
}

BOOST_CAPY_DECL
void
close(system::error_code& ec);

BOOST_CAPY_DECL
void
open(char const* path, file_mode mode, system::error_code& ec);

BOOST_CAPY_DECL
std::uint64_t
size(system::error_code& ec) const;

BOOST_CAPY_DECL
std::uint64_t
pos(system::error_code& ec) const;

BOOST_CAPY_DECL
void
seek(std::uint64_t offset, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
read(void* buffer, std::size_t n, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
write(void const* buffer, std::size_t n, system::error_code& ec);
};

} // detail
} // capy
} // boost

#endif

#endif
92 changes: 92 additions & 0 deletions include/boost/capy/detail/file_stdio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// Copyright (c) 2022 Vinnie Falco ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/capy
//

#ifndef BOOST_CAPY_DETAIL_FILE_STDIO_HPP
#define BOOST_CAPY_DETAIL_FILE_STDIO_HPP

#include <boost/capy/detail/config.hpp>
#include <boost/capy/error.hpp>
#include <boost/capy/file_mode.hpp>
#include <cstdio>
#include <cstdint>

namespace boost {
namespace capy {
namespace detail {

// Implementation of File which uses cstdio.
class file_stdio
{
std::FILE* f_ = nullptr;

public:
using native_handle_type = std::FILE*;

BOOST_CAPY_DECL
~file_stdio();

file_stdio() = default;

BOOST_CAPY_DECL
file_stdio(file_stdio&& other) noexcept;

BOOST_CAPY_DECL
file_stdio&
operator=(file_stdio&& other) noexcept;

std::FILE*
native_handle() const
{
return f_;
}

BOOST_CAPY_DECL
void
native_handle(std::FILE* f);

bool
is_open() const
{
return f_ != nullptr;
}

BOOST_CAPY_DECL
void
close(system::error_code& ec);

BOOST_CAPY_DECL
void
open(char const* path, file_mode mode, system::error_code& ec);

BOOST_CAPY_DECL
std::uint64_t
size(system::error_code& ec) const;

BOOST_CAPY_DECL
std::uint64_t
pos(system::error_code& ec) const;

BOOST_CAPY_DECL
void
seek(std::uint64_t offset, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
read(void* buffer, std::size_t n, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
write(void const* buffer, std::size_t n, system::error_code& ec);
};

} // detail
} // capy
} // boost

#endif
106 changes: 106 additions & 0 deletions include/boost/capy/detail/file_win32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Copyright (c) 2022 Vinnie Falco ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/capy
//

#ifndef BOOST_CAPY_DETAIL_FILE_WIN32_HPP
#define BOOST_CAPY_DETAIL_FILE_WIN32_HPP

#include <boost/capy/detail/config.hpp>

#if ! defined(BOOST_CAPY_USE_WIN32_FILE)
# ifdef _WIN32
# define BOOST_CAPY_USE_WIN32_FILE 1
# else
# define BOOST_CAPY_USE_WIN32_FILE 0
# endif
#endif

#if BOOST_CAPY_USE_WIN32_FILE

#include <boost/capy/error.hpp>
#include <boost/capy/file_mode.hpp>
#include <boost/winapi/handles.hpp>
#include <cstdint>

namespace boost {
namespace capy {
namespace detail {

// Implementation of File for Win32.
class file_win32
{
boost::winapi::HANDLE_ h_ =
boost::winapi::INVALID_HANDLE_VALUE_;

public:
using native_handle_type = boost::winapi::HANDLE_;

BOOST_CAPY_DECL
~file_win32();

file_win32() = default;

BOOST_CAPY_DECL
file_win32(file_win32&& other) noexcept;

BOOST_CAPY_DECL
file_win32&
operator=(file_win32&& other) noexcept;

native_handle_type
native_handle()
{
return h_;
}

BOOST_CAPY_DECL
void
native_handle(native_handle_type h);

bool
is_open() const
{
return h_ != boost::winapi::INVALID_HANDLE_VALUE_;
}

BOOST_CAPY_DECL
void
close(system::error_code& ec);

BOOST_CAPY_DECL
void
open(char const* path, file_mode mode, system::error_code& ec);

BOOST_CAPY_DECL
std::uint64_t
size(system::error_code& ec) const;

BOOST_CAPY_DECL
std::uint64_t
pos(system::error_code& ec) const;

BOOST_CAPY_DECL
void
seek(std::uint64_t offset, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
read(void* buffer, std::size_t n, system::error_code& ec);

BOOST_CAPY_DECL
std::size_t
write(void const* buffer, std::size_t n, system::error_code& ec);
};

} // detail
} // capy
} // boost

#endif

#endif
Loading
Loading