Skip to content

Commit be70313

Browse files
author
Leonardo
committed
Merge branch 'release/1.1.1'
2 parents 7bc2645 + 9e1df22 commit be70313

File tree

11 files changed

+227
-104
lines changed

11 files changed

+227
-104
lines changed

CMakeLists.txt

Lines changed: 129 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,138 @@
11
cmake_minimum_required(VERSION 3.26)
2-
project(naughty-buffers LANGUAGES C VERSION 1.1.0)
3-
include(CTest)
2+
project(naughty-buffers LANGUAGES C VERSION 1.1.1)
43

5-
set(CMAKE_C_STANDARD 99)
6-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
7-
set(CMAKE_C_EXTENSIONS OFF)
8-
set(CMAKE_CXX_EXTENSIONS OFF)
9-
set(CMAKE_C_VISIBILITY_PRESET hidden)
10-
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
11-
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
4+
include(GNUInstallDirs)
5+
include(GenerateExportHeader)
6+
include(CMakePackageConfigHelpers)
127

13-
add_subdirectory(src)
8+
set(
9+
CMAKE_C_STANDARD 99
10+
CMAKE_POSITION_INDEPENDENT_CODE ON
11+
CMAKE_C_EXTENSIONS OFF
12+
CMAKE_CXX_EXTENSIONS OFF
13+
CMAKE_C_VISIBILITY_PRESET hidden
14+
CMAKE_CXX_VISIBILITY_PRESET hidden
15+
)
16+
17+
set(NAUGHTY_BUFFERS_PUBLIC_HEADERS
18+
include/naughty-buffers/buffer.h
19+
include/naughty-buffers/array-generator.h
20+
${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers/naughty-buffers-export.h
21+
)
22+
23+
add_library(naughty-buffers-objects OBJECT
24+
src/naughty-buffers/buffer.c
25+
src/naughty-buffers/memory.h
26+
src/naughty-buffers/memory.c
27+
${NAUGHTY_BUFFERS_PUBLIC_HEADERS}
28+
)
29+
30+
target_include_directories(naughty-buffers-objects PUBLIC
31+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
32+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
33+
$<INSTALL_INTERFACE:include>
34+
)
35+
36+
set_property(TARGET naughty-buffers-objects PROPERTY POSITION_INDEPENDENT_CODE 1)
37+
38+
# shared version
39+
add_library(naughty-buffers SHARED $<TARGET_OBJECTS:naughty-buffers-objects>)
40+
add_library(naughty-buffers::naughty-buffers ALIAS naughty-buffers)
41+
42+
generate_export_header(naughty-buffers
43+
BASE_NAME naughty-buffers
44+
EXPORT_FILE_NAME naughty-buffers/naughty-buffers-export.h
45+
)
46+
47+
set_target_properties(naughty-buffers PROPERTIES
48+
VERSION ${naughty-buffers_VERSION}
49+
SO_VERSION ${naughty-buffers_VERSION_MAJOR}
50+
PUBLIC_HEADER "${NAUGHTY_BUFFERS_PUBLIC_HEADERS}"
51+
OUTPUT_NAME "naughty-buffers"
52+
RUNTIME_OUTPUT_NAME naughty-buffers-${naughty-buffers_VERSION}
53+
)
54+
55+
target_include_directories(naughty-buffers PUBLIC
56+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
57+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
58+
$<INSTALL_INTERFACE:include>
59+
)
60+
61+
# static vertsion
62+
63+
add_library(naughty-buffers-static STATIC $<TARGET_OBJECTS:naughty-buffers-objects>)
64+
add_library(naughty-buffers::naughty-buffers-static ALIAS naughty-buffers-static)
65+
66+
set_target_properties(naughty-buffers-static PROPERTIES
67+
VERSION ${naughty-buffers_VERSION}
68+
SO_VERSION ${naughty-buffers_VERSION_MAJOR}
69+
PUBLIC_HEADER "${NAUGHTY_BUFFERS_PUBLIC_HEADERS}"
70+
OUTPUT_NAME "naughty-buffers-static"
71+
RUNTIME_OUTPUT_NAME naughty-buffers-${naughty-buffers_VERSION}-static
72+
)
73+
74+
target_include_directories(naughty-buffers-static PUBLIC
75+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
76+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
77+
$<INSTALL_INTERFACE:include>
78+
)
79+
80+
if (NOT CMAKE_BUILD_TYPE MATCHES "Release")
81+
target_compile_options(naughty-buffers-objects PRIVATE
82+
$<$<OR:$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:GNU>>:-Wall -Wextra -pedantic -fvisibility=hidden -Werror>
83+
$<$<C_COMPILER_ID:MSVC>:/W3 /WX /wd4820 /wd4668 /wd4204>
84+
)
85+
endif ()
86+
87+
install(TARGETS naughty-buffers naughty-buffers-static
88+
EXPORT naughty-buffers
89+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
90+
COMPONENT "Naughty Buffers Runtime"
91+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
92+
COMPONENT "Naughty Buffers Runtime"
93+
NAMELINK_COMPONENT "Naughty Buffers Development"
94+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
95+
COMPONENT "Naughty Buffers Development"
96+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/naughty-buffers
97+
COMPONENT "Naughty Buffers Development"
98+
)
99+
100+
export(
101+
TARGETS naughty-buffers naughty-buffers-static
102+
NAMESPACE naughty-buffers::
103+
FILE "${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config.cmake"
104+
)
105+
106+
install(EXPORT naughty-buffers
107+
FILE naughty-buffers-config.cmake
108+
NAMESPACE naughty-buffers::
109+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/naughty-buffers
110+
)
111+
112+
write_basic_package_version_file(
113+
"${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config-version.cmake"
114+
VERSION ${naughty-buffers_VERSION}
115+
COMPATIBILITY SameMajorVersion
116+
)
117+
118+
install(
119+
FILES
120+
"${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config-version.cmake"
121+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/naughty-buffers
122+
COMPONENT "Naughty Buffers Development"
123+
)
124+
125+
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
126+
include(CTest)
127+
add_subdirectory(src/tests)
128+
endif ()
129+
130+
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES)
131+
add_subdirectory(src/examples)
132+
endif ()
14133

