meta: rename to fx
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_BITOP_H_
|
||||
#define BLUELIB_CORE_BITOP_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
|
||||
BLUE_API int b_popcountl(long v);
|
||||
BLUE_API int b_ctzl(long v);
|
||||
BLUE_API int b_clzl(long v);
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define b_cmpxchg(v, expected_val, new_val) \
|
||||
__atomic_compare_exchange_n( \
|
||||
v, expected_val, new_val, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED)
|
||||
#elif defined(_MSC_VER)
|
||||
/* TODO add MSVC support */
|
||||
#error MSVC intrinsics not yet supported
|
||||
#else
|
||||
#error Unsupported compiler
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
#ifndef BLUE_CORE_BSTR_H_
|
||||
#define BLUE_CORE_BSTR_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define B_BSTR_MAGIC 0x5005500550055005ULL
|
||||
|
||||
struct b_rope;
|
||||
|
||||
enum b_bstr_flags {
|
||||
B_BSTR_F_NONE = 0x00u,
|
||||
B_BSTR_F_ALLOC = 0x01u,
|
||||
};
|
||||
|
||||
typedef struct b_bstr {
|
||||
uint64_t bstr_magic;
|
||||
enum b_bstr_flags bstr_flags;
|
||||
char *bstr_buf;
|
||||
/* total number of characters in bstr_buf, not including null terminator */
|
||||
size_t bstr_len;
|
||||
/* number of bytes allocated for bstr_buf (includes space for the null
|
||||
* terminator) */
|
||||
size_t bstr_capacity;
|
||||
int *bstr_istack;
|
||||
int bstr_add_indent;
|
||||
size_t bstr_istack_ptr, bstr_istack_size;
|
||||
} b_bstr;
|
||||
|
||||
BLUE_API void b_bstr_begin(b_bstr *strv, char *buf, size_t max);
|
||||
BLUE_API void b_bstr_begin_dynamic(b_bstr *strv);
|
||||
BLUE_API char *b_bstr_end(b_bstr *strv);
|
||||
BLUE_API b_status b_bstr_reserve(b_bstr *strv, size_t len);
|
||||
|
||||
static inline size_t b_bstr_get_size(const b_bstr *str)
|
||||
{
|
||||
return str->bstr_len;
|
||||
}
|
||||
|
||||
static inline size_t b_bstr_get_capacity(const b_bstr *str)
|
||||
{
|
||||
return str->bstr_capacity;
|
||||
}
|
||||
|
||||
BLUE_API b_status b_bstr_push_indent(b_bstr *strv, int indent);
|
||||
BLUE_API b_status b_bstr_pop_indent(b_bstr *strv);
|
||||
|
||||
BLUE_API b_status b_bstr_write_char(b_bstr *strv, char c);
|
||||
BLUE_API b_status b_bstr_write_chars(
|
||||
b_bstr *strv, const char *cs, size_t len, size_t *nr_written);
|
||||
BLUE_API b_status b_bstr_write_cstr(
|
||||
b_bstr *strv, const char *str, size_t *nr_written);
|
||||
BLUE_API b_status b_bstr_write_cstr_list(
|
||||
b_bstr *strv, const char **strs, size_t *nr_written);
|
||||
BLUE_API b_status b_bstr_write_cstr_array(
|
||||
b_bstr *strv, const char **strs, size_t count, size_t *nr_written);
|
||||
BLUE_API b_status b_bstr_write_cstr_varg(b_bstr *strv, size_t *nr_written, ...);
|
||||
BLUE_API b_status b_bstr_write_rope(
|
||||
b_bstr *strv, const struct b_rope *rope, size_t *nr_written);
|
||||
BLUE_API b_status b_bstr_write_fmt(
|
||||
b_bstr *strv, size_t *nr_written, const char *format, ...);
|
||||
BLUE_API b_status b_bstr_write_vfmt(
|
||||
b_bstr *strv, size_t *nr_written, const char *format, va_list arg);
|
||||
|
||||
BLUE_API char *b_bstr_rope(const struct b_rope *rope, size_t *nr_written);
|
||||
BLUE_API char *b_bstr_fmt(size_t *nr_written, const char *format, ...);
|
||||
BLUE_API char *b_bstr_vfmt(size_t *nr_written, const char *format, va_list arg);
|
||||
|
||||
#endif
|
||||
@@ -1,359 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_BTREE_H_
|
||||
#define BLUELIB_CORE_BTREE_H_
|
||||
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_BTREE_INIT {0}
|
||||
#define B_TYPE_BTREE_ITERATOR (b_btree_iterator_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_btree_iterator);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_btree_iterator)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_btree_iterator)
|
||||
|
||||
/* defines a simple node insertion function.
|
||||
this function assumes that your nodes have simple integer keys that can be
|
||||
compared with the usual operators.
|
||||
|
||||
EXAMPLE:
|
||||
if you have a tree node type like this:
|
||||
|
||||
struct my_tree_node {
|
||||
int key;
|
||||
b_btree_node base;
|
||||
}
|
||||
|
||||
You would use the following call to generate an insert function for a tree
|
||||
with this node type:
|
||||
|
||||
BTREE_DEFINE_SIMPLE_INSERT(
|
||||
struct my_tree_node,
|
||||
base,
|
||||
key,
|
||||
my_tree_node_insert);
|
||||
|
||||
Which would emit a function defined like:
|
||||
|
||||
static void my_tree_node_insert(b_btree *tree, struct my_tree_node *node);
|
||||
|
||||
@param node_type your custom tree node type. usually a structure that
|
||||
contains a b_btree_node member.
|
||||
@param container_node_member the name of the b_btree_node member variable
|
||||
within your custom type.
|
||||
@param container_key_member the name of the key member variable within your
|
||||
custom type.
|
||||
@param function_name the name of the function to generate.
|
||||
*/
|
||||
#define B_BTREE_DEFINE_SIMPLE_INSERT( \
|
||||
node_type, container_node_member, container_key_member, function_name) \
|
||||
void function_name(b_btree *tree, node_type *node) \
|
||||
{ \
|
||||
if (!tree->b_root) { \
|
||||
tree->b_root = &node->container_node_member; \
|
||||
b_btree_insert_fixup(tree, &node->container_node_member); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
b_btree_node *cur = tree->b_root; \
|
||||
while (1) { \
|
||||
node_type *cur_node = b_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
b_btree_node *next = NULL; \
|
||||
\
|
||||
if (node->container_key_member \
|
||||
>= cur_node->container_key_member) { \
|
||||
next = b_btree_right(cur); \
|
||||
\
|
||||
if (!next) { \
|
||||
b_btree_put_right( \
|
||||
cur, \
|
||||
&node->container_node_member); \
|
||||
break; \
|
||||
} \
|
||||
} else if ( \
|
||||
node->container_key_member \
|
||||
< cur_node->container_key_member) { \
|
||||
next = b_btree_left(cur); \
|
||||
\
|
||||
if (!next) { \
|
||||
b_btree_put_left( \
|
||||
cur, \
|
||||
&node->container_node_member); \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
cur = next; \
|
||||
} \
|
||||
\
|
||||
b_btree_insert_fixup(tree, &node->container_node_member); \
|
||||
}
|
||||
|
||||
/* defines a node insertion function.
|
||||
this function should be used for trees with complex node keys that cannot be
|
||||
directly compared. a comparator for your keys must be supplied.
|
||||
|
||||
EXAMPLE:
|
||||
if you have a tree node type like this:
|
||||
|
||||
struct my_tree_node {
|
||||
complex_key_t key;
|
||||
b_btree_node base;
|
||||
}
|
||||
|
||||
You would need to define a comparator function or macro with the following
|
||||
signature:
|
||||
|
||||
int my_comparator(struct my_tree_node *a, struct my_tree_node *b);
|
||||
|
||||
Which implements the following:
|
||||
|
||||
return -1 if a < b
|
||||
return 0 if a == b
|
||||
return 1 if a > b
|
||||
|
||||
You would use the following call to generate an insert function for a tree
|
||||
with this node type:
|
||||
|
||||
BTREE_DEFINE_INSERT(struct my_tree_node, base, key, my_tree_node_insert,
|
||||
my_comparator);
|
||||
|
||||
Which would emit a function defined like:
|
||||
|
||||
static void my_tree_node_insert(b_btree *tree, struct my_tree_node *node);
|
||||
|
||||
@param node_type your custom tree node type. usually a structure that
|
||||
contains a b_btree_node member.
|
||||
@param container_node_member the name of the b_btree_node member variable
|
||||
within your custom type.
|
||||
@param container_key_member the name of the key member variable within your
|
||||
custom type.
|
||||
@param function_name the name of the function to generate.
|
||||
@param comparator the name of a comparator function or functional-macro that
|
||||
conforms to the requirements listed above.
|
||||
*/
|
||||
#define B_BTREE_DEFINE_INSERT( \
|
||||
node_type, container_node_member, container_key_member, function_name, \
|
||||
comparator) \
|
||||
void function_name(b_btree *tree, node_type *node) \
|
||||
{ \
|
||||
if (!tree->b_root) { \
|
||||
tree->b_root = &node->container_node_member; \
|
||||
b_btree_insert_fixup(tree, &node->container_node_member); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
b_btree_node *cur = tree->b_root; \
|
||||
while (1) { \
|
||||
node_type *cur_node = b_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
b_btree_node *next = NULL; \
|
||||
int cmp = comparator(node, cur_node); \
|
||||
\
|
||||
if (cmp >= 0) { \
|
||||
next = b_btree_right(cur); \
|
||||
\
|
||||
if (!next) { \
|
||||
b_btree_put_right( \
|
||||
cur, \
|
||||
&node->container_node_member); \
|
||||
break; \
|
||||
} \
|
||||
} else if (cmp < 0) { \
|
||||
next = b_btree_left(cur); \
|
||||
\
|
||||
if (!next) { \
|
||||
b_btree_put_left( \
|
||||
cur, \
|
||||
&node->container_node_member); \
|
||||
break; \
|
||||
} \
|
||||
} else { \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
cur = next; \
|
||||
} \
|
||||
\
|
||||
b_btree_insert_fixup(tree, &node->container_node_member); \
|
||||
}
|
||||
|
||||
/* defines a simple tree search function.
|
||||
this function assumes that your nodes have simple integer keys that can be
|
||||
compared with the usual operators.
|
||||
|
||||
EXAMPLE:
|
||||
if you have a tree node type like this:
|
||||
|
||||
struct my_tree_node {
|
||||
int key;
|
||||
b_btree_node base;
|
||||
}
|
||||
|
||||
You would use the following call to generate a search function for a tree
|
||||
with this node type:
|
||||
|
||||
BTREE_DEFINE_SIMPLE_GET(struct my_tree_node, int, base, key,
|
||||
my_tree_node_get);
|
||||
|
||||
Which would emit a function defined like:
|
||||
|
||||
static struct my_tree_node *my_tree_node_get(b_btree *tree, int key);
|
||||
|
||||
@param node_type your custom tree node type. usually a structure that
|
||||
contains a b_btree_node member.
|
||||
@param key_type the type name of the key embedded in your custom tree node
|
||||
type. this type must be compatible with the builtin comparison operators.
|
||||
@param container_node_member the name of the b_btree_node member variable
|
||||
within your custom type.
|
||||
@param container_key_member the name of the key member variable within your
|
||||
custom type.
|
||||
@param function_name the name of the function to generate.
|
||||
*/
|
||||
#define B_BTREE_DEFINE_SIMPLE_GET( \
|
||||
node_type, key_type, container_node_member, container_key_member, \
|
||||
function_name) \
|
||||
node_type *function_name(const b_btree *tree, key_type key) \
|
||||
{ \
|
||||
b_btree_node *cur = tree->b_root; \
|
||||
while (cur) { \
|
||||
node_type *cur_node = b_unbox( \
|
||||
node_type, cur, container_node_member); \
|
||||
if (key > cur_node->container_key_member) { \
|
||||
cur = b_btree_right(cur); \
|
||||
} else if (key < cur_node->container_key_member) { \
|
||||
cur = b_btree_left(cur); \
|
||||
} else { \
|
||||
return cur_node; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define b_btree_foreach(it, btree) \
|
||||
for (int z__b_unique_name() = b_btree_iterator_begin(btree, it); \
|
||||
(it)->node != NULL; b_btree_iterator_next(it))
|
||||
|
||||
/* binary tree nodes. this *cannot* be used directly. you need to define a
|
||||
custom node type that contains a member variable of type b_btree_node.
|
||||
|
||||
you would then use the supplied macros to define functions to manipulate your
|
||||
custom binary tree.
|
||||
*/
|
||||
typedef struct b_btree_node {
|
||||
struct b_btree_node *b_parent, *b_left, *b_right;
|
||||
unsigned short b_height;
|
||||
} b_btree_node;
|
||||
|
||||
/* binary tree. unlike b_btree_node, you can define variables of type b_btree.
|
||||
*/
|
||||
typedef struct b_btree {
|
||||
b_btree_node *b_root;
|
||||
} b_btree;
|
||||
|
||||
BLUE_API b_type b_btree_iterator_get_type(void);
|
||||
|
||||
/* re-balance a binary tree after an insertion operation.
|
||||
|
||||
NOTE that, if you define an insertion function using BTREE_DEFINE_INSERT or
|
||||
similar, this function will automatically called for you.
|
||||
|
||||
@param tree the tree to re-balance.
|
||||
@param node the node that was just inserted into the tree.
|
||||
*/
|
||||
BLUE_API void b_btree_insert_fixup(b_btree *tree, b_btree_node *node);
|
||||
|
||||
/* delete a node from a binary tree and re-balance the tree afterwards.
|
||||
|
||||
@param tree the tree to delete from
|
||||
@param node the node to delete.
|
||||
*/
|
||||
BLUE_API void b_btree_delete(b_btree *tree, b_btree_node *node);
|
||||
|
||||
/* get the first node in a binary tree.
|
||||
|
||||
this will be the node with the smallest key (i.e. the node that is
|
||||
furthest-left from the root)
|
||||
*/
|
||||
BLUE_API b_btree_node *b_btree_first(const b_btree *tree);
|
||||
|
||||
/* get the last node in a binary tree.
|
||||
|
||||
this will be the node with the largest key (i.e. the node that is
|
||||
furthest-right from the root)
|
||||
*/
|
||||
BLUE_API b_btree_node *b_btree_last(const b_btree *tree);
|
||||
/* for any binary tree node, this function returns the node with the
|
||||
* next-largest key value */
|
||||
BLUE_API b_btree_node *b_btree_next(const b_btree_node *node);
|
||||
/* for any binary tree node, this function returns the node with the
|
||||
* next-smallest key value */
|
||||
BLUE_API b_btree_node *b_btree_prev(const b_btree_node *node);
|
||||
/* return true if the btree is empty, false otherwise */
|
||||
static inline bool b_btree_empty(const b_btree *tree)
|
||||
{
|
||||
return tree->b_root == NULL;
|
||||
}
|
||||
|
||||
/* sets `child` as the immediate left-child of `parent` */
|
||||
static inline void b_btree_put_left(b_btree_node *parent, b_btree_node *child)
|
||||
{
|
||||
parent->b_left = child;
|
||||
child->b_parent = parent;
|
||||
}
|
||||
|
||||
/* sets `child` as the immediate right-child of `parent` */
|
||||
static inline void b_btree_put_right(b_btree_node *parent, b_btree_node *child)
|
||||
{
|
||||
parent->b_right = child;
|
||||
child->b_parent = parent;
|
||||
}
|
||||
|
||||
/* get the immediate left-child of `node` */
|
||||
static inline b_btree_node *b_btree_left(b_btree_node *node)
|
||||
{
|
||||
return node->b_left;
|
||||
}
|
||||
|
||||
/* get the immediate right-child of `node` */
|
||||
static inline b_btree_node *b_btree_right(b_btree_node *node)
|
||||
{
|
||||
return node->b_right;
|
||||
}
|
||||
|
||||
/* get the immediate parent of `node` */
|
||||
static inline b_btree_node *b_btree_parent(b_btree_node *node)
|
||||
{
|
||||
return node->b_parent;
|
||||
}
|
||||
|
||||
BLUE_API void b_btree_move(b_btree *tree, b_btree_node *dest, b_btree_node *src);
|
||||
|
||||
/* get the height of `node`.
|
||||
|
||||
the height of a node is defined as the length of the longest path
|
||||
between the node and a leaf node.
|
||||
|
||||
this count includes the node itself, so the height of a leaf node will be 1.
|
||||
*/
|
||||
static inline unsigned short b_btree_height(b_btree_node *node)
|
||||
{
|
||||
return node->b_height;
|
||||
}
|
||||
|
||||
BLUE_API b_iterator *b_btree_begin(b_btree *tree);
|
||||
BLUE_API const b_iterator *b_btree_cbegin(const b_btree *tree);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
#ifndef BLUE_OBJECT_CLASS_H_
|
||||
#define BLUE_OBJECT_CLASS_H_
|
||||
|
||||
#include <blue/core/type.h>
|
||||
|
||||
#define B_CLASS_MAGIC 0xDEADFACEDCAFEBEDULL
|
||||
#define B_CLASS(p) ((b_class *)(p))
|
||||
|
||||
typedef struct _b_class b_class;
|
||||
|
||||
BLUE_API void *b_class_get(b_type id);
|
||||
BLUE_API const char *b_class_get_name(const b_class *c);
|
||||
BLUE_API void *b_class_get_interface(const b_class *c, b_type id);
|
||||
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef BLUE_CORE_ENCODING_H_
|
||||
#define BLUE_CORE_ENCODING_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define B_WCHAR_INVALID ((b_wchar) - 1)
|
||||
|
||||
typedef int32_t b_wchar;
|
||||
|
||||
BLUE_API bool b_wchar_is_alpha(b_wchar c);
|
||||
BLUE_API bool b_wchar_is_number(b_wchar c);
|
||||
static inline bool b_wchar_is_bin_digit(b_wchar c)
|
||||
{
|
||||
return c >= '0' && c <= '1';
|
||||
}
|
||||
static inline bool b_wchar_is_oct_digit(b_wchar c)
|
||||
{
|
||||
return c >= '0' && c <= '7';
|
||||
}
|
||||
BLUE_API bool b_wchar_is_hex_digit(b_wchar c);
|
||||
BLUE_API bool b_wchar_is_space(b_wchar c);
|
||||
static inline bool b_wchar_is_alnum(b_wchar c)
|
||||
{
|
||||
return b_wchar_is_alpha(c) || b_wchar_is_number(c);
|
||||
}
|
||||
|
||||
BLUE_API bool b_wchar_is_punct(b_wchar c);
|
||||
|
||||
BLUE_API bool b_wchar_utf8_is_valid_scalar(b_wchar c);
|
||||
BLUE_API unsigned int b_wchar_utf8_header_decode(char c);
|
||||
BLUE_API unsigned int b_wchar_utf8_codepoint_size(b_wchar c);
|
||||
BLUE_API b_wchar b_wchar_utf8_codepoint_decode(const char *s);
|
||||
BLUE_API unsigned int b_wchar_utf8_codepoint_encode(b_wchar c, char s[4]);
|
||||
BLUE_API unsigned int b_wchar_utf8_codepoint_stride(const char *s);
|
||||
BLUE_API size_t b_wchar_utf8_codepoint_count(const char *s, size_t nr_bytes);
|
||||
BLUE_API size_t b_wchar_utf8_string_encoded_size(
|
||||
const b_wchar *s, size_t nr_codepoints);
|
||||
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_ENDIAN_H_
|
||||
#define BLUELIB_CORE_ENDIAN_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
unsigned char i_bytes[sizeof(uint16_t)];
|
||||
int16_t i_val;
|
||||
uint16_t i_uval;
|
||||
};
|
||||
} b_i16;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
unsigned char i_bytes[sizeof(uint32_t)];
|
||||
int32_t i_val;
|
||||
uint32_t i_uval;
|
||||
};
|
||||
} b_i32;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
unsigned char i_bytes[sizeof(uint64_t)];
|
||||
int64_t i_val;
|
||||
uint64_t i_uval;
|
||||
};
|
||||
} b_i64;
|
||||
|
||||
BLUE_API b_i16 b_i16_htob(uint16_t v);
|
||||
BLUE_API b_i16 b_i16_htos(uint16_t v);
|
||||
|
||||
BLUE_API uint16_t b_i16_btoh(b_i16 v);
|
||||
BLUE_API uint16_t b_i16_stoh(b_i16 v);
|
||||
|
||||
BLUE_API b_i32 b_i32_htob(uint32_t v);
|
||||
BLUE_API b_i32 b_i32_htos(uint32_t v);
|
||||
|
||||
BLUE_API uint32_t b_i32_btoh(b_i32 v);
|
||||
BLUE_API uint32_t b_i32_stoh(b_i32 v);
|
||||
|
||||
BLUE_API b_i64 b_i64_htob(uint64_t v);
|
||||
BLUE_API b_i64 b_i64_htos(uint64_t v);
|
||||
|
||||
BLUE_API uint64_t b_i64_btoh(b_i64 v);
|
||||
BLUE_API uint64_t b_i64_stoh(b_i64 v);
|
||||
|
||||
#endif
|
||||
@@ -1,418 +0,0 @@
|
||||
#ifndef BLUE_CORE_ERROR_H_
|
||||
#define BLUE_CORE_ERROR_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define B_ERROR_TEMPLATE_PARAMETER_MAX 4
|
||||
#define B_ERROR_MSG_ID_INVALID ((unsigned long)-1)
|
||||
|
||||
#define B_CATCH(err, expr) ((err = (expr)) != NULL)
|
||||
|
||||
#define b_result_is_error(result) ((result) != NULL)
|
||||
#define b_result_is_success(result) ((result) == NULL)
|
||||
|
||||
#define B_RESULT_SUCCESS ((b_result)NULL)
|
||||
#define B_RESULT_ERR(err_name) \
|
||||
b_error_with_code(b_error_vendor_get_builtin(), B_ERR_##err_name)
|
||||
#define B_RESULT_ERR_WITH_STRING(err_name, ...) \
|
||||
b_error_with_string( \
|
||||
b_error_vendor_get_builtin(), B_ERR_##err_name, __VA_ARGS__)
|
||||
#define B_RESULT_STATUS(code) \
|
||||
((code) == B_SUCCESS \
|
||||
? B_RESULT_SUCCESS \
|
||||
: (b_error_with_code(b_error_vendor_get_builtin(), code)))
|
||||
#define B_RESULT_STATUS_WITH_STRING(code, ...) \
|
||||
((code) == B_SUCCESS \
|
||||
? B_RESULT_SUCCESS \
|
||||
: (b_error_with_string( \
|
||||
b_error_vendor_get_builtin(), code, __VA_ARGS__)))
|
||||
|
||||
#define B_ERRORS_BUILTIN (b_error_vendor_get_builtin())
|
||||
#define B_ERRORS_ERRNO (b_error_vendor_get_errno())
|
||||
|
||||
#define B_ERROR_PARAM(name, value) \
|
||||
(b_error_template_parameter) \
|
||||
{ \
|
||||
.param_name = (name), .param_value = (uintptr_t)(value), \
|
||||
}
|
||||
|
||||
#define B_ERROR_TEMPLATE_PARAM(name, type, format) \
|
||||
(b_error_template_parameter_definition) \
|
||||
{ \
|
||||
.param_name = (name), .param_type = (type), \
|
||||
.param_format = (format), \
|
||||
}
|
||||
#define B_ERROR_DEFINITION(code, name, msg) \
|
||||
[code] = (b_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
}
|
||||
#define B_ERROR_DEFINITION_TEMPLATE(code, name, msg, ...) \
|
||||
[code] = (b_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
.err_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define B_ERROR_MSG(id, content) \
|
||||
[id] = (b_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), \
|
||||
}
|
||||
#define B_ERROR_MSG_TEMPLATE(id, content, ...) \
|
||||
[id] = (b_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), .msg_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define z__b_error_create_status(status_code) \
|
||||
(z__b_error_create( \
|
||||
b_error_vendor_get_builtin(), status_code, NULL, NULL, 0, \
|
||||
NULL, NULL))
|
||||
|
||||
/* Error creation macros */
|
||||
#define b_error_with_code(vendor, code) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define b_error_caused_by_error(vendor, code, cause_error) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define b_error_caused_by_status(vendor, code, cause_status) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, z__b_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define b_error_caused_by_code(vendor, code, cause_vendor, cause_code) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, b_error_with_code(cause_vendor, cause_code), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define b_error_with_string(vendor, code, ...) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define b_error_with_string_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define b_error_with_string_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__b_error_create( \
|
||||
vendor, code, z__b_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define b_error_with_msg(vendor, code, msg_id) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(b_error_template_parameter[]) {{}}))
|
||||
#define b_error_with_msg_caused_by_error(vendor, code, cause_error, msg_id) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (b_error_template_parameter[]) {{}}))
|
||||
#define b_error_with_msg_caused_by_status(vendor, code, cause_status, msg_id) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, z__b_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(b_error_template_parameter[]) {{}}))
|
||||
#define b_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define b_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause_error, msg_id, ...) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define b_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause_status, msg_id, ...) \
|
||||
(z__b_error_create_msg( \
|
||||
vendor, code, z__b_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define b_error_with_template(vendor, code, ...) \
|
||||
(z__b_error_create_template( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define b_error_with_template_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__b_error_create_template( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define b_error_with_template_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__b_error_create_template( \
|
||||
vendor, code, z__b_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
/* Error propagation macros */
|
||||
#define b_result_propagate(err) \
|
||||
(z__b_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define b_error_caused_by(err, caused_by) (z__b_error_caused_by(err, caused_by))
|
||||
#define b_error_caused_by_b_status(err, status) \
|
||||
(z__b_error_caused_by_b_status(err, status))
|
||||
#define b_error_replace(err, caused_by) \
|
||||
(z__b_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
/* Error throw macros */
|
||||
#define z__b_throw(err) (z__b_error_throw(err, NULL, 0, NULL))
|
||||
#define b_throw(err) (z__b_error_throw(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define b_throw_status(status) \
|
||||
(z__b_error_throw( \
|
||||
z__b_error_create( \
|
||||
b_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, NULL), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
#define b_throw_status_string(status, ...) \
|
||||
(z__b_error_throw( \
|
||||
z__b_error_create( \
|
||||
b_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, __VA_ARGS__), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
#define b_throw_error_code(vendor, code) \
|
||||
z__b_throw(b_error_with_code(vendor, code))
|
||||
#define b_throw_error_caused_by_error(vendor, code, cause) \
|
||||
z__b_throw(b_error_caused_by_error(vendor, code, cause))
|
||||
#define b_throw_error_caused_by_status(vendor, code, cause) \
|
||||
z__b_throw(b_error_caused_by_status(vendor, code, cause))
|
||||
#define b_throw_error_with_string(vendor, code, ...) \
|
||||
z__b_throw(b_error_with_string(vendor, code, __VA_ARGS__))
|
||||
#define b_throw_error_with_string_caused_by_error(vendor, code, cause, ...) \
|
||||
z__b_throw(b_error_with_string_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define b_throw_error_with_string_caused_by_status(vendor, code, cause, ...) \
|
||||
z__b_throw(b_error_with_string_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define b_throw_error_with_msg(vendor, code, msg_id) \
|
||||
z__b_throw(b_error_with_msg(vendor, code, msg_id))
|
||||
#define b_throw_error_with_msg_caused_by_error(vendor, code, cause, msg_id) \
|
||||
z__b_throw(b_error_with_msg_caused_by_error(vendor, code, cause, msg_id))
|
||||
#define b_throw_error_with_msg_caused_by_status(vendor, code, cause, msg_id) \
|
||||
z__b_throw(b_error_with_msg_caused_by_status(vendor, code, cause, msg_id))
|
||||
|
||||
#define b_throw_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
z__b_throw(b_error_with_msg_template(vendor, code, msg_id, __VA_ARGS__))
|
||||
#define b_throw_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__b_throw(b_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
#define b_throw_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__b_throw(b_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
|
||||
#define b_throw_error_with_template(vendor, code, ...) \
|
||||
z__b_throw(b_error_with_template(vendor, code, __VA_ARGS__))
|
||||
#define b_throw_error_with_template_caused_by_error(vendor, code, cause, ...) \
|
||||
z__b_throw(b_error_with_template_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define b_throw_error_with_template_caused_by_status(vendor, code, cause, ...) \
|
||||
z__b_throw(b_error_with_template_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define B_ERR_MSG(s) \
|
||||
{ \
|
||||
.msg_type = B_ERROR_MESSAGE_ERROR, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define B_ERR_MSG_WARN(s) \
|
||||
{ \
|
||||
.msg_type = B_ERROR_MESSAGE_WARN, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define B_ERR_MSG_INFO(s) \
|
||||
{ \
|
||||
.msg_type = B_ERROR_MESSAGE_INFO, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define B_ERR_MSG_END(s) \
|
||||
{ \
|
||||
.msg_type = B_ERROR_MESSAGE_NONE, \
|
||||
.msg_content = NULL, \
|
||||
}
|
||||
|
||||
typedef enum b_error_submsg_type {
|
||||
B_ERROR_SUBMSG_NONE = 0,
|
||||
B_ERROR_SUBMSG_ERROR,
|
||||
B_ERROR_SUBMSG_WARNING,
|
||||
B_ERROR_SUBMSG_INFO,
|
||||
} b_error_submsg_type;
|
||||
|
||||
typedef enum b_error_report_flags {
|
||||
B_ERROR_REPORT_NONE = 0,
|
||||
B_ERROR_REPORT_STATUS = 0x01u,
|
||||
B_ERROR_REPORT_DESCRIPTION = 0x02u,
|
||||
B_ERROR_REPORT_SUBMSG = 0x04u,
|
||||
B_ERROR_REPORT_STACK_TRACE = 0x08u,
|
||||
B_ERROR_REPORT_CAUSE = 0x10u,
|
||||
|
||||
B_ERROR_REPORT_MINIMAL = B_ERROR_REPORT_STATUS | B_ERROR_REPORT_DESCRIPTION,
|
||||
B_ERROR_REPORT_DEFAULT = B_ERROR_REPORT_MINIMAL | B_ERROR_REPORT_SUBMSG
|
||||
| B_ERROR_REPORT_CAUSE,
|
||||
B_ERROR_REPORT_ALL = B_ERROR_REPORT_DEFAULT | B_ERROR_REPORT_STACK_TRACE,
|
||||
} b_error_report_flags;
|
||||
|
||||
typedef enum b_error_template_parameter_type {
|
||||
B_ERROR_TEMPLATE_PARAM_NONE = 0,
|
||||
B_ERROR_TEMPLATE_PARAM_STRING,
|
||||
B_ERROR_TEMPLATE_PARAM_CHAR,
|
||||
B_ERROR_TEMPLATE_PARAM_INT,
|
||||
B_ERROR_TEMPLATE_PARAM_UINT,
|
||||
B_ERROR_TEMPLATE_PARAM_LONG,
|
||||
B_ERROR_TEMPLATE_PARAM_ULONG,
|
||||
B_ERROR_TEMPLATE_PARAM_LONGLONG,
|
||||
B_ERROR_TEMPLATE_PARAM_ULONGLONG,
|
||||
B_ERROR_TEMPLATE_PARAM_SIZE_T,
|
||||
B_ERROR_TEMPLATE_PARAM_INTPTR,
|
||||
B_ERROR_TEMPLATE_PARAM_UINTPTR,
|
||||
B_ERROR_TEMPLATE_PARAM_PTR,
|
||||
} b_error_template_parameter_type;
|
||||
|
||||
typedef struct b_error_template_parameter_definition {
|
||||
const char *param_name;
|
||||
b_error_template_parameter_type param_type;
|
||||
const char *param_format;
|
||||
} b_error_template_parameter_definition;
|
||||
|
||||
typedef struct b_error_template_parameter {
|
||||
const char *param_name;
|
||||
uintptr_t param_value;
|
||||
const struct b_error_template_parameter_definition *__param_def;
|
||||
} b_error_template_parameter;
|
||||
|
||||
struct b_error_vendor;
|
||||
|
||||
typedef struct b_error b_error;
|
||||
typedef struct b_error *b_result;
|
||||
typedef struct b_error_submsg b_error_submsg;
|
||||
typedef struct b_error_stack_frame b_error_stack_frame;
|
||||
typedef long b_error_status_code;
|
||||
typedef unsigned long b_error_msg_id;
|
||||
|
||||
typedef struct b_error_definition {
|
||||
const char *err_name;
|
||||
const char *err_message;
|
||||
const b_error_template_parameter_definition err_params[B_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} b_error_definition;
|
||||
|
||||
typedef struct b_error_msg {
|
||||
const char *msg_message;
|
||||
const b_error_template_parameter_definition msg_params[B_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} b_error_msg;
|
||||
|
||||
typedef const b_error_definition *(*b_error_status_code_get_definition)(
|
||||
const struct b_error_vendor *, b_error_status_code);
|
||||
typedef const b_error_msg *(*b_error_msg_get_definition)(
|
||||
const struct b_error_vendor *, b_error_msg_id);
|
||||
typedef void (*b_error_report_function)(
|
||||
const struct b_error *, b_error_report_flags);
|
||||
|
||||
typedef struct b_error_vendor {
|
||||
const char *v_name;
|
||||
|
||||
b_error_status_code_get_definition v_status_get_definition;
|
||||
b_error_msg_get_definition v_msg_get_definition;
|
||||
|
||||
const b_error_definition *v_error_definitions;
|
||||
size_t v_error_definitions_length;
|
||||
|
||||
const b_error_msg *v_msg;
|
||||
size_t v_msg_length;
|
||||
} b_error_vendor;
|
||||
|
||||
BLUE_API b_error *z__b_error_create_template(
|
||||
const b_error_vendor *, b_error_status_code, b_error *, const char *,
|
||||
unsigned int, const char *, const b_error_template_parameter[]);
|
||||
BLUE_API b_error *z__b_error_create_string(
|
||||
const b_error_vendor *, b_error_status_code, b_error *, const char *,
|
||||
unsigned int, const char *, const char *, va_list);
|
||||
BLUE_API b_error *z__b_error_create_msg(
|
||||
const b_error_vendor *, b_error_status_code, b_error *, const char *,
|
||||
unsigned int, const char *, b_error_msg_id,
|
||||
const b_error_template_parameter[]);
|
||||
BLUE_API b_error *z__b_error_propagate(
|
||||
b_error *, const char *, unsigned int, const char *);
|
||||
BLUE_API b_error *z__b_error_caused_by(b_error *, b_error *);
|
||||
BLUE_API b_error *z__b_error_caused_by_b_status(b_error *, b_status);
|
||||
BLUE_API void z__b_error_throw(b_error *, const char *, unsigned int, const char *);
|
||||
|
||||
BLUE_API bool b_result_is(
|
||||
b_result result, const b_error_vendor *vendor, b_error_status_code code);
|
||||
|
||||
BLUE_API const b_error_vendor *b_error_vendor_get_builtin(void);
|
||||
BLUE_API const b_error_vendor *b_error_vendor_get_errno(void);
|
||||
BLUE_API const b_error_definition *b_error_vendor_get_error_definition(
|
||||
const b_error_vendor *vendor, b_error_status_code code);
|
||||
BLUE_API const char *b_error_vendor_get_status_code_name(
|
||||
const b_error_vendor *vendor, b_error_status_code code);
|
||||
BLUE_API const char *b_error_vendor_get_status_code_description(
|
||||
const b_error_vendor *vendor, b_error_status_code code);
|
||||
BLUE_API const b_error_msg *b_error_vendor_get_msg(
|
||||
const b_error_vendor *vendor, b_error_msg_id msg_id);
|
||||
|
||||
static inline b_error *z__b_error_create(
|
||||
const b_error_vendor *v, b_error_status_code c, b_error *c2,
|
||||
const char *f0, unsigned int l, const char *f1, const char *d, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, d);
|
||||
b_error *err = z__b_error_create_string(v, c, c2, f0, l, f1, d, arg);
|
||||
va_end(arg);
|
||||
return err;
|
||||
}
|
||||
|
||||
BLUE_API enum b_status b_error_add_submsg_string(
|
||||
b_error *error, b_error_submsg_type type, const char *msg, ...);
|
||||
BLUE_API enum b_status z__b_error_add_submsg_template(
|
||||
b_error *error, b_error_submsg_type type, b_error_msg_id msg_id,
|
||||
b_error_template_parameter param[]);
|
||||
#define b_error_add_submsg(error, type, msg_id) \
|
||||
(z__b_error_add_submsg_template( \
|
||||
error, type, msg_id, (b_error_template_parameter[]) {{}}))
|
||||
#define b_error_add_submsg_template(error, type, msg_id, ...) \
|
||||
(z__b_error_add_submsg_template( \
|
||||
error, type, msg_id, \
|
||||
(b_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
BLUE_API void b_error_discard(b_error *error);
|
||||
|
||||
BLUE_API b_error_status_code b_error_get_status_code(const b_error *error);
|
||||
BLUE_API const b_error_vendor *b_error_get_vendor(const b_error *error);
|
||||
BLUE_API const b_error_definition *b_error_get_definition(const b_error *error);
|
||||
BLUE_API const b_error_template_parameter *b_error_get_template_parameter(
|
||||
const b_error *error, const char *param_name);
|
||||
BLUE_API const b_error_template_parameter *b_error_get_template_parameters(
|
||||
const b_error *error);
|
||||
BLUE_API const char *b_error_get_description(const b_error *error);
|
||||
BLUE_API const b_error_msg *b_error_get_msg(const b_error *error);
|
||||
BLUE_API const b_error_submsg *b_error_get_first_submsg(const b_error *error);
|
||||
BLUE_API const b_error_submsg *b_error_get_next_submsg(
|
||||
const b_error *error, const b_error_submsg *msg);
|
||||
BLUE_API const b_error_stack_frame *b_error_get_first_stack_frame(
|
||||
const b_error *error);
|
||||
BLUE_API const b_error_stack_frame *b_error_get_next_stack_frame(
|
||||
const b_error *error, const b_error_stack_frame *frame);
|
||||
BLUE_API const b_error *b_error_get_caused_by(const b_error *error);
|
||||
|
||||
BLUE_API b_error_submsg_type b_error_submsg_get_type(const b_error_submsg *msg);
|
||||
BLUE_API const char *b_error_submsg_get_content(const b_error_submsg *msg);
|
||||
BLUE_API const b_error_msg *b_error_submsg_get_msg(const b_error_submsg *msg);
|
||||
BLUE_API const b_error_template_parameter *b_error_submsg_get_template_parameters(
|
||||
const b_error_submsg *msg);
|
||||
|
||||
BLUE_API const char *b_error_stack_frame_get_filepath(
|
||||
const b_error_stack_frame *frame);
|
||||
BLUE_API unsigned int b_error_stack_frame_get_line_number(
|
||||
const b_error_stack_frame *frame);
|
||||
BLUE_API const char *b_error_stack_frame_get_function_name(
|
||||
const b_error_stack_frame *frame);
|
||||
|
||||
BLUE_API const b_error_template_parameter_definition *b_error_definition_get_template_parameter(
|
||||
const b_error_definition *error_def, const char *param_name);
|
||||
|
||||
BLUE_API const char *b_error_msg_get_content(const b_error_msg *msg);
|
||||
BLUE_API const b_error_template_parameter_definition *b_error_msg_get_template_parameter(
|
||||
const b_error_msg *msg, const char *param_name);
|
||||
|
||||
BLUE_API void b_set_error_report_function(
|
||||
b_error_report_function func, b_error_report_flags flags);
|
||||
|
||||
#endif
|
||||
@@ -1,111 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_HASH_H_
|
||||
#define BLUELIB_CORE_HASH_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define B_DIGEST_LENGTH_128 16
|
||||
#define B_DIGEST_LENGTH_160 20
|
||||
#define B_DIGEST_LENGTH_192 24
|
||||
#define B_DIGEST_LENGTH_224 28
|
||||
#define B_DIGEST_LENGTH_256 32
|
||||
#define B_DIGEST_LENGTH_384 48
|
||||
#define B_DIGEST_LENGTH_512 64
|
||||
|
||||
#define B_DIGEST_LENGTH_MD4 B_DIGEST_LENGTH_128
|
||||
#define B_DIGEST_LENGTH_MD5 B_DIGEST_LENGTH_128
|
||||
#define B_DIGEST_LENGTH_SHA1 B_DIGEST_LENGTH_160
|
||||
#define B_DIGEST_LENGTH_SHA2_224 B_DIGEST_LENGTH_224
|
||||
#define B_DIGEST_LENGTH_SHA2_256 B_DIGEST_LENGTH_256
|
||||
#define B_DIGEST_LENGTH_SHA2_384 B_DIGEST_LENGTH_384
|
||||
#define B_DIGEST_LENGTH_SHA2_512 B_DIGEST_LENGTH_512
|
||||
#define B_DIGEST_LENGTH_SHA3_224 B_DIGEST_LENGTH_224
|
||||
#define B_DIGEST_LENGTH_SHA3_256 B_DIGEST_LENGTH_256
|
||||
#define B_DIGEST_LENGTH_SHA3_384 B_DIGEST_LENGTH_384
|
||||
#define B_DIGEST_LENGTH_SHA3_512 B_DIGEST_LENGTH_512
|
||||
#define B_DIGEST_LENGTH_SHAKE128 B_DIGEST_LENGTH_128
|
||||
#define B_DIGEST_LENGTH_SHAKE256 B_DIGEST_LENGTH_256
|
||||
|
||||
struct b_hash_function_ops;
|
||||
struct b_rope;
|
||||
|
||||
typedef enum b_hash_function {
|
||||
B_HASH_NONE = 0,
|
||||
B_HASH_MD4,
|
||||
B_HASH_MD5,
|
||||
B_HASH_SHA1,
|
||||
B_HASH_SHA2_224,
|
||||
B_HASH_SHA2_256,
|
||||
B_HASH_SHA2_384,
|
||||
B_HASH_SHA2_512,
|
||||
B_HASH_SHA3_224,
|
||||
B_HASH_SHA3_256,
|
||||
B_HASH_SHA3_384,
|
||||
B_HASH_SHA3_512,
|
||||
B_HASH_SHAKE128,
|
||||
B_HASH_SHAKE256,
|
||||
} b_hash_function;
|
||||
|
||||
typedef struct b_hash_ctx {
|
||||
b_hash_function ctx_func;
|
||||
const struct b_hash_function_ops *ctx_ops;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t lo, hi;
|
||||
uint32_t a, b, c, d;
|
||||
uint32_t block[16];
|
||||
unsigned char buffer[64];
|
||||
} md4;
|
||||
|
||||
struct {
|
||||
unsigned int count[2];
|
||||
unsigned int a, b, c, d;
|
||||
unsigned int block[16];
|
||||
unsigned char input[64];
|
||||
} md5;
|
||||
|
||||
struct {
|
||||
uint32_t state[5];
|
||||
uint32_t count[2];
|
||||
unsigned char buffer[64];
|
||||
} sha1;
|
||||
|
||||
struct {
|
||||
uint64_t curlen;
|
||||
uint64_t length;
|
||||
unsigned char buf[128];
|
||||
uint32_t state[8];
|
||||
} sha2_256;
|
||||
|
||||
struct {
|
||||
uint64_t curlen;
|
||||
uint64_t length;
|
||||
unsigned char block[256];
|
||||
uint64_t state[8];
|
||||
} sha2_512;
|
||||
|
||||
struct {
|
||||
union {
|
||||
uint8_t b[200];
|
||||
uint64_t q[25];
|
||||
} st;
|
||||
|
||||
int pt, rsiz, mdlen;
|
||||
} sha3;
|
||||
} ctx_state;
|
||||
} b_hash_ctx;
|
||||
|
||||
BLUE_API uint64_t b_hash_cstr(const char *s);
|
||||
BLUE_API uint64_t b_hash_cstr_ex(const char *s, size_t *len);
|
||||
|
||||
BLUE_API b_status b_hash_ctx_init(b_hash_ctx *ctx, b_hash_function func);
|
||||
BLUE_API b_status b_hash_ctx_reset(b_hash_ctx *ctx);
|
||||
BLUE_API b_status b_hash_ctx_update(b_hash_ctx *ctx, const void *p, size_t len);
|
||||
BLUE_API b_status b_hash_ctx_update_rope(b_hash_ctx *ctx, const struct b_rope *rope);
|
||||
BLUE_API b_status b_hash_ctx_finish(
|
||||
b_hash_ctx *ctx, void *out_digest, size_t out_max);
|
||||
|
||||
#endif
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef BLUELIB_INIT_H_
|
||||
#define BLUELIB_INIT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define B_INIT(f) \
|
||||
static void f(void); \
|
||||
struct f##_t_ { \
|
||||
f##_t_(void) \
|
||||
{ \
|
||||
f(); \
|
||||
} \
|
||||
}; \
|
||||
static f##_t_ f##_; \
|
||||
static void f(void)
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma section(".CRT$XCU", read)
|
||||
#define B_INIT2_(f, p) \
|
||||
static void f(void); \
|
||||
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
|
||||
__pragma(comment(linker, "/include:" p #f "_")) static void f(void)
|
||||
#ifdef _WIN64
|
||||
#define B_INIT(f) B_INIT2_(f, "")
|
||||
#else
|
||||
#define B_INIT(f) B_INIT2_(f, "_")
|
||||
#endif
|
||||
#else
|
||||
#define B_INIT(f) \
|
||||
static void f(void) __attribute__((constructor)); \
|
||||
static void f(void)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,93 +0,0 @@
|
||||
#ifndef BLUE_CORE_ITERATOR_H_
|
||||
#define BLUE_CORE_ITERATOR_H_
|
||||
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define b_foreach(type, var, iterator) \
|
||||
for (type var = (type)b_iterator_get_value(iterator).v_int; \
|
||||
B_OK(b_iterator_get_status(iterator)); \
|
||||
b_iterator_move_next(iterator), \
|
||||
var = (type)b_iterator_get_value(iterator).v_int)
|
||||
#define b_foreach_ptr(type, var, iterator) \
|
||||
for (type *var = (type *)b_iterator_get_value(iterator).v_ptr; \
|
||||
B_OK(b_iterator_get_status(iterator)); \
|
||||
b_iterator_move_next(iterator), \
|
||||
var = (type *)b_iterator_get_value(iterator).v_ptr)
|
||||
#define b_foreach_c(type, var, iterator) \
|
||||
for (type var = (type)b_iterator_get_cvalue(iterator).v_int; \
|
||||
B_OK(b_iterator_get_status(iterator)); \
|
||||
b_iterator_move_next(iterator), \
|
||||
var = (type)b_iterator_get_cvalue(iterator).v_int)
|
||||
#define b_foreach_cptr(type, var, iterator) \
|
||||
for (const type *var \
|
||||
= (const type *)b_iterator_get_cvalue(iterator).v_cptr; \
|
||||
B_OK(b_iterator_get_status(iterator)); \
|
||||
b_iterator_move_next(iterator), \
|
||||
var = (const type *)b_iterator_get_cvalue(iterator).v_cptr)
|
||||
|
||||
#define B_ITERATOR_VALUE_INT(v) ((b_iterator_value) {.v_int = (v)})
|
||||
#define B_ITERATOR_VALUE_PTR(v) ((b_iterator_value) {.v_ptr = (v)})
|
||||
#define B_ITERATOR_VALUE_CPTR(v) ((const b_iterator_value) {.v_cptr = (v)})
|
||||
#define B_ITERATOR_VALUE_NULL ((b_iterator_value) {})
|
||||
#define B_ITERATOR_VALUE_IS_NULL(v) ((v)->v_ptr == NULL)
|
||||
|
||||
#define B_TYPE_ITERATOR (b_iterator_get_type())
|
||||
#define B_TYPE_ITERABLE (b_iterable_get_type())
|
||||
|
||||
typedef union b_iterator_value {
|
||||
uintptr_t v_int;
|
||||
void *v_ptr;
|
||||
const void *v_cptr;
|
||||
} b_iterator_value;
|
||||
|
||||
__B_DECLARE_TYPE(b_iterator);
|
||||
|
||||
B_DECLARE_TYPE(b_iterable);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_iterator)
|
||||
b_status (*it_move_next)(const b_iterator *);
|
||||
b_status (*it_erase)(b_iterator *);
|
||||
b_iterator_value (*it_get_value)(b_iterator *);
|
||||
const b_iterator_value (*it_get_cvalue)(const b_iterator *);
|
||||
B_TYPE_CLASS_DECLARATION_END(b_iterator)
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_iterable)
|
||||
b_iterator *(*it_begin)(b_iterable *);
|
||||
const b_iterator *(*it_cbegin)(const b_iterable *);
|
||||
B_TYPE_CLASS_DECLARATION_END(b_iterable)
|
||||
|
||||
BLUE_API b_type b_iterator_get_type(void);
|
||||
BLUE_API b_type b_iterable_get_type(void);
|
||||
|
||||
static inline const b_iterator *b_iterator_ref(const b_iterator *p)
|
||||
{
|
||||
return b_object_ref((b_object *)p);
|
||||
}
|
||||
static inline void b_iterator_unref(const b_iterator *p)
|
||||
{
|
||||
b_object_unref((b_object *)p);
|
||||
}
|
||||
|
||||
BLUE_API b_iterator *b_iterator_begin(b_iterable *it);
|
||||
BLUE_API const b_iterator *b_iterator_cbegin(const b_iterable *it);
|
||||
|
||||
BLUE_API b_status b_iterator_get_status(const b_iterator *it);
|
||||
BLUE_API b_status b_iterator_set_status(const b_iterator *it, b_status status);
|
||||
|
||||
BLUE_API b_status b_iterator_move_next(const b_iterator *it);
|
||||
BLUE_API b_iterator_value b_iterator_get_value(b_iterator *it);
|
||||
BLUE_API const b_iterator_value b_iterator_get_cvalue(const b_iterator *it);
|
||||
BLUE_API b_status b_iterator_erase(b_iterator *it);
|
||||
static inline bool b_iterator_is_valid(const b_iterator *it)
|
||||
{
|
||||
return B_OK(b_iterator_get_status(it));
|
||||
}
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
@@ -1,197 +0,0 @@
|
||||
#ifndef BLUE_CORE_MACROS_H_
|
||||
#define BLUE_CORE_MACROS_H_
|
||||
|
||||
#include <blue/core/class.h>
|
||||
#include <blue/core/object.h>
|
||||
#include <blue/core/thread.h>
|
||||
#include <blue/core/type.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define __B_IFACE_I0(p, x) p##x
|
||||
#define __B_IFACE_I1(p, x) __B_IFACE_I0(p, x)
|
||||
|
||||
/* Type definitions macros (for use in .c source file) */
|
||||
|
||||
#define B_TYPE_CLASS_DEFINITION_BEGIN(type_name) \
|
||||
static void type_name##_class_init(b_class *p, void *d) \
|
||||
{
|
||||
#define B_TYPE_CLASS_DEFINITION_END(type_name) }
|
||||
|
||||
#define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \
|
||||
interface_name##_class *__B_IFACE_I1(iface, __LINE__) \
|
||||
= b_class_get_interface(p, interface_id); \
|
||||
if (!__B_IFACE_I1(iface, __LINE__)) { \
|
||||
b_throw_error_with_msg_template( \
|
||||
B_ERRORS_BUILTIN, B_ERR_CLASS_INIT_FAILURE, \
|
||||
B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, \
|
||||
B_ERROR_PARAM("class_name", b_class_get_name(p)), \
|
||||
B_ERROR_PARAM("interface_name", #interface_name)); \
|
||||
exit(-1); \
|
||||
} else { \
|
||||
interface_name##_class *iface = __B_IFACE_I1(iface, __LINE__);
|
||||
#define B_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) }
|
||||
#define B_INTERFACE_ENTRY(slot) iface->slot
|
||||
|
||||
#define B_TYPE_DEFINITION_BEGIN(name) \
|
||||
static b_type_info name##_type_info = {0}; \
|
||||
static void name##_class_init(b_class *, void *); \
|
||||
static void name##_type_init(void) \
|
||||
{ \
|
||||
b_type_info *type_info = &name##_type_info; \
|
||||
unsigned int nr_vtables = 0; \
|
||||
type_info->t_name = #name; \
|
||||
type_info->t_class_init = name##_class_init;
|
||||
#define B_TYPE_DEFINITION_END(name) \
|
||||
b_result result = b_type_register(type_info); \
|
||||
if (b_result_is_error(result)) { \
|
||||
b_throw_error_caused_by_error( \
|
||||
B_ERRORS_BUILTIN, B_ERR_TYPE_REGISTRATION_FAILURE, \
|
||||
result); \
|
||||
abort(); \
|
||||
} \
|
||||
} \
|
||||
b_type name##_get_type(void) \
|
||||
{ \
|
||||
static b_once static_type_init = B_ONCE_INIT; \
|
||||
\
|
||||
if (b_init_once(&static_type_init)) { \
|
||||
name##_type_init(); \
|
||||
} \
|
||||
\
|
||||
return &name##_type_info.t_id; \
|
||||
}
|
||||
|
||||
#define B_TYPE_ID(a, b, c, d, e) b_type_id_init(&type_info->t_id, a, b, c, d, e)
|
||||
#define B_TYPE_EXTENDS(parent_id) \
|
||||
b_type_id_copy(parent_id, &type_info->t_parent_id)
|
||||
#define B_TYPE_IMPLEMENTS(interface_id) \
|
||||
b_type_id_copy( \
|
||||
interface_id, \
|
||||
&type_info->t_interfaces[type_info->t_nr_interfaces++])
|
||||
#define B_TYPE_CLASS(class_struct) \
|
||||
type_info->t_class_size = sizeof(class_struct)
|
||||
#define B_TYPE_FLAGS(flags) type_info->t_flags = (flags)
|
||||
#define B_TYPE_INSTANCE_INIT(func) type_info->t_instance_init = (func)
|
||||
#define B_TYPE_INSTANCE_FINI(func) type_info->t_instance_fini = (func)
|
||||
|
||||
#if 0
|
||||
#define B_TYPE_VTABLE_BEGIN(vtable_struct, interface_id) \
|
||||
vtable_struct __B_IFACE_I1(iface, __LINE__) = {0}; \
|
||||
{ \
|
||||
vtable_struct *iface = &__B_IFACE_I1(iface, __LINE__); \
|
||||
type_info->t_vtables[nr_vtables].v_vtable = iface; \
|
||||
type_info->t_vtables[nr_vtables].v_interface_id = interface_id; \
|
||||
nr_vtables++;
|
||||
#define B_TYPE_VTABLE_END(vtable_struct, interface_id) }
|
||||
#endif
|
||||
|
||||
#define B_TYPE_INSTANCE_PRIVATE(instance_struct) \
|
||||
type_info->t_instance_private_size = sizeof(instance_struct)
|
||||
#define B_TYPE_INSTANCE_PROTECTED(instance_struct) \
|
||||
type_info->t_instance_protected_size = sizeof(instance_struct)
|
||||
|
||||
/* Type declaration macros (for use in .h header file) */
|
||||
|
||||
#define __B_DECLARE_TYPE(name) \
|
||||
typedef B_TYPE_FWDREF(name) name; \
|
||||
typedef struct _##name##_class name##_class;
|
||||
|
||||
#define B_DECLARE_TYPE(name) \
|
||||
__B_DECLARE_TYPE(name); \
|
||||
static inline name *name##_ref(name *p) \
|
||||
{ \
|
||||
return b_object_ref(p); \
|
||||
} \
|
||||
static inline void name##_unref(name *p) \
|
||||
{ \
|
||||
b_object_unref(p); \
|
||||
}
|
||||
|
||||
#define B_TYPE_CLASS_DECLARATION_BEGIN(name) struct _##name##_class {
|
||||
#define B_TYPE_CLASS_DECLARATION_END(name) \
|
||||
} \
|
||||
;
|
||||
|
||||
#define B_TYPE_VIRTUAL_METHOD(return_type, method_name) \
|
||||
return_type(*method_name)
|
||||
|
||||
#define B_TYPE_DEFAULT_CONSTRUCTOR(type_name, type_id) \
|
||||
static inline type_name *type_name##_create(void) \
|
||||
{ \
|
||||
return b_object_create(type_id); \
|
||||
}
|
||||
|
||||
/* Other macros */
|
||||
|
||||
#define B_CLASS_DISPATCH_VIRTUAL( \
|
||||
type_name, type_id, default_value, func, object, ...) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= b_object_get_interface(object, type_id); \
|
||||
if (iface && iface->func) { \
|
||||
return iface->func(object, __VA_ARGS__); \
|
||||
} else { \
|
||||
return default_value; \
|
||||
} \
|
||||
} while (0)
|
||||
#define B_CLASS_DISPATCH_VIRTUAL_0(type_name, type_id, default_value, func, object) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= b_object_get_interface(object, type_id); \
|
||||
if (iface && iface->func) { \
|
||||
return iface->func(object); \
|
||||
} else { \
|
||||
return default_value; \
|
||||
} \
|
||||
} while (0)
|
||||
#define B_CLASS_DISPATCH_VIRTUAL_V(type_name, type_id, func, object, ...) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= b_object_get_interface(object, type_id); \
|
||||
if (iface && iface->func) { \
|
||||
iface->func(object, __VA_ARGS__); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
#define B_CLASS_DISPATCH_VIRTUAL_V0(type_name, type_id, func, object) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= b_object_get_interface(object, type_id); \
|
||||
if (iface && iface->func) { \
|
||||
iface->func(object); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define B_CLASS_DISPATCH_STATIC(type_id, func_name, obj, ...) \
|
||||
do { \
|
||||
void *priv = b_object_get_private(obj, type_id); \
|
||||
return func_name(priv, __VA_ARGS__); \
|
||||
} while (0)
|
||||
#define B_CLASS_DISPATCH_STATIC_V(type_id, func_name, obj, ...) \
|
||||
do { \
|
||||
void *priv = b_object_get_private(obj, type_id); \
|
||||
func_name(priv, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define B_CLASS_DISPATCH_STATIC_0(type_id, func_name, obj) \
|
||||
do { \
|
||||
void *priv = b_object_get_private(obj, type_id); \
|
||||
return func_name(priv); \
|
||||
} while (0)
|
||||
|
||||
#define B_CLASS_DISPATCH_STATIC_V0(type_id, func_name, obj) \
|
||||
do { \
|
||||
void *priv = b_object_get_private(obj, type_id); \
|
||||
func_name(priv); \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define B_DECLS_BEGIN extern "C" {
|
||||
#define B_DECLS_END }
|
||||
#else
|
||||
#define B_DECLS_BEGIN
|
||||
#define B_DECLS_END
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,118 +0,0 @@
|
||||
#ifndef BLUE_CORE_MISC_H_
|
||||
#define BLUE_CORE_MISC_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef _Nonnull
|
||||
#define _Nonnull
|
||||
#endif
|
||||
|
||||
#define B_NPOS ((size_t)-1)
|
||||
|
||||
#define b_min(type, x, y) (z__b_min_##type(x, y))
|
||||
#define b_max(type, x, y) (z__b_max_##type(x, y))
|
||||
|
||||
#define b_unbox(type, box, member) \
|
||||
((type *_Nonnull)((box) ? (uintptr_t)(box) - (offsetof(type, member)) : 0))
|
||||
|
||||
#define z__b_merge_(a, b) a##b
|
||||
#define z__b_label_(a) z__b_merge_(__unique_name_, a)
|
||||
#define z__b_unique_name() z__b_label_(__LINE__)
|
||||
#define z__b_numargs(arg_type, ...) \
|
||||
(sizeof((arg_type[]) {__VA_ARGS__}) / sizeof(arg_type))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef BLUELIB_STATIC
|
||||
#define BLUE_API extern
|
||||
#else
|
||||
#ifdef BLUELIB_EXPORT
|
||||
#define BLUE_API extern __declspec(dllexport)
|
||||
#else
|
||||
#define BLUE_API extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define BLUE_API extern
|
||||
#endif
|
||||
|
||||
static inline char z__b_min_char(char x, char y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline unsigned char z__b_min_uchar(unsigned char x, unsigned char y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline int z__b_min_int(int x, int y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline unsigned int z__b_min_uint(unsigned int x, unsigned int y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline long z__b_min_long(long x, long y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline unsigned int z__b_min_ulong(unsigned long x, unsigned long y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline long long z__b_min_longlong(long long x, long long y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline unsigned long long z__b_min_ulonglong(
|
||||
unsigned long long x, unsigned long long y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
static inline size_t z__b_min_size_t(size_t x, size_t y)
|
||||
{
|
||||
return x < y ? x : y;
|
||||
}
|
||||
|
||||
static inline char z__b_max_char(char x, char y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline unsigned char z__b_max_uchar(unsigned char x, unsigned char y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline int z__b_max_int(int x, int y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline unsigned int z__b_max_uint(unsigned int x, unsigned int y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline long z__b_max_long(long x, long y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline unsigned int z__b_max_ulong(unsigned long x, unsigned long y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline long long z__b_max_longlong(long long x, long long y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline unsigned long long z__b_max_ulonglong(
|
||||
unsigned long long x, unsigned long long y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
static inline size_t z__b_max_size_t(size_t x, size_t y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
|
||||
BLUE_API size_t b_int_length(intptr_t v);
|
||||
BLUE_API size_t b_uint_length(uintptr_t v);
|
||||
|
||||
#endif // BLUE_CORE_MISC_H_
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef BLUE_CORE_OBJECT_H_
|
||||
#define BLUE_CORE_OBJECT_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/type.h>
|
||||
|
||||
#define B_OBJECT_MAGIC 0xDECAFC0C0ABEEF13ULL
|
||||
|
||||
#define B_OBJECT(p) ((b_object *)(p))
|
||||
#define B_TYPE_OBJECT (b_object_get_type())
|
||||
|
||||
#define B_TYPE_FWDREF(name) struct _b_object
|
||||
|
||||
#define B_RV(p) (b_object_make_rvalue(p))
|
||||
|
||||
typedef B_TYPE_FWDREF(b_object) b_object;
|
||||
|
||||
typedef struct _b_object_class {
|
||||
void (*to_string)(const b_object *, B_TYPE_FWDREF(b_stream) *);
|
||||
} b_object_class;
|
||||
|
||||
BLUE_API b_type b_object_get_type(void);
|
||||
|
||||
BLUE_API void *b_object_get_private(const b_object *object, b_type type);
|
||||
BLUE_API void *b_object_get_protected(const b_object *object, b_type type);
|
||||
BLUE_API void *b_object_get_interface(const b_object *object, b_type type);
|
||||
BLUE_API b_status b_object_get_data(
|
||||
const b_object *object, b_type type, void **priv, void **prot,
|
||||
void **iface);
|
||||
|
||||
BLUE_API b_object *b_object_ref(b_object *p);
|
||||
BLUE_API void b_object_unref(b_object *p);
|
||||
BLUE_API b_object *b_object_make_rvalue(b_object *p);
|
||||
|
||||
BLUE_API b_object *b_object_create(b_type type);
|
||||
BLUE_API void b_object_to_string(const b_object *p, B_TYPE_FWDREF(b_stream) * out);
|
||||
BLUE_API bool b_object_is_type(const b_object *p, b_type type);
|
||||
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
#ifndef BLUE_CORE_QUEUE_H_
|
||||
#define BLUE_CORE_QUEUE_H_
|
||||
|
||||
#include <blue/core/iterator.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_TYPE_QUEUE_ITERATOR (b_queue_iterator_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_queue_iterator);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_queue_iterator)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_queue_iterator)
|
||||
|
||||
#define B_QUEUE_INIT ((b_queue) {.q_first = NULL, .q_last = NULL})
|
||||
#define B_QUEUE_ENTRY_INIT ((b_queue_entry) {.qe_next = NULL, .qe_prev = NULL})
|
||||
|
||||
typedef struct b_queue_entry {
|
||||
struct b_queue_entry *qe_next;
|
||||
struct b_queue_entry *qe_prev;
|
||||
} b_queue_entry;
|
||||
|
||||
typedef struct b_queue {
|
||||
b_queue_entry *q_first;
|
||||
b_queue_entry *q_last;
|
||||
} b_queue;
|
||||
|
||||
static inline void b_queue_init(b_queue *q)
|
||||
{
|
||||
memset(q, 0x00, sizeof *q);
|
||||
}
|
||||
static inline bool b_queue_empty(const b_queue *q)
|
||||
{
|
||||
return q ? (q->q_first == NULL) : true;
|
||||
}
|
||||
|
||||
static inline b_queue_entry *b_queue_first(const b_queue *q)
|
||||
{
|
||||
return q ? q->q_first : NULL;
|
||||
}
|
||||
static inline b_queue_entry *b_queue_last(const b_queue *q)
|
||||
{
|
||||
return q ? q->q_last : NULL;
|
||||
}
|
||||
static inline b_queue_entry *b_queue_next(const b_queue_entry *entry)
|
||||
{
|
||||
return entry ? entry->qe_next : NULL;
|
||||
}
|
||||
static inline b_queue_entry *b_queue_prev(const b_queue_entry *entry)
|
||||
{
|
||||
return entry ? entry->qe_prev : NULL;
|
||||
}
|
||||
|
||||
BLUE_API b_type b_queue_iterator_get_type(void);
|
||||
|
||||
BLUE_API size_t b_queue_length(const b_queue *q);
|
||||
|
||||
BLUE_API void b_queue_insert_before(
|
||||
b_queue *q, b_queue_entry *entry, b_queue_entry *before);
|
||||
BLUE_API void b_queue_insert_after(
|
||||
b_queue *q, b_queue_entry *entry, b_queue_entry *after);
|
||||
|
||||
BLUE_API void b_queue_push_front(b_queue *q, b_queue_entry *entry);
|
||||
BLUE_API void b_queue_push_back(b_queue *q, b_queue_entry *entry);
|
||||
|
||||
BLUE_API b_queue_entry *b_queue_pop_front(b_queue *q);
|
||||
BLUE_API b_queue_entry *b_queue_pop_back(b_queue *q);
|
||||
|
||||
BLUE_API void b_queue_move(b_queue *q, b_queue_entry *dest, b_queue_entry *src);
|
||||
BLUE_API void b_queue_delete(b_queue *q, b_queue_entry *entry);
|
||||
BLUE_API void b_queue_delete_all(b_queue *q);
|
||||
|
||||
BLUE_API b_iterator *b_queue_begin(b_queue *q);
|
||||
BLUE_API b_iterator *b_queue_cbegin(const b_queue *q);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
#ifndef BLUELIB_RANDOM_H_
|
||||
#define BLUELIB_RANDOM_H_
|
||||
|
||||
#include <blue/core/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct b_random_algorithm;
|
||||
|
||||
typedef enum b_random_flags {
|
||||
/* algorithm selection */
|
||||
B_RANDOM_MT19937 = 0x01u,
|
||||
|
||||
/* generation flags */
|
||||
B_RANDOM_SECURE = 0x100u,
|
||||
} b_random_flags;
|
||||
|
||||
typedef struct b_random_ctx {
|
||||
b_random_flags __f;
|
||||
struct b_random_algorithm *__a;
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned long long mt[312];
|
||||
size_t mti;
|
||||
} __mt19937;
|
||||
};
|
||||
} b_random_ctx;
|
||||
|
||||
BLUE_API b_random_ctx *b_random_global_ctx(void);
|
||||
|
||||
BLUE_API b_status b_random_init(b_random_ctx *ctx, b_random_flags flags);
|
||||
BLUE_API unsigned long long b_random_next_int64(b_random_ctx *ctx);
|
||||
BLUE_API double b_random_next_double(b_random_ctx *ctx);
|
||||
BLUE_API void b_random_next_bytes(
|
||||
b_random_ctx *ctx, unsigned char *out, size_t nbytes);
|
||||
|
||||
#endif
|
||||
@@ -1,47 +0,0 @@
|
||||
#ifndef BLUE_CORE_RINGBUFFER_H_
|
||||
#define BLUE_CORE_RINGBUFFER_H_
|
||||
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_TYPE_RINGBUFFER (b_ringbuffer_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_ringbuffer);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_ringbuffer)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_ringbuffer)
|
||||
|
||||
BLUE_API b_type b_ringbuffer_get_type(void);
|
||||
|
||||
BLUE_API b_ringbuffer *b_ringbuffer_create(size_t capacity);
|
||||
BLUE_API b_ringbuffer *b_ringbuffer_create_with_buffer(void *ptr, size_t capacity);
|
||||
|
||||
BLUE_API b_status b_ringbuffer_clear(b_ringbuffer *buf);
|
||||
|
||||
BLUE_API b_status b_ringbuffer_read(
|
||||
b_ringbuffer *buf, void *p, size_t count, size_t *nr_read);
|
||||
BLUE_API b_status b_ringbuffer_write(
|
||||
b_ringbuffer *buf, const void *p, size_t count, size_t *nr_written);
|
||||
|
||||
BLUE_API int b_ringbuffer_getc(b_ringbuffer *buf);
|
||||
BLUE_API b_status b_ringbuffer_putc(b_ringbuffer *buf, int c);
|
||||
|
||||
BLUE_API size_t b_ringbuffer_write_capacity_remaining(const b_ringbuffer *buf);
|
||||
BLUE_API size_t b_ringbuffer_available_data_remaining(const b_ringbuffer *buf);
|
||||
|
||||
BLUE_API b_status b_ringbuffer_open_read_buffer(
|
||||
b_ringbuffer *buf, const void **ptr, size_t *length);
|
||||
BLUE_API b_status b_ringbuffer_close_read_buffer(
|
||||
b_ringbuffer *buf, const void **ptr, size_t nr_read);
|
||||
|
||||
BLUE_API b_status b_ringbuffer_open_write_buffer(
|
||||
b_ringbuffer *buf, void **ptr, size_t *capacity);
|
||||
BLUE_API b_status b_ringbuffer_close_write_buffer(
|
||||
b_ringbuffer *buf, void **ptr, size_t nr_written);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
@@ -1,109 +0,0 @@
|
||||
#ifndef BLUE_CORE_ROPE_H_
|
||||
#define BLUE_CORE_ROPE_H_
|
||||
|
||||
#include <blue/core/hash.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
struct b_string;
|
||||
struct b_bstr;
|
||||
|
||||
#define B_ROPE_TYPE(f) ((f) & 0xFF)
|
||||
|
||||
#define B_ROPE_CHAR(c) \
|
||||
\
|
||||
{ \
|
||||
.r_flags = B_ROPE_F_CHAR, .r_len_total = 1, \
|
||||
.r_v = {.v_char = (c) } \
|
||||
}
|
||||
|
||||
#define B_ROPE_CSTR(str) \
|
||||
{ \
|
||||
.r_flags = B_ROPE_F_CSTR_BORROWED, \
|
||||
.r_len_total = strlen(str), \
|
||||
.r_v = { \
|
||||
.v_cstr = { \
|
||||
.s = (str), \
|
||||
.hash = b_hash_cstr(str), \
|
||||
}, \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define B_ROPE_CSTR_STATIC(str) \
|
||||
{ \
|
||||
.r_flags = B_ROPE_F_CSTR_STATIC, \
|
||||
.r_len_total = strlen(str), \
|
||||
.r_v = { \
|
||||
.v_cstr = { \
|
||||
.s = (str), \
|
||||
.hash = b_hash_cstr(str), \
|
||||
}, \
|
||||
}, \
|
||||
}
|
||||
#define B_ROPE_INT(v) \
|
||||
\
|
||||
{ \
|
||||
.r_flags = B_ROPE_F_INT, .r_len_total = b_int_length(v), \
|
||||
.r_v = {.v_int = (v) } \
|
||||
}
|
||||
#define B_ROPE_UINT(v) \
|
||||
\
|
||||
{ \
|
||||
.r_flags = B_ROPE_F_UINT, .r_len_total = b_uint_length(v), \
|
||||
.r_v = {.v_uint = (v) } \
|
||||
}
|
||||
|
||||
typedef enum b_rope_flags {
|
||||
B_ROPE_F_NONE = 0x0000u,
|
||||
B_ROPE_F_CHAR = 0x0001u,
|
||||
B_ROPE_F_CSTR = 0x0002u,
|
||||
B_ROPE_F_CSTR_BORROWED = 0x0003u,
|
||||
B_ROPE_F_CSTR_STATIC = 0x0004u,
|
||||
B_ROPE_F_INT = 0x0005u,
|
||||
B_ROPE_F_UINT = 0x0006u,
|
||||
B_ROPE_F_COMPOSITE = 0x0007u,
|
||||
B_ROPE_F_MALLOC = 0x0100u,
|
||||
} b_rope_flags;
|
||||
|
||||
typedef struct b_rope {
|
||||
b_rope_flags r_flags;
|
||||
unsigned long r_len_left, r_len_total;
|
||||
|
||||
union {
|
||||
char v_char;
|
||||
intptr_t v_int;
|
||||
uintptr_t v_uint;
|
||||
|
||||
struct {
|
||||
const char *s;
|
||||
uint64_t hash;
|
||||
} v_cstr;
|
||||
|
||||
struct {
|
||||
const struct b_rope *r_left, *r_right;
|
||||
} v_composite;
|
||||
} r_v;
|
||||
} b_rope;
|
||||
|
||||
BLUE_API void b_rope_init_char(b_rope *rope, char c);
|
||||
BLUE_API void b_rope_init_cstr(b_rope *rope, const char *s);
|
||||
BLUE_API void b_rope_init_cstr_borrowed(b_rope *rope, const char *s);
|
||||
BLUE_API void b_rope_init_cstr_static(b_rope *rope, const char *s);
|
||||
BLUE_API void b_rope_init_int(b_rope *rope, intptr_t v);
|
||||
BLUE_API void b_rope_init_uint(b_rope *rope, uintptr_t v);
|
||||
|
||||
BLUE_API void b_rope_destroy(b_rope *rope);
|
||||
|
||||
BLUE_API void b_rope_iterate(
|
||||
const b_rope *rope, void (*func)(const b_rope *, void *), void *arg);
|
||||
BLUE_API size_t b_rope_get_size(const b_rope *rope);
|
||||
BLUE_API void b_rope_concat(b_rope *result, const b_rope *left, const b_rope *right);
|
||||
BLUE_API void b_rope_join(b_rope *result, const b_rope **ropes, size_t nr_ropes);
|
||||
|
||||
BLUE_API b_status b_rope_to_cstr(const b_rope *rope, char *out, size_t max);
|
||||
BLUE_API b_status b_rope_to_bstr(const b_rope *rope, struct b_bstr *str);
|
||||
BLUE_API b_status b_rope_to_string(const b_rope *rope, b_stream *out);
|
||||
|
||||
#endif
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_STATUS_H_
|
||||
#define BLUELIB_CORE_STATUS_H_
|
||||
|
||||
#include <blue/core/misc.h>
|
||||
|
||||
#define B_OK(status) ((enum b_status)((uintptr_t)(status)) == B_SUCCESS)
|
||||
#define B_ERR(status) ((status) != B_SUCCESS)
|
||||
|
||||
typedef enum b_status {
|
||||
B_SUCCESS = 0x00u,
|
||||
B_ERR_NO_MEMORY,
|
||||
B_ERR_OUT_OF_BOUNDS,
|
||||
B_ERR_INVALID_ARGUMENT,
|
||||
B_ERR_NAME_EXISTS,
|
||||
B_ERR_NOT_SUPPORTED,
|
||||
B_ERR_BAD_STATE,
|
||||
B_ERR_NO_ENTRY,
|
||||
B_ERR_NO_DATA,
|
||||
B_ERR_NO_SPACE,
|
||||
B_ERR_UNKNOWN_FUNCTION,
|
||||
B_ERR_BAD_FORMAT,
|
||||
B_ERR_IO_FAILURE,
|
||||
B_ERR_IS_DIRECTORY,
|
||||
B_ERR_NOT_DIRECTORY,
|
||||
B_ERR_PERMISSION_DENIED,
|
||||
B_ERR_BUSY,
|
||||
|
||||
/* blue-compress specific code */
|
||||
B_ERR_COMPRESSION_FAILURE,
|
||||
|
||||
/* blue-object specific code */
|
||||
B_ERR_TYPE_REGISTRATION_FAILURE,
|
||||
B_ERR_CLASS_INIT_FAILURE,
|
||||
} b_status;
|
||||
|
||||
typedef enum b_status_msg {
|
||||
B_MSG_SUCCESS = 0,
|
||||
|
||||
/* blue-object specific messages */
|
||||
B_MSG_TYPE_REGISTRATION_FAILURE,
|
||||
B_MSG_CLASS_INIT_FAILURE,
|
||||
B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE,
|
||||
} b_status_msg;
|
||||
|
||||
BLUE_API const char *b_status_to_string(b_status status);
|
||||
BLUE_API const char *b_status_description(b_status status);
|
||||
|
||||
#endif
|
||||
@@ -1,100 +0,0 @@
|
||||
#ifndef BLUE_CORE_STREAM_H_
|
||||
#define BLUE_CORE_STREAM_H_
|
||||
|
||||
#include <blue/core/encoding.h>
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define b_stdin (z__b_stream_get_stdin())
|
||||
#define b_stdout (z__b_stream_get_stdout())
|
||||
#define b_stderr (z__b_stream_get_stderr())
|
||||
|
||||
#define B_TYPE_STREAM (b_stream_get_type())
|
||||
#define B_TYPE_STREAM_BUFFER (b_stream_buffer_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_stream);
|
||||
B_DECLARE_TYPE(b_stream_buffer);
|
||||
|
||||
typedef enum b_stream_mode {
|
||||
B_STREAM_READ = 0x01u,
|
||||
B_STREAM_WRITE = 0x02u,
|
||||
B_STREAM_BINARY = 0x10u,
|
||||
Z__B_STREAM_STATIC = 0x80u,
|
||||
} b_stream_mode;
|
||||
|
||||
typedef enum b_stream_seek_origin {
|
||||
B_STREAM_SEEK_START = 0x01u,
|
||||
B_STREAM_SEEK_CURRENT = 0x02u,
|
||||
B_STREAM_SEEK_END = 0x03u,
|
||||
} b_stream_seek_origin;
|
||||
|
||||
typedef struct b_stream_cfg {
|
||||
b_stream_mode s_mode;
|
||||
} b_stream_cfg;
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream)
|
||||
b_status (*s_close)(b_stream *);
|
||||
b_status (*s_seek)(b_stream *, long long, b_stream_seek_origin);
|
||||
b_status (*s_tell)(const b_stream *, size_t *);
|
||||
b_status (*s_getc)(b_stream *, b_wchar *);
|
||||
b_status (*s_read)(b_stream *, void *, size_t, size_t *);
|
||||
b_status (*s_write)(b_stream *, const void *, size_t, size_t *);
|
||||
b_status (*s_reserve)(b_stream *, size_t);
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream)
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream_buffer)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream_buffer)
|
||||
|
||||
BLUE_API b_type b_stream_get_type();
|
||||
BLUE_API b_type b_stream_buffer_get_type();
|
||||
|
||||
BLUE_API b_stream *z__b_stream_get_stdin(void);
|
||||
BLUE_API b_stream *z__b_stream_get_stdout(void);
|
||||
BLUE_API b_stream *z__b_stream_get_stderr(void);
|
||||
|
||||
BLUE_API b_stream_buffer *b_stream_buffer_create(void *p, size_t len);
|
||||
BLUE_API b_stream_buffer *b_stream_buffer_create_dynamic(size_t buffer_size);
|
||||
|
||||
BLUE_API b_stream *b_stream_open_fp(FILE *fp);
|
||||
|
||||
BLUE_API b_status b_stream_reserve(b_stream *stream, size_t len);
|
||||
BLUE_API b_status b_stream_seek(
|
||||
b_stream *stream, long long offset, b_stream_seek_origin origin);
|
||||
BLUE_API size_t b_stream_cursor(const b_stream *stream);
|
||||
|
||||
BLUE_API b_status b_stream_push_indent(b_stream *stream, int indent);
|
||||
BLUE_API b_status b_stream_pop_indent(b_stream *stream);
|
||||
|
||||
BLUE_API b_status b_stream_read_char(b_stream *stream, b_wchar *c);
|
||||
|
||||
BLUE_API b_status b_stream_read_bytes(
|
||||
b_stream *stream, void *buf, size_t count, size_t *nr_read);
|
||||
|
||||
BLUE_API b_status b_stream_read_line(b_stream *stream, char *s, size_t max);
|
||||
BLUE_API b_status b_stream_read_line_s(b_stream *src, b_stream *dest);
|
||||
|
||||
BLUE_API b_status b_stream_read_all_bytes(
|
||||
b_stream *stream, void *p, size_t max, size_t *nr_read);
|
||||
BLUE_API b_status b_stream_read_all_bytes_s(
|
||||
b_stream *src, b_stream *dest, b_stream_buffer *buffer, size_t *nr_read);
|
||||
|
||||
BLUE_API b_status b_stream_write_char(b_stream *stream, b_wchar c);
|
||||
BLUE_API b_status b_stream_write_string(
|
||||
b_stream *stream, const char *s, size_t *nr_written);
|
||||
|
||||
BLUE_API b_status b_stream_write_bytes(
|
||||
b_stream *stream, const void *buf, size_t count, size_t *nr_written);
|
||||
|
||||
BLUE_API b_status b_stream_write_fmt(
|
||||
b_stream *stream, size_t *nr_written, const char *format, ...);
|
||||
BLUE_API b_status b_stream_write_vfmt(
|
||||
b_stream *stream, size_t *nr_written, const char *format, va_list arg);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef BLUE_CORE_STRINGSTREAM_H_
|
||||
#define BLUE_CORE_STRINGSTREAM_H_
|
||||
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/core/stream.h>
|
||||
#include <stddef.h>
|
||||
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
#define B_TYPE_STRINGSTREAM (b_stringstream_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_stringstream);
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stringstream)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stringstream)
|
||||
|
||||
BLUE_API b_type b_stringstream_get_type(void);
|
||||
|
||||
BLUE_API b_stringstream *b_stringstream_create(void);
|
||||
BLUE_API b_stringstream *b_stringstream_create_with_buffer(char *buf, size_t max);
|
||||
|
||||
BLUE_API b_status b_stringstream_reset(b_stringstream *strv);
|
||||
BLUE_API b_status b_stringstream_reset_with_buffer(
|
||||
b_stringstream *strv, char *buf, size_t max);
|
||||
|
||||
BLUE_API const char *b_stringstream_ptr(const b_stringstream *strv);
|
||||
BLUE_API char *b_stringstream_steal(b_stringstream *strv);
|
||||
|
||||
BLUE_API size_t b_stringstream_get_length(const b_stringstream *strv);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef BLUELIB_CORE_THREAD_H_
|
||||
#define BLUELIB_CORE_THREAD_H_
|
||||
|
||||
#include <blue/core/bitop.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(__linux__)
|
||||
#include <pthread.h>
|
||||
|
||||
#define B_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
|
||||
|
||||
typedef pthread_mutex_t b_mutex;
|
||||
#else
|
||||
#error Unsupported compiler/system
|
||||
#endif
|
||||
|
||||
#define B_ONCE_INIT ((b_once)0)
|
||||
|
||||
typedef struct b_thread b_thread;
|
||||
|
||||
typedef int b_once;
|
||||
|
||||
static inline bool b_init_once(b_once *once)
|
||||
{
|
||||
int x = 0;
|
||||
return b_cmpxchg(once, &x, 1);
|
||||
}
|
||||
|
||||
BLUE_API b_thread *b_thread_self(void);
|
||||
|
||||
BLUE_API bool b_mutex_lock(b_mutex *mut);
|
||||
BLUE_API bool b_mutex_trylock(b_mutex *mut);
|
||||
BLUE_API bool b_mutex_unlock(b_mutex *mut);
|
||||
|
||||
#endif
|
||||
@@ -1,66 +0,0 @@
|
||||
#ifndef BLUE_CORE_TYPE_H_
|
||||
#define BLUE_CORE_TYPE_H_
|
||||
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define B_TYPE_MAX_INTERFACES 64
|
||||
|
||||
struct _b_class;
|
||||
struct _b_object;
|
||||
|
||||
typedef void (*b_class_init_function)(struct _b_class *, void *);
|
||||
typedef void (*b_instance_init_function)(struct _b_object *, void *);
|
||||
typedef void (*b_instance_fini_function)(struct _b_object *, void *);
|
||||
|
||||
typedef const union b_type {
|
||||
struct {
|
||||
uint64_t p00, p01;
|
||||
} a;
|
||||
|
||||
unsigned char b[16];
|
||||
} *b_type;
|
||||
|
||||
typedef enum b_type_flags {
|
||||
B_TYPE_F_ABSTRACT = 0x01u,
|
||||
} b_type_flags;
|
||||
|
||||
typedef struct b_type_info {
|
||||
union b_type t_id;
|
||||
union b_type t_parent_id;
|
||||
const char *t_name;
|
||||
b_type_flags t_flags;
|
||||
union b_type t_interfaces[B_TYPE_MAX_INTERFACES];
|
||||
size_t t_nr_interfaces;
|
||||
size_t t_class_size;
|
||||
b_class_init_function t_class_init;
|
||||
size_t t_instance_private_size;
|
||||
size_t t_instance_protected_size;
|
||||
b_instance_init_function t_instance_init;
|
||||
b_instance_fini_function t_instance_fini;
|
||||
} b_type_info;
|
||||
|
||||
BLUE_API void b_type_id_init(
|
||||
union b_type *out, uint32_t a, uint16_t b, uint16_t c, uint16_t d,
|
||||
uint64_t e);
|
||||
static inline void b_type_id_copy(b_type src, union b_type *dest)
|
||||
{
|
||||
dest->a.p00 = src->a.p00;
|
||||
dest->a.p01 = src->a.p01;
|
||||
}
|
||||
|
||||
static inline int b_type_id_compare(b_type a, b_type b)
|
||||
{
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return memcmp(a, b, sizeof(union b_type));
|
||||
}
|
||||
|
||||
BLUE_API b_result b_type_register(b_type_info *info);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user