Jackalope / jlib (public) (License: GPLv3 or later) (since 2019-11-18) (hash sha1)
jlib C++ template library
Used to replace std functionality without exception handling.
- data structures
- filesystem routines
- crossplatform threads interface (currently only pthreads implementation)
- thread pool
- crossplatform dynamic memory functions interface (allocate, reallocate, deallocate) with alignment support
- high percision timer routines based on timespec
List of commits:
Subject Hash Author Date (UTC)
comments 610cb9723e9451e21ee23bfd2748febb1d8d5889 TheArtOfGriefing 2020-02-13 18:26:23
darray function insert dummy item without size checking b3bf411a1545760ee5a7dc8f5afc455335a1927e Jackalope 2020-02-04 05:35:07
make array count functions static and constexpr 272f99f2929b282513aaa529089a8f093db1c8c0 Jackalope 2020-02-01 05:42:45
grammar correction for allocate.h bf1c90dfe7335bb6e57e9bdec7833ef842c616fd TheArtOfGriefing 2020-01-27 20:09:18
changed array2D and array3D template arguments order 37f03f7de5ccc7fbc0c3c77db0b9f0c10e0dc027 jp.larry 2020-01-14 00:28:33
debug assert voiding msg on release 4fe51953aedb28bdcac8b43184dcff6bc5a7c4eb jp.larry 2020-01-10 10:49:49
max min and max constexpr c1110b3513eef049cf717f1f41782474d5e1d6fa jp.larry 2020-01-06 07:26:09
last and first functions for array 5c5883b926743d897e921f5bdeab6c71856ad2ff jp.larry 2020-01-05 03:21:48
check if cut resize size is 0 a96cfa8397b91fd00a2c2d9ba54a066a716db485 jp.larry 2019-12-29 23:05:11
darray identation change 4517cde552dc545b8de0b61f1096003e5d08143e jp.larry 2019-12-29 23:02:50
sharray identation fixed aa721791d655529b1c69060ade81c9e5f3360f51 jp.larry 2019-12-29 22:24:55
darray sorted find_or_insert function d96940317c4b701aa351930a5d7a1dd311424811 jp.larry 2019-12-29 22:21:14
darray cut_if_oversize removed from non-check functions. why it was there? 6a639746490da4059f4517b165a9238f3cb86dfd jp.larry 2019-12-29 22:20:39
new array call_all function 0f4c133956ce154804ea889107a22e79c5d61802 Jackalope 2019-12-28 15:40:51
rarray contructor from range of values a5692aeede43201f9744128a7ce9a2b227e83436 jp.larry 2019-12-28 06:33:39
array init and destroy function 8bdcbcda4f40bb9e5267f9932f52e3d84e27b2d2 jp.larry 2019-12-27 22:18:13
array call all function removed a174efc464dd51adf9cdd850a8b61f6e817016db jp.larry 2019-12-27 20:39:56
array call_all function 01f4adbc7d7e433e77b06e89dab1dbeace11afb3 jp.larry 2019-12-26 01:19:50
time ambigeous operators removed bd281bc6f10f0451257e00a60b18a3e48a564d4b jp.larry 2019-12-23 22:36:12
assert macro fixed e67ca2008ac68451837db3f4296e251d88397c6b Your Name 2019-12-15 14:22:09
Commit 610cb9723e9451e21ee23bfd2748febb1d8d5889 - comments
Author: TheArtOfGriefing
Author date (UTC): 2020-02-13 18:26
Committer name: TheArtOfGriefing
Committer date (UTC): 2020-02-13 18:26
Parent(s): ea8ef33e21562cdccf31938264cad4a49bcc212d
Signer:
Signing key:
Signing status: N
Tree: 77ad452f1bfba349456f8dc8ecf7ebfb3ab3de7c
File Lines added Lines deleted
include/jlib/allocate.h 1 1
include/jlib/darray.h 83 81
File include/jlib/allocate.h changed (mode: 100644) (index 488b643..7d77d12)
... ... namespace jl
39 39 if (alignment == 0 || reinterpret_cast<size_t>(p_new) % alignment == 0) if (alignment == 0 || reinterpret_cast<size_t>(p_new) % alignment == 0)
40 40 return p_new; return p_new;
41 41
42 //if reallocated memory badly aligned, allocate manually
42 //if reallocated memory is poorly aligned, allocate manually
43 43 p_to_realloc = allocate_bytes<T>(byte_count, alignment); p_to_realloc = allocate_bytes<T>(byte_count, alignment);
44 44 memcpy(p_to_realloc, p_new, malloc_usable_size(p_to_realloc)); memcpy(p_to_realloc, p_new, malloc_usable_size(p_to_realloc));
45 45 free(p_new); free(p_new);
File include/jlib/darray.h changed (mode: 100644) (index 2fbb598..b6cfdc6)
... ... namespace jl { template<typename T, typename G = grow_policy<>> struct darray; }
17 17 * *
18 18 * Made for usage without constructors, destructors, exceptions. * Made for usage without constructors, destructors, exceptions.
19 19 * *
20 * Before using any function, darray must be initialized
20 * Before using a function, darray must be initialized
21 21 * by any of darray::init functions * by any of darray::init functions
22 22 * *
23 23 * Methods in jl::item_call specifies what to do with elements * Methods in jl::item_call specifies what to do with elements
 
