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)
replaced built_move, built_const and init_move with constructors, for emulating initializer-lists bd60c52d8e0d475dd69f11a48c05224507cfae0e Your Name 2019-11-27 03:42:54
make free deprecated a68c1b809ddc5c2a0018142a8435c67b8e4e0cf6 Your Name 2019-11-26 22:13:26
new template data structure jl::array as static c-array wrapper 68ff5a4049985d4ed013d0976b32e0613bb11ff0 jp.larry 2019-11-25 20:16:39
jassert release macro was wrong 97964f5cf3485502675b77b4df5b322921355cf7 jp.larry 2019-11-25 20:15:13
darray insert functions without checking for resize 0a168f4fc057f697bec6ad1f90faaaa7977c9537 Your Name 2019-11-25 08:39:45
replaced free with jl::deallocate 1d25f7cfe0a36ce04eeb8a6a08dc9f9eefe5c2df Your Name 2019-11-25 07:28:42
jabort_release and jassert_release macros 71349de13d880a9a13eb7cca9c46d460c30705b2 Your Name 2019-11-25 07:00:50
endianness convertion function fbff0fbb13891f7ad2975e226476cf0b56eabb36 Your Name 2019-11-25 06:06:17
overwise -> otherwise 89d07c9f30aba52e50526b0ecf1ed6eddb791764 Your Name 2019-11-25 06:01:13
init function was incorrect 6c820a36720b41b2efbfcf101bd12eb43f69a91d Your Name 2019-11-25 05:59:05
time struct for time measurements d6e362c72596c97abbd7c6f87c25eca1d3127c46 Your Name 2019-11-25 05:58:50
jassert macro, assert alternative e5b46d371c19ec6608c861c8b93a9963f117ec6d Your Name 2019-11-25 05:43:03
typo 14b869ada95c37bcc75a549cdcedae1b0b2ba76d Your Name 2019-11-25 03:27:12
thread pool cleanup 0b783f47cd02fb118f299784b52209e259646b25 Your Name 2019-11-25 03:23:02
removed nodiscard for optional function 3ba7da3a20d2ef5e8bc70d1ff14b9db973bba0dd Your Name 2019-11-25 03:22:13
rarray allocation fix e192f65d453e4e858bc0c034b5b431591175886d Your Name 2019-11-25 03:20:49
new darray function 41ed65d9c71ba226572b451f487ac381bdcb382d Your Name 2019-11-25 03:20:26
threads wrapper and thread pool moved to jlib e902ab04f388b331f7b0201a01591c52c0fb44a5 Your Name 2019-11-25 02:11:05
sharray implementation 84f563f018049700a9aaa3d9b915cd8e60010d6a Your Name 2019-11-25 02:10:39
removed excess cmake variable 5391e7b7eb08e7aef83e7b3783c3eb405b701f99 Your Name 2019-11-25 02:09:41
Commit bd60c52d8e0d475dd69f11a48c05224507cfae0e - replaced built_move, built_const and init_move with constructors, for emulating initializer-lists
Author: Your Name
Author date (UTC): 2019-11-27 03:42
Committer name: Your Name
Committer date (UTC): 2019-11-27 03:42
Parent(s): a68c1b809ddc5c2a0018142a8435c67b8e4e0cf6
Signer:
Signing key:
Signing status: N
Tree: e481b727cd818d2bb695964f78f820a0fe3de563
File Lines added Lines deleted
include/jlib/rarray.h 33 63
include/jlib/string.h 7 12
File include/jlib/rarray.h changed (mode: 100644) (index 5001c81..f0bd40c)
10 10 #include <cinttypes> #include <cinttypes>
11 11 #include "assert.h" #include "assert.h"
12 12
13 #include <type_traits>
14
13 15 namespace jl namespace jl
14 16 { {
15 17 /** /**
 
... ... namespace jl
37 39 */ */
38 40 void init() { *this = {}; } void init() { *this = {}; }
39 41
42 rarray() = default;
43
40 44 /** /**
41 * @brief Initialize array with specified items count.
42 *
43 * Function must only be called if darray was not initialized by any of rarray::init functions.
45 * @brief Initialize read-only rarray as array with single value.
44 46 * *
45 * @param[in] count Space specified by count of items to allocate in the array.
46 *
47 * @return True if success, otherwise false and allocation is failed,
48 * array cannot be used until this function is successfull.
47 * @param value Single item to be pointed to.
49 48 */ */
50 [[nodiscard]] bool init(size_t count)
51 {
52 jassert(count, "must not be 0, use init() instead");
53 if (not jl::allocate(&p_begin, count))
54 return false;
55 p_end_allocated = p_begin + count;
56 return true;
57 }
49 rarray(T &value) : p_begin(&value), p_end_allocated(p_begin+1)
50 { static_assert (std::is_const<T>::value, "only for read-only rarray"); }
58 51
59 52 /** /**
60 53 * @brief Initialize with already allocated memory. * @brief Initialize with already allocated memory.
 
... ... namespace jl
66 59 * Allocated memory must only be deallocated outside of rarray, so * Allocated memory must only be deallocated outside of rarray, so
67 60 * memory will deallocate in rarray::destroy or rarray::resize, for example: * memory will deallocate in rarray::destroy or rarray::resize, for example:
68 61 * @code * @code
69 * darray<char> data;
62 * darray<int> data;
70 63 * data.init(); * data.init();
71 * data.insert(8, 0);
64 * data.insert(4);
65 * data.insert(8);
72 66 * rarray arr; * rarray arr;
73 * arr.init_move(data.begin(), data.end()); // darray p_allocation_end can be bigger
74 * // than pointer returned by end(),
75 * // but it does not affect deallocating.
67 * arr = {data.begin(), data.end()}; // darray p_allocation_end can be bigger
68 * // than pointer returned by end(),
69 * // but it does not affect deallocating.
76 70 * data.init(); // reset dynamic array clean to prevent double memory deallocation * data.init(); // reset dynamic array clean to prevent double memory deallocation
77 71 * arr.destroy(); // deallocate memory * arr.destroy(); // deallocate memory
78 72 * @endcode * @endcode
 
... ... namespace jl
80 74 * @param[in] p_allocated_mem Pointer to begin of already allocated memory. * @param[in] p_allocated_mem Pointer to begin of already allocated memory.
81 75 * @param[in] p_end_alocated_mem Pointer to end of already allocated memory, first byte after an allocation. * @param[in] p_end_alocated_mem Pointer to end of already allocated memory, first byte after an allocation.
82 76 */ */
83 void init_move(T *p_allocated_mem, T *p_end_alocated_mem)
84 {
85 jassert(p_end_alocated_mem >= p_allocated_mem, "end must be after beginning");
86 p_begin = p_allocated_mem;
87 p_end_allocated = p_end_alocated_mem;
88 }
77 rarray(T* p_allocated_mem, T* p_end_alocated_mem)
78 : p_begin(p_allocated_mem), p_end_allocated(p_end_alocated_mem)
79 { jassert(p_end_allocated >= p_begin, "wrong pointers order"); }
89 80
90 81 /** /**
91 82 * @brief Initialize with already allocated memory. * @brief Initialize with already allocated memory.
92 83 * *
93 * Same as rarray::init_move, but with different second argument
84 * Same as rarray::rarray(T* p_allocated_mem, T* p_end_alocated_mem), but with alternative second argument
94 85 * *
95 86 * @param[in] p_allocated_mem Pointer to begin of already allocated memory. * @param[in] p_allocated_mem Pointer to begin of already allocated memory.
96 87 * @param[in] allocated_count Size of allocated memory in items count. * @param[in] allocated_count Size of allocated memory in items count.
97 88 * *
98 * @see rarray::init_move
99 */
100 void init_move(T *p_allocated_mem, size_t allocated_count)
101 { init_move(p_allocated_mem, p_allocated_mem + allocated_count); }
102
103 /**
104 * @brief Create rarray with already allocated memory.
105 * @return rarray
106 * @see rarray::init_move
89 * @see rarray::rarray(T* p_allocated_mem, T* p_end_alocated_mem)
107 90 */ */
108 template<typename ...Args>
109 [[nodiscard]] static rarray built_move(Args ... args)
110 {
111 rarray r;
112 r.init_move(args...);
113 return r;
114 }
91 rarray(T *p_allocated_mem, size_t allocated_count)
92 : p_begin(p_allocated_mem), p_end_allocated(p_allocated_mem + allocated_count){}
115 93
116 94 /** /**
117 * @brief Create read-only rarray by pointer to array.
95 * @brief Initialize array with specified items count.
118 96 * *
119 * @param[in] p_begin Pointer to begin of array.
120 * @param[in] p_end Pointer to end of array, first byte after last byte of an array.
97 * Function must only be called if darray was not initialized by any of rarray::init functions.
98 *
99 * @param[in] count Space specified by count of items to allocate in the array.
121 100 * *
122 * @return read-only rarray
101 * @return True if success, otherwise false and allocation is failed,
102 * array cannot be used until this function is successfull.
123 103 */ */
124 [[nodiscard]] static rarray<const T> built_const(const T *p_begin, const T *p_end)
104 [[nodiscard]] bool init(size_t count)
125 105 { {
126 jassert(p_end >= p_begin, "end must be after beginning");
127 rarray r;
128 r.p_begin = p_begin;
129 r.p_end_allocated = p_end;
130 return r;
106 jassert(count, "must not be 0, use init() instead");
107 if (not jl::allocate(&p_begin, count))
108 return false;
109 p_end_allocated = p_begin + count;
110 return true;
131 111 } }
132 112
133 /**
134 * @brief Create read-only rarray by pointer to array.
135 *
136 * @param[in] p_begin Pointer to begin of array.
137 * @param[in] count Size of array in items count.
138 *
139 * @return read-only rarray
140 */
141 [[nodiscard]] static rarray<const T> built_const(const T *p_begin, size_t count)
142 { return built_const(p_begin, p_begin + count); }
143 113 /** /**
144 114 * @brief Deallocate space, set item count to 0. * @brief Deallocate space, set item count to 0.
145 115 * *
File include/jlib/string.h changed (mode: 100644) (index 81a5681..72b8259)
... ... namespace jl
25 25 struct carray : rarray<T> struct carray : rarray<T>
26 26 { {
27 27 using rarray<T>::init; using rarray<T>::init;
28
29 template<typename ...Args>
30 [[nodiscard]] static carray<const T> built_const(Args ...args)
31 { return carray<const T>(rarray<T>::built_const(args...)); }
28 using rarray<T>::rarray;
32 29
33 30 /** /**
34 31 * @brief Initialize array with c-style string. * @brief Initialize array with c-style string.
 
... ... namespace jl
88 85 return true; return true;
89 86 } }
90 87
88 /// @see rarray(T &value)
89 carray(T &value) : rarray<T>(value) {}
90
91 91 /** /**
92 92 * @brief Built read-only access carray by given c-string pointer. * @brief Built read-only access carray by given c-string pointer.
93 93 * *
 
... ... namespace jl
95 95 * *
96 96 * @param[in] null_terminated_str Pointer to C-style null-terminated string, * @param[in] null_terminated_str Pointer to C-style null-terminated string,
97 97 * must be valid pointer while carray is in use. * must be valid pointer while carray is in use.
98 * @return Read-only carray.
99 98 */ */
100 [[nodiscard]] static carray<const T> built_const(const char *null_terminated_str)
101 {
102 jassert(null_terminated_str, "invalid pointer");
103 carray<const T> ca;
104 ca.init_move(null_terminated_str, strlen(null_terminated_str)+1);
105 return ca;
106 }
99 carray(const char *null_terminated_str)
100 : rarray<const char>(null_terminated_str, strlen(null_terminated_str)+1)
101 { jassert(null_terminated_str, "invalid pointer"); }
107 102
108 103
109 104 /// @brief Length of character array, specified by count of chars, excluding null-char '\0'. /// @brief Length of character array, specified by count of chars, excluding null-char '\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