Skip to content

Commit 4b00a36

Browse files
committed
refactor: migrate from Boost.Buffers to Boost.Capy.Buffers
- Remove Boost::buffers dependency from CMakeLists.txt and Jamfile - Change all includes from boost/buffers/ to boost/capy/buffers/ - Replace buffers:: namespace with capy:: throughout codebase - Rename buffers::size() to capy::buffer_size() - Rename buffers::dynamic_for() to capy::make_any() - Add dynamic_buffer_ref wrapper in impl/parser.hpp for reference semantics - Update test files to use new capy buffer types and functions - Add .temp/ to .gitignore for build outputs
1 parent dd11df6 commit 4b00a36

37 files changed

+417
-304
lines changed

.cursor/rules/build-outputs.mdc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
description: Build outputs must go in .temp directory
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# Build Output Directory Policy
8+
9+
**All build artifacts, intermediate files, and temporary outputs MUST go in the `.temp/` directory.**
10+
11+
## Required Directory Structure
12+
13+
- `.temp/build-msvc/` - MSVC/Visual Studio builds
14+
- `.temp/build-gcc/` - GCC builds (via MSYS2)
15+
- `.temp/build-clang/` - Clang builds
16+
- `.temp/build-ninja/` - Ninja builds
17+
- `.temp/` - Any other temporary or generated files
18+
19+
## Rules
20+
21+
1. **Never create executables, object files, or build artifacts in source directories**
22+
2. **Never commit anything from `.temp/`** - it is in `.gitignore`
23+
3. When configuring CMake, always use `-B .temp/build-<compiler>`
24+
4. When running direct compiler commands, output to `.temp/build-<compiler>/`
25+
26+
## Example Commands
27+
28+
### CMake (MSVC)
29+
```powershell
30+
cmake -B .temp/build-msvc -G "Visual Studio 18 2026" -A x64
31+
cmake --build .temp/build-msvc --config Release
32+
```
33+
34+
### CMake (GCC via MSYS2)
35+
```bash
36+
cmake -B .temp/build-gcc -G "Unix Makefiles"
37+
cmake --build .temp/build-gcc
38+
```
39+
40+
### Direct GCC compilation
41+
```bash
42+
mkdir -p .temp/build-gcc
43+
g++ -std=c++20 -O3 src/main.cpp -o .temp/build-gcc/main.exe
44+
```
45+
46+
### Direct MSVC compilation
47+
```powershell
48+
New-Item -ItemType Directory -Force -Path .temp/build-msvc
49+
cl /std:c++20 /O2 src/main.cpp /Fe:.temp/build-msvc/main.exe
50+
```

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ temp
2020
/.cache
2121
/.clangd
2222
/compile_commands.json
23+
24+
/.temp
25+

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ set(BOOST_SRC_DIR ${DEFAULT_BOOST_SRC_DIR} CACHE STRING "Boost source dir to use
5555
# The boost super-project requires one explicit dependency per-line.
5656
set(BOOST_HTTP_DEPENDENCIES
5757
Boost::assert
58-
Boost::buffers
5958
Boost::capy
6059
Boost::config
6160
Boost::core
@@ -122,7 +121,7 @@ if (BOOST_HTTP_IS_ROOT)
122121
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${BOOST_SRC_DIR}/tools/cmake/include")
123122
else ()
124123
# From Boost Package
125-
find_package(Boost REQUIRED COMPONENTS buffers filesystem json url)
124+
find_package(Boost REQUIRED COMPONENTS filesystem json url)
126125
foreach (BOOST_INCLUDE_LIBRARY ${BOOST_INCLUDE_LIBRARIES})
127126
if (NOT TARGET Boost::${BOOST_INCLUDE_LIBRARY})
128127
add_library(Boost::${BOOST_INCLUDE_LIBRARY} ALIAS Boost::headers)

build/Jamfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ explicit http_sources ;
3939
lib boost_http
4040
: http_sources
4141
: requirements
42-
<library>/boost//buffers
4342
<library>/boost//capy
4443
<library>/boost/json//boost_json/<warnings-as-errors>off
4544
<library>/boost//url
4645
<include>../
4746
<define>BOOST_HTTP_SOURCE
4847
: usage-requirements
49-
<library>/boost//buffers
5048
<library>/boost//capy
5149
<library>/boost/json//boost_json/<warnings-as-errors>off
5250
<library>/boost//url

include/boost/http/file_sink.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class file_sink
6868
BOOST_HTTP_DECL
6969
results
7070
on_write(
71-
buffers::const_buffer, bool) override;
71+
capy::const_buffer, bool) override;
7272
};
7373

