Flow 1.0.2
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 S_SHARING_ALLOWED = false>
31class Basic_blob;
32template<bool S_SHARING_ALLOWED = false>
33class Blob_with_log_context;
34
35/**
36 * Short-hand for a Basic_blob that allocates/deallocates in regular heap and is itself assumed to be stored
37 * in heap or on stack; sharing feature compile-time-disabled (with perf boost as a result).
38 *
39 * @see Consider also #Blob which takes a log::Logger at construction and stores it; so it is not
40 * necessary to provide one to each individual API one wants to log. It also adds logging where it is normally not
41 * possible (as of this writing at least the dtor). See Basic_blob doc header "Logging" section for brief
42 * discussion of trade-offs.
43 */
45
46/**
47 * Identical to #Blob_sans_log_context but with sharing feature compile-time-enabled. The latter fact implies
48 * a small perf hit; see details in Basic_blob doc header.
49 *
50 * @see Consider also #Sharing_blob; and see #Blob_sans_log_context similar "See" note for more info as to why.
51 */
53
54/**
55 * A concrete Blob_with_log_context that compile-time-disables Basic_blob::share() and the sharing API derived from it.
56 * It is likely the user will refer to #Blob (or #Sharing_blob) rather than Blob_with_log_context.
57 *
58 * @see Also consider #Blob_sans_log_context.
59 */
61
62/**
63 * A concrete Blob_with_log_context that compile-time-enables Basic_blob::share() and the sharing API derived from it.
64 * It is likely the user will refer to #Sharing_blob (or #Blob) rather than Blob_with_log_context.
65 *
66 * @see Also consider #Sharing_blob_sans_log_context.
67 */
69
70// Free functions.
71
72/**
73 * Returns `true` if and only if both given objects are not `zero() == true`, and they either co-own a common underlying
74 * buffer, or *are* the same object. Note: by the nature of Basic_blob::share(), a `true` returned value is orthogonal
75 * to whether Basic_blob::start() and Basic_blob::size() values are respectively equal; `true` may be returned even if
76 * their [`begin()`, `end()`) ranges don't overlap at all -- as long as the allocated buffer is co-owned by the 2
77 * `Basic_blob`s.
78 *
79 * If `&blob1 != &blob2`, `true` indicates `blob1` was obtained from `blob2` via a chain of Basic_blob::share() (or
80 * wrapper thereof) calls, or vice versa.
81 *
82 * @relatesalso Basic_blob
83 * @param blob1
84 * Object.
85 * @param blob2
86 * Object.
87 * @return Whether `blob1` and `blob2` both operate on the same underlying buffer.
88 */
89template<typename Allocator, bool S_SHARING_ALLOWED>
92
93/**
94 * Equivalent to `blob1.swap(blob2)`.
95 *
96 * @relatesalso Basic_blob
97 * @param blob1
98 * Object.
99 * @param blob2
100 * Object.
101 * @param logger_ptr
102 * The Logger implementation to use in *this* routine (synchronously) only. Null allowed.
103 */
104template<typename Allocator, bool S_SHARING_ALLOWED>
107
108/**
109 * On top of the similar Basic_blob related function, logs using the stored log context of `blob1`.
110 *
111 * @relatesalso Blob_with_log_context
112 * @param blob1
113 * See super-class related API.
114 * @param blob2
115 * See super-class related API.
116 */
117template<bool S_SHARING_ALLOWED>
119
120} // namespace flow::util
Interface that the user should implement, passing the implementing Logger into logging classes (Flow'...
Definition: log.hpp:1291
A hand-optimized and API-tweaked replacement for vector<uint8_t>, i.e., buffer of bytes inside an all...
Definition: basic_blob.hpp:247
Basic_blob that works in regular heap (and is itself placed in heap or stack) and memorizes a log::Lo...
Definition: blob.hpp:81
Flow module containing miscellaneous general-use facilities that don't fit into any other Flow module...
Definition: basic_blob.hpp:29
void swap(Basic_blob< Allocator, S_SHARING_ALLOWED > &blob1, Basic_blob< Allocator, S_SHARING_ALLOWED > &blob2, log::Logger *logger_ptr)
Equivalent to blob1.swap(blob2).
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:60
bool blobs_sharing(const Basic_blob< Allocator, S_SHARING_ALLOWED > &blob1, const Basic_blob< Allocator, S_SHARING_ALLOWED > &blob2)
Returns true if and only if both given objects are not zero() == true, and they either co-own a commo...