Fixposition SDK 0.0.0-heads/main-0-g90a51ff
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 *
9 * Partially based on work by flipflip (https://github.com/phkehl)
10 * \endverbatim
11 *
12 * @file
13 * @brief Fixposition SDK: Utilities
14 *
15 * @page FPSDK_COMMON_UTILS Utilities
16 *
17 * **API**: fpsdk_common/utils.hpp and fpsdk::common::utils
18 *
19 */
20#ifndef __FPSDK_COMMON_UTILS_HPP__
21#define __FPSDK_COMMON_UTILS_HPP__
22
23/* LIBC/STL */
24#include <algorithm>
25#include <cstdint>
26#include <vector>
27
28/* EXTERNAL */
29
30/* PACKAGE */
31
32namespace fpsdk {
33namespace common {
34/**
35 * @brief Utilities
36 */
37namespace utils {
38/* ****************************************************************************************************************** */
39
40/**
41 * @brief Get version string
42 *
43 * @returns the version string (e.g. "0.0.0-heads/feature/something-0-gf61ae50-dirty")
44 */
45const char* GetVersionString();
46
47/**
48 * @brief Get copyright string
49 *
50 * @returns the copyright string
51 */
52const char* GetCopyrightString();
53
54/**
55 * @brief Get license string
56 *
57 * @returns the license string
58 */
59const char* GetLicenseString();
60
61/**
62 * Circular buffer for chunks of data (bytes, memory). For objects use use boost::circular_buffer or std::deque.
63 */
65{
66 public:
67 /**
68 * @brief Constructor
69 *
70 * @param[in] size Size of buffer [bytes]
71 */
72 CircularBuffer(const std::size_t size);
73
74 /**
75 * @brief Reset buffer, discard all data
76 */
77 void Reset();
78
79 /**
80 * @brief Get size (capacity) of buffer
81 *
82 * @returns the size (capacity) of the buffer
83 */
84 std::size_t Size() const;
85
86 /**
87 * @brief Check if empty
88 *
89 * @returns true if the buffer is empty, false otherwise
90 */
91 bool Empty() const;
92
93 /**
94 * @brief Check if full
95 *
96 * @returns true if the buffer is completely full
97 */
98 bool Full() const;
99
100 /**
101 * @brief Get size used
102 *
103 * @returns the size of the used part of the buffer
104 */
105 std::size_t Used() const;
106
107 /**
108 * @brief Get size available
109 *
110 * @returns the size of the unused part of the buffer
111 */
112 std::size_t Avail() const;
113
114 /**
115 * @brief Write chunk of data to buffer
116 *
117 * @param[in] data Pointer to the data
118 * @param[in] size Size of the data (> 0)
119 *
120 * @returns true if data was copied to the buffer, false otherwise (not enough free space, bad params)
121 */
122 bool Write(const uint8_t* data, const std::size_t size);
123
124 /**
125 * @brief Read chunk of data from buffer
126 *
127 * @param[in] data Pointer to the data
128 * @param[out] size Size of the data (> 0)
129 *
130 * @returns true if data was copied from the buffer, false otherwise (not enough available data, bad params)
131 */
132 bool Read(uint8_t* data, const std::size_t size);
133
134 /**
135 * @brief Read chunk of data from buffer (but don't remove it from the buffer)
136 *
137 * @param[in] data Pointer to the data
138 * @param[out] size Size of the data (> 0)
139 *
140 * @returns true if data was copied from the buffer, false otherwise (not enough available data, bad params)
141 */
142 bool Peek(uint8_t* data, const std::size_t size);
143
144 private:
145 std::vector<uint8_t> buf_; //!< Buffer/memory
146 std::size_t read_; //!< Read pointer (index)
147 std::size_t write_; //!< Write pointer (index)
148 bool full_; //!< Buffer full flag
149};
150
151/* ****************************************************************************************************************** */
152} // namespace utils
153} // namespace common
154} // namespace fpsdk
155#endif // __FPSDK_COMMON_UTILS_HPP__
bool Read(uint8_t *data, const std::size_t size)
Read chunk of data from buffer.
bool Write(const uint8_t *data, const std::size_t size)
Write chunk of data to buffer.
CircularBuffer(const std::size_t size)
Constructor.
void Reset()
Reset buffer, discard all data.
std::size_t Avail() const
Get size available.
bool Full() const
Check if full.
std::size_t Size() const
Get size (capacity) of buffer.
bool Empty() const
Check if empty.
std::size_t Used() const
Get size used.
bool Peek(uint8_t *data, const std::size_t size)
Read chunk of data from buffer (but don't remove it from the buffer)
const char * GetVersionString()
Get version string.
const char * GetLicenseString()
Get license string.
const char * GetCopyrightString()
Get copyright string.
Fixposition SDK.