LCOV - code coverage report
Current view: top level - http_proto - fields_view_base.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 10 10 100.0 %
Date: 2023-01-15 07:18:31 Functions: 4 4 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot 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_FIELDS_VIEW_BASE_HPP
      11             : #define BOOST_HTTP_PROTO_FIELDS_VIEW_BASE_HPP
      12             : 
      13             : #include <boost/http_proto/detail/config.hpp>
      14             : #include <boost/http_proto/detail/header.hpp>
      15             : #include <boost/url/grammar/recycled.hpp>
      16             : #include <boost/url/grammar/type_traits.hpp>
      17             : #include <iterator>
      18             : #include <memory>
      19             : #include <string>
      20             : 
      21             : namespace boost {
      22             : namespace http_proto {
      23             : 
      24             : /** A read-only, bidirectional range of HTTP fields
      25             : 
      26             :     This is a mix-in used to add common
      27             :     functionality to derived classes.
      28             : */
      29             : class BOOST_SYMBOL_VISIBLE
      30             :     fields_view_base
      31             : {
      32             :     detail::header const* ph_;
      33             : 
      34             :     friend class fields;
      35             :     friend class fields_base;
      36             :     friend class fields_view;
      37             :     friend class message_base;
      38             :     friend class message_view_base;
      39             :     friend class request;
      40             :     friend class request_view;
      41             :     friend class response;
      42             :     friend class response_view;
      43             :     friend class serializer;
      44             : 
      45             :     explicit
      46         518 :     fields_view_base(
      47             :         detail::header const* ph) noexcept
      48         518 :         : ph_(ph)
      49             :     {
      50         518 :     }
      51             : 
      52             :     fields_view_base(
      53             :         fields_view_base const&) = default;
      54             :     fields_view_base&
      55             :         operator=(fields_view_base const&) = default;
      56             : 
      57             : public:
      58             :     //--------------------------------------------
      59             :     //
      60             :     // Types
      61             :     //
      62             :     //--------------------------------------------
      63             : 
      64             :     /** A field
      65             :     */
      66             :     /**@{*/
      67             :     struct reference
      68             :     {
      69             :         field const id;
      70             :         string_view const name;
      71             :         string_view const value;
      72             : 
      73             :     #ifndef BOOST_HTTP_PROTO_DOCS
      74             :         reference const*
      75        2600 :         operator->() const noexcept
      76             :         {
      77        2600 :             return this;
      78             :         }
      79             :     #endif
      80             :     };
      81             : 
      82             :     typedef reference const_reference;
      83             :     /**@}*/
      84             :  
      85             :     /** A type which can represent a field as a value
      86             : 
      87             :         This type allows for making a copy of
      88             :         a field where ownership is retained
      89             :         in the copy.
      90             :     */
      91             :     struct value_type
      92             :     {
      93             :         field id;
      94             :         std::string name;
      95             :         std::string value;
      96             : 
      97             :         BOOST_HTTP_PROTO_DECL
      98             :         value_type(
      99             :             reference const& other);
     100             : 
     101             :         operator reference() const noexcept;
     102             :     };
     103             : 
     104             :     /** An unsigned integer type
     105             :     */
     106             :     using size_type = std::size_t;
     107             : 
     108             :     /** A signed integer type
     109             :     */
     110             :     using difference_type =
     111             :         std::ptrdiff_t;
     112             : 
     113             :     /** A bidirectional iterator to HTTP fields
     114             :     */
     115             :     /**@{*/
     116             : #ifdef BOOST_HTTP_PROTO_DOCS
     117             :     using iterator = __see_below__;
     118             : #else
     119             :     class iterator;
     120             : #endif
     121             : 
     122             :     using const_iterator = iterator;
     123             :     /**@}*/
     124             : 
     125             :     /** A bidirectional reverse iterator to HTTP fields
     126             :     */
     127             :     /**@{*/
     128             : #ifdef BOOST_HTTP_PROTO_DOCS
     129             :     using reverse_iterator = __see_below__;
     130             : #else
     131             :     class reverse_iterator;
     132             : #endif
     133             : 
     134             :     using const_reverse_iterator = reverse_iterator;
     135             :     /**@}*/
     136             : 
     137             :     /** A forward range of matching fields
     138             : 
     139             :         Objects of this type are returned by
     140             :         the function @ref find_all.
     141             :     */
     142             : #ifdef BOOST_HTTP_PROTO_DOCS
     143             :     using subrange = __see_below__;
     144             : #else
     145             :     class subrange;
     146             : #endif
     147             : 
     148             :     //--------------------------------------------
     149             :     //
     150             :     // Observers
     151             :     //
     152             :     //--------------------------------------------
     153             : 
     154             :     /** Returns the largest possible serialized message
     155             :     */
     156             :     static
     157             :     constexpr
     158             :     std::size_t
     159             :     max_size() noexcept
     160             :     {
     161             :         return max_off_t;
     162             :     }
     163             : 
     164             :     /** Return an iterator to the beginning
     165             :     */
     166             :     iterator
     167             :     begin() const noexcept;
     168             : 
     169             :     /** Return an iterator to the end
     170             :     */
     171             :     iterator
     172             :     end() const noexcept;
     173             : 
     174             :     /** Return a reverse iterator to the beginning
     175             :     */
     176             :     reverse_iterator
     177             :     rbegin() const noexcept;
     178             : 
     179             :     /** Return a reverse iterator to the end
     180             :     */
     181             :     reverse_iterator
     182             :     rend() const noexcept;
     183             : 
     184             :     //---
     185             : 
     186             :     /** Return a string representing the serialized data
     187             :     */
     188             :     string_view
     189         388 :     buffer() const noexcept
     190             :     {
     191         776 :         return string_view(
     192         388 :             ph_->cbuf, ph_->size);
     193             :     }
     194             : 
     195             :     /** Returns the number of fields in the container
     196             :     */
     197             :     std::size_t
     198         537 :     size() const noexcept
     199             :     {
     200         537 :         return ph_->count;
     201             :     }
     202             : 
     203             :     /** Return true if a field exists
     204             :     */
     205             :     BOOST_HTTP_PROTO_DECL
     206             :     bool
     207             :     exists(field id) const noexcept;
     208             : 
     209             :     /** Return true if a field exists
     210             :     */
     211             :     BOOST_HTTP_PROTO_DECL
     212             :     bool
     213             :     exists(string_view name) const noexcept;
     214             : 
     215             :     /** Return the number of matching fields
     216             :     */
     217             :     BOOST_HTTP_PROTO_DECL
     218             :     std::size_t
     219             :     count(field id) const noexcept;
     220             : 
     221             :     /** Return the number of matching fields
     222             :     */
     223             :     BOOST_HTTP_PROTO_DECL
     224             :     std::size_t
     225             :     count(string_view name) const noexcept;
     226             : 
     227             :     /** Returns an iterator to the matching element if it exists
     228             :     */
     229             :     BOOST_HTTP_PROTO_DECL
     230             :     iterator
     231             :     find(field id) const noexcept;
     232             : 
     233             :     /** Returns an iterator to the matching element if it exists
     234             : 
     235             :         If `name` refers to a known field, it is faster
     236             :         to call @ref find with a field id instead of a
     237             :         string.
     238             :     */
     239             :     BOOST_HTTP_PROTO_DECL
     240             :     iterator
     241             :     find(string_view name) const noexcept;
     242             : 
     243             :     /** Returns an iterator to the matching element if it exists
     244             :     */
     245             :     BOOST_HTTP_PROTO_DECL
     246             :     iterator
     247             :     find(
     248             :         iterator from,
     249             :         field id) const noexcept;
     250             : 
     251             :     /** Returns an iterator to the matching element if it exists
     252             :     */
     253             :     BOOST_HTTP_PROTO_DECL
     254             :     iterator
     255             :     find(
     256             :         iterator from, 
     257             :         string_view name) const noexcept;
     258             : 
     259             :     /** Returns an iterator to the matching element if it exists
     260             :     */
     261             :     BOOST_HTTP_PROTO_DECL
     262             :     iterator
     263             :     find_last(
     264             :         iterator before,
     265             :         field id) const noexcept;
     266             : 
     267             :     /** Returns an iterator to the matching element if it exists
     268             :     */
     269             :     BOOST_HTTP_PROTO_DECL
     270             :     iterator
     271             :     find_last(
     272             :         iterator before, 
     273             :         string_view name) const noexcept;
     274             : 
     275             :     /** Return the value of a field
     276             :     */
     277             :     BOOST_HTTP_PROTO_DECL
     278             :     string_view
     279             :     value_or(
     280             :         field id,
     281             :         string_view s) const noexcept;
     282             : 
     283             :     /** Return the value of a field
     284             :     */
     285             :     BOOST_HTTP_PROTO_DECL
     286             :     string_view
     287             :     value_or(
     288             :         string_view name,
     289             :         string_view s) const noexcept;
     290             : 
     291             :     //---
     292             : 
     293             :     /** Return a forward range containing values for all matching fields
     294             :     */
     295             :     BOOST_HTTP_PROTO_DECL
     296             :     subrange
     297             :     find_all(field id) const noexcept;
     298             : 
     299             :     /** Return a forward range containing values for all matching fields
     300             :     */
     301             :     BOOST_HTTP_PROTO_DECL
     302             :     subrange
     303             :     find_all(string_view name) const noexcept;
     304             : };
     305             : 
     306             : } // http_proto
     307             : } // boost
     308             : 
     309             : #include <boost/http_proto/impl/fields_view_base.hpp>
     310             : 
     311             : #endif

Generated by: LCOV version 1.15