From 9615ba3eab3894b2b4bc4130104ab95f9ff8b4ee Mon Sep 17 00:00:00 2001 From: rozmansi Date: Mon, 7 Mar 2022 10:38:08 +0000 Subject: [PATCH] deploy: 09d0f347e807c2cb15726f3f4ff38cdc641d72c9 --- annotated.html | 4 +- base64_8h_source.html | 314 +++++++++++++++++ classes.html | 4 +- classstdex_1_1base64__dec-members.html | 4 +- classstdex_1_1base64__dec.html | 8 +- classstdex_1_1base64__enc-members.html | 4 +- classstdex_1_1base64__enc.html | 8 +- classstdex_1_1hex__dec-members.html | 4 +- classstdex_1_1hex__dec.html | 8 +- classstdex_1_1hex__enc-members.html | 4 +- classstdex_1_1hex__enc.html | 8 +- classstdex_1_1idrec_1_1record-members.html | 4 +- classstdex_1_1idrec_1_1record.html | 8 +- classstdex_1_1vector__queue-members.html | 4 +- classstdex_1_1vector__queue.html | 8 +- dir_d44c64559bbebec7f509842c48db8b23.html | 4 +- dir_fca3c47b2ea228727bd6729832f89576.html | 16 +- files.html | 85 +++++ functions.html | 4 +- functions_func.html | 4 +- functions_type.html | 4 +- functions_vars.html | 4 +- hex_8h_source.html | 205 +++++++++++ idrec_8h_source.html | 268 ++++++++++++++ index.html | 4 +- menudata.js | 4 +- vector__queue_8h_source.html | 383 +++++++++++++++++++++ 27 files changed, 1330 insertions(+), 49 deletions(-) create mode 100644 base64_8h_source.html create mode 100644 files.html create mode 100644 hex_8h_source.html create mode 100644 idrec_8h_source.html create mode 100644 vector__queue_8h_source.html diff --git a/annotated.html b/annotated.html index 20235a1b7..453cb3014 100644 --- a/annotated.html +++ b/annotated.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -81,7 +81,7 @@ $(function() { diff --git a/base64_8h_source.html b/base64_8h_source.html new file mode 100644 index 000000000..916dd218b --- /dev/null +++ b/base64_8h_source.html @@ -0,0 +1,314 @@ + + + + + + + +stdex: include/stdex/base64.h Source File + + + + + + + + + +
+
+ + + + + + +
+
stdex +
+
Additional custom or not Standard C++ covered algorithms
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
base64.h
+
+
+
1/*
+
2 SPDX-License-Identifier: MIT
+
3 Copyright © 2016-2022 Amebis
+
4*/
+
5
+
6#pragma once
+
7
+
8#include <string>
+
9#include <vector>
+
10
+
11
+
12namespace stdex
+
13{
+ +
18 {
+
19 public:
+
23 base64_enc() noexcept : num(0)
+
24 {
+
25 buf[0] = 0;
+
26 buf[1] = 0;
+
27 buf[2] = 0;
+
28 }
+
29
+
30
+
39 template<class _Elem, class _Traits, class _Ax>
+
40 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size, _In_opt_ bool is_last = true)
+
41 {
+
42 assert(data || !size);
+
43
+
44 // Preallocate output
+
45 out.reserve(out.size() + enc_size(size));
+
46
+
47 // Convert data character by character.
+
48 for (size_t i = 0;; i++) {
+
49 if (num >= 3) {
+
50 encode(out);
+
51 num = 0;
+
52 }
+
53
+
54 if (i >= size)
+
55 break;
+
56
+
57 buf[num++] = reinterpret_cast<const unsigned char*>(data)[i];
+
58 }
+
59
+
60 // If this is the last block, flush the buffer.
+
61 if (is_last && num) {
+
62 encode(out, num);
+
63 num = 0;
+
64 }
+
65 }
+
66
+
67
+
71 void clear() noexcept
+
72 {
+
73 num = 0;
+
74 }
+
75
+
76
+
84 size_t enc_size(size_t size) const noexcept
+
85 {
+
86 return ((num + size + 2)/3)*4;
+
87 }
+
88
+
89
+
90 protected:
+
94 template<class _Elem, class _Traits, class _Ax>
+
95 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out)
+
96 {
+
97 out += base64_enc_lookup[ buf[0] >> 2 ];
+
98 out += base64_enc_lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f];
+
99 out += base64_enc_lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f];
+
100 out += base64_enc_lookup[ buf[2] & 0x3f];
+
101 }
+
102
+
103
+
107 template<class _Elem, class _Traits, class _Ax>
+
108 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_ size_t size)
+
109 {
+
110 if (size > 0) {
+
111 out += base64_enc_lookup[buf[0] >> 2];
+
112 if (size > 1) {
+
113 out += base64_enc_lookup[((buf[0] << 4) | (buf[1] >> 4)) & 0x3f];
+
114 if (size > 2) {
+
115 out += base64_enc_lookup[((buf[1] << 2) | (buf[2] >> 6)) & 0x3f];
+
116 out += base64_enc_lookup[buf[2] & 0x3f];
+
117 } else {
+
118 out += base64_enc_lookup[(buf[1] << 2) & 0x3f];
+
119 out += '=';
+
120 }
+
121 } else {
+
122 out += base64_enc_lookup[(buf[0] << 4) & 0x3f];
+
123 out += '=';
+
124 out += '=';
+
125 }
+
126 } else {
+
127 out += '=';
+
128 out += '=';
+
129 out += '=';
+
130 out += '=';
+
131 }
+
132 }
+
133
+
134
+
135 protected:
+
136 unsigned char buf[3];
+
137 size_t num;
+
138 };
+
139
+
140
+
142 static const char base64_enc_lookup[64] = {
+
143 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+
144 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+
145 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+
146 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
+
147 };
+
149
+
150
+ +
155 {
+
156 public:
+
160 base64_dec() noexcept : num(0)
+
161 {
+
162 buf[0] = 0;
+
163 buf[1] = 0;
+
164 buf[2] = 0;
+
165 buf[3] = 0;
+
166 }
+
167
+
168
+
177 template<class _Ty, class _Ax, class _Tchr>
+
178 void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size)
+
179 {
+
180 is_last = false;
+
181
+
182 // Trim data size to first terminator.
+
183 for (size_t k = 0; k < size; k++)
+
184 if (!data[k]) { size = k; break; }
+
185
+
186 // Preallocate output
+
187 out.reserve(out.size() + dec_size(size));
+
188
+
189 for (size_t i = 0;; i++) {
+
190 if (num >= 4) {
+
191 // Buffer full; decode it.
+
192 size_t nibbles = decode(out);
+
193 num = 0;
+
194 if (nibbles < 3) {
+
195 is_last = true;
+
196 break;
+
197 }
+
198 }
+
199
+
200 if (i >= size)
+
201 break;
+
202
+
203 int x = data[i];
+
204 if ((buf[num] = x < _countof(base64_dec_lookup) ? base64_dec_lookup[x] : 255) != 255)
+
205 num++;
+
206 }
+
207 }
+
208
+
209
+
213 void clear() noexcept
+
214 {
+
215 num = 0;
+
216 }
+
217
+
218
+
226 size_t dec_size(size_t size) const noexcept
+
227 {
+
228 return ((num + size + 3)/4)*3;
+
229 }
+
230
+
231
+
232 protected:
+
236 template<class _Ty, class _Ax>
+
237 size_t decode(_Inout_ std::vector<_Ty, _Ax> &out)
+
238 {
+
239 out.push_back((_Ty)(((buf[0] << 2) | (buf[1] >> 4)) & 0xff));
+
240 if (buf[2] < 64) {
+
241 out.push_back((_Ty)(((buf[1] << 4) | (buf[2] >> 2)) & 0xff));
+
242 if (buf[3] < 64) {
+
243 out.push_back((_Ty)(((buf[2] << 6) | buf[3]) & 0xff));
+
244 return 3;
+
245 } else
+
246 return 2;
+
247 } else
+
248 return 1;
+
249 }
+
250
+
251
+
252 protected:
+
253 unsigned char buf[4];
+
254 size_t num;
+
255 };
+
256
+
257
+
259 static const unsigned char base64_dec_lookup[256] = {
+
260 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
+
261 /* 0 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
262 /* 1 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
263 /* 2 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
+
264 /* 3 */ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 64, 255, 255,
+
265 /* 4 */ 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+
266 /* 5 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
+
267 /* 6 */ 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+
268 /* 7 */ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255,
+
269 /* 8 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
270 /* 9 */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
271 /* A */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
272 /* B */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
273 /* C */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
274 /* D */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
275 /* E */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
+
276 /* F */ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255
+
277 };
+
279}
+
Base64 decoding session.
Definition: base64.h:155
+
size_t num
Number of bytes used in buf
Definition: base64.h:254
+
base64_dec() noexcept
Constructs blank decoding session.
Definition: base64.h:160
+
void decode(std::vector< _Ty, _Ax > &out, bool &is_last, const _Tchr *data, size_t size)
Decodes one block of information, and appends it to the output.
Definition: base64.h:178
+
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition: base64.h:226
+
size_t decode(std::vector< _Ty, _Ax > &out)
Decodes one complete internal buffer of data.
Definition: base64.h:237
+
void clear() noexcept
Resets decoding session.
Definition: base64.h:213
+
unsigned char buf[4]
Internal buffer.
Definition: base64.h:253
+
Base64 encoding session.
Definition: base64.h:18
+
void encode(std::basic_string< _Elem, _Traits, _Ax > &out, const void *data, size_t size, bool is_last=true)
Encodes one block of information, and appends it to the output.
Definition: base64.h:40
+
unsigned char buf[3]
Internal buffer.
Definition: base64.h:136
+
void encode(std::basic_string< _Elem, _Traits, _Ax > &out)
Encodes one complete internal buffer of data.
Definition: base64.h:95
+
size_t num
Number of bytes used in buf
Definition: base64.h:137
+
void encode(std::basic_string< _Elem, _Traits, _Ax > &out, size_t size)
Encodes partial internal buffer of data.
Definition: base64.h:108
+
base64_enc() noexcept
Constructs blank encoding session.
Definition: base64.h:23
+
void clear() noexcept
Resets encoding session.
Definition: base64.h:71
+
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition: base64.h:84
+
+ + + + diff --git a/classes.html b/classes.html index 1254ac31f..ef7e9621a 100644 --- a/classes.html +++ b/classes.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -84,7 +84,7 @@ $(function() { diff --git a/classstdex_1_1base64__dec-members.html b/classstdex_1_1base64__dec-members.html index e7959d3be..60f2f2700 100644 --- a/classstdex_1_1base64__dec-members.html +++ b/classstdex_1_1base64__dec-members.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -83,7 +83,7 @@ $(function() { diff --git a/classstdex_1_1base64__dec.html b/classstdex_1_1base64__dec.html index bbbf22593..8a84177b7 100644 --- a/classstdex_1_1base64__dec.html +++ b/classstdex_1_1base64__dec.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -78,6 +78,8 @@ $(function() {

Base64 decoding session. More...

+ +

#include <stdex/base64.h>

@@ -216,12 +218,12 @@ template<class _Ty , class _Ax , class _Tchr >
The documentation for this class was generated from the following file: diff --git a/classstdex_1_1base64__enc-members.html b/classstdex_1_1base64__enc-members.html index 4c68dd94e..fd160837f 100644 --- a/classstdex_1_1base64__enc-members.html +++ b/classstdex_1_1base64__enc-members.html @@ -23,7 +23,7 @@ @@ -84,7 +84,7 @@ $(function() {

Public Member Functions

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
diff --git a/classstdex_1_1base64__enc.html b/classstdex_1_1base64__enc.html index 27710a78b..a1715966e 100644 --- a/classstdex_1_1base64__enc.html +++ b/classstdex_1_1base64__enc.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -78,6 +78,8 @@ $(function() {

Base64 encoding session. More...

+ +

#include <stdex/base64.h>

@@ -221,12 +223,12 @@ template<class _Elem , class _Traits , class _Ax >
The documentation for this class was generated from the following file: diff --git a/classstdex_1_1hex__dec-members.html b/classstdex_1_1hex__dec-members.html index 1b16a64e7..f3e2a7018 100644 --- a/classstdex_1_1hex__dec-members.html +++ b/classstdex_1_1hex__dec-members.html @@ -23,7 +23,7 @@ @@ -82,7 +82,7 @@ $(function() {

Public Member Functions

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
diff --git a/classstdex_1_1hex__dec.html b/classstdex_1_1hex__dec.html index b926ae92b..403f9d6ab 100644 --- a/classstdex_1_1hex__dec.html +++ b/classstdex_1_1hex__dec.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -77,6 +77,8 @@ $(function() {

Hexadecimal decoding session. More...

+ +

#include <stdex/hex.h>

@@ -207,12 +209,12 @@ template<class _Ty , class _Ax , class _Tchr >
The documentation for this class was generated from the following file: diff --git a/classstdex_1_1hex__enc-members.html b/classstdex_1_1hex__enc-members.html index 913c908ae..6ace43286 100644 --- a/classstdex_1_1hex__enc-members.html +++ b/classstdex_1_1hex__enc-members.html @@ -23,7 +23,7 @@ @@ -79,7 +79,7 @@ $(function() {

Public Member Functions

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
diff --git a/classstdex_1_1hex__enc.html b/classstdex_1_1hex__enc.html index 2d6537a59..9032e4f2a 100644 --- a/classstdex_1_1hex__enc.html +++ b/classstdex_1_1hex__enc.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -76,6 +76,8 @@ $(function() {

Hexadecimal encoding session. More...

+ +

#include <stdex/hex.h>

@@ -184,12 +186,12 @@ template<class _Elem , class _Traits , class _Ax >
The documentation for this class was generated from the following file: diff --git a/classstdex_1_1idrec_1_1record-members.html b/classstdex_1_1idrec_1_1record-members.html index 5fb201afe..a7e6d28c5 100644 --- a/classstdex_1_1idrec_1_1record-members.html +++ b/classstdex_1_1idrec_1_1record-members.html @@ -23,7 +23,7 @@ @@ -84,7 +84,7 @@ $(function() {

Public Member Functions

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
diff --git a/classstdex_1_1idrec_1_1record.html b/classstdex_1_1idrec_1_1record.html index d4717c697..21b726775 100644 --- a/classstdex_1_1idrec_1_1record.html +++ b/classstdex_1_1idrec_1_1record.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -79,6 +79,8 @@ $(function() {

Helper class for read/write of records to/from memory. More...

+ +

#include <stdex/idrec.h>

@@ -370,12 +372,12 @@ template<class T , class T_ID , class T_SIZE , unsigned int ALIGN>
The documentation for this class was generated from the following file: diff --git a/classstdex_1_1vector__queue-members.html b/classstdex_1_1vector__queue-members.html index 0f53a1df8..082c07ff8 100644 --- a/classstdex_1_1vector__queue-members.html +++ b/classstdex_1_1vector__queue-members.html @@ -23,7 +23,7 @@ @@ -115,7 +115,7 @@ $(function() {

Public Member Functions

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
diff --git a/classstdex_1_1vector__queue.html b/classstdex_1_1vector__queue.html index f1187d4f3..c565d13eb 100644 --- a/classstdex_1_1vector__queue.html +++ b/classstdex_1_1vector__queue.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -78,6 +78,8 @@ $(function() {

Helper class to allow limited size FIFO queues implemented as vector of elements. More...

+ +

#include <stdex/vector_queue.h>

@@ -781,12 +783,12 @@ template<class T >
The documentation for this class was generated from the following file: diff --git a/dir_d44c64559bbebec7f509842c48db8b23.html b/dir_d44c64559bbebec7f509842c48db8b23.html index 25fa91cf7..ce26abc40 100644 --- a/dir_d44c64559bbebec7f509842c48db8b23.html +++ b/dir_d44c64559bbebec7f509842c48db8b23.html @@ -23,7 +23,7 @@ @@ -79,7 +79,7 @@ Directories diff --git a/dir_fca3c47b2ea228727bd6729832f89576.html b/dir_fca3c47b2ea228727bd6729832f89576.html index f0cfc069b..e8f11a26d 100644 --- a/dir_fca3c47b2ea228727bd6729832f89576.html +++ b/dir_fca3c47b2ea228727bd6729832f89576.html @@ -23,7 +23,7 @@ @@ -70,10 +70,22 @@ $(function() {
stdex Directory Reference
+

Public Types

stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
+ + + + + + + + + +

+Files

file  base64.h [code]
 
file  hex.h [code]
 
file  idrec.h [code]
 
file  vector_queue.h [code]
 
diff --git a/files.html b/files.html new file mode 100644 index 000000000..605ec90b3 --- /dev/null +++ b/files.html @@ -0,0 +1,85 @@ + + + + + + + +stdex: File List + + + + + + + + + +
+
+ + + + + + +
+
stdex +
+
Additional custom or not Standard C++ covered algorithms
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
File List
+
+
+
Here is a list of all documented files with brief descriptions:
+
[detail level 123]
+ + + + + + +
  include
  stdex
 base64.h
 hex.h
 idrec.h
 vector_queue.h
+
+
+ + + + diff --git a/functions.html b/functions.html index 3ba549f4b..0658f61e6 100644 --- a/functions.html +++ b/functions.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -179,7 +179,7 @@ $(function() { diff --git a/functions_func.html b/functions_func.html index dd535f112..39fd1b1a4 100644 --- a/functions_func.html +++ b/functions_func.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -153,7 +153,7 @@ $(function() { diff --git a/functions_type.html b/functions_type.html index 5dc2839a3..9f2d163f6 100644 --- a/functions_type.html +++ b/functions_type.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -74,7 +74,7 @@ $(function() { diff --git a/functions_vars.html b/functions_vars.html index 1dceb2605..074d48344 100644 --- a/functions_vars.html +++ b/functions_vars.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -76,7 +76,7 @@ $(function() { diff --git a/hex_8h_source.html b/hex_8h_source.html new file mode 100644 index 000000000..6c5c86486 --- /dev/null +++ b/hex_8h_source.html @@ -0,0 +1,205 @@ + + + + + + + +stdex: include/stdex/hex.h Source File + + + + + + + + + +
+
+ + + + + + +
+
stdex +
+
Additional custom or not Standard C++ covered algorithms
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
hex.h
+
+
+
1/*
+
2 SPDX-License-Identifier: MIT
+
3 Copyright © 2016-2022 Amebis
+
4*/
+
5
+
6#pragma once
+
7
+
8#include <string>
+
9#include <vector>
+
10
+
11
+
12namespace stdex
+
13{
+
17 class hex_enc
+
18 {
+
19 public:
+
23 hex_enc() noexcept
+
24 {
+
25 }
+
26
+
27
+
35 template<class _Elem, class _Traits, class _Ax>
+
36 void encode(_Inout_ std::basic_string<_Elem, _Traits, _Ax> &out, _In_bytecount_(size) const void *data, _In_ size_t size)
+
37 {
+
38 assert(data || !size);
+
39
+
40 // Preallocate output
+
41 out.reserve(out.size() + enc_size(size));
+
42
+
43 // Convert data character by character.
+
44 for (size_t i = 0; i < size; i++) {
+
45 unsigned char
+
46 x = reinterpret_cast<const unsigned char*>(data)[i],
+
47 x_h = ((x & 0xf0) >> 4),
+
48 x_l = ((x & 0x0f) );
+
49
+
50 out += x_h < 10 ? '0' + x_h : 'A' - 10 + x_h;
+
51 out += x_l < 10 ? '0' + x_l : 'A' - 10 + x_l;
+
52 }
+
53 }
+
54
+
55
+
63 size_t enc_size(size_t size) const noexcept
+
64 {
+
65 return size*2;
+
66 }
+
67 };
+
68
+
69
+
73 class hex_dec
+
74 {
+
75 public:
+
79 hex_dec() noexcept :
+
80 buf(0),
+
81 num(0)
+
82 {
+
83 }
+
84
+
85
+
94 template<class _Ty, class _Ax, class _Tchr>
+
95 void decode(_Inout_ std::vector<_Ty, _Ax> &out, _Out_ bool &is_last, _In_z_count_(size) const _Tchr *data, _In_ size_t size)
+
96 {
+
97 is_last = false;
+
98
+
99 // Trim data size to first terminator.
+
100 for (size_t k = 0; k < size; k++)
+
101 if (!data[k]) { size = k; break; }
+
102
+
103 // Preallocate output
+
104 out.reserve(out.size() + dec_size(size));
+
105
+
106 for (size_t i = 0;; i++) {
+
107 if (num >= 2) {
+
108 // Buffer full.
+
109 out.push_back(buf);
+
110 num = 0;
+
111 is_last = true;
+
112 } else
+
113 is_last = false;
+
114
+
115 if (i >= size)
+
116 break;
+
117
+
118 int x = data[i];
+
119 if ('0' <= x && x <= '9') {
+
120 buf = ((buf & 0xf) << 4) | (unsigned char)(x - '0');
+
121 num++;
+
122 } else if ('A' <= x && x <= 'F') {
+
123 buf = ((buf & 0xf) << 4) | (unsigned char)(x - ('A' - 10));
+
124 num++;
+
125 } else if ('a' <= x && x <= 'f') {
+
126 buf = ((buf & 0xf) << 4) | (unsigned char)(x - ('a' - 10));
+
127 num++;
+
128 }
+
129 }
+
130 }
+
131
+
132
+
136 void clear() noexcept
+
137 {
+
138 num = 0;
+
139 }
+
140
+
141
+
149 size_t dec_size(size_t size) const noexcept
+
150 {
+
151 return (size + 1)/2;
+
152 }
+
153
+
154
+
155 protected:
+
156 unsigned char buf;
+
157 size_t num;
+
158 };
+
159}
+
Hexadecimal decoding session.
Definition: hex.h:74
+
unsigned char buf
Internal buffer.
Definition: hex.h:156
+
void clear() noexcept
Resets decoding session.
Definition: hex.h:136
+
hex_dec() noexcept
Constructs blank decoding session.
Definition: hex.h:79
+
size_t num
Number of nibbles used in buf
Definition: hex.h:157
+
void decode(std::vector< _Ty, _Ax > &out, bool &is_last, const _Tchr *data, size_t size)
Decodes one block of information, and appends it to the output.
Definition: hex.h:95
+
size_t dec_size(size_t size) const noexcept
Returns maximum decoded size.
Definition: hex.h:149
+
Hexadecimal encoding session.
Definition: hex.h:18
+
size_t enc_size(size_t size) const noexcept
Returns maximum encoded size.
Definition: hex.h:63
+
void encode(std::basic_string< _Elem, _Traits, _Ax > &out, const void *data, size_t size)
Encodes one block of information, and appends it to the output.
Definition: hex.h:36
+
hex_enc() noexcept
Constructs blank encoding session.
Definition: hex.h:23
+
+ + + + diff --git a/idrec_8h_source.html b/idrec_8h_source.html new file mode 100644 index 000000000..4f40bb2ee --- /dev/null +++ b/idrec_8h_source.html @@ -0,0 +1,268 @@ + + + + + + + +stdex: include/stdex/idrec.h Source File + + + + + + + + + +
+
+ + + + + + +
+
stdex +
+
Additional custom or not Standard C++ covered algorithms
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
idrec.h
+
+
+
1/*
+
2 SPDX-License-Identifier: MIT
+
3 Copyright © 2016-2022 Amebis
+
4*/
+
5
+
6#pragma once
+
7
+
8#include <ios>
+
9#include <istream>
+
10#include <ostream>
+
11
+
12
+
13namespace stdex {
+
14 namespace idrec {
+
26 template <class T_ID>
+
27 _Success_(return) bool read_id(_In_ std::istream& stream, _Out_ T_ID &id, _In_opt_ std::streamoff end = (std::streamoff)-1)
+
28 {
+
29 if (end == (std::streamoff)-1 || stream.tellg() < end) {
+
30 stream.read((char*)&id, sizeof(id));
+
31 return stream.good();
+
32 } else
+
33 return false;
+
34 }
+
35
+
36
+
46 template <class T_SIZE, unsigned int ALIGN>
+
47 bool ignore(_In_ std::istream& stream)
+
48 {
+
49 // Read record size.
+
50 T_SIZE size;
+
51 stream.read((char*)&size, sizeof(size));
+
52 if (!stream.good()) return false;
+
53
+
54 // Skip the record data.
+
55 size += (T_SIZE)(ALIGN - size) % ALIGN;
+
56 stream.ignore(size);
+
57 if (!stream.good()) return false;
+
58
+
59 return true;
+
60 }
+
61
+
62
+
74 template <class T_ID, class T_SIZE, unsigned int ALIGN>
+
75 bool find(_In_ std::istream& stream, _In_ T_ID id, _In_opt_ std::streamoff end = (std::streamoff)-1)
+
76 {
+
77 T_ID _id;
+
78
+
79 while (end == (std::streamoff)-1 || stream.tellg() < end) {
+
80 stream.read((char*)&_id, sizeof(_id));
+
81 if (!stream.good()) return false;
+
82
+
83 if (_id == id) {
+
84 // The record was found.
+
85 return true;
+
86 } else
+
87 ignore<T_SIZE, ALIGN>(stream);
+
88 }
+
89
+
90 return false;
+
91 }
+
92
+
93
+
102 template <class T_ID, class T_SIZE>
+
103 std::streamoff open(_In_ std::ostream& stream, _In_ T_ID id)
+
104 {
+
105 std::streamoff start = stream.tellp();
+
106
+
107 // Write ID.
+
108 if (stream.fail()) return (std::streamoff)-1;
+
109 stream.write((const char*)&id, sizeof(id));
+
110
+
111 // Write 0 as a placeholder for data size.
+
112 if (stream.fail()) return (std::streamoff)-1;
+
113 T_SIZE size = 0;
+
114 stream.write((const char*)&size, sizeof(size));
+
115
+
116 return start;
+
117 }
+
118
+
119
+
128 template <class T_ID, class T_SIZE, unsigned int ALIGN>
+
129 std::streamoff close(_In_ std::ostream& stream, _In_ std::streamoff start)
+
130 {
+
131 std::streamoff end = stream.tellp();
+
132 T_SIZE
+
133 size = (T_SIZE)(end - start - sizeof(T_ID) - sizeof(T_SIZE)),
+
134 remainder = (T_SIZE)(ALIGN - size) % ALIGN; // Number of bytes we need to add, to keep the data integral number of ALIGN blocks long
+
135
+
136 if (remainder) {
+
137 // Append padding.
+
138 static const char padding[ALIGN] = {};
+
139 stream.write(padding, remainder);
+
140 end += remainder;
+
141 }
+
142
+
143 // Update the data size.
+
144 if (stream.fail()) return (std::streamoff)-1;
+
145 stream.seekp(start + sizeof(T_ID));
+
146 stream.write((const char*)&size, sizeof(size));
+
147 stream.seekp(end);
+
148
+
149 return end;
+
150 }
+
151
+
152
+
156 template <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
+
157 class record
+
158 {
+
159 public:
+
165 record(_In_ T &d) : data(d) {}
+
166
+
167
+
173 record(_In_ const T &d) : data((T&)d) {}
+
174
+
175
+ +
184 {
+
185 data = r.data;
+
186 return *this;
+
187 }
+
188
+
189
+
197 static std::streamoff open(_In_ std::ostream& stream)
+
198 {
+
199 return stdex::idrec::open<T_ID, T_SIZE>(stream, id);
+
200 }
+
201
+
202
+
211 static std::streamoff close(_In_ std::ostream& stream, _In_ std::streamoff start)
+
212 {
+
213 return stdex::idrec::close<T_ID, T_SIZE, ALIGN>(stream, start);
+
214 }
+
215
+
216
+
227 static bool find(_In_ std::istream& stream, _In_opt_ std::streamoff end = (std::streamoff)-1)
+
228 {
+
229 return stdex::idrec::find<T_ID, T_SIZE, ALIGN>(stream, id, end);
+
230 }
+
231
+
232
+
233 static const T_ID id;
+
234 T &data;
+
235 };
+
236 };
+
237};
+
238
+
239
+
248template <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
+
249std::ostream& operator <<(_In_ std::ostream& stream, _In_ const stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
+
250{
+
251 // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
+
252
+
253 std::streamoff start = r.open(stream);
+
254 if (stream.fail()) return stream;
+
255 stream << r.data;
+
256 r.close(stream, start);
+
257
+
258 return stream;
+
259}
+
260
+
261
+
270template <class T, class T_ID, class T_SIZE, unsigned int ALIGN>
+
271std::istream& operator >>(_In_ std::istream& stream, _In_ stdex::idrec::record<T, T_ID, T_SIZE, ALIGN> r)
+
272{
+
273 // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway.
+
274
+
275 // Read data size.
+
276 T_SIZE size;
+
277 stream.read((char*)&size, sizeof(size));
+
278 if (!stream.good()) return stream;
+
279
+
280 // Read data.
+
281 std::streamoff start = stream.tellg();
+
282 stream >> r.data; // TODO: operator >> should not read past the record data! Make a size limited stream and read from it instead.
+
283
+
284 size += (T_SIZE)(ALIGN - size) % ALIGN;
+
285 stream.seekg(start + size);
+
286
+
287 return stream;
+
288}
+
Helper class for read/write of records to/from memory.
Definition: idrec.h:158
+
T & data
Record data reference.
Definition: idrec.h:234
+
static std::streamoff close(std::ostream &stream, std::streamoff start)
Updates record header.
Definition: idrec.h:211
+
static bool find(std::istream &stream, std::streamoff end=(std::streamoff) -1)
Finds record data.
Definition: idrec.h:227
+
static const T_ID id
Record id.
Definition: idrec.h:233
+
static std::streamoff open(std::ostream &stream)
Writes record header.
Definition: idrec.h:197
+
record(const T &d)
Constructs the class.
Definition: idrec.h:173
+
record(T &d)
Constructs the class.
Definition: idrec.h:165
+
const record< T, T_ID, T_SIZE, ALIGN > & operator=(const record< T, T_ID, T_SIZE, ALIGN > &r)
Assignment operator.
Definition: idrec.h:183
+
+ + + + diff --git a/index.html b/index.html index 7e3c7ad51..fa6a8360c 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@
stdex
-
Additional templates and function helpers for Microsoft Active Template Library
+
Additional custom or not Standard C++ covered algorithms
@@ -69,7 +69,7 @@ $(function() { diff --git a/menudata.js b/menudata.js index e4bfaa685..9502aab3a 100644 --- a/menudata.js +++ b/menudata.js @@ -62,4 +62,6 @@ var menudata={children:[ {text:"v",url:"functions_func.html#index_v"}, {text:"~",url:"functions_func.html#index__7E"}]}, {text:"Variables",url:"functions_vars.html"}, -{text:"Typedefs",url:"functions_type.html"}]}]}]} +{text:"Typedefs",url:"functions_type.html"}]}]}, +{text:"Files",url:"files.html",children:[ +{text:"File List",url:"files.html"}]}]} diff --git a/vector__queue_8h_source.html b/vector__queue_8h_source.html new file mode 100644 index 000000000..153ef0c5c --- /dev/null +++ b/vector__queue_8h_source.html @@ -0,0 +1,383 @@ + + + + + + + +stdex: include/stdex/vector_queue.h Source File + + + + + + + + + +
+
+ + + + + + +
+
stdex +
+
Additional custom or not Standard C++ covered algorithms
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
vector_queue.h
+
+
+
1/*
+
2 SPDX-License-Identifier: MIT
+
3 Copyright © 2016-2022 Amebis
+
4*/
+
5
+
6#pragma once
+
7
+
8namespace stdex
+
9{
+
13 template <class T>
+ +
15 {
+
16 public:
+
20 typedef size_t size_type;
+
21
+
25 typedef T value_type;
+
26
+
30 typedef T& reference;
+
31
+
35 typedef const T& const_reference;
+
36
+
40 typedef T* pointer;
+
41
+
45 typedef const T* const_pointer;
+
46
+
47 public:
+
53 vector_queue(_In_ size_type size_max) :
+
54 m_data(new value_type[size_max]),
+
55 m_head(0),
+
56 m_count(0),
+
57 m_size_max(size_max)
+
58 {
+
59 }
+
60
+ +
67 m_data(new value_type[other.m_size_max]),
+
68 m_head(other.m_head),
+
69 m_count(other.m_count),
+ +
71 {
+
72 // Copy elements.
+
73 for (size_type i = 0; i < m_count; i++) {
+
74 size_type i_l = abs(i);
+
75 m_data[i_l] = other.m_data[i_l];
+
76 }
+
77 }
+
78
+
82 virtual ~vector_queue()
+
83 {
+
84 if (m_data) delete [] m_data;
+
85 }
+
86
+ +
93 m_data (std::move(other.m_data )),
+
94 m_head (std::move(other.m_head )),
+
95 m_count (std::move(other.m_count )),
+
96 m_size_max(std::move(other.m_size_max))
+
97 {
+
98 // Reset other to consistent state.
+
99 other.m_data = NULL;
+
100 other.m_head = 0;
+
101 other.m_count = 0;
+
102 other.m_size_max = 0;
+
103 }
+
104
+ +
111 {
+
112 if (this != std::addressof(other)) {
+
113 m_head = other.m_head;
+
114 m_count = other.m_count;
+
115 m_size_max = other.m_size_max;
+
116
+
117 // Copy elements.
+
118 if (m_data) delete [] m_data;
+
119 m_data = new value_type[other.m_size_max];
+
120 for (size_type i = 0; i < m_count; i++) {
+
121 size_type i_l = abs(i);
+
122 m_data[i_l] = other.m_data[i_l];
+
123 }
+
124 }
+
125
+
126 return *this;
+
127 }
+
128
+ +
135 {
+
136 if (this != std::addressof(other)) {
+
137 m_data = std::move(other.m_data );
+
138 m_head = std::move(other.m_head );
+
139 m_count = std::move(other.m_count );
+
140 m_size_max = std::move(other.m_size_max);
+
141
+
142 // Reset other to consistent state.
+
143 other.m_data = NULL;
+
144 other.m_head = 0;
+
145 other.m_count = 0;
+
146 other.m_size_max = 0;
+
147 }
+
148
+
149 return *this;
+
150 }
+
151
+ +
156 {
+
157 return m_count;
+
158 }
+
159
+ +
164 {
+
165 return m_size_max;
+
166 }
+
167
+
171 void clear()
+
172 {
+
173 m_count = 0;
+
174 }
+
175
+
179 bool empty() const
+
180 {
+
181 return m_count == 0;
+
182 }
+
183
+ +
190 {
+
191 if (pos >= m_count) throw std::invalid_argument("Invalid subscript");
+
192 return m_data[abs(pos)];
+
193 }
+
194
+ +
201 {
+
202 if (pos >= m_count) throw std::invalid_argument("Invalid subscript");
+
203 return m_data[abs(pos)];
+
204 }
+
205
+ +
212 {
+
213 if (pos >= m_count) throw std::invalid_argument("Invalid subscript");
+
214 return m_data[abs(pos)];
+
215 }
+
216
+ +
223 {
+
224 if (pos >= m_count) throw std::invalid_argument("Invalid subscript");
+
225 return m_data[abs(pos)];
+
226 }
+
227
+ +
236 {
+
237 if (pos >= m_size_max) throw std::invalid_argument("Invalid subscript");
+
238 return m_data[pos];
+
239 }
+
240
+ +
249 {
+
250 if (pos >= m_size_max) throw std::invalid_argument("Invalid subscript");
+
251 return m_data[pos];
+
252 }
+
253
+ +
262 {
+
263 if (m_count < m_size_max) {
+
264 size_type pos = abs(m_count);
+
265 m_data[pos] = v;
+
266 m_count++;
+
267 return pos;
+
268 } else {
+
269 size_type pos = m_head;
+
270 m_data[pos] = v;
+
271 m_head = abs(1);
+
272 return pos;
+
273 }
+
274 }
+
275
+ +
284 {
+
285 if (m_count < m_size_max) {
+
286 size_type pos = abs(m_count);
+
287 m_data[pos] = std::move(v);
+
288 m_count++;
+
289 return pos;
+
290 } else {
+
291 size_type pos = m_head;
+
292 m_data[pos] = std::move(v);
+
293 m_head = abs(1);
+
294 return pos;
+
295 }
+
296 }
+
297
+
301 void pop_back()
+
302 {
+
303 if (!m_count) throw std::invalid_argument("Empty storage");
+
304 m_count--;
+
305 }
+
306
+ +
315 {
+
316 m_head = abs(-1);
+
317 if (m_count < m_size_max)
+
318 m_count++;
+
319 m_data[m_head] = v;
+
320 return m_head;
+
321 }
+
322
+ +
331 {
+
332 m_head = abs(-1);
+
333 if (m_count < m_size_max)
+
334 m_count++;
+
335 m_data[m_head] = std::move(v);
+
336 return m_head;
+
337 }
+
338
+ +
343 {
+
344 if (!m_count) throw std::invalid_argument("Empty storage");
+
345 m_head = abs(1);
+
346 m_count--;
+
347 }
+
348
+ +
353 {
+
354 if (!m_count) throw std::invalid_argument("Empty storage");
+
355 return m_data[m_head];
+
356 }
+
357
+ +
362 {
+
363 if (!m_count) throw std::invalid_argument("Empty storage");
+
364 return m_data[m_head];
+
365 }
+
366
+ +
371 {
+
372 return m_data[tail()];
+
373 }
+
374
+ +
379 {
+
380 return m_data[tail()];
+
381 }
+
382
+ +
387 {
+
388 return m_head;
+
389 }
+
390
+ +
395 {
+
396 if (!m_count) throw std::invalid_argument("Empty storage");
+
397 return abs(m_count - 1);
+
398 }
+
399
+
402 size_type abs(_In_ size_type pos) const
+
403 {
+
404 return (m_head + pos) % m_size_max;
+
405 }
+
406
+
407 protected:
+ + + + +
412 };
+
413}
+
Helper class to allow limited size FIFO queues implemented as vector of elements.
Definition: vector_queue.h:15
+
vector_queue< value_type > & operator=(const vector_queue< value_type > &other)
Copies existing queue.
Definition: vector_queue.h:110
+
const T * const_pointer
Constant pointer to element.
Definition: vector_queue.h:45
+
bool empty() const
Tests if the queue is empty.
Definition: vector_queue.h:179
+
size_type tail() const
Returns absolute subscript or position number of the last element in the queue. The element must exis...
Definition: vector_queue.h:394
+
reference operator[](size_type pos)
Returns a reference to the element at a specified location in the queue.
Definition: vector_queue.h:200
+
vector_queue(const vector_queue< value_type > &other)
Copies existing queue.
Definition: vector_queue.h:66
+
value_type * m_data
Underlying data container.
Definition: vector_queue.h:408
+
size_t size_type
Type to measure element count and indices in.
Definition: vector_queue.h:20
+
T & reference
Reference to element type.
Definition: vector_queue.h:30
+
const_reference back() const
Returns a constant reference to the last element in the queue.
Definition: vector_queue.h:378
+
vector_queue(vector_queue< value_type > &&other)
Moves existing queue.
Definition: vector_queue.h:92
+
reference back()
Returns a reference to the last element in the queue.
Definition: vector_queue.h:370
+
size_type push_back(value_type &&v)
Moves the element to the end of the queue, overriding the first one when queue is out of space.
Definition: vector_queue.h:283
+
size_type head() const
Returns absolute subscript or position number of the head element in the queue. The element does not ...
Definition: vector_queue.h:386
+
size_type m_count
Number of elements.
Definition: vector_queue.h:410
+
virtual ~vector_queue()
Destroys the queue.
Definition: vector_queue.h:82
+
reference front()
Returns a reference to the head element in the queue.
Definition: vector_queue.h:352
+
size_type m_size_max
Maximum size.
Definition: vector_queue.h:411
+
vector_queue< value_type > & operator=(vector_queue< value_type > &&other)
Moves existing queue.
Definition: vector_queue.h:134
+
reference at_abs(size_type pos)
Returns a reference to the element at the absolute location in the queue.
Definition: vector_queue.h:235
+
void clear()
Erases the elements of the queue.
Definition: vector_queue.h:171
+
const_reference front() const
Returns a constant reference to the head element in the queue.
Definition: vector_queue.h:361
+
vector_queue(size_type size_max)
Construct queue of fixed size.
Definition: vector_queue.h:53
+
T value_type
Element type.
Definition: vector_queue.h:25
+
size_type push_back(const value_type &v)
Copies an existing element to the end of the queue, overriding the first one when queue is out of spa...
Definition: vector_queue.h:261
+
void pop_back()
Removes (dequeues) the last element of the queue.
Definition: vector_queue.h:301
+
size_type m_head
Index of the first element.
Definition: vector_queue.h:409
+
T * pointer
Pointer to element.
Definition: vector_queue.h:40
+
const_reference at(size_type pos) const
Returns a constant reference to the element at a specified location in the queue.
Definition: vector_queue.h:211
+
const_reference operator[](size_type pos) const
Returns a constant reference to the element at a specified location in the queue.
Definition: vector_queue.h:222
+
size_type size() const
Returns the number of elements in the vector.
Definition: vector_queue.h:155
+
void pop_front()
Removes (dequeues) the head element of the queue.
Definition: vector_queue.h:342
+
size_type capacity() const
Returns the number of elements that the queue can contain before overwriting head ones.
Definition: vector_queue.h:163
+
size_type push_front(const value_type &v)
Copies an existing element to the head of the queue, overriding the last one when queue is out of spa...
Definition: vector_queue.h:314
+
reference at(size_type pos)
Returns a reference to the element at a specified location in the queue.
Definition: vector_queue.h:189
+
size_type abs(size_type pos) const
Returns absolute subscript or position number of the given element in the queue.
Definition: vector_queue.h:402
+
size_type push_front(value_type &&v)
Moves the element to the head of the queue, overriding the last one when queue is out of space and mo...
Definition: vector_queue.h:330
+
const T & const_reference
Constant reference to element type.
Definition: vector_queue.h:35
+
const_reference at_abs(size_type pos) const
Returns a constant reference to the element at the absolute location in the queue: measured from the ...
Definition: vector_queue.h:248
+
+ + + +