15134
if (BUILD_DOCUMENTATION)
16135
add_subdirectory(doc)
17136
endif()
18137

19-
include(cmake/setup-exports.cmake)
20138
include(cmake/naughty-buffers-cpack.cmake)

cmake/naughty-buffers-config.cmake

Lines changed: 0 additions & 1 deletion
This file was deleted.

cmake/naughty-buffers-cpack.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ endif (MSVC)
1212

1313
set(CPACK_PACKAGE_VENDOR "Leonardo G. L. de Freitas")
1414
set(CPACK_PACKAGE_DESCRIPTION
15-
"Font Chef is a cross-platform C99 library providing dynamic generic buffers")
15+
"Naughty Buffers is a cross-platform C99 library providing dynamic generic buffers")
1616
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_DESCRIPTION}")
1717
set(CPACK_PACKAGE_FILE_NAME
1818
"${PROJECT_NAME}-${PROJECT_VERSION}-${NAUGHTY_BUFFERS_SYSTEM_NAME}-${NAUGHTY_BUFFERS_ARCH}-${NAUGHTY_BUFFERS_COMPILER_TARGET}")
1919
set(CPACK_SOURCE_PACKAGE_FILE_NAME
2020
"${PROJECT_NAME}-${PROJECT_VERSION}")
21-
set(CPACK_PACKAGE_NAME KiWi)
21+
set(CPACK_PACKAGE_NAME naughty-buffers)
2222

2323
set(CPACK_SOURCE_IGNORE_FILES .*build.*/ .idea/ .git/)
2424

@@ -30,4 +30,4 @@ else ()
3030
set(CPACK_GENERATOR "TGZ")
3131
endif ()
3232

33-
include(CPack)
33+
include(CPack)

cmake/setup-exports.cmake