7474
} // http

include/boost/http/file_source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class file_source
7878
BOOST_HTTP_DECL
7979
results
8080
on_read(
81-
buffers::mutable_buffer b) override;
81+
capy::mutable_buffer b) override;
8282
};
8383

8484
} // http

include/boost/http/impl/parser.hpp

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,69 @@
2020

2121
namespace boost {
2222
namespace http {
23+
namespace detail {
24+
25+
// A wrapper that provides reference semantics for dynamic buffers
26+
// while satisfying the dynamic_buffer concept
27+
template<class DynamicBuffer>
28+
class dynamic_buffer_ref
29+
{
30+
DynamicBuffer* p_;
31+
32+
public:
33+
using const_buffers_type = typename DynamicBuffer::const_buffers_type;
34+
using mutable_buffers_type = typename DynamicBuffer::mutable_buffers_type;
35+
36+
explicit
37+
dynamic_buffer_ref(DynamicBuffer& b) noexcept
38+
: p_(&b)
39+
{
40+
}
41+
42+
std::size_t
43+
size() const noexcept
44+
{
45+
return p_->size();
46+
}
47+
48+
std::size_t
49+
max_size() const noexcept
50+
{
51+
return p_->max_size();
52+
}
53+
54+
std::size_t
55+
capacity() const noexcept
56+
{
57+
return p_->capacity();
58+
}
59+
60+
const_buffers_type
61+
data() const noexcept
62+
{
63+
return p_->data();
64+
}
65+
66+
mutable_buffers_type
67+
prepare(std::size_t n)
68+
{
69+
return p_->prepare(n);
70+
}
71+
72+
void
73+
commit(std::size_t n)
74+
{
75+
p_->commit(n);
76+
}
77+
78+
void
79+
consume(std::size_t n)
80+
{
81+
p_->consume(n);
82+
}
83+
};
84+
85+
} // detail
2386

2487
template<class ElasticBuffer>
2588
typename std::enable_if<
@@ -39,7 +102,7 @@ set_body(
39102

40103
// Check ElasticBuffer type requirements
41104
static_assert(
42-
buffers::is_dynamic_buffer<ElasticBuffer>::value,
105+
capy::is_dynamic_buffer<ElasticBuffer>::value,
43106
"Type requirements not met.");
44107

45108
// body must not already be set
@@ -51,7 +114,7 @@ set_body(
51114
detail::throw_logic_error();
52115

53116
auto& dyn = ws().emplace<
54-
buffers::any_dynamic_buffer_impl<typename
117+
capy::any_dynamic_buffer_impl<typename
55118
std::decay<ElasticBuffer>::type,
56119
buffers_N>>(std::forward<ElasticBuffer>(eb));
57120

@@ -66,7 +129,7 @@ set_body(
66129
{
67130
// Check ElasticBuffer type requirements
68131
static_assert(
69-
buffers::is_dynamic_buffer<ElasticBuffer>::value,
132+
capy::is_dynamic_buffer<ElasticBuffer>::value,
70133
"Type requirements not met.");
71134

72135
// body must not already be set
@@ -77,10 +140,11 @@ set_body(
77140
if(! got_header())
78141
detail::throw_logic_error();
79142

143+
// Use dynamic_buffer_ref to provide reference semantics
80144
auto& dyn = ws().emplace<
81-
buffers::any_dynamic_buffer_impl<typename
82-
std::decay<ElasticBuffer>::type&,
83-
buffers_N>>(eb);
145+
capy::any_dynamic_buffer_impl<
146+
detail::dynamic_buffer_ref<ElasticBuffer>,
147+
buffers_N>>(eb.get());
84148

85149
set_body_impl(dyn);
86150
}

include/boost/http/impl/serializer.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class serializer::cbs_gen
2828
// Return the next non-empty buffer or an
2929
// empty buffer if none remain.
3030
virtual
31-
buffers::const_buffer
31+
capy::const_buffer
3232
next() = 0;
3333

3434
// Return the total size and count of
@@ -48,27 +48,27 @@ template<class ConstBufferSequence>
4848
class serializer::cbs_gen_impl
4949
: public cbs_gen
5050
{
51-
using it_t = decltype(buffers::begin(
51+
using it_t = decltype(capy::begin(
5252
std::declval<ConstBufferSequence>()));
5353

5454
ConstBufferSequence cbs_;
5555
it_t curr_;
5656

5757
public:
5858
using const_buffer =
59-
buffers::const_buffer;
59+
capy::const_buffer;
6060

6161
explicit
6262
cbs_gen_impl(ConstBufferSequence cbs)
6363
: cbs_(std::move(cbs))
64-
, curr_(buffers::begin(cbs_))
64+
, curr_(capy::begin(cbs_))
6565
{
6666
}
6767

6868
const_buffer
6969
next() override
7070
{
71-
while(curr_ != buffers::end(cbs_))
71+
while(curr_ != capy::end(cbs_))
7272
{
7373
// triggers conversion operator
7474
const_buffer buf = *curr_++;
@@ -82,7 +82,7 @@ class serializer::cbs_gen_impl
8282
stats() const override
8383
{
8484
stats_t r;
85-
for(auto it = curr_; it != buffers::end(cbs_); ++it)
85+
for(auto it = curr_; it != capy::end(cbs_); ++it)
8686
{
8787
// triggers conversion operator
8888
const_buffer buf = *it;
@@ -98,7 +98,7 @@ class serializer::cbs_gen_impl
9898
bool
9999
is_empty() const override
100100
{
101-
for(auto it = curr_; it != buffers::end(cbs_); ++it)
101+
for(auto it = curr_; it != capy::end(cbs_); ++it)
102102
{
103103
// triggers conversion operator
104104
const_buffer buf = *it;
@@ -120,8 +120,8 @@ start(
120120
message_base const& m,
121121
ConstBufferSequence&& cbs)
122122
{
123-
static_assert(buffers::is_const_buffer_sequence<
124-
ConstBufferSequence>::value,
123+
static_assert(
124+
capy::const_buffer_sequence<ConstBufferSequence>,
125125
"ConstBufferSequence type requirements not met");
126126

127127
start_init(m);

include/boost/http/impl/sink.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#ifndef BOOST_HTTP_IMPL_SINK_HPP
1111
#define BOOST_HTTP_IMPL_SINK_HPP
1212

13-
#include <boost/buffers/buffer.hpp>
14-
#include <boost/buffers/range.hpp>
13+
#include <boost/capy/buffers.hpp>
14+
#include <boost/capy/buffers/range.hpp>
1515
#include <boost/http/detail/except.hpp>
1616
#include <boost/assert.hpp>
1717

@@ -44,10 +44,10 @@ write_impl(
4444
{
4545
results rv;
4646
constexpr int SmallArraySize = 16;
47-
buffers::const_buffer tmp[SmallArraySize];
47+
capy::const_buffer tmp[SmallArraySize];
4848
auto const tmp_end = tmp + SmallArraySize;
49-
auto it = buffers::begin(bs);
50-
auto const end_ = buffers::end(bs);
49+
auto it = capy::begin(bs);
50+
auto const end_ = capy::end(bs);
5151
while(it != end_)
5252
{
5353
auto p = tmp;
@@ -59,7 +59,7 @@ write_impl(
5959
p != tmp_end &&
6060
it != end_);
6161
rv += on_write(boost::span<
62-
buffers::const_buffer const>(
62+
capy::const_buffer const>(
6363
tmp, p - tmp),
6464
it != end_ || more);
6565
if(rv.ec.failed())

include/boost/http/impl/source.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ read_impl(
4343
{
4444
results rv;
4545
constexpr int SmallArraySize = 16;
46-
buffers::mutable_buffer tmp[SmallArraySize];
46+
capy::mutable_buffer tmp[SmallArraySize];
4747
auto const tmp_end =
4848
tmp + SmallArraySize;
49-
auto it = buffers::begin(bs);
50-
auto const end_ = buffers::end(bs);
49+
auto it = capy::begin(bs);
50+
auto const end_ = capy::end(bs);
5151
while(it != end_)
5252
{
5353
auto p = tmp;
@@ -59,7 +59,7 @@ read_impl(
5959
p != tmp_end &&
6060
it != end_);
6161
rv += on_read(boost::span<
62-
buffers::mutable_buffer const>(
62+
capy::mutable_buffer const>(
6363
tmp, p - tmp));
6464
if(rv.ec.failed())
6565
return rv;

0 commit comments

Comments
 (0)