Compare commits
15 Commits
main
...
7b42a023e4
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b42a023e4 | |||
| 7d78d7d314 | |||
| 4f40bfd9a0 | |||
| a339b6e01a | |||
| 604ddfcebf | |||
| c78ea4bfa6 | |||
| b951577f48 | |||
| 5d1b2aabbb | |||
| a65eb5c161 | |||
| 9b8c0f8763 | |||
| c04c2e8f12 | |||
| b8cf2b379b | |||
| 274a48a845 | |||
| 47feee7b1a | |||
| 7db5fefe25 |
+6
-6
@@ -56,8 +56,8 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
---
|
||||
Language: ObjC
|
||||
DerivePointerAlignment: false
|
||||
@@ -114,8 +114,8 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
---
|
||||
Language: Cpp
|
||||
DerivePointerAlignment: false
|
||||
@@ -172,5 +172,5 @@ AttributeMacros:
|
||||
ForEachMacros:
|
||||
- fx_btree_foreach
|
||||
- fx_queue_foreach
|
||||
MacroBlockBegin: "FX_TYPE_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_TYPE_.*_END"
|
||||
MacroBlockBegin: "FX_(TYPE|ASSEMBLY)_.*_BEGIN"
|
||||
MacroBlockEnd: "FX_(TYPE|ASSEMBLY)_.*_END"
|
||||
|
||||
+20
-47
@@ -9,8 +9,12 @@ set(CMAKE_C_EXTENSIONS OFF)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
if (NOT DEFINED fx_modules)
|
||||
set(fx_modules core ds serial term cmd io compress)
|
||||
set(fx_all_assemblies
|
||||
fx.runtime
|
||||
fx.collections)
|
||||
|
||||
if (NOT DEFINED fx_assemblies)
|
||||
set(fx_assemblies ${fx_all_assemblies})
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED fx_enable_floating_point)
|
||||
@@ -32,50 +36,19 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
foreach (module ${fx_modules})
|
||||
add_subdirectory(${module})
|
||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module})
|
||||
message(STATUS "Building unit tests for module ${module}")
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates.cmake)
|
||||
|
||||
if (fx_enable_tests AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c)
|
||||
add_executable(fx-${module}-units
|
||||
test/${module}/${module}-units.c
|
||||
misc/AllTests.c
|
||||
misc/CuTest.c
|
||||
misc/CuTest.h)
|
||||
target_link_libraries(fx-${module}-units fx-${module})
|
||||
target_include_directories(fx-${module}-units PRIVATE misc/)
|
||||
set_target_properties(fx-${module}-units PROPERTIES FOLDER "Tests/${module}")
|
||||
endif ()
|
||||
|
||||
file(GLOB test_sources test/${module}/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c")
|
||||
|
||||
if (fx_enable_tests)
|
||||
foreach (test_file ${test_sources})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_executable(fx-${module}-${test_name} ${test_file})
|
||||
|
||||
set_target_properties(fx-${module}-${test_name} PROPERTIES FOLDER "Tests/${module}")
|
||||
|
||||
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
||||
endforeach (test_file)
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach (module)
|
||||
|
||||
if (fx_enable_tests)
|
||||
file(GLOB test_sources test/*.c)
|
||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/units.c")
|
||||
|
||||
foreach (test_file ${test_sources})
|
||||
get_filename_component(test_name ${test_file} NAME_WE)
|
||||
add_executable(fx-${test_name} ${test_file})
|
||||
|
||||
set_target_properties(fx-${test_name} PROPERTIES FOLDER "Tests")
|
||||
|
||||
foreach (module ${fx_modules})
|
||||
target_link_libraries(fx-${test_name} fx-${module})
|
||||
endforeach (module)
|
||||
endforeach (test_file)
|
||||
if ("fx.runtime" IN_LIST fx_assemblies)
|
||||
add_fx_assembly(
|
||||
NAME fx.runtime
|
||||
NAMESPACES fx fx.reflection)
|
||||
endif ()
|
||||
|
||||
if ("fx.collections" IN_LIST fx_assemblies)
|
||||
add_fx_assembly(
|
||||
NAME fx.collections
|
||||
NAMESPACES fx.collections
|
||||
DEPENDENCIES fx.runtime)
|
||||
endif ()
|
||||
|
||||
add_executable(dynamic-test test/dynamic-test.c)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
FX_ASSEMBLY_BEGIN()
|
||||
FX_ASSEMBLY_NAME("fx.collections");
|
||||
FX_ASSEMBLY_VERSION(1, 0, 0, 0);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "array", fx_array);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "bitbuffer", fx_bitbuffer);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "bitmap", fx_bitmap);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "dict", fx_dict);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "hashmap", fx_hashmap);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "list", fx_list);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.collections", "tree", fx_tree);
|
||||
FX_ASSEMBLY_END()
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
FX_ASSEMBLY_BEGIN()
|
||||
FX_ASSEMBLY_NAME("fx.runtime");
|
||||
FX_ASSEMBLY_VERSION(1, 0, 0, 0);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "stream", fx_stream);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "string", fx_string);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "stringstream", fx_stringstream);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx", "iterator", fx_iterator);
|
||||
FX_ASSEMBLY_EXPORT_TYPE("fx.reflection", "assembly", fx_assembly);
|
||||
FX_ASSEMBLY_END()
|
||||
+60
-69
@@ -1,109 +1,100 @@
|
||||
function(add_fx_module)
|
||||
function(add_fx_assembly)
|
||||
set(options)
|
||||
set(one_value_args NAME)
|
||||
set(multi_value_args
|
||||
NAMESPACES
|
||||
DEPENDENCIES
|
||||
SUBDIRS
|
||||
EXTRA_SOURCES
|
||||
LIBS
|
||||
INCLUDE_DIRS
|
||||
DEFINES)
|
||||
LIBS)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||
"${options}"
|
||||
"${one_value_args}"
|
||||
"${multi_value_args}")
|
||||
|
||||
set(module_name ${arg_NAME})
|
||||
set(assembly_name ${arg_NAME})
|
||||
string(REPLACE "." "/" assembly_path ${assembly_name})
|
||||
set(assembly_target_name ${assembly_name})
|
||||
string(REPLACE "." "_" assembly_token ${assembly_name})
|
||||
string(TOUPPER ${assembly_token} assembly_token)
|
||||
|
||||
file(GLOB sources *.c *.h)
|
||||
set(assembly_include_paths "")
|
||||
set(assembly_sources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/assemblies/${assembly_name}.c)
|
||||
|
||||
foreach (dir ${arg_SUBDIRS})
|
||||
file(GLOB dir_sources ${dir}/*.c ${dir}/*.h)
|
||||
set(sources ${sources} ${dir_sources})
|
||||
foreach (dir ${arg_NAMESPACES})
|
||||
add_subdirectory(${dir})
|
||||
set(assembly_sources ${assembly_sources} ${namespace_sources})
|
||||
set(assembly_include_paths ${assembly_include_paths} ${namespace_include_paths})
|
||||
endforeach (dir)
|
||||
|
||||
file(GLOB sys_sources sys/${fx_system_name}/*.c sys/${fx_system_name}/*.h)
|
||||
set(root_header include/fx/${module_name}.h)
|
||||
file(GLOB headers include/fx/${module_name}/*.h)
|
||||
message(STATUS "Building assembly ${assembly_name}")
|
||||
add_library(${assembly_target_name} SHARED
|
||||
${assembly_sources})
|
||||
|
||||
string(REPLACE "-" "_" module_preproc_token ${module_name})
|
||||
string(TOUPPER ${module_preproc_token} module_preproc_token)
|
||||
set(module_preproc_token FX_${module_preproc_token})
|
||||
target_include_directories(${assembly_target_name} PUBLIC ${assembly_include_paths})
|
||||
|
||||
message(STATUS "Building module ${module_name} (shared)")
|
||||
add_library(fx-${module_name} SHARED
|
||||
${sources}
|
||||
${sys_sources}
|
||||
${root_header}
|
||||
${headers}
|
||||
${arg_EXTRA_SOURCES})
|
||||
message(STATUS "Building module ${module_name} (static)")
|
||||
add_library(fx-${module_name}-s STATIC
|
||||
${sources}
|
||||
${sys_sources}
|
||||
${root_header}
|
||||
${headers}
|
||||
${arg_EXTRA_SOURCES})
|
||||
|
||||
target_include_directories(fx-${module_name} PUBLIC include/)
|
||||
target_include_directories(fx-${module_name}-s PUBLIC include/)
|
||||
|
||||
target_compile_definitions(fx-${module_name} PUBLIC
|
||||
${module_preproc_token}
|
||||
target_compile_definitions(${assembly_target_name} PUBLIC
|
||||
FX_EXPORT=1
|
||||
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||
target_compile_definitions(fx-${module_name}-s PUBLIC
|
||||
${module_preproc_token}
|
||||
FX_EXPORT=1
|
||||
FX_STATIC=1
|
||||
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||
|
||||
set_target_properties(fx-${module_name}
|
||||
set_target_properties(${assembly_target_name}
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
foreach (dep ${arg_DEPENDENCIES})
|
||||
target_link_libraries(fx-${module_name} fx-${dep})
|
||||
target_link_libraries(fx-${module_name}-s fx-${dep}-s)
|
||||
target_link_libraries(${assembly_target_name} ${dep})
|
||||
endforeach (dep)
|
||||
|
||||
foreach (lib ${arg_LIBS})
|
||||
target_link_libraries(fx-${module_name} ${lib})
|
||||
target_link_libraries(fx-${module_name}-s ${lib})
|
||||
target_link_libraries(${assembly_target_name} ${lib})
|
||||
endforeach (lib)
|
||||
|
||||
foreach (dir ${arg_INCLUDE_DIRS})
|
||||
target_include_directories(fx-${module_name} PRIVATE
|
||||
${dir})
|
||||
target_include_directories(fx-${module_name}-s PRIVATE
|
||||
${dir})
|
||||
target_include_directories(${assembly_target_name} PRIVATE ${dir})
|
||||
endforeach (dir)
|
||||
|
||||
foreach (def ${arg_DEFINES})
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
${def})
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
${def})
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE ${def})
|
||||
endforeach (def)
|
||||
|
||||
set_target_properties(fx-${module_name} PROPERTIES
|
||||
FOLDER "Shared/${module_name}")
|
||||
set_target_properties(fx-${module_name}-s PROPERTIES
|
||||
FOLDER "Static/${module_name}")
|
||||
set_target_properties(${assembly_target_name} PROPERTIES
|
||||
FOLDER "${assembly_name}")
|
||||
|
||||
TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
|
||||
if(IS_BIG_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
BIG_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE
|
||||
BIG_ENDIAN)
|
||||
else()
|
||||
target_compile_definitions(fx-${module_name} PRIVATE
|
||||
LITTLE_ENDIAN)
|
||||
target_compile_definitions(fx-${module_name}-s PRIVATE
|
||||
target_compile_definitions(${assembly_target_name} PRIVATE
|
||||
LITTLE_ENDIAN)
|
||||
endif()
|
||||
|
||||
install(TARGETS fx-${module_name} fx-${module_name}-s)
|
||||
install(FILES ${root_header} DESTINATION include/fx)
|
||||
install(FILES ${headers} DESTINATION include/fx/${module_name})
|
||||
endfunction(add_fx_module)
|
||||
install(TARGETS ${assembly_target_name})
|
||||
install(FILES ${headers} DESTINATION include/${assembly_path})
|
||||
endfunction(add_fx_assembly)
|
||||
|
||||
macro(export_fx_namespace_details)
|
||||
set(options)
|
||||
set(one_value_args NAME)
|
||||
set(multi_value_args)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 arg
|
||||
"${options}"
|
||||
"${one_value_args}"
|
||||
"${multi_value_args}")
|
||||
|
||||
set(namespace_name ${arg_NAME})
|
||||
string(REPLACE "." "/" namespace_path ${namespace_name})
|
||||
set(namespace_target_name ${namespace_name})
|
||||
|
||||
set(namespace_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
file(GLOB namespace_sources
|
||||
*.c *.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/${namespace_path}/*.h)
|
||||
file(GLOB sys_sources sys/${fx_system_name}/*.c sys/${fx_system_name}/*.h)
|
||||
file(GLOB headers include/${namespace_path}/*.h)
|
||||
set(namespace_sources
|
||||
${namespace_sources}
|
||||
${sys_sources}
|
||||
${headers}
|
||||
PARENT_SCOPE)
|
||||
endmacro(export_fx_namespace_details)
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
include(../cmake/Templates.cmake)
|
||||
|
||||
add_fx_module(
|
||||
NAME core
|
||||
SUBDIRS hash)
|
||||
@@ -1,418 +0,0 @@
|
||||
#ifndef FX_CORE_ERROR_H_
|
||||
#define FX_CORE_ERROR_H_
|
||||
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAMETER_MAX 4
|
||||
#define FX_ERROR_MSG_ID_INVALID ((unsigned long)-1)
|
||||
|
||||
#define FX_CATCH(err, expr) ((err = (expr)) != NULL)
|
||||
|
||||
#define fx_result_is_error(result) ((result) != NULL)
|
||||
#define fx_result_is_success(result) ((result) == NULL)
|
||||
|
||||
#define FX_RESULT_SUCCESS ((fx_result)NULL)
|
||||
#define FX_RESULT_ERR(err_name) \
|
||||
fx_error_with_code(fx_error_vendor_get_builtin(), FX_ERR_##err_name)
|
||||
#define FX_RESULT_ERR_WITH_STRING(err_name, ...) \
|
||||
fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), FX_ERR_##err_name, __VA_ARGS__)
|
||||
#define FX_RESULT_STATUS(code) \
|
||||
((code) == FX_SUCCESS \
|
||||
? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_code(fx_error_vendor_get_builtin(), code)))
|
||||
#define FX_RESULT_STATUS_WITH_STRING(code, ...) \
|
||||
((code) == FX_SUCCESS \
|
||||
? FX_RESULT_SUCCESS \
|
||||
: (fx_error_with_string( \
|
||||
fx_error_vendor_get_builtin(), code, __VA_ARGS__)))
|
||||
|
||||
#define FX_ERRORS_BUILTIN (fx_error_vendor_get_builtin())
|
||||
#define FX_ERRORS_ERRNO (fx_error_vendor_get_errno())
|
||||
|
||||
#define FX_ERROR_PARAM(name, value) \
|
||||
(fx_error_template_parameter) \
|
||||
{ \
|
||||
.param_name = (name), .param_value = (uintptr_t)(value), \
|
||||
}
|
||||
|
||||
#define FX_ERROR_TEMPLATE_PARAM(name, type, format) \
|
||||
(fx_error_template_parameter_definition) \
|
||||
{ \
|
||||
.param_name = (name), .param_type = (type), \
|
||||
.param_format = (format), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION(code, name, msg) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
}
|
||||
#define FX_ERROR_DEFINITION_TEMPLATE(code, name, msg, ...) \
|
||||
[code] = (fx_error_definition) \
|
||||
{ \
|
||||
.err_name = (name), .err_message = (msg), \
|
||||
.err_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define FX_ERROR_MSG(id, content) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), \
|
||||
}
|
||||
#define FX_ERROR_MSG_TEMPLATE(id, content, ...) \
|
||||
[id] = (fx_error_msg) \
|
||||
{ \
|
||||
.msg_message = (content), .msg_params = __VA_ARGS__, \
|
||||
}
|
||||
|
||||
#define z__fx_error_create_status(status_code) \
|
||||
(z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status_code, NULL, NULL, 0, \
|
||||
NULL, NULL))
|
||||
|
||||
/* Error creation macros */
|
||||
#define fx_error_with_code(vendor, code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_error(vendor, code, cause_error) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_status(vendor, code, cause_status) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_caused_by_code(vendor, code, cause_vendor, cause_code) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, fx_error_with_code(cause_vendor, cause_code), \
|
||||
__FILE__, __LINE__, __FUNCTION__, NULL))
|
||||
#define fx_error_with_string(vendor, code, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
__VA_ARGS__))
|
||||
#define fx_error_with_string_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__fx_error_create( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, __VA_ARGS__))
|
||||
#define fx_error_with_msg(vendor, code, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_error(vendor, code, cause_error, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_caused_by_status(vendor, code, cause_status, msg_id) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause_error, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
msg_id, (fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause_status, msg_id, ...) \
|
||||
(z__fx_error_create_msg( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template(vendor, code, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, NULL, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_error(vendor, code, cause_error, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, cause_error, __FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
#define fx_error_with_template_caused_by_status(vendor, code, cause_status, ...) \
|
||||
(z__fx_error_create_template( \
|
||||
vendor, code, z__fx_error_create_status(cause_status), \
|
||||
__FILE__, __LINE__, __FUNCTION__, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
/* Error propagation macros */
|
||||
#define fx_result_propagate(err) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_error_caused_by(err, caused_by) (z__fx_error_caused_by(err, caused_by))
|
||||
#define fx_error_caused_by_fx_status(err, status) \
|
||||
(z__fx_error_caused_by_fx_status(err, status))
|
||||
#define fx_error_replace(err, caused_by) \
|
||||
(z__fx_error_propagate(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
/* Error throw macros */
|
||||
#define z__fx_throw(err) (z__fx_error_throw(err, NULL, 0, NULL))
|
||||
#define fx_throw(err) (z__fx_error_throw(err, __FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_throw_status(status) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, NULL), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
|
||||
#define fx_throw_status_string(status, ...) \
|
||||
(z__fx_error_throw( \
|
||||
z__fx_error_create( \
|
||||
fx_error_vendor_get_builtin(), status, NULL, NULL, 0, \
|
||||
NULL, __VA_ARGS__), \
|
||||
__FILE__, __LINE__, __FUNCTION__))
|
||||
#define fx_throw_error_code(vendor, code) \
|
||||
z__fx_throw(fx_error_with_code(vendor, code))
|
||||
#define fx_throw_error_caused_by_error(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_error(vendor, code, cause))
|
||||
#define fx_throw_error_caused_by_status(vendor, code, cause) \
|
||||
z__fx_throw(fx_error_caused_by_status(vendor, code, cause))
|
||||
#define fx_throw_error_with_string(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_string(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define fx_throw_error_with_string_caused_by_status(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_string_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_msg(vendor, code, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg(vendor, code, msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_error(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_error(vendor, code, cause, msg_id))
|
||||
#define fx_throw_error_with_msg_caused_by_status(vendor, code, cause, msg_id) \
|
||||
z__fx_throw(fx_error_with_msg_caused_by_status(vendor, code, cause, msg_id))
|
||||
|
||||
#define fx_throw_error_with_msg_template(vendor, code, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template(vendor, code, msg_id, __VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_error( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
#define fx_throw_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, ...) \
|
||||
z__fx_throw(fx_error_with_msg_template_caused_by_status( \
|
||||
vendor, code, cause, msg_id, __VA_ARGS__))
|
||||
|
||||
#define fx_throw_error_with_template(vendor, code, ...) \
|
||||
z__fx_throw(fx_error_with_template(vendor, code, __VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_error(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_error( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
#define fx_throw_error_with_template_caused_by_status(vendor, code, cause, ...) \
|
||||
z__fx_throw(fx_error_with_template_caused_by_status( \
|
||||
vendor, code, cause, __VA_ARGS__))
|
||||
|
||||
#define FX_ERR_MSG(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_ERROR, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_WARN(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_WARN, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_INFO(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_INFO, \
|
||||
.msg_content = (s), \
|
||||
}
|
||||
#define FX_ERR_MSG_END(s) \
|
||||
{ \
|
||||
.msg_type = FX_ERROR_MESSAGE_NONE, \
|
||||
.msg_content = NULL, \
|
||||
}
|
||||
|
||||
typedef enum fx_error_submsg_type {
|
||||
FX_ERROR_SUBMSG_NONE = 0,
|
||||
FX_ERROR_SUBMSG_ERROR,
|
||||
FX_ERROR_SUBMSG_WARNING,
|
||||
FX_ERROR_SUBMSG_INFO,
|
||||
} fx_error_submsg_type;
|
||||
|
||||
typedef enum fx_error_report_flags {
|
||||
FX_ERROR_REPORT_NONE = 0,
|
||||
FX_ERROR_REPORT_STATUS = 0x01u,
|
||||
FX_ERROR_REPORT_DESCRIPTION = 0x02u,
|
||||
FX_ERROR_REPORT_SUBMSG = 0x04u,
|
||||
FX_ERROR_REPORT_STACK_TRACE = 0x08u,
|
||||
FX_ERROR_REPORT_CAUSE = 0x10u,
|
||||
|
||||
FX_ERROR_REPORT_MINIMAL = FX_ERROR_REPORT_STATUS | FX_ERROR_REPORT_DESCRIPTION,
|
||||
FX_ERROR_REPORT_DEFAULT = FX_ERROR_REPORT_MINIMAL | FX_ERROR_REPORT_SUBMSG
|
||||
| FX_ERROR_REPORT_CAUSE,
|
||||
FX_ERROR_REPORT_ALL = FX_ERROR_REPORT_DEFAULT | FX_ERROR_REPORT_STACK_TRACE,
|
||||
} fx_error_report_flags;
|
||||
|
||||
typedef enum fx_error_template_parameter_type {
|
||||
FX_ERROR_TEMPLATE_PARAM_NONE = 0,
|
||||
FX_ERROR_TEMPLATE_PARAM_STRING,
|
||||
FX_ERROR_TEMPLATE_PARAM_CHAR,
|
||||
FX_ERROR_TEMPLATE_PARAM_INT,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINT,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_LONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_ULONGLONG,
|
||||
FX_ERROR_TEMPLATE_PARAM_SIZE_T,
|
||||
FX_ERROR_TEMPLATE_PARAM_INTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_UINTPTR,
|
||||
FX_ERROR_TEMPLATE_PARAM_PTR,
|
||||
} fx_error_template_parameter_type;
|
||||
|
||||
typedef struct fx_error_template_parameter_definition {
|
||||
const char *param_name;
|
||||
fx_error_template_parameter_type param_type;
|
||||
const char *param_format;
|
||||
} fx_error_template_parameter_definition;
|
||||
|
||||
typedef struct fx_error_template_parameter {
|
||||
const char *param_name;
|
||||
uintptr_t param_value;
|
||||
const struct fx_error_template_parameter_definition *__param_def;
|
||||
} fx_error_template_parameter;
|
||||
|
||||
struct fx_error_vendor;
|
||||
|
||||
typedef struct fx_error fx_error;
|
||||
typedef struct fx_error *fx_result;
|
||||
typedef struct fx_error_submsg fx_error_submsg;
|
||||
typedef struct fx_error_stack_frame fx_error_stack_frame;
|
||||
typedef long fx_error_status_code;
|
||||
typedef unsigned long fx_error_msg_id;
|
||||
|
||||
typedef struct fx_error_definition {
|
||||
const char *err_name;
|
||||
const char *err_message;
|
||||
const fx_error_template_parameter_definition err_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_definition;
|
||||
|
||||
typedef struct fx_error_msg {
|
||||
const char *msg_message;
|
||||
const fx_error_template_parameter_definition msg_params[FX_ERROR_TEMPLATE_PARAMETER_MAX];
|
||||
} fx_error_msg;
|
||||
|
||||
typedef const fx_error_definition *(*fx_error_status_code_get_definition)(
|
||||
const struct fx_error_vendor *, fx_error_status_code);
|
||||
typedef const fx_error_msg *(*fx_error_msg_get_definition)(
|
||||
const struct fx_error_vendor *, fx_error_msg_id);
|
||||
typedef void (*fx_error_report_function)(
|
||||
const struct fx_error *, fx_error_report_flags);
|
||||
|
||||
typedef struct fx_error_vendor {
|
||||
const char *v_name;
|
||||
|
||||
fx_error_status_code_get_definition v_status_get_definition;
|
||||
fx_error_msg_get_definition v_msg_get_definition;
|
||||
|
||||
const fx_error_definition *v_error_definitions;
|
||||
size_t v_error_definitions_length;
|
||||
|
||||
const fx_error_msg *v_msg;
|
||||
size_t v_msg_length;
|
||||
} fx_error_vendor;
|
||||
|
||||
FX_API fx_error *z__fx_error_create_template(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_create_string(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, const char *, va_list);
|
||||
FX_API fx_error *z__fx_error_create_msg(
|
||||
const fx_error_vendor *, fx_error_status_code, fx_error *, const char *,
|
||||
unsigned int, const char *, fx_error_msg_id,
|
||||
const fx_error_template_parameter[]);
|
||||
FX_API fx_error *z__fx_error_propagate(
|
||||
fx_error *, const char *, unsigned int, const char *);
|
||||
FX_API fx_error *z__fx_error_caused_by(fx_error *, fx_error *);
|
||||
FX_API fx_error *z__fx_error_caused_by_fx_status(fx_error *, fx_status);
|
||||
FX_API void z__fx_error_throw(fx_error *, const char *, unsigned int, const char *);
|
||||
|
||||
FX_API bool fx_result_is(
|
||||
fx_result result, const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_builtin(void);
|
||||
FX_API const fx_error_vendor *fx_error_vendor_get_errno(void);
|
||||
FX_API const fx_error_definition *fx_error_vendor_get_error_definition(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_name(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const char *fx_error_vendor_get_status_code_description(
|
||||
const fx_error_vendor *vendor, fx_error_status_code code);
|
||||
FX_API const fx_error_msg *fx_error_vendor_get_msg(
|
||||
const fx_error_vendor *vendor, fx_error_msg_id msg_id);
|
||||
|
||||
static inline fx_error *z__fx_error_create(
|
||||
const fx_error_vendor *v, fx_error_status_code c, fx_error *c2,
|
||||
const char *f0, unsigned int l, const char *f1, const char *d, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, d);
|
||||
fx_error *err = z__fx_error_create_string(v, c, c2, f0, l, f1, d, arg);
|
||||
va_end(arg);
|
||||
return err;
|
||||
}
|
||||
|
||||
FX_API enum fx_status fx_error_add_submsg_string(
|
||||
fx_error *error, fx_error_submsg_type type, const char *msg, ...);
|
||||
FX_API enum fx_status z__fx_error_add_submsg_template(
|
||||
fx_error *error, fx_error_submsg_type type, fx_error_msg_id msg_id,
|
||||
fx_error_template_parameter param[]);
|
||||
#define fx_error_add_submsg(error, type, msg_id) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, type, msg_id, (fx_error_template_parameter[]) {{}}))
|
||||
#define fx_error_add_submsg_template(error, type, msg_id, ...) \
|
||||
(z__fx_error_add_submsg_template( \
|
||||
error, type, msg_id, \
|
||||
(fx_error_template_parameter[]) {__VA_ARGS__, {}}))
|
||||
|
||||
FX_API void fx_error_discard(fx_error *error);
|
||||
|
||||
FX_API fx_error_status_code fx_error_get_status_code(const fx_error *error);
|
||||
FX_API const fx_error_vendor *fx_error_get_vendor(const fx_error *error);
|
||||
FX_API const fx_error_definition *fx_error_get_definition(const fx_error *error);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameter(
|
||||
const fx_error *error, const char *param_name);
|
||||
FX_API const fx_error_template_parameter *fx_error_get_template_parameters(
|
||||
const fx_error *error);
|
||||
FX_API const char *fx_error_get_description(const fx_error *error);
|
||||
FX_API const fx_error_msg *fx_error_get_msg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_first_submsg(const fx_error *error);
|
||||
FX_API const fx_error_submsg *fx_error_get_next_submsg(
|
||||
const fx_error *error, const fx_error_submsg *msg);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_first_stack_frame(
|
||||
const fx_error *error);
|
||||
FX_API const fx_error_stack_frame *fx_error_get_next_stack_frame(
|
||||
const fx_error *error, const fx_error_stack_frame *frame);
|
||||
FX_API const fx_error *fx_error_get_caused_by(const fx_error *error);
|
||||
|
||||
FX_API fx_error_submsg_type fx_error_submsg_get_type(const fx_error_submsg *msg);
|
||||
FX_API const char *fx_error_submsg_get_content(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_msg *fx_error_submsg_get_msg(const fx_error_submsg *msg);
|
||||
FX_API const fx_error_template_parameter *fx_error_submsg_get_template_parameters(
|
||||
const fx_error_submsg *msg);
|
||||
|
||||
FX_API const char *fx_error_stack_frame_get_filepath(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API unsigned int fx_error_stack_frame_get_line_number(
|
||||
const fx_error_stack_frame *frame);
|
||||
FX_API const char *fx_error_stack_frame_get_function_name(
|
||||
const fx_error_stack_frame *frame);
|
||||
|
||||
FX_API const fx_error_template_parameter_definition *fx_error_definition_get_template_parameter(
|
||||
const fx_error_definition *error_def, const char *param_name);
|
||||
|
||||
FX_API const char *fx_error_msg_get_content(const fx_error_msg *msg);
|
||||
FX_API const fx_error_template_parameter_definition *fx_error_msg_get_template_parameter(
|
||||
const fx_error_msg *msg, const char *param_name);
|
||||
|
||||
FX_API void fx_set_error_report_function(
|
||||
fx_error_report_function func, fx_error_report_flags flags);
|
||||
|
||||
#endif
|
||||
@@ -1,3 +0,0 @@
|
||||
include(../cmake/Templates.cmake)
|
||||
|
||||
add_fx_module(NAME ds DEPENDENCIES core)
|
||||
@@ -0,0 +1,2 @@
|
||||
export_fx_namespace_details(
|
||||
NAME fx.collections)
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/array.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <fx/ds/bitbuffer.h>
|
||||
#include <fx/collections/bitbuffer.h>
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/bitop.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/bitmap.h>
|
||||
#include <fx/bitop.h>
|
||||
#include <fx/collections/bitmap.h>
|
||||
#include <fx/stream.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BITS_PER_WORD (8 * sizeof(bitmap_word_t))
|
||||
@@ -36,11 +36,17 @@ static void bitmap_clear_bit(struct fx_bitmap_p *map, size_t bit)
|
||||
map->map_words[index] &= ~mask;
|
||||
}
|
||||
|
||||
static void bitmap_set_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
||||
static void bitmap_set_range(
|
||||
struct fx_bitmap_p *map,
|
||||
size_t first_bit,
|
||||
size_t nbits)
|
||||
{
|
||||
}
|
||||
|
||||
static void bitmap_clear_range(struct fx_bitmap_p *map, size_t first_bit, size_t nbits)
|
||||
static void bitmap_clear_range(
|
||||
struct fx_bitmap_p *map,
|
||||
size_t first_bit,
|
||||
size_t nbits)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -216,13 +222,21 @@ void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit)
|
||||
void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_TYPE_BITMAP, bitmap_set_range, map, first_bit, nbits);
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_set_range,
|
||||
map,
|
||||
first_bit,
|
||||
nbits);
|
||||
}
|
||||
|
||||
void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_TYPE_BITMAP, bitmap_clear_range, map, first_bit, nbits);
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_clear_range,
|
||||
map,
|
||||
first_bit,
|
||||
nbits);
|
||||
}
|
||||
|
||||
void fx_bitmap_set_all(fx_bitmap *map)
|
||||
@@ -247,7 +261,10 @@ size_t fx_bitmap_count_set_bits(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_count_clear_bits(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_count_clear_bits, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_count_clear_bits,
|
||||
map);
|
||||
}
|
||||
|
||||
size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
||||
@@ -257,7 +274,10 @@ size_t fx_bitmap_highest_set_bit(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_highest_clear_bit(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_highest_clear_bit, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_highest_clear_bit,
|
||||
map);
|
||||
}
|
||||
|
||||
size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
||||
@@ -267,7 +287,10 @@ size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map)
|
||||
|
||||
size_t fx_bitmap_lowest_clear_bit(const fx_bitmap *map)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BITMAP, bitmap_lowest_clear_bit, map);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_BITMAP,
|
||||
bitmap_lowest_clear_bit,
|
||||
map);
|
||||
}
|
||||
|
||||
/*** PUBLIC ALIAS FUNCTIONS ***************************************************/
|
||||
@@ -285,7 +308,8 @@ static void bitmap_fini(fx_object *obj, void *priv)
|
||||
|
||||
static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||
{
|
||||
const struct fx_bitmap_p *map = fx_object_get_private(obj, FX_TYPE_BITMAP);
|
||||
const struct fx_bitmap_p *map
|
||||
= fx_object_get_private(obj, FX_TYPE_BITMAP);
|
||||
|
||||
unsigned char *bytes = (unsigned char *)map->map_words;
|
||||
size_t nr_bytes = map->map_nr_words * sizeof(bitmap_word_t);
|
||||
@@ -294,10 +318,16 @@ static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||
for (size_t i = 0; i < nr_bytes - 1; i++) {
|
||||
c = bytes[i];
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%c%c%c%c%c%c%c%c", c & 0x80 ? '1' : '0',
|
||||
c & 0x40 ? '1' : '0', c & 0x20 ? '1' : '0',
|
||||
c & 0x10 ? '1' : '0', c & 0x08 ? '1' : '0',
|
||||
c & 0x04 ? '1' : '0', c & 0x02 ? '1' : '0',
|
||||
out,
|
||||
NULL,
|
||||
"%c%c%c%c%c%c%c%c",
|
||||
c & 0x80 ? '1' : '0',
|
||||
c & 0x40 ? '1' : '0',
|
||||
c & 0x20 ? '1' : '0',
|
||||
c & 0x10 ? '1' : '0',
|
||||
c & 0x08 ? '1' : '0',
|
||||
c & 0x04 ? '1' : '0',
|
||||
c & 0x02 ? '1' : '0',
|
||||
c & 0x01 ? '1' : '0');
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/ds/buffer.h>
|
||||
#include <fx/collections/buffer.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -21,7 +21,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
||||
{
|
||||
if (buffer->buf_cap < new_capacity) {
|
||||
void *new_data = realloc(
|
||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
||||
buffer->buf_data,
|
||||
new_capacity * buffer->buf_itemsz);
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -29,7 +30,8 @@ static fx_status resize_buffer(struct fx_buffer_p *buffer, size_t new_capacity)
|
||||
buffer->buf_data = new_data;
|
||||
} else {
|
||||
void *new_data = realloc(
|
||||
buffer->buf_data, new_capacity * buffer->buf_itemsz);
|
||||
buffer->buf_data,
|
||||
new_capacity * buffer->buf_itemsz);
|
||||
if (!new_data) {
|
||||
return FX_ERR_NO_MEMORY;
|
||||
}
|
||||
@@ -78,7 +80,10 @@ static enum fx_status buffer_resize(struct fx_buffer_p *buf, size_t length)
|
||||
}
|
||||
|
||||
static enum fx_status buffer_insert(
|
||||
struct fx_buffer_p *buffer, const void *p, size_t count, size_t at)
|
||||
struct fx_buffer_p *buffer,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t at)
|
||||
{
|
||||
if (at == FX_NPOS) {
|
||||
at = buffer->buf_len;
|
||||
@@ -110,7 +115,10 @@ static enum fx_status buffer_insert(
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static enum fx_status buffer_remove(struct fx_buffer_p *buffer, size_t at, size_t count)
|
||||
static enum fx_status buffer_remove(
|
||||
struct fx_buffer_p *buffer,
|
||||
size_t at,
|
||||
size_t count)
|
||||
{
|
||||
if (at >= buffer->buf_len) {
|
||||
return FX_ERR_OUT_OF_BOUNDS;
|
||||
@@ -162,7 +170,9 @@ static enum fx_status buffer_clear(struct fx_buffer_p *buffer)
|
||||
}
|
||||
|
||||
static enum fx_status buffer_push_back(
|
||||
struct fx_buffer_p *buf, size_t count, void **p)
|
||||
struct fx_buffer_p *buf,
|
||||
size_t count,
|
||||
void **p)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -181,7 +191,9 @@ static enum fx_status buffer_push_back(
|
||||
}
|
||||
|
||||
static enum fx_status buffer_push_front(
|
||||
struct fx_buffer_p *buf, size_t count, void **p)
|
||||
struct fx_buffer_p *buf,
|
||||
size_t count,
|
||||
void **p)
|
||||
{
|
||||
enum fx_status status = FX_SUCCESS;
|
||||
|
||||
@@ -286,7 +298,10 @@ fx_buffer *fx_buffer_create_from_bytes(const void *buf, size_t len)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
fx_buffer *fx_buffer_create_from_array(const void *buf, size_t item_sz, size_t len)
|
||||
fx_buffer *fx_buffer_create_from_array(
|
||||
const void *buf,
|
||||
size_t item_sz,
|
||||
size_t len)
|
||||
{
|
||||
fx_buffer *buffer = fx_object_create(FX_TYPE_BUFFER);
|
||||
if (!buffer) {
|
||||
@@ -325,14 +340,28 @@ enum fx_status fx_buffer_resize(fx_buffer *buf, size_t length)
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_insert(
|
||||
fx_buffer *buffer, const void *p, size_t count, size_t at)
|
||||
fx_buffer *buffer,
|
||||
const void *p,
|
||||
size_t count,
|
||||
size_t at)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_insert, buffer, p, count, at);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_insert,
|
||||
buffer,
|
||||
p,
|
||||
count,
|
||||
at);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_remove(fx_buffer *buffer, size_t at, size_t count)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_remove, buffer, at, count);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_remove,
|
||||
buffer,
|
||||
at,
|
||||
count);
|
||||
}
|
||||
|
||||
void *fx_buffer_ptr(const fx_buffer *buffer)
|
||||
@@ -362,12 +391,22 @@ enum fx_status fx_buffer_clear(fx_buffer *buffer)
|
||||
|
||||
enum fx_status fx_buffer_push_back(fx_buffer *buf, size_t count, void **p)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_back, buf, count, p);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_push_back,
|
||||
buf,
|
||||
count,
|
||||
p);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_push_front(fx_buffer *buf, size_t count, void **p)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_BUFFER, buffer_push_front, buf, count, p);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_BUFFER,
|
||||
buffer_push_front,
|
||||
buf,
|
||||
count,
|
||||
p);
|
||||
}
|
||||
|
||||
enum fx_status fx_buffer_pop_back(fx_buffer *buf, size_t count)
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/datetime.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/datetime.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
/*** PRIVATE DATA *************************************************************/
|
||||
|
||||
@@ -89,7 +89,8 @@ static bool is_zone_valid(const struct fx_datetime_p *dt)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(dt->dt_zone_offset_minute >= 0 && dt->dt_zone_offset_minute <= 59)) {
|
||||
if (!(dt->dt_zone_offset_minute >= 0
|
||||
&& dt->dt_zone_offset_minute <= 59)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -309,12 +310,18 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *out)
|
||||
static enum fx_status encode_rfc3339(
|
||||
const struct fx_datetime_p *dt,
|
||||
fx_stream *out)
|
||||
{
|
||||
if (dt->dt_has_date) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
||||
dt->dt_month, dt->dt_day);
|
||||
out,
|
||||
NULL,
|
||||
"%04ld-%02ld-%02ld",
|
||||
dt->dt_year,
|
||||
dt->dt_month,
|
||||
dt->dt_day);
|
||||
}
|
||||
|
||||
if (dt->dt_has_date && dt->dt_has_time) {
|
||||
@@ -323,7 +330,11 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
|
||||
if (dt->dt_has_time) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
||||
out,
|
||||
NULL,
|
||||
"%02ld:%02ld:%02ld",
|
||||
dt->dt_hour,
|
||||
dt->dt_min,
|
||||
dt->dt_sec);
|
||||
|
||||
if (dt->dt_msec > 0) {
|
||||
@@ -336,7 +347,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
fx_stream_write_char(out, 'Z');
|
||||
} else {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%c%02ld:%02ld",
|
||||
out,
|
||||
NULL,
|
||||
"%c%02ld:%02ld",
|
||||
dt->dt_zone_offset_negative ? '-' : '+',
|
||||
dt->dt_zone_offset_hour,
|
||||
dt->dt_zone_offset_minute);
|
||||
@@ -348,7 +361,9 @@ static enum fx_status encode_rfc3339(const struct fx_datetime_p *dt, fx_stream *
|
||||
}
|
||||
|
||||
static void datetime_to_string(
|
||||
const struct fx_datetime_p *dt, fx_datetime_format format, fx_stream *dest)
|
||||
const struct fx_datetime_p *dt,
|
||||
fx_datetime_format format,
|
||||
fx_stream *dest)
|
||||
{
|
||||
switch (format) {
|
||||
case FX_DATETIME_FORMAT_RFC3339:
|
||||
@@ -453,10 +468,16 @@ fx_datetime *fx_datetime_parse(enum fx_datetime_format format, const char *s)
|
||||
}
|
||||
|
||||
void fx_datetime_to_string(
|
||||
const fx_datetime *dt, fx_datetime_format format, fx_stream *dest)
|
||||
const fx_datetime *dt,
|
||||
fx_datetime_format format,
|
||||
fx_stream *dest)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_DATETIME, datetime_to_string, dt, format, dest);
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_to_string,
|
||||
dt,
|
||||
format,
|
||||
dest);
|
||||
}
|
||||
|
||||
bool fx_datetime_is_localtime(const fx_datetime *dt)
|
||||
@@ -512,17 +533,25 @@ long fx_datetime_subsecond(const fx_datetime *dt)
|
||||
bool fx_datetime_zone_offset_is_negative(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME, datetime_zone_offset_is_negative, dt);
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_is_negative,
|
||||
dt);
|
||||
}
|
||||
|
||||
long fx_datetime_zone_offset_hour(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_hour, dt);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_hour,
|
||||
dt);
|
||||
}
|
||||
|
||||
long fx_datetime_zone_offset_minute(const fx_datetime *dt)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DATETIME, datetime_zone_offset_minute, dt);
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_TYPE_DATETIME,
|
||||
datetime_zone_offset_minute,
|
||||
dt);
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
@@ -543,8 +572,12 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (dt->dt_has_date) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%04ld-%02ld-%02ld", dt->dt_year,
|
||||
dt->dt_month, dt->dt_day);
|
||||
out,
|
||||
NULL,
|
||||
"%04ld-%02ld-%02ld",
|
||||
dt->dt_year,
|
||||
dt->dt_month,
|
||||
dt->dt_day);
|
||||
}
|
||||
|
||||
if (dt->dt_has_date && dt->dt_has_time) {
|
||||
@@ -553,7 +586,11 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (dt->dt_has_time) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, "%02ld:%02ld:%02ld", dt->dt_hour, dt->dt_min,
|
||||
out,
|
||||
NULL,
|
||||
"%02ld:%02ld:%02ld",
|
||||
dt->dt_hour,
|
||||
dt->dt_min,
|
||||
dt->dt_sec);
|
||||
|
||||
if (dt->dt_msec > 0) {
|
||||
@@ -562,7 +599,9 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
if (!dt->dt_localtime) {
|
||||
fx_stream_write_fmt(
|
||||
out, NULL, " %c%02ld:%02ld",
|
||||
out,
|
||||
NULL,
|
||||
" %c%02ld:%02ld",
|
||||
dt->dt_zone_offset_negative ? '-' : '+',
|
||||
dt->dt_zone_offset_hour,
|
||||
dt->dt_zone_offset_minute);
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/dict.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/dict.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/stream.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/hashmap.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/collections/hashmap.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -42,9 +42,16 @@ struct fx_hashmap_iterator_p {
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
static FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct fx_hashmap_bucket, uint64_t, bk_node, bk_hash, get_bucket);
|
||||
struct fx_hashmap_bucket,
|
||||
uint64_t,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
get_bucket);
|
||||
static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
struct fx_hashmap_bucket, bk_node, bk_hash, put_bucket);
|
||||
struct fx_hashmap_bucket,
|
||||
bk_node,
|
||||
bk_hash,
|
||||
put_bucket);
|
||||
|
||||
static uint64_t hash_data(const void *p, size_t size)
|
||||
{
|
||||
@@ -69,7 +76,8 @@ static uint64_t hash_key(const struct fx_hashmap_key *key)
|
||||
}
|
||||
|
||||
static bool compare_key(
|
||||
const struct fx_hashmap_key *a, const struct fx_hashmap_key *b)
|
||||
const struct fx_hashmap_key *a,
|
||||
const struct fx_hashmap_key *b)
|
||||
{
|
||||
const void *a_data = NULL, *fx_data = NULL;
|
||||
size_t a_len = 0, fx_len = 0;
|
||||
@@ -99,8 +107,10 @@ static bool compare_key(
|
||||
}
|
||||
|
||||
static bool get_next_node(
|
||||
struct fx_bst_node *cur_node, struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node, struct fx_queue_entry **out_next_entry)
|
||||
struct fx_bst_node *cur_node,
|
||||
struct fx_queue_entry *cur_entry,
|
||||
struct fx_bst_node **out_next_node,
|
||||
struct fx_queue_entry **out_next_entry)
|
||||
{
|
||||
struct fx_hashmap_bucket *cur_bucket
|
||||
= fx_unbox(struct fx_hashmap_bucket, cur_node, bk_node);
|
||||
@@ -122,8 +132,10 @@ static bool get_next_node(
|
||||
return false;
|
||||
}
|
||||
|
||||
struct fx_hashmap_bucket *next_bucket
|
||||
= fx_unbox(struct fx_hashmap_bucket, next_node, bk_node);
|
||||
struct fx_hashmap_bucket *next_bucket = fx_unbox(
|
||||
struct fx_hashmap_bucket,
|
||||
next_node,
|
||||
bk_node);
|
||||
if (!next_bucket) {
|
||||
return false;
|
||||
}
|
||||
@@ -169,11 +181,13 @@ static struct fx_hashmap_bucket_item *create_bucket_item(void)
|
||||
}
|
||||
|
||||
static fx_status hashmap_put(
|
||||
struct fx_hashmap_p *hashmap, const fx_hashmap_key *key,
|
||||
struct fx_hashmap_p *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
|
||||
if (!bucket) {
|
||||
bucket = create_bucket();
|
||||
@@ -187,8 +201,10 @@ static fx_status hashmap_put(
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
memcpy(&item->bi_value, value, sizeof *value);
|
||||
@@ -213,19 +229,23 @@ static fx_status hashmap_put(
|
||||
}
|
||||
|
||||
static const struct fx_hashmap_value *hashmap_get(
|
||||
const struct fx_hashmap_p *hashmap, const struct fx_hashmap_key *key)
|
||||
const struct fx_hashmap_p *hashmap,
|
||||
const struct fx_hashmap_key *key)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
if (!bucket) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
return &item->bi_value;
|
||||
@@ -238,18 +258,22 @@ static const struct fx_hashmap_value *hashmap_get(
|
||||
}
|
||||
|
||||
static bool hashmap_has_key(
|
||||
const struct fx_hashmap_p *hashmap, const fx_hashmap_key *key)
|
||||
const struct fx_hashmap_p *hashmap,
|
||||
const fx_hashmap_key *key)
|
||||
{
|
||||
uint64_t hash = hash_key(key);
|
||||
struct fx_hashmap_bucket *bucket = get_bucket(&hashmap->h_buckets, hash);
|
||||
struct fx_hashmap_bucket *bucket
|
||||
= get_bucket(&hashmap->h_buckets, hash);
|
||||
if (!bucket) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&bucket->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
|
||||
if (compare_key(&item->bi_key, key)) {
|
||||
return true;
|
||||
@@ -276,8 +300,10 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
||||
}
|
||||
|
||||
fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
||||
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
first_entry,
|
||||
bi_entry);
|
||||
if (!first_item) {
|
||||
return true;
|
||||
}
|
||||
@@ -286,7 +312,8 @@ static bool hashmap_is_empty(const struct fx_hashmap_p *hashmap)
|
||||
}
|
||||
|
||||
static fx_status delete_item(
|
||||
struct fx_hashmap_p *hashmap, struct fx_hashmap_bucket *bucket,
|
||||
struct fx_hashmap_p *hashmap,
|
||||
struct fx_hashmap_bucket *bucket,
|
||||
struct fx_hashmap_bucket_item *item)
|
||||
{
|
||||
fx_queue_delete(&bucket->bk_items, &item->bi_entry);
|
||||
@@ -313,7 +340,8 @@ static fx_status delete_item(
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_hashmap *fx_hashmap_create(
|
||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor)
|
||||
fx_hashmap_key_destructor key_dtor,
|
||||
fx_hashmap_value_destructor value_dtor)
|
||||
{
|
||||
fx_hashmap *hashmap = fx_object_create(FX_TYPE_HASHMAP);
|
||||
if (!hashmap) {
|
||||
@@ -330,9 +358,11 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_hashmap_p *p = fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
||||
struct fx_hashmap_p *p
|
||||
= fx_object_get_private(hashmap, FX_TYPE_HASHMAP);
|
||||
|
||||
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size; i++) {
|
||||
for (size_t i = 0; items[i].key.key_data && items[i].key.key_size;
|
||||
i++) {
|
||||
hashmap_put(p, &items[i].key, &items[i].value);
|
||||
}
|
||||
|
||||
@@ -340,20 +370,32 @@ fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items)
|
||||
}
|
||||
|
||||
fx_status fx_hashmap_put(
|
||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value)
|
||||
fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_put, hashmap, key, value);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_HASHMAP,
|
||||
hashmap_put,
|
||||
hashmap,
|
||||
key,
|
||||
value);
|
||||
}
|
||||
|
||||
const struct fx_hashmap_value *fx_hashmap_get(
|
||||
const fx_hashmap *hashmap, const struct fx_hashmap_key *key)
|
||||
const fx_hashmap *hashmap,
|
||||
const struct fx_hashmap_key *key)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_get, hashmap, key);
|
||||
}
|
||||
|
||||
bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_HASHMAP, hashmap_has_key, hashmap, key);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_HASHMAP,
|
||||
hashmap_has_key,
|
||||
hashmap,
|
||||
key);
|
||||
}
|
||||
|
||||
size_t fx_hashmap_get_size(const fx_hashmap *hashmap)
|
||||
@@ -368,7 +410,8 @@ bool fx_hashmap_is_empty(const fx_hashmap *hashmap)
|
||||
|
||||
fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
||||
{
|
||||
fx_hashmap_iterator *it_obj = fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
||||
fx_hashmap_iterator *it_obj
|
||||
= fx_object_create(FX_TYPE_HASHMAP_ITERATOR);
|
||||
struct fx_hashmap_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_HASHMAP_ITERATOR);
|
||||
|
||||
@@ -391,9 +434,12 @@ fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap)
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *first_entry = fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item
|
||||
= fx_unbox(struct fx_hashmap_bucket_item, first_entry, bi_entry);
|
||||
struct fx_queue_entry *first_entry
|
||||
= fx_queue_first(&first_bucket->bk_items);
|
||||
struct fx_hashmap_bucket_item *first_item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item,
|
||||
first_entry,
|
||||
bi_entry);
|
||||
if (!first_item) {
|
||||
memset(&it->item, 0x0, sizeof it->item);
|
||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
||||
@@ -435,8 +481,11 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
||||
struct fx_queue_entry *entry = fx_queue_first(&b->bk_items);
|
||||
while (entry) {
|
||||
struct fx_hashmap_bucket_item *item = fx_unbox(
|
||||
struct fx_hashmap_bucket_item, entry, bi_entry);
|
||||
struct fx_queue_entry *next_entry = fx_queue_next(entry);
|
||||
struct fx_hashmap_bucket_item,
|
||||
entry,
|
||||
bi_entry);
|
||||
struct fx_queue_entry *next_entry
|
||||
= fx_queue_next(entry);
|
||||
fx_queue_delete(&b->bk_items, entry);
|
||||
|
||||
if (map->h_key_dtor) {
|
||||
@@ -444,7 +493,8 @@ static void hashmap_fini(fx_object *obj, void *priv)
|
||||
}
|
||||
|
||||
if (map->h_value_dtor) {
|
||||
map->h_value_dtor((void *)item->bi_value.value_data);
|
||||
map->h_value_dtor(
|
||||
(void *)item->bi_value.value_data);
|
||||
}
|
||||
|
||||
free(item);
|
||||
@@ -524,7 +574,8 @@ static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
|
||||
if (next_item) {
|
||||
memcpy(&it->item.key, &next_item->bi_key, sizeof it->item.key);
|
||||
memcpy(&it->item.value, &next_item->bi_value,
|
||||
memcpy(&it->item.value,
|
||||
&next_item->bi_value,
|
||||
sizeof it->item.value);
|
||||
|
||||
it->_cbn = next_node;
|
||||
@@ -9,10 +9,10 @@
|
||||
#ifndef FX_DS_ARRAY_H_
|
||||
#define FX_DS_ARRAY_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -51,11 +51,13 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_array, FX_TYPE_ARRAY);
|
||||
* @return A pointer to the new fx_array, or NULL if an error occurred.
|
||||
*/
|
||||
FX_API fx_array *fx_array_create_with_values(
|
||||
fx_object *const *values, size_t nr_values);
|
||||
fx_object *const *values,
|
||||
size_t nr_values);
|
||||
|
||||
/**
|
||||
* Remove all object references from an fx_array, resetting the size of the array to zero.
|
||||
* The reference counts of all objects in the array will be decremented.
|
||||
* Remove all object references from an fx_array, resetting the size of the
|
||||
* array to zero. The reference counts of all objects in the array will be
|
||||
* decremented.
|
||||
*
|
||||
* @param array The fx_array to clear.
|
||||
*/
|
||||
@@ -116,11 +118,12 @@ FX_API fx_status fx_array_remove(fx_array *array, size_t at);
|
||||
|
||||
/**
|
||||
* Removes the object at the beginning of an fx_array. The reference count
|
||||
* of the removed object will be decremented. The remaining objects will be moved
|
||||
* to fill the empty space created by the object's removal.
|
||||
* of the removed object will be decremented. The remaining objects will be
|
||||
* moved to fill the empty space created by the object's removal.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||
* error that occurred.
|
||||
*/
|
||||
FX_API fx_status fx_array_remove_front(fx_array *array);
|
||||
|
||||
@@ -129,7 +132,8 @@ FX_API fx_status fx_array_remove_front(fx_array *array);
|
||||
* of the removed object will be decremented.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
|
||||
* @return FX_SUCCESS if the object was removed, or a status code describing any
|
||||
* error that occurred.
|
||||
*/
|
||||
FX_API fx_status fx_array_remove_back(fx_array *array);
|
||||
|
||||
@@ -162,8 +166,8 @@ FX_API fx_object *fx_array_pop(fx_array *array, size_t at);
|
||||
FX_API fx_object *fx_array_pop_front(fx_array *array);
|
||||
|
||||
/**
|
||||
* Removes the object at the end of an fx_array, and returns a pointer to it. The
|
||||
* reference count of the removed object will NOT be decremented. The caller
|
||||
* Removes the object at the end of an fx_array, and returns a pointer to it.
|
||||
* The reference count of the removed object will NOT be decremented. The caller
|
||||
* becomes the owner of the array's reference to the object.
|
||||
*
|
||||
* @param array The fx_array to remove the object from.
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_BITBUFFER_H_
|
||||
#define FX_DS_BITBUFFER_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -13,12 +13,18 @@ FX_TYPE_CLASS_DECLARATION_END(fx_bitbuffer);
|
||||
|
||||
FX_API fx_status fx_bitbuffer_put_bit(fx_bitbuffer *buf, int bit);
|
||||
FX_API fx_status fx_bitbuffer_put_bool(fx_bitbuffer *buf, bool b);
|
||||
FX_API fx_status fx_bitbuffer_put_int(
|
||||
fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
||||
FX_API fx_status
|
||||
fx_bitbuffer_put_int(fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
|
||||
FX_API fx_status fx_bitbuffer_put_bytes(
|
||||
fx_bitbuffer *buf, const void *p, size_t len, size_t bits_per_byte);
|
||||
fx_bitbuffer *buf,
|
||||
const void *p,
|
||||
size_t len,
|
||||
size_t bits_per_byte);
|
||||
FX_API fx_status fx_bitbuffer_put_string(
|
||||
fx_bitbuffer *buf, const char *p, size_t len, size_t bits_per_char);
|
||||
fx_bitbuffer *buf,
|
||||
const char *p,
|
||||
size_t len,
|
||||
size_t bits_per_char);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef FX_DS_BITMAP_H_
|
||||
#define FX_DS_BITMAP_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -21,7 +21,10 @@ FX_API fx_bitmap *fx_bitmap_create(size_t nr_bits);
|
||||
FX_API void fx_bitmap_set_bit(fx_bitmap *map, size_t bit);
|
||||
FX_API void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit);
|
||||
FX_API void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
||||
FX_API void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits);
|
||||
FX_API void fx_bitmap_clear_range(
|
||||
fx_bitmap *map,
|
||||
size_t first_bit,
|
||||
size_t nbits);
|
||||
FX_API void fx_bitmap_set_all(fx_bitmap *map);
|
||||
FX_API void fx_bitmap_clear_all(fx_bitmap *map);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_BUFFER_H_
|
||||
#define FX_DS_BUFFER_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
#include <stddef.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -18,16 +18,19 @@ FX_API fx_type fx_buffer_get_type(void);
|
||||
FX_API fx_buffer *fx_buffer_create(size_t item_sz);
|
||||
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
|
||||
FX_API fx_buffer *fx_buffer_create_from_array(
|
||||
const void *p, size_t item_sz, size_t len);
|
||||
const void *p,
|
||||
size_t item_sz,
|
||||
size_t len);
|
||||
|
||||
FX_API void *fx_buffer_steal(fx_buffer *buf);
|
||||
FX_API fx_status fx_buffer_reserve(fx_buffer *buf, size_t capacity);
|
||||
FX_API fx_status fx_buffer_resize(fx_buffer *buf, size_t length);
|
||||
|
||||
FX_API fx_status fx_buffer_append(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status fx_buffer_insert(
|
||||
fx_buffer *dest, const void *p, size_t count, size_t at);
|
||||
FX_API fx_status
|
||||
fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
|
||||
FX_API fx_status
|
||||
fx_buffer_insert(fx_buffer *dest, const void *p, size_t count, size_t at);
|
||||
FX_API fx_status fx_buffer_remove(fx_buffer *dest, size_t at, size_t count);
|
||||
FX_API fx_status fx_buffer_clear(fx_buffer *buf);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_DATETIME_H_
|
||||
#define FX_DS_DATETIME_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <ctype.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -24,7 +24,8 @@ FX_TYPE_DEFAULT_CONSTRUCTOR(fx_datetime, FX_TYPE_DATETIME);
|
||||
|
||||
FX_API fx_datetime *fx_datetime_parse(fx_datetime_format format, const char *s);
|
||||
FX_API void fx_datetime_to_string(
|
||||
const fx_datetime *dt, fx_datetime_format format,
|
||||
const fx_datetime *dt,
|
||||
fx_datetime_format format,
|
||||
FX_TYPE_FWDREF(fx_stream) * dest);
|
||||
|
||||
FX_API bool fx_datetime_is_localtime(const fx_datetime *dt);
|
||||
@@ -1,12 +1,12 @@
|
||||
#ifndef FX_DS_DICT_H_
|
||||
#define FX_DS_DICT_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -27,9 +27,10 @@ FX_TYPE_CLASS_DECLARATION_END(fx_dict_iterator)
|
||||
#define FX_DICT_ITEM(k, v) {.key = (k), .value = (v)}
|
||||
#define FX_DICT_ITEM_END {.key = NULL, .value = NULL}
|
||||
|
||||
#define fx_dict_foreach(it, dict) \
|
||||
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
|
||||
(it)->key != NULL; fx_dict_iterator_next(it))
|
||||
#define fx_dict_foreach(it, dict) \
|
||||
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
|
||||
(it)->key != NULL; \
|
||||
fx_dict_iterator_next(it))
|
||||
|
||||
typedef struct fx_dict_item {
|
||||
const fx_string *key;
|
||||
@@ -46,7 +47,8 @@ FX_API fx_dict *fx_dict_create_with_items(const fx_dict_item *items);
|
||||
#endif
|
||||
|
||||
FX_API fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value);
|
||||
FX_API fx_status fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
||||
FX_API fx_status
|
||||
fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
|
||||
FX_API fx_object *fx_dict_at(const fx_dict *dict, const char *key);
|
||||
FX_API fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key);
|
||||
FX_API fx_object *fx_dict_get(fx_dict *dict, const char *key);
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef FX_DS_HASHMAP_H_
|
||||
#define FX_DS_HASHMAP_H_
|
||||
|
||||
#include <fx/core/bst.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/bst.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/status.h>
|
||||
#include <stddef.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -27,14 +27,15 @@ FX_TYPE_CLASS_DECLARATION_END(fx_hashmap_iterator)
|
||||
#define FX_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
|
||||
#define FX_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
|
||||
|
||||
#define FX_HASHMAP_ITEM(k, ks, v, vs) \
|
||||
#define FX_HASHMAP_ITEM(k, ks, v, vs) \
|
||||
{.key = FX_HASHMAP_KEY(k, ks), .value = FX_HASHMAP_VALUE(v, vs)}
|
||||
|
||||
#define FX_HASHMAP_ITEM_END {.key = {0}, .value = {0}}
|
||||
|
||||
#define fx_hashmap_foreach(it, hashmap) \
|
||||
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
|
||||
(it)->key != NULL; fx_hashmap_iterator_next(it))
|
||||
#define fx_hashmap_foreach(it, hashmap) \
|
||||
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
|
||||
(it)->key != NULL; \
|
||||
fx_hashmap_iterator_next(it))
|
||||
|
||||
typedef void (*fx_hashmap_key_destructor)(void *);
|
||||
typedef void (*fx_hashmap_value_destructor)(void *);
|
||||
@@ -63,15 +64,21 @@ FX_API fx_type fx_hashmap_get_type(void);
|
||||
FX_API fx_type fx_hashmap_iterator_get_type(void);
|
||||
|
||||
FX_API fx_hashmap *fx_hashmap_create(
|
||||
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor);
|
||||
fx_hashmap_key_destructor key_dtor,
|
||||
fx_hashmap_value_destructor value_dtor);
|
||||
FX_API fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items);
|
||||
|
||||
FX_API fx_status fx_hashmap_put(
|
||||
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value);
|
||||
fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key,
|
||||
const fx_hashmap_value *value);
|
||||
FX_API const fx_hashmap_value *fx_hashmap_get(
|
||||
const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
||||
const fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key);
|
||||
|
||||
FX_API bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key);
|
||||
FX_API bool fx_hashmap_has_key(
|
||||
const fx_hashmap *hashmap,
|
||||
const fx_hashmap_key *key);
|
||||
FX_API size_t fx_hashmap_get_size(const fx_hashmap *hashmap);
|
||||
FX_API bool fx_hashmap_is_empty(const fx_hashmap *hashmap);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_LIST_H_
|
||||
#define FX_DS_LIST_H_
|
||||
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -39,9 +39,13 @@ FX_API fx_list_entry *fx_list_prev(const fx_list_entry *entry);
|
||||
FX_API size_t fx_list_length(const fx_list *q);
|
||||
|
||||
FX_API fx_list_entry *fx_list_insert_before(
|
||||
fx_list *q, void *ptr, fx_list_entry *before);
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
fx_list_entry *before);
|
||||
FX_API fx_list_entry *fx_list_insert_after(
|
||||
fx_list *q, void *ptr, fx_list_entry *after);
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
fx_list_entry *after);
|
||||
|
||||
FX_API fx_list_entry *fx_list_push_front(fx_list *q, void *ptr);
|
||||
FX_API fx_list_entry *fx_list_push_back(fx_list *q, void *ptr);
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef FX_DS_NUMBER_H
|
||||
#define FX_DS_NUMBER_H
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/macros.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
@@ -133,7 +133,9 @@ static inline fx_number *fx_number_create_size_t(size_t value)
|
||||
|
||||
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
|
||||
FX_API int fx_number_get_value(
|
||||
const fx_number *number, fx_number_type type, void *value_ptr);
|
||||
const fx_number *number,
|
||||
fx_number_type type,
|
||||
void *value_ptr);
|
||||
|
||||
static inline int8_t fx_number_get_int8(const fx_number *number)
|
||||
{
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifndef FX_DS_TREE_H_
|
||||
#define FX_DS_TREE_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/misc.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
@@ -22,7 +22,7 @@ FX_TYPE_CLASS_DECLARATION_END(fx_tree_iterator)
|
||||
|
||||
#define FX_TREE_NODE_INIT ((fx_tree_node) {0})
|
||||
|
||||
#define FX_TREE_CONTAINER(t, m, v) \
|
||||
#define FX_TREE_CONTAINER(t, m, v) \
|
||||
((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
|
||||
|
||||
typedef struct fx_tree_node {
|
||||
@@ -50,7 +50,8 @@ FX_API fx_iterator *fx_tree_node_begin(fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
|
||||
|
||||
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(const fx_tree_node *node);
|
||||
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||
const fx_tree_node *node);
|
||||
|
||||
FX_DECLS_END;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifndef FX_DS_UUID_H_
|
||||
#define FX_DS_UUID_H_
|
||||
|
||||
#include <fx/core/macros.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
|
||||
#define FX_UUID_NBYTES 16
|
||||
#define FX_UUID_STRING_MAX 37
|
||||
@@ -29,19 +29,34 @@ FX_API fx_type fx_uuid_get_type(void);
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
|
||||
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytes(
|
||||
unsigned char u00, unsigned char u01, unsigned char u02,
|
||||
unsigned char u03, unsigned char u04, unsigned char u05,
|
||||
unsigned char u06, unsigned char u07, unsigned char u08,
|
||||
unsigned char u09, unsigned char u10, unsigned char u11, unsigned char u12,
|
||||
unsigned char u13, unsigned char u14, unsigned char u15);
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytev(const unsigned char bytes[FX_UUID_NBYTES]);
|
||||
unsigned char u00,
|
||||
unsigned char u01,
|
||||
unsigned char u02,
|
||||
unsigned char u03,
|
||||
unsigned char u04,
|
||||
unsigned char u05,
|
||||
unsigned char u06,
|
||||
unsigned char u07,
|
||||
unsigned char u08,
|
||||
unsigned char u09,
|
||||
unsigned char u10,
|
||||
unsigned char u11,
|
||||
unsigned char u12,
|
||||
unsigned char u13,
|
||||
unsigned char u14,
|
||||
unsigned char u15);
|
||||
FX_API fx_uuid *fx_uuid_create_from_bytev(
|
||||
const unsigned char bytes[FX_UUID_NBYTES]);
|
||||
FX_API fx_uuid *fx_uuid_create_from_uuid_bytes(const fx_uuid_bytes *bytes);
|
||||
FX_API fx_uuid *fx_uuid_create_from_string(const fx_string *string);
|
||||
FX_API fx_uuid *fx_uuid_create_from_cstr(const char *s);
|
||||
|
||||
FX_API fx_status fx_uuid_to_cstr(const fx_uuid *uuid, char out[FX_UUID_STRING_MAX]);
|
||||
FX_API fx_status fx_uuid_to_cstr(
|
||||
const fx_uuid *uuid,
|
||||
char out[FX_UUID_STRING_MAX]);
|
||||
FX_API void fx_uuid_get_bytes(
|
||||
const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES]);
|
||||
const fx_uuid *uuid,
|
||||
unsigned char bytes[FX_UUID_NBYTES]);
|
||||
FX_API void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, fx_uuid_bytes *bytes);
|
||||
FX_API fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <fx/core/iterator.h>
|
||||
#include <fx/core/queue.h>
|
||||
#include <fx/ds/list.h>
|
||||
#include <fx/collections/list.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/queue.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -109,7 +109,9 @@ static struct fx_list_entry *make_entry(void *item)
|
||||
}
|
||||
|
||||
static struct fx_list_entry *list_insert_before(
|
||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *before)
|
||||
struct fx_list_p *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *before)
|
||||
{
|
||||
struct fx_list_entry *entry = make_entry(ptr);
|
||||
if (!entry) {
|
||||
@@ -122,7 +124,9 @@ static struct fx_list_entry *list_insert_before(
|
||||
}
|
||||
|
||||
static struct fx_list_entry *list_insert_after(
|
||||
struct fx_list_p *q, void *ptr, struct fx_list_entry *after)
|
||||
struct fx_list_p *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *after)
|
||||
{
|
||||
struct fx_list_entry *entry = make_entry(ptr);
|
||||
if (!entry) {
|
||||
@@ -226,7 +230,9 @@ static fx_status list_delete_item(struct fx_list_p *q, void *ptr)
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_status list_delete_entry(struct fx_list_p *q, struct fx_list_entry *entry)
|
||||
static fx_status list_delete_entry(
|
||||
struct fx_list_p *q,
|
||||
struct fx_list_entry *entry)
|
||||
{
|
||||
fx_queue_delete(&q->l_queue, &entry->e_entry);
|
||||
q->l_len--;
|
||||
@@ -314,15 +320,29 @@ size_t fx_list_length(const fx_list *q)
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_insert_before(
|
||||
fx_list *q, void *ptr, struct fx_list_entry *before)
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *before)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_before, q, ptr, before);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_LIST,
|
||||
list_insert_before,
|
||||
q,
|
||||
ptr,
|
||||
before);
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_insert_after(
|
||||
fx_list *q, void *ptr, struct fx_list_entry *after)
|
||||
fx_list *q,
|
||||
void *ptr,
|
||||
struct fx_list_entry *after)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_LIST, list_insert_after, q, ptr, after);
|
||||
FX_CLASS_DISPATCH_STATIC(
|
||||
FX_TYPE_LIST,
|
||||
list_insert_after,
|
||||
q,
|
||||
ptr,
|
||||
after);
|
||||
}
|
||||
|
||||
struct fx_list_entry *fx_list_push_front(fx_list *q, void *ptr)
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <fx/core/stream.h>
|
||||
#include <fx/ds/number.h>
|
||||
#include <fx/collections/number.h>
|
||||
#include <fx/stream.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <fx/ds/tree.h>
|
||||
#include <fx/collections/tree.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -33,7 +33,9 @@ static void tree_set_root(struct fx_tree_p *tree, struct fx_tree_node *node)
|
||||
}
|
||||
|
||||
static const struct fx_tree_node *next_node(
|
||||
const struct fx_tree_node *node, bool recursive, int *depth_diff)
|
||||
const struct fx_tree_node *node,
|
||||
bool recursive,
|
||||
int *depth_diff)
|
||||
{
|
||||
if (!node) {
|
||||
return NULL;
|
||||
@@ -101,7 +103,8 @@ static void remove_node(struct fx_tree_node *node)
|
||||
}
|
||||
|
||||
static void reparent_children(
|
||||
struct fx_tree_node *old_parent, struct fx_tree_node *new_parent)
|
||||
struct fx_tree_node *old_parent,
|
||||
struct fx_tree_node *new_parent)
|
||||
{
|
||||
struct fx_tree_node *last = NODE_FIRST_CHILD(new_parent);
|
||||
while (last && NODE_NEXT_SIBLING(last)) {
|
||||
@@ -132,7 +135,9 @@ void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node)
|
||||
FX_CLASS_DISPATCH_STATIC(FX_TYPE_TREE, tree_set_root, tree, node);
|
||||
}
|
||||
|
||||
void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *child)
|
||||
void fx_tree_node_add_child(
|
||||
struct fx_tree_node *parent,
|
||||
struct fx_tree_node *child)
|
||||
{
|
||||
if (NODE_PARENT(child)) {
|
||||
return;
|
||||
@@ -152,7 +157,9 @@ void fx_tree_node_add_child(struct fx_tree_node *parent, struct fx_tree_node *ch
|
||||
NODE_NEXT_SIBLING(cur) = child;
|
||||
}
|
||||
|
||||
void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to_add)
|
||||
void fx_tree_node_add_sibling(
|
||||
struct fx_tree_node *node,
|
||||
struct fx_tree_node *to_add)
|
||||
{
|
||||
if (NODE_PARENT(to_add) || !NODE_PARENT(node)) {
|
||||
return;
|
||||
@@ -161,7 +168,9 @@ void fx_tree_node_add_sibling(struct fx_tree_node *node, struct fx_tree_node *to
|
||||
fx_tree_node_add_child(NODE_PARENT(node), to_add);
|
||||
}
|
||||
|
||||
struct fx_tree_node *fx_tree_node_get_child(struct fx_tree_node *node, size_t at)
|
||||
struct fx_tree_node *fx_tree_node_get_child(
|
||||
struct fx_tree_node *node,
|
||||
size_t at)
|
||||
{
|
||||
size_t i = 0;
|
||||
struct fx_tree_node *cur = NODE_FIRST_CHILD(node);
|
||||
@@ -233,7 +242,8 @@ fx_iterator *fx_tree_node_begin_recursive(struct fx_tree_node *node)
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
const fx_iterator *fx_tree_node_cbegin_recursive(const struct fx_tree_node *node)
|
||||
const fx_iterator *fx_tree_node_cbegin_recursive(
|
||||
const struct fx_tree_node *node)
|
||||
{
|
||||
return fx_tree_node_begin_recursive((struct fx_tree_node *)node);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <ctype.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/ds/uuid.h>
|
||||
#include <fx/collections/uuid.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -0,0 +1,6 @@
|
||||
set(namespace_include_paths ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
|
||||
|
||||
file(GLOB namespace_sources
|
||||
*.c *.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/fx/reflection/*.h)
|
||||
set(namespace_sources ${namespace_sources} PARENT_SCOPE)
|
||||
@@ -0,0 +1,264 @@
|
||||
#include <fx/bst.h>
|
||||
#include <fx/hash.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/reflection/assembly.h>
|
||||
|
||||
enum map_entry_type {
|
||||
MAP_ENTRY_NONE = 0,
|
||||
MAP_ENTRY_ITEM,
|
||||
MAP_ENTRY_BUCKET,
|
||||
};
|
||||
|
||||
struct map_entry {
|
||||
enum map_entry_type e_type;
|
||||
uint64_t e_hash;
|
||||
union {
|
||||
fx_queue_entry e_entry;
|
||||
fx_bst_node e_node;
|
||||
};
|
||||
};
|
||||
|
||||
struct map_bucket {
|
||||
struct map_entry b_entry;
|
||||
fx_queue b_items;
|
||||
};
|
||||
|
||||
struct map_item {
|
||||
struct map_entry i_entry;
|
||||
const char *i_name;
|
||||
};
|
||||
|
||||
struct map {
|
||||
fx_bst m_entries;
|
||||
};
|
||||
|
||||
struct type {
|
||||
struct map_item e_map_item;
|
||||
fx_type e_type;
|
||||
};
|
||||
|
||||
struct fx_assembly_p {
|
||||
const char *a_name;
|
||||
struct map a_types;
|
||||
|
||||
struct {
|
||||
long v_major;
|
||||
long v_minor;
|
||||
long v_build;
|
||||
long v_revision;
|
||||
} a_version;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct map_entry,
|
||||
uint64_t,
|
||||
e_node,
|
||||
e_hash,
|
||||
map_get_entry);
|
||||
FX_BST_DEFINE_SIMPLE_INSERT(struct map_entry, e_node, e_hash, map_put_entry);
|
||||
|
||||
static struct map_bucket *map_item_convert_to_bucket(
|
||||
struct map *map,
|
||||
struct map_item *item)
|
||||
{
|
||||
struct map_bucket *bucket = malloc(sizeof *bucket);
|
||||
|
||||
memset(bucket, 0x0, sizeof *bucket);
|
||||
|
||||
bucket->b_entry.e_hash = item->i_entry.e_hash;
|
||||
bucket->b_entry.e_type = MAP_ENTRY_BUCKET;
|
||||
|
||||
fx_bst_delete(&map->m_entries, &item->i_entry.e_node);
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
map_put_entry(&map->m_entries, &bucket->b_entry);
|
||||
|
||||
return bucket;
|
||||
}
|
||||
|
||||
static void map_put(struct map *map, const char *name, struct map_item *item)
|
||||
{
|
||||
uint64_t hash = fx_hash_cstr(name);
|
||||
|
||||
item->i_entry.e_type = MAP_ENTRY_ITEM;
|
||||
item->i_entry.e_hash = hash;
|
||||
item->i_name = name;
|
||||
|
||||
struct map_entry *entry = map_get_entry(&map->m_entries, hash);
|
||||
if (!entry) {
|
||||
map_put_entry(&map->m_entries, &item->i_entry);
|
||||
return;
|
||||
}
|
||||
|
||||
struct map_item *existing_item = NULL;
|
||||
struct map_bucket *bucket = NULL;
|
||||
switch (entry->e_type) {
|
||||
case MAP_ENTRY_ITEM:
|
||||
existing_item = (struct map_item *)entry;
|
||||
bucket = map_item_convert_to_bucket(map, existing_item);
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
break;
|
||||
case MAP_ENTRY_BUCKET:
|
||||
bucket = (struct map_bucket *)entry;
|
||||
fx_queue_push_back(&bucket->b_items, &item->i_entry.e_entry);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void assembly_set_name(struct fx_assembly_p *asm, const char *name)
|
||||
{
|
||||
asm->a_name = name;
|
||||
}
|
||||
|
||||
static void assembly_set_version(
|
||||
struct fx_assembly_p *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision)
|
||||
{
|
||||
asm->a_version.v_major = major;
|
||||
asm->a_version.v_minor = minor;
|
||||
asm->a_version.v_build = build;
|
||||
asm->a_version.v_revision = revision;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
static void assembly_add_type(
|
||||
struct fx_assembly_p *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
{
|
||||
struct type *type = malloc(sizeof *type);
|
||||
memset(type, 0x0, sizeof *type);
|
||||
|
||||
map_put(&asm->a_types, full_name, &type->e_map_item);
|
||||
}
|
||||
|
||||
static void map_item_dump(struct map_item *item)
|
||||
{
|
||||
struct type *type = (struct type *)item;
|
||||
printf(" Type: %s\n", type->e_map_item.i_name);
|
||||
}
|
||||
|
||||
static void assembly_dump(struct fx_assembly_p *asm)
|
||||
{
|
||||
printf("Loaded assembly:\n");
|
||||
printf(" %s, Version=%ld.%ld.%ld.%ld\n",
|
||||
asm->a_name,
|
||||
asm->a_version.v_major,
|
||||
asm->a_version.v_minor,
|
||||
asm->a_version.v_build,
|
||||
asm->a_version.v_revision);
|
||||
|
||||
fx_bst_node *cur_node = fx_bst_first(&asm->a_types.m_entries);
|
||||
while (cur_node) {
|
||||
struct map_entry *entry
|
||||
= fx_unbox(struct map_entry, cur_node, e_node);
|
||||
switch (entry->e_type) {
|
||||
case MAP_ENTRY_ITEM: {
|
||||
struct map_item *item = (struct map_item *)entry;
|
||||
map_item_dump(item);
|
||||
break;
|
||||
}
|
||||
|
||||
case MAP_ENTRY_BUCKET: {
|
||||
struct map_bucket *bucket = (struct map_bucket *)entry;
|
||||
fx_queue_entry *cur_qentry
|
||||
= fx_queue_first(&bucket->b_items);
|
||||
while (cur_qentry) {
|
||||
struct map_item *item = fx_unbox(
|
||||
struct map_item,
|
||||
cur_qentry,
|
||||
i_entry.e_entry);
|
||||
map_item_dump(item);
|
||||
cur_qentry = fx_queue_next(cur_qentry);
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
cur_node = fx_bst_next(cur_node);
|
||||
}
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
void fx_assembly_set_name(fx_assembly *asm, const char *name)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_set_name,
|
||||
asm,
|
||||
name);
|
||||
}
|
||||
|
||||
void fx_assembly_set_version(
|
||||
fx_assembly *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_set_version,
|
||||
asm,
|
||||
major,
|
||||
minor,
|
||||
build,
|
||||
revision);
|
||||
}
|
||||
|
||||
void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_add_type,
|
||||
asm,
|
||||
full_name,
|
||||
type_id);
|
||||
}
|
||||
|
||||
void fx_assembly_dump(const fx_assembly *asm)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
assembly_dump,
|
||||
asm);
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void assembly_init(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
static void assembly_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_assembly)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_ID(0xf6690c30, 0x6642, 0x42f0, 0xb79f, 0xe2baf3684b1b);
|
||||
FX_TYPE_CLASS(fx_assembly_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_assembly_p);
|
||||
FX_TYPE_INSTANCE_INIT(assembly_init);
|
||||
FX_TYPE_INSTANCE_FINI(assembly_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_assembly)
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef FX_REFLECTION_ASSEMBLY_H_
|
||||
#define FX_REFLECTION_ASSEMBLY_H_
|
||||
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
#define FX_REFLECTION_TYPE_ASSEMBLY (fx_assembly_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_assembly);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_assembly)
|
||||
|
||||
FX_API fx_type fx_assembly_get_type();
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_assembly, FX_REFLECTION_TYPE_ASSEMBLY);
|
||||
|
||||
FX_API void fx_assembly_set_name(fx_assembly *asm, const char *name);
|
||||
FX_API void fx_assembly_set_version(
|
||||
fx_assembly *asm,
|
||||
long major,
|
||||
long minor,
|
||||
long build,
|
||||
long revision);
|
||||
|
||||
FX_API void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id);
|
||||
|
||||
FX_API void fx_assembly_dump(const fx_assembly *asm);
|
||||
|
||||
FX_DECLS_END
|
||||
;
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user