Lines changed: 0 additions & 24 deletions
This file was deleted.

doc/Doxyfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ PROJECT_NUMBER = @naughty-buffers_VERSION@
5454
# for a project that appears at the top of each page and should give viewer a
5555
# quick idea about the purpose of the project. Keep the description short.
5656

57-
PROJECT_BRIEF = "A font cooking library"
57+
PROJECT_BRIEF = "A dynamic buffer library for C"
5858

5959
# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
6060
# in the documentation. The maximum height of the logo should not exceed 55

include/naughty-buffers/buffer.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ struct nb_buffer_memory_context {
124124
void * context;
125125
};
126126

127+
/**
128+
* @brief Structure returned by ::nb_iterator containing enough information to control a for-loop
129+
*
130+
* @sa ::nb_iterator
131+
* @ingroup buffer
132+
*/
133+
struct nb_buffer_iterator {
134+
/** Marks the initial data block */
135+
void * begin;
136+
137+
/** Marks past the final data block. Do not dereference it. */
138+
void * end;
139+
140+
/** The value to add to the block pointer in each iteration */
141+
size_t increment;
142+
};
143+
127144
/**
128145
* @brief a structure holding the buffer data and metadata about the blocks.
129146
*
@@ -474,6 +491,42 @@ NAUGHTY_BUFFERS_EXPORT void nb_sort(struct nb_buffer * buffer, nb_compare_fn com
474491
*/
475492
NAUGHTY_BUFFERS_EXPORT void nb_release(struct nb_buffer * buffer);
476493

494+
/**
495+
* @brief Creates and returns an iterator that allows for performance-friendly traversal.
496+
*
497+
* If you intend to access a lot of elements in sequence, this is the preferred method to do so as it offers better
498+
* performance in comparison to ::nb_at
499+
*
500+
* @param buffer A pointer to a ::nb_buffer struct
501+
* @returns A `nb_buffer_iterator` struct with values that can be used to control a for-loop.
502+
* @ingroup buffer
503+
*
504+
* **Example**
505+
* @code
506+
int main(void) {
507+
struct nb_buffer buffer;
508+
nb_init(&buffer, sizeof(int));
509+
510+
int value;
511+
512+
value = 0; nb_push(&buffer, &value);
513+
value = 10; nb_push(&buffer, &value);
514+
value = 20; nb_push(&buffer, &value);
515+
516+
struct nb_buffer_iterator itr = nb_iterator(&buffer);
517+
518+
for (uint8_t * block = itr.begin; block != itr.end; block += itr.increment) {
519+
int * data = (int *) block;
520+
printf("data: %d\n", *data);
521+
}
522+
523+
nb_release(&buffer);
524+
return 0;
525+
}
526+
* @endcode
527+
*/
528+
NAUGHTY_BUFFERS_EXPORT struct nb_buffer_iterator nb_iterator(struct nb_buffer * buffer);
529+
477530
#ifdef __cplusplus
478531
};
479532
#endif

src/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/naughty-buffers/CMakeLists.txt

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/naughty-buffers/buffer.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,11 @@ void nb_remove_at(struct nb_buffer * buffer, size_t index) {
149149
void nb_sort(struct nb_buffer * buffer, nb_compare_fn compare_fn) {
150150
qsort(buffer->data, buffer->block_count, buffer->block_size, compare_fn);
151151
}
152+
153+
struct nb_buffer_iterator nb_iterator(struct nb_buffer * buffer) {
154+
return (struct nb_buffer_iterator) {
155+
.begin = (uint8_t *) buffer->data,
156+
.end = (uint8_t *) buffer->data + (buffer->block_count * buffer->block_size),
157+
.increment = buffer->block_size
158+
};
159+
}

src/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ nb_test(test-insert insert.c)
2727
nb_test(test-remove remove.c)
2828
nb_test(test-sort sort.c)
2929
nb_test(test-array-generator array-generator.c)
30+
nb_test(test-iterators iterators.c)

0 commit comments

Comments
 (0)