... ... struct jl::darray
50 50 /** /**
51 51 * @brief Initialize array with reserved allocated memory. * @brief Initialize array with reserved allocated memory.
52 52 * *
53 * Function must not be called if darray was already initialized and not destroyed.
53 * Function must not be called if darray was already
54 * initialized and not destroyed.
54 55 * *
55 56 * @param[in] reserved_count Reserved count of items, * @param[in] reserved_count Reserved count of items,
56 57 * which can fit without reallocating the array * which can fit without reallocating the array
57 58 * @return If memory allocation failed, false is returned * @return If memory allocation failed, false is returned
58 * and darray is an undefined state.
59 * and darray is in an undefined state.
59 60 */ */
60 61 [[nodiscard]] bool init(size_t reserved_count) [[nodiscard]] bool init(size_t reserved_count)
61 62 { {
 
... ... struct jl::darray
72 73 /** /**
73 74 * @brief Set array item count to zero. * @brief Set array item count to zero.
74 75 * *
75 * Function will not do anything with items,
76 * just will make darray to forget about them.
77 * Array items will be unaccessible after,
78 * so they must be cleaned up before, if needed.
76 * The items must be cleaned up beforehand, if needed.
79 77 * Memory allocation size will be unchanged. * Memory allocation size will be unchanged.
80 78 */ */
81 79 void clean() { p_end = p_begin_allocated; } void clean() { p_end = p_begin_allocated; }
82 80
83 81 /** /**
84 * @brief Destroy all array items by using pointer to function
85 * or to member function.
82 * @brief Destroy all array items by using pointer
83 * to function or to member function.
86 84 * *
87 * Function reduce used elements count to 0,
88 * while allocated size unchanged.
89 * Array items will be unaccessible after,
90 * so they must be cleaned up by item_call meshod.
85 * Function reduces used elements count to 0,
86 * while allocated size remains unchanged.
87 * Array items will become unaccessible,
88 * so they must be cleaned up by item_call method.
91 89 * *
92 90 * @tparam P_FOO Type of pointer to function or to member function. * @tparam P_FOO Type of pointer to function or to member function.
93 * @tparam Args Parameters pack template, should not be specified
94 * in template instantiation
91 * @tparam Args Parameter pack template, should not be specified
92 * in template instantiation.
95 93 * @param[in] pfoo Pointer to function with first argument must be * @param[in] pfoo Pointer to function with first argument must be
96 * copy or refference of item (T)
94 * a copy, a refference of item (T)
97 95 * or pointer to member function. * or pointer to member function.
98 96 * @param[in,out] args Pack of arguments to pass to pfoo function. * @param[in,out] args Pack of arguments to pass to pfoo function.
99 97 */ */
 
... ... struct jl::darray
108 106 /** /**
109 107 * @brief Deallocate memory used by darray. * @brief Deallocate memory used by darray.
110 108 * *
111 * All items in the array will be unavailable after.
109 * All items in the array will become unavailable.
112 110 * *
113 111 * @see darray::clean * @see darray::clean
114 112 * @see darray::destroy * @see darray::destroy
 
... ... struct jl::darray
154 152 [[nodiscard]] uint8_t count8() const [[nodiscard]] uint8_t count8() const
155 153 { return uint8_t (count()); } { return uint8_t (count()); }
156 154
157 ///@brief Count of items, which can fit without growing allocation size.
155 ///@brief Count of items, which can fit without increasing allocation size.
158 156 [[nodiscard]] size_t reserved_count() const [[nodiscard]] size_t reserved_count() const
159 157 { return size_t(p_end_allocated - p_end) / sizeof(T); } { return size_t(p_end_allocated - p_end) / sizeof(T); }
160 158
 
... ... struct jl::darray
173 171 } }
174 172
175 173 ///@brief Reduce allocated size to max_item_count, ///@brief Reduce allocated size to max_item_count,
176 /// but only if used_size is less and allocated size is greater.
174 /// if max_item_count is greater than used_size and less than allocated size.
177 175 bool cut_if_oversize(size_t max_item_count) { bool cut_if_oversize(size_t max_item_count) {
178 176 if (count() < max_item_count if (count() < max_item_count
179 177 and size_allocated() > max_item_count * sizeof(T)) and size_allocated() > max_item_count * sizeof(T))
 
... ... struct jl::darray
191 189 * @brief Set reserved count of items. * @brief Set reserved count of items.
192 190 * *
193 191 * @param[in] count Set count of items to be reserved, overwriting existing * @param[in] count Set count of items to be reserved, overwriting existing
194 * value, function will ignore if reserved count already
195 * larger or equal than requested count.
196 * @return if needed to reallocated memory and reallocation fails,
197 * false is returned, requested reserved count will not be set.
192 * value, function will do nothing if reserved count already
193 * larger or equal to requested count.
194 * @return if memory reallocation is needed and it fails,
195 * false is returned and requested reserved count will not be set.
198 196 */ */
199 197 [[nodiscard]] bool reserve(size_t count) { [[nodiscard]] bool reserve(size_t count) {
200 198 int64_t extra_count = int64_t(count - reserved_count()); int64_t extra_count = int64_t(count - reserved_count());
 
... ... struct jl::darray
208 206 /** /**
209 207 * @brief Insert specified count of items without initializing them. * @brief Insert specified count of items without initializing them.
210 208 * *
211 * @param[in] count Count of items to insert, default is 1.
209 * @param[in] count Count of items to insert, 1 by default.
212 210 * *
213 211 * @return False if reserved count is less than insertion * @return False if reserved count is less than insertion
214 212 * count and memory reallocation fails. * count and memory reallocation fails.
 
... ... struct jl::darray
223 221 /** /**
224 222 * @brief Insert specified count of items and call function for them. * @brief Insert specified count of items and call function for them.
225 223 * *
226 * Point of pfoo pointer to function or to member
227 * function is to initialize items.
228 * Example, conditionally initializing 10 ints with value 4 or 3:
224 * pfoo pointer to function or to member
225 * function is used to initialize items.
226 * Example: conditionally initializing 10 ints with value 4 or 3:
229 227 * @code * @code
230 228 * bool is_true = true; * bool is_true = true;
231 229 * darray<int> da = {}; * darray<int> da = {};
 
... ... struct jl::darray
236 234 * @tparam Args Parameters pack template, * @tparam Args Parameters pack template,
237 235 * should not be specified in template instantiation * should not be specified in template instantiation
238 236 * *
239 * @param[in] count Count of items to insert, default is 1.
240 * @param[in] pfoo Pointer to function with first argument
241 * must be pointer to item (T*)
242 * or pointer to member function.
237 * @param[in] count Count of items to insert, 1 by default.
238 * @param[in] pfoo Pointer to function where first argument
239 * must be a pointer to item (T*)
240 * or to member function.
243 241 * @param[in,out] args Pack of arguments to pass to pfoo function. * @param[in,out] args Pack of arguments to pass to pfoo function.
244 242 * *
245 243 * @return False if reserved count is less than insertion * @return False if reserved count is less than insertion
 
... ... struct jl::darray
289 287 } }
290 288
291 289 /** /**
292 * @brief Insert single item, copied from value, to the end.
290 * @brief Copy an item from value and insert it in the and of the array.
293 291 * *
294 * @param[in] value Item value to be copited to new item in the end of array
292 * @param[in] value Item value that gets copied to new item in
293 * the end of array
295 294 * @return False if reserved count is zero * @return False if reserved count is zero
296 295 * and memory reallocation fails. * and memory reallocation fails.
297 296 */ */
 
... ... struct jl::darray
303 302 } }
304 303
305 304 /** /**
306 * @brief Insert single item, copied from value,
307 * to position of iterator pointed to.
305 * @brief Copy an item from value and insert it
306 * in the position pointed by itterator.
308 307 * *
309 308 * All items from position of iterator to the end of the array * All items from position of iterator to the end of the array
310 * will be moved by 1 position right, to free space for new item.
309 * will be moved 1 position to the right, to free up the space for new item.
311 310 * *
312 * @param[in] value Item value to be copited to new item
311 * @param[in] value Item value that gets copied to new item
313 312 * in the position of iterator * in the position of iterator
314 * @param[in] iterator Valid pointer to the item in the range [begin,end].
313 * @param[in] iterator Valid pointer to the item in range [begin,end].
315 314 * @return False if reserved count is zero and memory reallocation fails. * @return False if reserved count is zero and memory reallocation fails.
316 315 */ */
317 316 [[nodiscard]] bool insert(const T &value, T* iterator) { [[nodiscard]] bool insert(const T &value, T* iterator) {
 
... ... struct jl::darray
324 323 } }
325 324
326 325 /** /**
327 * @brief Insert single item, copied from value, to the index position.
326 * @brief Copy an item from value and insert it to the index position.
328 327 * *
329 328 * All items from index position to the end of the array * All items from index position to the end of the array
330 * will be moved by 1 position right, to free space for new item.
329 * will be moved 1 position right, to free up the space for new item.
331 330 * *
332 * @param[in] value Item value to be copited to new item by index
331 * @param[in] value Item value that gets copied to new item by index
333 332 * @param[in] index Ofset from darray::begin, * @param[in] index Ofset from darray::begin,
334 333 * not greater or equal than darray::count. * not greater or equal than darray::count.
335 334 * @return False if reserved count is zero and memory reallocation fails. * @return False if reserved count is zero and memory reallocation fails.
 
... ... struct jl::darray
340 339 } }
341 340
342 341 /** /**
343 * @brief Remove item by iterator position.
342 * @brief Remove item at iterator position.
344 343 * *
345 * All items after removed one will be shifted to the left by 1
346 * to fill freed slot.
344 * After an item gets removed all other items will be shifted to the left
345 * by 1 to fill the freed slot.
347 346 * *
348 * @param[in] iterator Valid pointer to the item in the range [begin,end).
347 * @param[in] iterator Valid pointer to the item in range [begin,end).
349 348 * *
350 349 * @see darray::begin * @see darray::begin
351 350 * @see darray::end * @see darray::end
 
... ... struct jl::darray
360 359 } }
361 360
362 361 /** /**
363 * @brief Call function with item from iterator position, and remove.
362 * @brief Call function for an item from iterator position, and remove it.
364 363 * *
365 * All items after removed one will be shifted to the left by 1
366 * to fill freed slot.
364 * After an item gets removed all other items will be shifted to the left
365 * by 1 to fill the freed slot.
367 366 * *
368 * @param[in] iterator Valid pointer to the item in the range [begin,end).
367 * @param[in] iterator Valid pointer to item in the range [begin,end).
369 368 * @param[in] pfoo Pointer to function with first argument must be * @param[in] pfoo Pointer to function with first argument must be
370 369 * pointer to item (T*) or pointer to member function. * pointer to item (T*) or pointer to member function.
371 * @param[in,out] args Pack of arguments for function call.
370 * @param[in,out] args Pack of arguments used to call the function.
372 371 * *
373 372 * @see darray::begin * @see darray::begin
374 373 * @see darray::end * @see darray::end
 
... ... struct jl::darray
383 382 } }
384 383
385 384 /** /**
386 * @brief Remove item by index.
385 * @brief Remove item based on index.
387 386 * *
388 * Same function as darray::remove, but by index istead of pointer.
387 * Same as darray::remove
388 * Removes an item, but based on index istead of pointer.
389 389 * *
390 390 * @param[in] index Offset from darray::begin, * @param[in] index Offset from darray::begin,
391 391 * must be less than darray::count. * must be less than darray::count.
 
... ... struct jl::darray
394 394 void remove(size_t index) { remove(begin() + index); } void remove(size_t index) { remove(begin() + index); }
395 395
396 396 /** /**
397 * @brief Call function with item and remove this item by index.
397 * @brief Call function for an item and remove this item based on index.
398 398 * *
399 * Same function as darray::remove, but by index istead of pointer.
399 * Same as darray::remove.
400 * Removes an item, but based on index istead of pointer.
400 401 * *
401 402 * @param[in] index Ofset from darray::begin, * @param[in] index Ofset from darray::begin,
402 * not greater or equal than darray::count.
403 * must be less or equal to darray::count.
403 404 * @see darray::remove * @see darray::remove
404 405 */ */
405 406 template<typename P_FOO, typename ... Args> template<typename P_FOO, typename ... Args>
 
... ... struct jl::darray
413 414 return *end(); return *end();
414 415 } }
415 416
416 /// @brief Put last item to *p_dst, remove and return true,
417 /// @brief Put last item to *p_dst, remove it and return true,
417 418 /// if array is not empty, otherwise return false. /// if array is not empty, otherwise return false.
418 419 [[nodiscard]] bool remove_last_if_exist(T *p_dst) { [[nodiscard]] bool remove_last_if_exist(T *p_dst) {
419 420 if (count() > 0) if (count() > 0)
 
... ... struct jl::darray
427 428 * *
428 429 * @param[in] pfoo_cond Function or member function, must return bool. * @param[in] pfoo_cond Function or member function, must return bool.
429 430 * Item will be removed if true is returned. Function * Item will be removed if true is returned. Function
430 * must take item copy or refference in the
431 * must take an item copy or refference in the
431 432 * first argument, member function does not. * first argument, member function does not.
432 433 * *
433 434 * @param[in,out] args Argument pack to pass to function or member function. * @param[in,out] args Argument pack to pass to function or member function.
 
... ... struct jl::darray
443 444 } }
444 445
445 446 /** /**
446 * @brief Get pointer to item, which is equal to value_to_search.
447 * @brief Get pointer of an item, which is equal to value_to_search.
447 448 * *
448 449 * @tparam T_CMP T type must have overloaded "==" * @tparam T_CMP T type must have overloaded "=="
449 * operator for value of type T_CMP
450 * @param[in] value_to_search Value of type T_CMP for searching
451 * @param[out] p_p_dst Pointer to variable, for placing pointer
452 * to found item on success
450 * operator for value of T_CMP type
451 * @param[in] value_to_search Value of T_CMP type for searching
452 * @param[out] p_p_dst Pointer to variable, for placing a pointer
453 * on item found upon success
453 454 * @return bool "is item found" * @return bool "is item found"
454 455 */ */
455 456 template<typename T_CMP> template<typename T_CMP>
 
