File: buffer_tmpl.hpp

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (113 lines) | stat: -rw-r--r-- 3,464 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef PROTOZERO_BUFFER_TMPL_HPP
#define PROTOZERO_BUFFER_TMPL_HPP

/*****************************************************************************

protozero - Minimalistic protocol buffer decoder and encoder in C++.

This file is from https://github.com/mapbox/protozero where you can find more
documentation.

*****************************************************************************/

/**
 * @file buffer_tmpl.hpp
 *
 * @brief Contains the customization points for buffer implementations.
 */

#include <cstddef>
#include <iterator>
#include <string>

namespace protozero {

// Implementation of buffer customizations points for std::string

/// @cond INTERNAL
template <typename T>
struct buffer_customization {

    /**
     * Get the number of bytes currently used in the buffer.
     *
     * @param buffer Pointer to the buffer.
     * @returns number of bytes used in the buffer.
     */
    static std::size_t size(const std::string* buffer);

    /**
     * Append count bytes from data to the buffer.
     *
     * @param buffer Pointer to the buffer.
     * @param data Pointer to the data.
     * @param count Number of bytes to be added to the buffer.
     */
    static void append(std::string* buffer, const char* data, std::size_t count);

    /**
     * Append count zero bytes to the buffer.
     *
     * @param buffer Pointer to the buffer.
     * @param count Number of bytes to be added to the buffer.
     */
    static void append_zeros(std::string* buffer, std::size_t count);

    /**
     * Shrink the buffer to the specified size. The new size will always be
     * smaller than the current size.
     *
     * @param buffer Pointer to the buffer.
     * @param size New size of the buffer.
     *
     * @pre size < current size of buffer
     */
    static void resize(std::string* buffer, std::size_t size);

    /**
     * Reserve an additional size bytes for use in the buffer. This is used for
     * variable-sized buffers to tell the buffer implementation that soon more
     * memory will be used. The implementation can ignore this.
     *
     * @param buffer Pointer to the buffer.
     * @param size Number of bytes to reserve.
     */
    static void reserve_additional(std::string* buffer, std::size_t size);

    /**
     * Delete data from the buffer. This must move back the data after the
     * part being deleted and resize the buffer accordingly.
     *
     * @param buffer Pointer to the buffer.
     * @param from Offset into the buffer where we want to erase from.
     * @param to Offset into the buffer one past the last byte we want to erase.
     *
     * @pre from, to <= size of the buffer, from < to
     */
    static void erase_range(std::string* buffer, std::size_t from, std::size_t to);

    /**
     * Return a pointer to the memory at the specified position in the buffer.
     *
     * @param buffer Pointer to the buffer.
     * @param pos The position in the buffer.
     * @returns pointer to the memory in the buffer at the specified position.
     *
     * @pre pos <= size of the buffer
     */
    static char* at_pos(std::string* buffer, std::size_t pos);

    /**
     * Add a char to the buffer incrementing the number of chars in the buffer.
     *
     * @param buffer Pointer to the buffer.
     * @param ch The character to add.
     */
    static void push_back(std::string* buffer, char ch);

};
/// @endcond

} // namespace protozero

#endif // PROTOZERO_BUFFER_TMPL_HPP