LCOV - code coverage report
Current view: top level - boost/http_proto/detail/workspace.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 5 5
Test Date: 2024-05-23 18:56:44 Functions: 100.0 % 3 3

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
       3              : //
       4              : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       5              : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       6              : //
       7              : // Official repository: https://github.com/cppalliance/http_proto
       8              : //
       9              : 
      10              : #ifndef BOOST_HTTP_PROTO_DETAIL_WORKSPACE_HPP
      11              : #define BOOST_HTTP_PROTO_DETAIL_WORKSPACE_HPP
      12              : 
      13              : #include <boost/http_proto/detail/config.hpp>
      14              : #include <boost/http_proto/detail/except.hpp>
      15              : #include <boost/assert.hpp>
      16              : #include <cstdlib>
      17              : #include <new>
      18              : #include <utility>
      19              : #include <stddef.h> // ::max_align_t
      20              : 
      21              : namespace boost {
      22              : namespace http_proto {
      23              : namespace detail {
      24              : 
      25              : /** A contiguous buffer of storage used by algorithms.
      26              : 
      27              :     Objects of this type retain ownership of a
      28              :     contiguous buffer of storage allocated upon
      29              :     construction. This storage is divided into
      30              :     three regions:
      31              : 
      32              :     @code
      33              :     | front | free | acquired | back |
      34              :     @endcode
      35              : 
      36              :     @li The reserved area, which starts at the
      37              :         beginning of the buffer and can grow
      38              :         upwards towards the end of the buffer.
      39              : 
      40              :     @li The acquired area, which starts at the
      41              :         end of the buffer and can grow downwards
      42              :         towards the beginning of the buffer.
      43              : 
      44              :     @li The unused area, which starts from the
      45              :         end of the reserved area and stretches
      46              :         until the beginning of the acquired area.
      47              : */
      48              : class BOOST_HTTP_PROTO_DECL workspace
      49              : {
      50              :     unsigned char* begin_ = nullptr;
      51              :     unsigned char* front_ = nullptr;
      52              :     unsigned char* head_ = nullptr;
      53              :     unsigned char* back_ = nullptr;
      54              :     unsigned char* end_ = nullptr;
      55              : 
      56              :     template<class>
      57              :     struct any_impl;
      58              :     struct any;
      59              :     struct undo;
      60              : 
      61              : public:
      62              :     /** Return the number of aligned bytes required for T
      63              :     */
      64              :     template<class T>
      65              :     static
      66              :     constexpr
      67              :     std::size_t
      68              :     space_needed();
      69              : 
      70              :     /** Destructor.
      71              :     */
      72              :     ~workspace();
      73              : 
      74              :     /** Constructor.
      75              : 
      76              :         @param n The number of bytes of storage
      77              :             to allocate for the internal buffer.
      78              :     */
      79              :     explicit
      80              :     workspace(
      81              :         std::size_t n);
      82              : 
      83              :     /** Constructor.
      84              :     */
      85         1064 :     workspace() = default;
      86              : 
      87              :     /** Constructor.
      88              :     */
      89              :     workspace(workspace&&) noexcept;
      90              : 
      91              :     /** Allocate internal storage.
      92              : 
      93              :         @throws std::logic_error this->size() > 0
      94              : 
      95              :         @throws std::invalid_argument n == 0
      96              :     */
      97              :     void
      98              :     allocate(
      99              :         std::size_t n);
     100              : 
     101              :     /** Return a pointer to the unused area.
     102              :     */
     103              :     unsigned char*
     104        15819 :     data() noexcept
     105              :     {
     106        15819 :         return front_;
     107              :     }
     108              : 
     109              :     /** Return the size of the unused area.
     110              :     */
     111              :     std::size_t
     112         3567 :     size() const noexcept
     113              :     {
     114         3567 :         return head_ - front_;
     115              :     }
     116              : 
     117              :     /** Clear the contents while preserving capacity.
     118              :     */
     119              :     void
     120              :     clear() noexcept;
     121              : 
     122              :     /** Convert unused storage to reserved storage.
     123              : 
     124              :         @throws std::invalid_argument n >= this->size()
     125              :     */
     126              :     unsigned char*
     127              :     reserve_front(
     128              :         std::size_t n);
     129              : 
     130              :     template<class T, class... Args>
     131              :     typename std::decay<T>::type&
     132              :     emplace(Args&&... args);
     133              : 
     134              :     template<class T>
     135              :     T*
     136              :     push_array(
     137              :         std::size_t n,
     138              :         T const& t);
     139              : 
     140              :     unsigned char*
     141              :     reserve_back(
     142              :         std::size_t n);
     143              : 
     144              : private:
     145              :     unsigned char*
     146              :     bump_down(
     147              :         std::size_t size,
     148              :         std::size_t align);
     149              : };
     150              : 
     151              : } // detail
     152              : } // http_proto
     153              : } // boost
     154              : 
     155              : #include <boost/http_proto/detail/impl/workspace.hpp>
     156              : 
     157              : #endif
        

Generated by: LCOV version 2.1