... ... struct jl::darray
457 458 { return search(begin(), end(), value_to_search, p_p_dst); } { return search(begin(), end(), value_to_search, p_p_dst); }
458 459
459 460 /** /**
460 * @brief Get copy of item, which is equal to value_to_search.
461 * @brief Get a copy of an item, which is equal to value_to_search.
461 462 * *
462 * Same as darray::find, but for getting found value copy, instead of pointer.
463 * Same as darray::find.
464 * but for getting found value copy, instead of pointer.
463 465 * *
464 * @param[out] p_dst Pointer to variable for placing copy
465 * of found item on success
466 * @param[out] p_dst Pointer to variable, for placing a copy
467 * of found item upon success
466 468 * @see darray::find * @see darray::find
467 469 */ */
468 470 template<typename T_CMP> template<typename T_CMP>
 
... ... struct jl::darray
474 476 } }
475 477
476 478 /** /**
477 * @brief Get pointer to the begin of memory where items are stored.
478 * @return Pointer to the begin of memory.
479 * @brief Get pointer to the beginning of memory where items are stored.
480 * @return Pointer to the beginning of memory.
479 481 */ */
480 482 [[nodiscard]] T* begin() [[nodiscard]] T* begin()
481 483 { return reinterpret_cast<T*>(p_begin_allocated); } { return reinterpret_cast<T*>(p_begin_allocated); }
482 484 /** /**
483 * @brief Get pointer to the begin of memory where items are stored
485 * @brief Get pointer to the beginning of memory where items are stored
484 486 * with read-only access. * with read-only access.
485 * @return Pointer to the begin of memory where items are stored
487 * @return Pointer to the beginning of memory where items are stored
486 488 * with read-only access. * with read-only access.
487 489 */ */
488 490 [[nodiscard]] const T* begin() const [[nodiscard]] const T* begin() const
489 491 { return reinterpret_cast<T*>(p_begin_allocated); } { return reinterpret_cast<T*>(p_begin_allocated); }
490 492
491 493 /** /**
492 * @brief Get pointer to first byte after the last item.
493 * @return Pointer with read-only access to first byte after last item
494 * in the array, or to the begin of memory where items are stored,
494 * @brief Get pointer to the first byte after the last item.
495 * @return Pointer with read-only access to the first byte after the last item
496 * in the array, or to the beginning of memory where items are stored,
495 497 * if item count is zero. * if item count is zero.
496 498 */ */
497 499 [[nodiscard]] T* end() [[nodiscard]] T* end()
498 500 { return reinterpret_cast<T*>(p_end); } { return reinterpret_cast<T*>(p_end); }
499 501
500 502 /** /**
501 * @brief Get pointer to first byte after the last item with read-only access.
502 * @return Pointer with read-only access to first byte after last item
503 * in the array, or to the begin of memory where items are stored,
503 * @brief Get pointer to the first byte after the last item with read-only access.
504 * @return Pointer with read-only access to the first byte after the last item
505 * in the array, or to the begining of memory where items are stored,
504 506 * if item count is zero. * if item count is zero.
505 507 */ */
506 508 [[nodiscard]] const T* end() const [[nodiscard]] const T* end() const
507 509 { return reinterpret_cast<T*>(p_end); } { return reinterpret_cast<T*>(p_end); }
508 510
509 511 /** /**
510 * @brief Get refference to item by index.
512 * @brief Get a refference to item by index.
511 513 * *
512 514 * Must not be called if current item count is zero * Must not be called if current item count is zero
513 515 * *
514 516 * @param[in] i Index-offset, specified by item count, from begining * @param[in] i Index-offset, specified by item count, from begining
515 517 * of the array, must be less than item count. * of the array, must be less than item count.
516 * @return Refference to item, stored by index.
518 * @return Refference to item by index.
517 519 * *
518 520 * @see darray::count * @see darray::count
519 521 */ */
 
... ... struct jl::darray
529 531 * *
530 532 * @param[in] i Index-offset, specified by item count, from begining * @param[in] i Index-offset, specified by item count, from begining
531 533 * of the array, must be less than item count. * of the array, must be less than item count.
532 * @return Read-only refference to item, stored by index.
534 * @return Read-only refference to item by index.
533 535 * *
534 536 * @see darray::count * @see darray::count
535 537 */ */
 
... ... struct jl::darray
555 557 * *
556 558 * @param[in] count_to_add Count of items that must fit in the array * @param[in] count_to_add Count of items that must fit in the array
557 559 * after resize. * after resize.
558 * @return If true is returned, than array can fit count_to add,
559 * else false is returned, signaling that reallocation failed.
560 * @return If true is returned, array can fit count_to_add.
561 * if false is returned, reallocation failed.
560 562 * @see insert_no_resize_check * @see insert_no_resize_check
561 563 */ */
562 564 [[nodiscard]] bool resize_if_full(size_t count_to_add = 0) { [[nodiscard]] bool resize_if_full(size_t count_to_add = 0) {
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jlib

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jlib

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jlib

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main