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)
new carray, string, string_const templates e194dca9ee1d7844d13b66749f795666cc28df96 Your Name 2019-11-22 01:18:48
grow.h and item_call.h renamed e17eec6aae4ba4083e837534bb2f98cf2b7a6673 Your Name 2019-11-22 00:57:40
io agents renamed 321c4633ba149484d9855c063e80c46ed43ee7e7 Your Name 2019-11-22 00:57:16
renamed arrays a2d0d5706f1131d553cc0d02cf7f714b3ee921c6 Your Name 2019-11-22 00:55:25
new ResizableArray template 26bf1df5faa43acdfb3fef739831f6e5ba1ad37a Your Name 2019-11-21 21:32:41
more documentation for dynamic array 2729fc335189e151aa132be3244cfea6a713896f Your Name 2019-11-21 21:30:37
io_agent interface and etalon realizations 4464bf88e4da18966ad522709f7490c15d3fd3d0 Your Name 2019-11-21 19:33:31
dynamic array bug fixes a558181cb2c9f3e76e928de8be74684e0c14baa2 Your Name 2019-11-21 19:32:37
deallocate func bug fixed b7b6aa7595db24836e78f892cdce9ffa78b15bf8 Your Name 2019-11-21 19:31:53
added dots =) 5272ca044750a014547db3edcde79e2fe6dbb6ca Your Name 2019-11-21 13:59:21
disabled man generation by doxygen 6dbfdbe48c16b07bd8afc247ae2fa995f56a5332 Your Name 2019-11-21 13:39:46
function commentary improved 791e5df05a5bf6acb18984b5d31260e7f9718466 Your Name 2019-11-21 13:38:54
DynamicArray_sorted instert function bug fix 7677fded3f22300d92a497d787b135a2e7ac988a Your Name 2019-11-20 21:25:15
moved doxygen search path 245fc569f64ae36e7fc8ab93ea954e98696512ed Your Name 2019-11-20 19:02:23
renamed jtl to jlib and namespace jl 343794453e4b4643cb53d01d8fde4a2e75d6bdc1 Your Name 2019-11-20 18:53:58
disabled doxygen sorting e23e48587d14715bc4b2b44ac5d0016525bc1a0d Your Name 2019-11-20 18:45:03
documentation improved by tags 63f7874b0f9d9864a39f408478f56fc5a3c114d2 Your Name 2019-11-20 18:10:30
added doxygen to gitignore 7dff94b8d776d61b9a48b1fbbd8cd6116ec600c0 Your Name 2019-11-20 00:20:22
doxygen documentation 8d1302091cb159975bee74ab8d011d2d21e6ade2 Your Name 2019-11-20 00:13:57
this file no need 571e8c3919e7aef0b7a6d5c1ddccb115d76eb238 Your Name 2019-11-20 00:13:41
Commit e194dca9ee1d7844d13b66749f795666cc28df96 - new carray, string, string_const templates
Author: Your Name
Author date (UTC): 2019-11-22 01:18
Committer name: Your Name
Committer date (UTC): 2019-11-22 01:18
Parent(s): e17eec6aae4ba4083e837534bb2f98cf2b7a6673
Signer:
Signing key:
Signing status: N
Tree: 664e7c21bc6d06ede37b8182c4592352b7050df4
File Lines added Lines deleted
include/jlib/string.h 138 0
File include/jlib/string.h added (mode: 100644) (index 0000000..5a515bc)
1 /**
2 * @file string.h
3 * @brief carray, string and string_const declaration.
4 */
5
6 #pragma once
7
8 #include "resizable_array.h"
9 #include <cstring>
10
11 namespace jl
12 {
13 /**
14 * @brief character array template inherited from rarray.
15 *
16 * Made for usage without constructors, destructors, exceptions.
17 *
18 * Before using any function, carray must be initialized by any of carray::init functions
19 *
20 * @tparam T Type of chars to store in the array.
21 *
22 * @see rarray
23 */
24 template<typename T>
25 struct carray : rarray<T>
26 {
27 using rarray<T>::init;
28 /**
29 * @brief Initialize array with c-style string.
30 *
31 * Allocate memory with length of c-style string and copy data from it.
32 *
33 * Function must only be called if carray was not initialized by any of carray::init or rarray::init functions.
34 *
35 * @param[in] null_terminated_str C-style null-terminated string.
36 * @return If memory allocation failed, false is returned
37 * and carray is an undefined state.
38 */
39 [[nodiscard]] bool init(const char *null_terminated_str)
40 {
41 return init(null_terminated_str, strlen(null_terminated_str));
42 }
43
44 /**
45 * @brief Initialize array with string and given length.
46 *
47 * Allocate memory with length of c-style string and copy data from it.
48 *
49 * Function must only be called if carray was not initialized by any of carray::init or rarray::init functions.
50 *
51 * @param[in] str Pointer to array of at least str_length length.
52 * @param[in] str_length Length specified by count of chars to copy.
53 * @return If memory allocation failed, false is returned
54 * and carray is an undefined state.
55 */
56 [[nodiscard]] bool init(const T *str, size_t str_length)
57 {
58 if (not this->init(str_length+1))
59 return false;
60
61 memcpy(this->p_begin, str, str_length);
62 this->last() = '\0';
63
64 return true;
65 }
66
67 /**
68 * @brief Initialize array by copying from rarray or carray.
69 *
70 * Function must only be called if carray was not initialized by any of carray::init or rarray::init functions.
71 *
72 * @param[in] a rarray or carray to copy data from.
73 * @return If memory allocation failed, false is returned
74 * and carray is an undefined state.
75 */
76 [[nodiscard]] bool init(const rarray<const T> &a)
77 {
78 if (not this->init(a.size_allocated()))
79 return false;
80
81 memcpy(this->begin(), a.begin(), a.size_allocated());
82 return true;
83 }
84
85 /**
86 * @brief Built read-only access carray by given c-string pointer.
87 *
88 * read-only carray cannot be destroyed, so it is safe built.
89 *
90 * @param[in] null_terminated_str Pointer to C-style null-terminated string,
91 * must be valid pointer while carray is in use.
92 * @return Read-only carray.
93 */
94 [[nodiscard]] static carray<const T> built_const(const char *null_terminated_str)
95 {
96 carray<const T> ca;
97 ca.init_move(null_terminated_str, strlen(null_terminated_str)+1);
98 return ca;
99 }
100
101
102 /// @brief Length of character array, specified by count of chars, excluding null-char '\0'.
103 [[nodiscard]] inline size_t length() const { return this->count()-1; }
104 /// @brief Allocated size in bytes for carray.
105 [[nodiscard]] inline size_t size() const { return this->size_allocated(); }
106
107 [[nodiscard]] inline bool operator == (const carray<T> &a) const
108 {
109 if (this->size() != a.size())
110 return false;
111 return compare(a) == 0;
112 }
113 [[nodiscard]] inline bool operator != (const carray<T> &a) const { return !((*this) == a); }
114 [[nodiscard]] inline bool operator > (const carray<T> &a) const { return compare(a) > 0; }
115 [[nodiscard]] inline bool operator >= (const carray<T> &a) const { return compare(a) >= 0; }
116 [[nodiscard]] inline bool operator <= (const carray<T> &a) const { return compare(a) <= 0; }
117 [[nodiscard]] inline bool operator < (const carray<T> &a) const { return compare(a) < 0; }
118
119 /// @brief Convert to read-only version without issues
120 operator carray<const T> () const { return carray<const T>{this->operator rarray<const T>()}; }
121 protected:
122 /// @brief Same as strcmp, but for carray, instead of const char*.
123 [[nodiscard]] int compare(const carray<T> &a) const
124 {
125 auto p1 = this->begin();
126 auto p2 = a.begin();
127 for(; *p1 == *p2; ++p1, ++p2)
128 if (*p1 == '\0')
129 return *p2 == '\0' ? 0 : -1;
130 return *p1 < *p2 ? -1 : 1;
131 }
132 };
133
134 /// @brief Typedef of carray, using char as character type. @see carray
135 using string = carray<char>;
136 /// @brief Typedef of read-only carray, using char as character type. @see carray
137 using string_const = carray<const char>;
138 }
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