Fixposition SDK 0.0.0-heads/main-0-gd0a6ce2
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 <string>
27#include <vector>
28
29/* EXTERNAL */
30
31/* PACKAGE */
32
33namespace fpsdk {
34namespace common {
35/**
36 * @brief Utilities
37 */
38namespace utils {
39/* ****************************************************************************************************************** */
40
41/**
42 * @brief Get version string
43 *
44 * @returns the version string (e.g. "0.0.0-heads/feature/something-0-gf61ae50-dirty")
45 */
46const char* GetVersionString();
47
48/**
49 * @brief Get copyright string
50 *
51 * @returns the copyright string
52 */
53const char* GetCopyrightString();
54
55/**
56 * @brief Get license string
57 *
58 * @returns the license string
59 */
60const char* GetLicenseString();
61
62/**
63 * @brief Get a HTTP User-Agent string
64 *
65 * @returns a string suitable as the value for the HTTP User-Agent header
66 */
67std::string GetUserAgentStr();
68
69/**
70 * Circular buffer for chunks of data (bytes, memory). For objects use use boost::circular_buffer or std::deque.
71 */
73{
74 public:
75 /**
76 * @brief Constructor
77 *
78 * @param[in] size Size of buffer [bytes]
79 */
80 CircularBuffer(const std::size_t size);
81
82 /**
83 * @brief Reset buffer, discard all data
84 */
85 void Reset();
86
87 /**
88 * @brief Get size (capacity) of buffer
89 *
90 * @returns the size (capacity) of the buffer
91 */
92 std::size_t Size() const;
93
94 /**
95 * @brief Check if empty
96 *
97 * @returns true if the buffer is empty, false otherwise
98 */
99 bool Empty() const;
100
101 /**
102 * @brief Check if full
103 *
104 * @returns true if the buffer is completely full
105 */
106 bool Full() const;
107
108 /**
109 * @brief Get size used
110 *
111 * @returns the size of the used part of the buffer
112 */
113 std::size_t Used() const;
114
115 /**
116 * @brief Get size available
117 *
118 * @returns the size of the unused part of the buffer
119 */
120 std::size_t Avail() const;
121
122 /**
123 * @brief Write chunk of data to buffer
124 *
125 * @param[in] data Pointer to the data
126 * @param[in] size Size of the data (> 0)
127 *
128 * @returns true if data was copied to the buffer, false otherwise (not enough free space, bad params)
129 */
130 bool Write(const uint8_t* data, const std::size_t size);
131
132 /**
133 * @brief Read chunk of data from buffer
134 *
135 * @param[in] data Pointer to the data
136 * @param[out] size Size of the data (> 0)
137 *
138 * @returns true if data was copied from the buffer, false otherwise (not enough available data, bad params)
139 */
140 bool Read(uint8_t* data, const std::size_t size);
141
142 /**
143 * @brief Read chunk of data from buffer (but don't remove it from the buffer)
144 *
145 * @param[in] data Pointer to the data
146 * @param[out] size Size of the data (> 0)
147 *
148 * @returns true if data was copied from the buffer, false otherwise (not enough available data, bad params)
149 */
150 bool Peek(uint8_t* data, const std::size_t size);
151
152 private:
153 std::vector<uint8_t> buf_; //!< Buffer/memory
154 std::size_t read_; //!< Read pointer (index)
155 std::size_t write_; //!< Write pointer (index)
156 bool full_; //!< Buffer full flag
157};
158
159/* ****************************************************************************************************************** */
160} // namespace utils
161} // namespace common
162} // namespace fpsdk
163#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)
std::string GetUserAgentStr()
Get a HTTP User-Agent string.
const char * GetVersionString()
Get version string.
const char * GetLicenseString()
Get license string.
const char * GetCopyrightString()
Get copyright string.
Fixposition SDK.