Flow 2.0.0
Flow project: Full implementation reference.
blob_fwd.hpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19#pragma once
20
21#include "flow/log/log_fwd.hpp"
22#include <memory>
23
24namespace flow::util
25{
26// Types.
27
28// Find doc headers near the bodies of these compound types.
29
30template<typename Allocator = std::allocator<uint8_t>, bool SHARING = false>
31class Basic_blob;
32template<bool SHARING = false>
33class Blob_with_log_context;
34
35struct Clear_on_alloc;
36
37/**
38 * Short-hand for a Basic_blob that allocates/deallocates in regular heap and is itself assumed to be stored
39 * in heap or on stack; sharing feature compile-time-disabled (with perf boost as a result).
40 *
41 * @see Consider also #Blob which takes a log::Logger at construction and stores it; so it is not
42 * necessary to provide one to each individual API one wants to log. It also adds logging where it is normally not
43 * possible (as of this writing at least the dtor). See Basic_blob doc header "Logging" section for brief
44 * discussion of trade-offs.
45 */
47
48/**
49 * Identical to #Blob_sans_log_context but with sharing feature compile-time-enabled. The latter fact implies
50 * a small perf hit; see details in Basic_blob doc header.
51 *
52 * @see Consider also #Sharing_blob; and see #Blob_sans_log_context similar "See" note for more info as to why.
53 */
55
56/**
57 * A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API derived from it.
58 * It is likely the user will refer to #Blob (or #Sharing_blob) rather than Blob_with_log_context.
59 *
60 * @see Also consider #Blob_sans_log_context.
61 */
63
64/**
65 * A concrete Blob_with_log_context that compile-time-enables Basic_blob::share() and the sharing API derived from it.
66 * It is likely the user will refer to #Sharing_blob (or #Blob) rather than Blob_with_log_context.
67 *
68 * @see Also consider #Sharing_blob_sans_log_context.
69 */
71
72// Constants.
73
74/// Tag value indicating init-with-zeroes-on-alloc policy.
76
77// Free functions.
78
79/**
80 * Returns `true` if and only if both given objects are not `zero() == true`, and they either co-own a common underlying
81 * buffer, or *are* the same object. Note: by the nature of Basic_blob::share(), a `true` returned value is orthogonal
82 * to whether Basic_blob::start() and Basic_blob::size() values are respectively equal; `true` may be returned even if
83 * their [`begin()`, `end()`) ranges don't overlap at all -- as long as the allocated buffer is co-owned by the 2
84 * `Basic_blob`s.
85 *
86 * If `&blob1 != &blob2`, `true` indicates `blob1` was obtained from `blob2` via a chain of Basic_blob::share() (or
87 * wrapper thereof) calls, or vice versa.
88 *
89 * @relatesalso Basic_blob
90 * @param blob1
91 * Object.
92 * @param blob2
93 * Object.
94 * @return Whether `blob1` and `blob2` both operate on the same underlying buffer.
95 */
96template<typename Allocator, bool SHARING>
98
99/**
100 * Equivalent to `blob1.swap(blob2)`.
101 *
102 * @relatesalso Basic_blob
103 * @param blob1
104 * Object.
105 * @param blob2
106 * Object.
107 * @param logger_ptr
108 * The Logger implementation to use in *this* routine (synchronously) only. Null allowed.
109 */
110template<typename Allocator, bool SHARING>
112 Basic_blob<Allocator, SHARING>& blob2, log::Logger* logger_ptr = nullptr) noexcept;
113
114/**
115 * On top of the similar Basic_blob related function, logs using the stored log context of `blob1`.
116 *
117 * @relatesalso Blob_with_log_context
118 * @param blob1
119 * See super-class related API.
120 * @param blob2
121 * See super-class related API.
122 */
123template<bool SHARING>
124void swap(Blob_with_log_context<SHARING>& blob1, Blob_with_log_context<SHARING>& blob2) noexcept;
125
126} // namespace flow::util
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Definition: log.hpp:1286
A hand-optimized and API-tweaked replacement for vector<uint8_t>, i.e., buffer of bytes inside an all...
Definition: basic_blob.hpp:276
Basic_blob that works in regular heap (and is itself placed in heap or stack) and memorizes a log::Lo...
Definition: blob.hpp:83
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
Definition: basic_blob.hpp:31
bool blobs_sharing(const Basic_blob< Allocator, SHARING > &blob1, const Basic_blob< Allocator, SHARING > &blob2)
Returns true if and only if both given objects are not zero() == true, and they either co-own a commo...
void swap(Basic_blob< Allocator, SHARING > &blob1, Basic_blob< Allocator, SHARING > &blob2, log::Logger *logger_ptr) noexcept
Equivalent to blob1.swap(blob2).
const Clear_on_alloc CLEAR_ON_ALLOC
Tag value indicating init-with-zeroes-on-alloc policy.
Definition: blob.cpp:27
Blob_with_log_context<> Blob
A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API d...
Definition: blob_fwd.hpp:62
Tag type used at least in Basic_blob and Blob_with_log_context to specify that an allocated buffer be...
Definition: basic_blob.hpp:40