├── doxygen ├── .gitignore └── main-page.md ├── external ├── flatcc │ ├── support │ │ ├── README │ │ ├── cdump.h │ │ ├── hexdump.h │ │ ├── readfile.h │ │ └── elapsed.h │ ├── portable │ │ ├── include │ │ │ ├── linux │ │ │ │ └── endian.h │ │ │ ├── std │ │ │ │ ├── inttypes.h │ │ │ │ ├── stdalign.h │ │ │ │ ├── stdbool.h │ │ │ │ └── stdint.h │ │ │ └── README │ │ ├── portable.h │ │ ├── pversion.h │ │ ├── pinline.h │ │ ├── pdiagnostic_pop.h │ │ ├── LICENSE │ │ ├── portable_basic.h │ │ ├── pstdbool.h │ │ ├── pprintfp.h │ │ ├── pcrt.h │ │ ├── pinttypes.h │ │ ├── pdiagnostic_push.h │ │ ├── pwarnings.h │ │ ├── pstatic_assert.h │ │ ├── pattributes.h │ │ ├── pdiagnostic.h │ │ ├── README.md │ │ ├── pendian_detect.h │ │ ├── pstdalign.h │ │ └── pendian.h │ ├── flatcc_epilogue.h │ ├── flatcc_prologue.h │ ├── flatcc_portable.h │ ├── flatcc_version.h │ ├── flatcc_unaligned.h │ ├── flatcc_iov.h │ ├── reflection │ │ └── README │ ├── flatcc_assert.h │ ├── flatcc_flatbuffers.h │ ├── flatcc_types.h │ ├── flatcc_alloc.h │ ├── flatcc_endian.h │ ├── flatcc_identifier.h │ ├── flatcc_refmap.h │ └── flatcc_rtconfig.h ├── README.md └── flatbuffers │ ├── flex_flat_util.h │ ├── bfbs_generator.h │ ├── file_manager.h │ ├── buffer_ref.h │ ├── struct.h │ ├── string.h │ ├── default_allocator.h │ ├── allocator.h │ ├── code_generator.h │ ├── detached_buffer.h │ ├── hash.h │ ├── flatc.h │ └── registry.h ├── examples ├── c-tasks │ ├── .gitignore │ ├── tasklist.fbs │ ├── build.sh │ ├── objectbox-model.json │ ├── CMakeLists.txt │ └── objectbox-model.h ├── tasks │ ├── .gitignore │ ├── tasklist.fbs │ ├── build.sh │ ├── objectbox-model.json │ ├── CMakeLists.txt │ ├── tasklist.obx.hpp │ ├── objectbox-model.h │ ├── tasklist.obx.cpp │ └── main.cpp ├── c-tasks-lowlevel │ ├── .gitignore │ ├── task.fbs │ ├── generate-flat-schema.sh │ ├── build.sh │ ├── CMakeLists.txt │ ├── task_reader.h │ ├── task_builder.h │ └── README.md ├── vectorsearch-cities │ ├── .gitignore │ ├── city.fbs │ ├── build.sh │ ├── objectbox-model.json │ ├── city.obx.hpp │ ├── CMakeLists.txt │ ├── city.obx.cpp │ ├── objectbox-model.h │ ├── main.cpp │ └── README.md ├── CMakeLists.txt ├── regenerate-schemas.sh └── README.md ├── src-test ├── c_test.fbs ├── README.md ├── c_test_objects.h ├── CMakeLists.txt ├── c_test_reader.h ├── c_test_builder.h └── c_test_objects.c ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── ci.yml ├── .gitignore ├── src-test-gen ├── README.md ├── CMakeLists.txt ├── c_test.fbs ├── objectbox-model.h ├── objectbox-model.json └── plain-c-test-main.c ├── test.sh ├── .gitlab-ci.yml └── include └── objectbox-dart.h /doxygen/.gitignore: -------------------------------------------------------------------------------- 1 | html/ -------------------------------------------------------------------------------- /external/flatcc/support/README: -------------------------------------------------------------------------------- 1 | support files mainly used for testing 2 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/linux/endian.h: -------------------------------------------------------------------------------- 1 | #include "portable/pendian.h" 2 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/std/inttypes.h: -------------------------------------------------------------------------------- 1 | #include "portable/inttypes.h" 2 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/std/stdalign.h: -------------------------------------------------------------------------------- 1 | #include "portable/pstdalign.h" 2 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/std/stdbool.h: -------------------------------------------------------------------------------- 1 | #include "portable/pstdbool.h" 2 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/std/stdint.h: -------------------------------------------------------------------------------- 1 | #include "portable/pstdint.h" 2 | -------------------------------------------------------------------------------- /examples/c-tasks/.gitignore: -------------------------------------------------------------------------------- 1 | # build.sh uses build/ directory 2 | build/ 3 | 4 | # ObjectBox Database files 5 | **/data.mdb 6 | **/lock.mdb -------------------------------------------------------------------------------- /examples/tasks/.gitignore: -------------------------------------------------------------------------------- 1 | # build.sh uses build/ directory 2 | build/ 3 | 4 | # ObjectBox Database files 5 | **/data.mdb 6 | **/lock.mdb -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/.gitignore: -------------------------------------------------------------------------------- 1 | # build.sh uses build/ directory 2 | build/ 3 | 4 | # ObjectBox Database files 5 | **/data.mdb 6 | **/lock.mdb -------------------------------------------------------------------------------- /external/flatcc/portable/portable.h: -------------------------------------------------------------------------------- 1 | /* portable.h is widely used, so we redirect to a less conflicting name. */ 2 | #include "portable_basic.h" 3 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/.gitignore: -------------------------------------------------------------------------------- 1 | # build.sh uses build/ directory 2 | build/ 3 | 4 | # ObjectBox Database files 5 | **/data.mdb 6 | **/lock.mdb -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/task.fbs: -------------------------------------------------------------------------------- 1 | table Task { 2 | id: ulong; 3 | text: string; 4 | date_created: ulong; 5 | date_finished: ulong; 6 | } 7 | -------------------------------------------------------------------------------- /src-test/c_test.fbs: -------------------------------------------------------------------------------- 1 | table Foo { 2 | id: ulong; 3 | text: string; 4 | } 5 | table Bar { 6 | id: ulong; 7 | text: string; 8 | fooId: ulong; 9 | } -------------------------------------------------------------------------------- /external/flatcc/flatcc_epilogue.h: -------------------------------------------------------------------------------- 1 | /* Include guard intentionally left out. */ 2 | 3 | #ifdef __cplusplus 4 | } 5 | #endif 6 | 7 | #include "flatcc/portable/pdiagnostic_pop.h" 8 | 9 | -------------------------------------------------------------------------------- /examples/c-tasks/tasklist.fbs: -------------------------------------------------------------------------------- 1 | table Task { 2 | id: ulong; 3 | text: string; 4 | 5 | /// objectbox:date 6 | date_created: ulong; 7 | 8 | /// objectbox:date 9 | date_finished: ulong; 10 | } 11 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_prologue.h: -------------------------------------------------------------------------------- 1 | /* Include guard intentionally left out. */ 2 | 3 | #define PDIAGNOSTIC_IGNORE_UNUSED 4 | #include "flatcc/portable/pdiagnostic_push.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | -------------------------------------------------------------------------------- /external/flatcc/portable/pversion.h: -------------------------------------------------------------------------------- 1 | #define PORTABLE_VERSION_TEXT "0.2.6-pre" 2 | #define PORTABLE_VERSION_MAJOR 0 3 | #define PORTABLE_VERSION_MINOR 2 4 | #define PORTABLE_VERSION_PATCH 6 5 | /* 1 or 0 */ 6 | #define PORTABLE_VERSION_RELEASED 0 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Question 4 | url: https://stackoverflow.com/questions/tagged/objectbox 5 | about: Ask how to do something, or why it isn't working on Stack Overflow. 6 | -------------------------------------------------------------------------------- /external/flatcc/portable/include/README: -------------------------------------------------------------------------------- 1 | This directory holds subdirectories it can be added to the include path 2 | such that standard and OS specific header includes like , 3 | and can succeed without explicitly including 4 | special headers explicitly. 5 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_portable.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_PORTABLE_H 2 | #define FLATCC_PORTABLE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "flatcc/portable/portable_basic.h" 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif /* FLATCC_PORTABLE_H */ 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | download/ 2 | lib/ 3 | build/ 4 | 5 | # DB files 6 | *.mdb 7 | 8 | # Build targets 9 | objectbox-c-test 10 | 11 | # CMake build files 12 | CMakeFiles/ 13 | CMakeCache.txt 14 | Makefile 15 | cmake_install.cmake 16 | 17 | # IDE (e.g. CLion) 18 | .idea/ 19 | cmake-build-debug/ 20 | cmake-build-release/ -------------------------------------------------------------------------------- /external/flatcc/flatcc_version.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #define FLATCC_VERSION_TEXT "0.6.2" 6 | #define FLATCC_VERSION_MAJOR 0 7 | #define FLATCC_VERSION_MINOR 6 8 | #define FLATCC_VERSION_PATCH 2 9 | /* 1 or 0 */ 10 | #define FLATCC_VERSION_RELEASED 0 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | -------------------------------------------------------------------------------- /examples/tasks/tasklist.fbs: -------------------------------------------------------------------------------- 1 | /// A task with a description, a creation and completion date. 2 | table Task { 3 | id: ulong; 4 | text: string; 5 | 6 | /// objectbox:date 7 | date_created: long; 8 | 9 | /// objectbox:date 10 | /// If not set (zero value), the task is not finished. 11 | date_finished: long; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_unaligned.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_UNLIGNED_H 2 | #define FLATCC_UNLIGNED_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "flatcc/portable/punaligned.h" 9 | 10 | #define FLATCC_ALLOW_UNALIGNED_ACCESS PORTABLE_UNALIGNED_ACCESS 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif /* FLATCC_UNLIGNED_H */ 17 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/city.fbs: -------------------------------------------------------------------------------- 1 | /// A city with a 2D location vector for vector search. 2 | table City { 3 | id: ulong; 4 | name: string; 5 | 6 | /// A 2D vector representing the city's location with latitude and longitude. 7 | /// Using the "Geo" distance type, which specializes in geospatial search (haversine distance). 8 | /// objectbox: index=hnsw, hnsw-dimensions=2 9 | /// objectbox: hnsw-distance-type=Geo 10 | location: [float]; 11 | } 12 | -------------------------------------------------------------------------------- /src-test/README.md: -------------------------------------------------------------------------------- 1 | ### Using `flatcc` and direct flatbuffers access 2 | This directory shows one of the variants of working with ObjectBox from plain C99/C11 - by using `flatcc` generated 3 | files and direct flatbuffers access to read and write objects. 4 | 5 | If you'd like to recreate the generated files, you'll need the [flatcc](https://github.com/dvidelabs/flatcc) binary installed/available. 6 | ```shell script 7 | flatcc --version 8 | flatcc --common --builder c_test.fbs 9 | ``` 10 | -------------------------------------------------------------------------------- /src-test-gen/README.md: -------------------------------------------------------------------------------- 1 | ### Using `objectbox-cgen` and generated structs 2 | This directory shows one of the variants of working with ObjectBox from plain C99/C11 - by using `objectbox-generator -c` 3 | to generate model, struct and binding files providing a simplified way to read and write objects. 4 | 5 | If you'd like to recreate the generated files, you'll need the `objectbox-generator` binary installed/available. 6 | ```shell script 7 | objectbox-generator -version 8 | objectbox-generator -c c_test.fbs 9 | ``` 10 | -------------------------------------------------------------------------------- /src-test-gen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_STANDARD 99) 2 | 3 | include_directories(../include ../external) 4 | 5 | project(objectbox-c-gen-test C) 6 | 7 | add_executable(${PROJECT_NAME} 8 | plain-c-test-main.c 9 | ../external/flatcc-src/builder.c 10 | ../external/flatcc-src/emitter.c 11 | ../external/flatcc-src/refmap.c 12 | ) 13 | 14 | target_link_libraries(${PROJECT_NAME} objectbox) 15 | 16 | IF (CMAKE_ANDROID) 17 | target_link_libraries(${PROJECT_NAME} log) 18 | ENDIF () 19 | -------------------------------------------------------------------------------- /external/flatcc/portable/pinline.h: -------------------------------------------------------------------------------- 1 | #ifndef PINLINE_H 2 | #define PINLINE_H 3 | 4 | #ifndef __cplusplus 5 | 6 | #if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 7 | /* C99 or newer */ 8 | #elif _MSC_VER >= 1500 /* MSVC 9 or newer */ 9 | #undef inline 10 | #define inline __inline 11 | #elif __GNUC__ >= 3 /* GCC 3 or newer */ 12 | #define inline __inline 13 | #else /* Unknown or ancient */ 14 | #define inline 15 | #endif 16 | 17 | #endif /* __cplusplus */ 18 | 19 | #endif /* PINLINE_H */ 20 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/generate-flat-schema.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | 7 | # Adjust to your local paths if you don't have flatcc/objectbox-generator in your system path 8 | flatcc=flatcc 9 | #flatcc="${script_dir}/../../flatcc/bin/flatcc" # from checked out repo 10 | 11 | ${flatcc} --version || true 12 | 13 | cd "$script_dir" 14 | ${flatcc} --common --builder task.fbs || echo " >> Warning: without flatcc, you cannot generate plain C sources <<" 15 | -------------------------------------------------------------------------------- /src-test/c_test_objects.h: -------------------------------------------------------------------------------- 1 | #ifndef PROJECT_C_TEST_OBJECTS_H 2 | #define PROJECT_C_TEST_OBJECTS_H 3 | 4 | #include 5 | 6 | #include "objectbox.h" 7 | #include "c_test_builder.h" 8 | 9 | int create_foo(flatcc_builder_t *B, uint64_t id, char* text); 10 | int put_foo(OBX_cursor* cursor, uint64_t* idInOut, char* text); 11 | Foo_table_t get_foo(OBX_cursor* cursor, uint64_t id); 12 | 13 | int create_bar(flatcc_builder_t *B, uint64_t id, char* text, uint64_t fooId); 14 | int put_bar(OBX_cursor* cursor, uint64_t* idInOut, char* text, uint64_t fooId); 15 | Bar_table_t get_bar(OBX_cursor* cursor, uint64_t id); 16 | 17 | #endif //PROJECT_C_TEST_OBJECTS_H 18 | -------------------------------------------------------------------------------- /examples/tasks/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | build_dir="${script_dir}/build" 7 | 8 | if [[ "${1:-}" == "--clean" ]]; then 9 | echo "Cleaning build directory..." 10 | rm -rf "${build_dir}" 11 | shift 12 | fi 13 | 14 | mkdir -p "${build_dir}" 15 | pushd "${build_dir}" 16 | 17 | cmake .. 18 | cmake --build . 19 | 20 | if [[ "${1:-}" == "run" ]]; then # Run the executable after building; pass any remaining arguments to it. 21 | shift 22 | ./objectbox-examples-tasks "$@" 23 | fi 24 | 25 | popd 26 | -------------------------------------------------------------------------------- /examples/c-tasks/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | build_dir="${script_dir}/build" 7 | 8 | if [[ "${1:-}" == "--clean" ]]; then 9 | echo "Cleaning build directory..." 10 | rm -rf "${build_dir}" 11 | shift 12 | fi 13 | 14 | mkdir -p "${build_dir}" 15 | pushd "${build_dir}" 16 | 17 | cmake .. 18 | cmake --build . 19 | 20 | if [[ "${1:-}" == "run" ]]; then # Run the executable after building; pass any remaining arguments to it. 21 | shift 22 | ./objectbox-examples-c-tasks "$@" 23 | fi 24 | 25 | popd 26 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | build_dir="${script_dir}/build" 7 | 8 | if [[ "${1:-}" == "--clean" ]]; then 9 | echo "Cleaning build directory..." 10 | rm -rf "${build_dir}" 11 | shift 12 | fi 13 | 14 | mkdir -p "${build_dir}" 15 | pushd "${build_dir}" 16 | 17 | cmake .. 18 | cmake --build . 19 | 20 | if [[ "${1:-}" == "run" ]]; then # Run the executable after building; pass any remaining arguments to it. 21 | shift 22 | ./objectbox-examples-c-tasks-lowlevel "$@" 23 | fi 24 | 25 | popd 26 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | build_dir="${script_dir}/build" 7 | 8 | if [[ "${1:-}" == "--clean" ]]; then 9 | echo "Cleaning build directory..." 10 | rm -rf "${build_dir}" 11 | shift 12 | fi 13 | 14 | mkdir -p "${build_dir}" 15 | pushd "${build_dir}" 16 | 17 | cmake .. 18 | cmake --build . 19 | 20 | if [[ "${1:-}" == "run" ]]; then # Run the executable after building; pass any remaining arguments to it. 21 | shift 22 | ./objectbox-examples-vectorsearch-cities "$@" 23 | fi 24 | 25 | popd 26 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(c-cursor-no-gen) 2 | add_subdirectory(c-gen) 3 | add_subdirectory(cpp-gen) 4 | add_subdirectory(cpp-gen-sync) 5 | 6 | # Since core project is also using this CMakeLists.txt and it did not fetch the ObjectBoxGenerator, find it quietly. 7 | find_package(ObjectBoxGenerator 4.0.0 QUIET) 8 | # Some platforms such as Linux ARM(64) and Windows ARM(64) are not supported. 9 | # We exclude this example for these cases where the generator was not found. 10 | if (ObjectBoxGenerator_FOUND) 11 | add_subdirectory(cpp-autogen) 12 | else () 13 | message(STATUS "Did not add all examples, as the ObjectBoxGenerator CMake was not found") 14 | endif () 15 | add_subdirectory(vectorsearch-cities) 16 | -------------------------------------------------------------------------------- /external/flatcc/portable/pdiagnostic_pop.h: -------------------------------------------------------------------------------- 1 | #if defined(PDIAGNOSTIC_PUSHED_MSVC) 2 | #if PDIAGNOSTIC_PUSHED_MSVC 3 | #pragma warning( pop ) 4 | #endif // PDIAGNOSTIC_PUSHED_MSVC 5 | #undef PDIAGNOSTIC_PUSHED_MSVC 6 | #endif // defined(PDIAGNOSTIC_PUSHED_MSVC) 7 | 8 | #if defined(PDIAGNOSTIC_PUSHED_CLANG) 9 | #if PDIAGNOSTIC_PUSHED_CLANG 10 | #pragma clang diagnostic pop 11 | #endif // PDIAGNOSTIC_PUSHED_CLANG 12 | #undef PDIAGNOSTIC_PUSHED_CLANG 13 | #endif // defined(PDIAGNOSTIC_PUSHED_CLANG) 14 | 15 | #if defined(PDIAGNOSTIC_PUSHED_GCC) 16 | #if PDIAGNOSTIC_PUSHED_GCC 17 | #pragma GCC diagnostic pop 18 | #endif // PDIAGNOSTIC_PUSHED_GCC 19 | #undef PDIAGNOSTIC_PUSHED_GCC 20 | #endif // defined(PDIAGNOSTIC_PUSHED_GCC) 21 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_iov.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_IOV_H 2 | #define FLATCC_IOV_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | /* 11 | * The emitter receives one, or a few buffers at a time via 12 | * this type. compatible iovec structure used for 13 | * allocation and emitter interface. 14 | */ 15 | typedef struct flatcc_iovec flatcc_iovec_t; 16 | struct flatcc_iovec { 17 | void *iov_base; 18 | size_t iov_len; 19 | }; 20 | 21 | /* 22 | * The largest iovec vector the builder will issue. It will 23 | * always be a relatively small number. 24 | */ 25 | #define FLATCC_IOV_COUNT_MAX 8 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif /* FLATCC_IOV_H */ 32 | -------------------------------------------------------------------------------- /external/README.md: -------------------------------------------------------------------------------- 1 | External sources 2 | ================ 3 | This folder contains sources that may be used by test/example applications. 4 | 5 | flatcc/flatcc-src 6 | ----------------- 7 | FlatBuffers API for C: see https://github.com/dvidelabs/flatcc 8 | 9 | Flatcc is NOT part of the ObjectBox C API itself. 10 | If you want to use ObjectBox in a C application, you should manage a flatcc dependency yourself. 11 | 12 | You can use libobjectbox in another language than C with a FlatBuffers library for that language. 13 | 14 | flatbuffers 15 | ----------------- 16 | FlatBuffers API for C++: see https://github.com/google/flatbuffers/ 17 | 18 | FlatBuffers is NOT part of the ObjectBox C/C++ API itself, you should manage the dependency yourself. 19 | -------------------------------------------------------------------------------- /external/flatcc/portable/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Mikkel F. Jørgensen, dvide.com 2 | Some files also Copyright author of MathGeoLib (https://github.com/juj) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. http://www.apache.org/licenses/LICENSE-2.0 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | :rotating_light: First, please check: 11 | - existing issues, 12 | - Docs https://cpp.objectbox.io/ 13 | 14 | Start with a clear and concise description of what problem you are trying to solve. 15 | Often there is already a solution! 16 | 17 | **Describe the solution you'd like** 18 | A clear and concise description of what you want to happen. 19 | 20 | **Describe alternatives you've considered** 21 | A clear and concise description of any alternative solutions or features you've considered. 22 | 23 | **Additional context** 24 | Add any other context (e.g. platform or language) about the feature request here. 25 | -------------------------------------------------------------------------------- /external/flatcc/portable/portable_basic.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTABLE_BASIC_H 2 | #define PORTABLE_BASIC_H 3 | 4 | /* 5 | * Basic features need to make compilers support the most common moden C 6 | * features, and endian / unligned read support as well. 7 | * 8 | * It is not assumed that this file is always included. 9 | * Other include files are independent or include what they need. 10 | */ 11 | 12 | #include "pversion.h" 13 | #include "pwarnings.h" 14 | 15 | /* Featutures that ought to be supported by C11, but some aren't. */ 16 | #include "pinttypes.h" 17 | #include "pstdalign.h" 18 | #include "pinline.h" 19 | #include "pstatic_assert.h" 20 | 21 | /* These are not supported by C11 and are general platform abstractions. */ 22 | #include "pendian.h" 23 | #include "punaligned.h" 24 | 25 | #endif /* PORTABLE_BASIC_H */ 26 | -------------------------------------------------------------------------------- /external/flatcc/portable/pstdbool.h: -------------------------------------------------------------------------------- 1 | #ifndef PSTDBOOL_H 2 | #define PSTDBOOL_H 3 | 4 | #if !defined(__cplusplus) && !__bool_true_false_are_defined && !defined(bool) && !defined(__STDBOOL_H) 5 | 6 | #ifdef HAVE_STDBOOL_H 7 | 8 | #include 9 | 10 | #elif (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 11 | /* C99 or newer */ 12 | 13 | #define bool _Bool 14 | #define true 1 15 | #define false 0 16 | #define __bool_true_false_are_defined 1 17 | 18 | #elif defined(__GNUC__) && !defined(__STRICT_ANSI__) 19 | 20 | #define bool bool 21 | #define true true 22 | #define false false 23 | #define __bool_true_false_are_defined 1 24 | 25 | #else 26 | 27 | typedef unsigned char _Portable_bool; 28 | #define bool _Portable_bool 29 | #define true 1 30 | #define false 0 31 | #define __bool_true_false_are_defined 1 32 | 33 | #endif 34 | 35 | #endif 36 | 37 | #endif /* PSTDBOOL_H */ 38 | -------------------------------------------------------------------------------- /src-test-gen/c_test.fbs: -------------------------------------------------------------------------------- 1 | table Foo { 2 | id: ulong; 3 | text: string; 4 | } 5 | 6 | table Bar { 7 | id: ulong; 8 | text: string; 9 | fooId: ulong; 10 | } 11 | 12 | // Unused but it's here to verify there are no C compilation errors with any of the supported types. 13 | table Typeful { 14 | id : uint64 ; 15 | int : int ; 16 | int8 : int8 ; 17 | int16 : int16 ; 18 | int32 : int32 ; 19 | int64 : int64 ; 20 | uint : uint ; 21 | uint8 : uint8 ; 22 | uint16 : uint16 ; 23 | uint32 : uint32 ; 24 | uint64 : uint64 ; 25 | bool : bool ; 26 | string : string ; 27 | stringvector : [string] ; 28 | byte : byte ; 29 | ubyte : ubyte ; 30 | bytevector : [byte] ; 31 | ubytevector : [ubyte] ; 32 | float32 : float32 ; 33 | float64 : float64 ; 34 | float : float ; 35 | double : double ; 36 | } -------------------------------------------------------------------------------- /external/flatcc/reflection/README: -------------------------------------------------------------------------------- 1 | Generated by flatcc 2 | 3 | Keep checked in - needed by flatcc to generate binary schema. 4 | 5 | NOTE TO CONTRIBUTORS: DO NOT EDIT THESE FILES BY HAND 6 | 7 | If you need to change anything here, it is done in the code generator, 8 | possibly followed by running `reflection/generate_code.sh` from the 9 | project root. But please only do this for testing do not include the 10 | generated files in a pull request unless agreed otherwise, and if so, 11 | do it in a separate commit. 12 | 13 | Normally new reflection code is generated during a release which also 14 | updates the version number in comments and there is no reason to update 15 | reflection on every commit unless it breaks something fundamentally. 16 | 17 | There is a build option `FLATCC_REFLECTION` to disable reflection which 18 | is helpful while making changes that affect the content of these files 19 | in a way that would prevent the flatcc compiler from building. 20 | -------------------------------------------------------------------------------- /external/flatcc/support/cdump.h: -------------------------------------------------------------------------------- 1 | #ifndef CDUMP_H 2 | #define CDUMP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | /* Generates a constant a C byte array. */ 11 | static void cdump(const char *name, void *addr, size_t len, FILE *fp) { 12 | unsigned int i; 13 | unsigned char *pc = (unsigned char*)addr; 14 | 15 | // Output description if given. 16 | name = name ? name : "dump"; 17 | fprintf(fp, "const unsigned char %s[] = {", name); 18 | 19 | // Process every byte in the data. 20 | for (i = 0; i < (unsigned int)len; i++) { 21 | // Multiple of 16 means new line (with line offset). 22 | 23 | if ((i % 16) == 0) { 24 | fprintf(fp, "\n "); 25 | } else if ((i % 8) == 0) { 26 | fprintf(fp, " "); 27 | } 28 | 29 | fprintf(fp, " 0x%02x,", pc[i]); 30 | } 31 | fprintf(fp, "\n};\n"); 32 | } 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif /* CDUMP_H */ 39 | -------------------------------------------------------------------------------- /src-test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_STANDARD 99) 2 | 3 | include_directories(../include ../external) 4 | 5 | set(PLAIN_C_TEST_SOURCES 6 | plain-c-test-main.c 7 | c_test_objects.c 8 | c_test_objects.h 9 | ../external/flatcc-src/builder.c 10 | ../external/flatcc-src/emitter.c 11 | ../external/flatcc-src/refmap.c 12 | ) 13 | 14 | add_executable(objectbox-c-test ${PLAIN_C_TEST_SOURCES}) 15 | target_link_libraries(objectbox-c-test objectbox) 16 | 17 | if (CMAKE_ANDROID) 18 | target_link_libraries(objectbox-c-test log) 19 | endif () 20 | 21 | if (TARGET objectbox-static-distribution-lib) 22 | # Even if it doesn't do much, this is already useful e.g. to detect missing symbols during linking 23 | add_executable(objectbox-c-test-static-lib ${PLAIN_C_TEST_SOURCES}) 24 | target_link_libraries(objectbox-c-test-static-lib objectbox-static-distribution-lib stdc++ pthread m) 25 | IF (CMAKE_ANDROID) 26 | target_link_libraries(objectbox-c-test-static-lib log) 27 | endif () 28 | endif () -------------------------------------------------------------------------------- /external/flatcc/portable/pprintfp.h: -------------------------------------------------------------------------------- 1 | #ifndef PPRINTFP_H 2 | #define PPRINTFP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION 9 | #include "pdiagnostic_push.h" 10 | 11 | #ifndef PORTABLE_USE_GRISU3 12 | #define PORTABLE_USE_GRISU3 1 13 | #endif 14 | 15 | 16 | #if PORTABLE_USE_GRISU3 17 | #include "grisu3_print.h" 18 | #endif 19 | 20 | #ifdef grisu3_print_double_is_defined 21 | /* Currently there is not special support for floats. */ 22 | #define print_float(n, p) grisu3_print_double((float)(n), (p)) 23 | #define print_double(n, p) grisu3_print_double((double)(n), (p)) 24 | #else 25 | #include 26 | #define print_float(n, p) sprintf(p, "%.9g", (float)(n)) 27 | #define print_double(n, p) sprintf(p, "%.17g", (double)(n)) 28 | #endif 29 | 30 | #define print_hex_float(n, p) sprintf(p, "%a", (float)(n)) 31 | #define print_hex_double(n, p) sprintf(p, "%a", (double)(n)) 32 | 33 | #include "pdiagnostic_pop.h" 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* PPRINTFP_H */ 40 | -------------------------------------------------------------------------------- /examples/regenerate-schemas.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # macOS does not have realpath and readlink does not have -f option, so do this instead: 5 | script_dir=$( cd "$(dirname "$0")" ; pwd -P ) 6 | 7 | # Adjust to your local paths if you don't have flatcc/objectbox-generator in your system path 8 | flatcc=flatcc 9 | #flatcc="${script_dir}/../../flatcc/bin/flatcc" # from checked out repo 10 | obxgen=objectbox-generator 11 | #obxgen="${script_dir}/../../objectbox-generator/objectbox-generator" # from checked out repo 12 | 13 | ${flatcc} --version || true 14 | ${obxgen} -version 15 | 16 | ( 17 | cd c-cursor-no-gen 18 | ${flatcc} --common --builder task.fbs || echo " >> Warning: without flatcc, you cannot generate plain C sources <<" 19 | ) 20 | 21 | ( 22 | cd c-gen 23 | ${obxgen} -c tasklist.fbs 24 | ) 25 | 26 | ( 27 | cd cpp-gen 28 | ${obxgen} -cpp11 tasklist.fbs 29 | ) 30 | 31 | ( 32 | cd cpp-gen-sync 33 | ${obxgen} -cpp11 tasklist.fbs 34 | ) 35 | 36 | ( 37 | cd vectorsearch-cities 38 | ${obxgen} -cpp city.fbs 39 | ) 40 | -------------------------------------------------------------------------------- /external/flatcc/portable/pcrt.h: -------------------------------------------------------------------------------- 1 | #ifndef PCRT_H 2 | #define PCRT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | /* 10 | * Assertions and pointer violations in debug mode may trigger a dialog 11 | * on Windows. When running headless this is not helpful, but 12 | * unfortunately it cannot be disabled with a compiler option so code 13 | * must be injected into the runtime early in the main function. 14 | * A call to the provided `init_headless_crt()` macro does this in 15 | * a portable manner. 16 | * 17 | * See also: 18 | * https://stackoverflow.com/questions/13943665/how-can-i-disable-the-debug-assertion-dialog-on-windows 19 | */ 20 | 21 | #if defined(_WIN32) 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | static int _portable_msvc_headless_report_hook(int reportType, char *message, int *returnValue) 28 | { 29 | fprintf(stderr, "CRT[%d]: %s\n", reportType, message); 30 | *returnValue = 1; 31 | exit(1); 32 | return 1; 33 | } 34 | 35 | #define init_headless_crt() _CrtSetReportHook(_portable_msvc_headless_report_hook) 36 | 37 | #else 38 | 39 | #define init_headless_crt() ((void)0) 40 | 41 | #endif 42 | 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* PCRT_H */ 49 | -------------------------------------------------------------------------------- /external/flatcc/portable/pinttypes.h: -------------------------------------------------------------------------------- 1 | #ifndef PINTTYPES_H 2 | #define PINTTYPES_H 3 | 4 | #ifndef PRId16 5 | 6 | #if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 7 | /* C99 or newer */ 8 | #include 9 | #else 10 | 11 | /* 12 | * This is not a complete implementation of , just the most 13 | * useful printf modifiers. 14 | */ 15 | 16 | #include "pstdint.h" 17 | 18 | #ifndef PRINTF_INT64_MODIFIER 19 | #error "please define PRINTF_INT64_MODIFIER" 20 | #endif 21 | 22 | #ifndef PRId64 23 | #define PRId64 PRINTF_INT64_MODIFIER "d" 24 | #define PRIu64 PRINTF_INT64_MODIFIER "u" 25 | #define PRIx64 PRINTF_INT64_MODIFIER "x" 26 | #endif 27 | 28 | #ifndef PRINTF_INT32_MODIFIER 29 | #define PRINTF_INT32_MODIFIER "l" 30 | #endif 31 | 32 | #ifndef PRId32 33 | #define PRId32 PRINTF_INT32_MODIFIER "d" 34 | #define PRIu32 PRINTF_INT32_MODIFIER "u" 35 | #define PRIx32 PRINTF_INT32_MODIFIER "x" 36 | #endif 37 | 38 | #ifndef PRINTF_INT16_MODIFIER 39 | #define PRINTF_INT16_MODIFIER "h" 40 | #endif 41 | 42 | #ifndef PRId16 43 | #define PRId16 PRINTF_INT16_MODIFIER "d" 44 | #define PRIu16 PRINTF_INT16_MODIFIER "u" 45 | #define PRIx16 PRINTF_INT16_MODIFIER "x" 46 | #endif 47 | 48 | # endif /* __STDC__ */ 49 | 50 | #endif /* PRId16 */ 51 | 52 | #endif /* PINTTYPES */ 53 | -------------------------------------------------------------------------------- /external/flatcc/support/hexdump.h: -------------------------------------------------------------------------------- 1 | #ifndef HEXDUMP_H 2 | #define HEXDUMP_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | /* Based on: http://stackoverflow.com/a/7776146 */ 11 | static void hexdump(const char *desc, const void *addr, size_t len, FILE *fp) { 12 | unsigned int i; 13 | unsigned char buf[17]; 14 | const unsigned char *pc = (const unsigned char*)addr; 15 | 16 | /* Output description if given. */ 17 | if (desc != NULL) fprintf(fp, "%s:\n", desc); 18 | 19 | for (i = 0; i < (unsigned int)len; i++) { 20 | 21 | if ((i % 16) == 0) { 22 | if (i != 0) fprintf(fp, " |%s|\n", buf); 23 | fprintf(fp, "%08x ", i); 24 | } else if ((i % 8) == 0) { 25 | fprintf(fp, " "); 26 | } 27 | fprintf(fp, " %02x", pc[i]); 28 | if ((pc[i] < 0x20) || (pc[i] > 0x7e)) { 29 | buf[i % 16] = '.'; 30 | } else { 31 | buf[i % 16] = pc[i]; 32 | } 33 | buf[(i % 16) + 1] = '\0'; 34 | } 35 | if (i % 16 <= 8 && i % 16 != 0) fprintf(fp, " "); 36 | while ((i % 16) != 0) { 37 | fprintf(fp, " "); 38 | i++; 39 | } 40 | fprintf(fp, " |%s|\n", buf); 41 | } 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* HEXDUMP_H */ 48 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ObjectBox C test script: build the test and run it 3 | 4 | set -eo pipefail 5 | 6 | case $1 in 7 | --clean) 8 | clean=true 9 | shift 10 | ;; 11 | esac 12 | 13 | buildDir=${1:-build-test} 14 | 15 | if ${clean:-false}; then 16 | echo "Cleaning \"${buildDir}\"..." 17 | rm -rfv ${buildDir} 18 | exit 0 19 | fi 20 | 21 | buildSubDir= 22 | if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then 23 | buildSubDir=Debug 24 | # After `cmake ..` is executed, we need to copy the .dll to the same dir as the test executable. 25 | # This path may change in future CMake versions so watch for `cp` failures after upgrading CMake. 26 | # Since test.sh is here (almost exclusively) for CI, end-users of the library aren't affected if the path changes. 27 | testPrepCmd="cp ../../_deps/objectbox-download-src/lib/objectbox.dll ./" 28 | fi 29 | 30 | # Don't use any installed library; but the one downloaded by CMake 31 | export LD_LIBRARY_PATH= 32 | 33 | echo "Building into \"${buildDir}\"..." 34 | mkdir -p ${buildDir} 35 | cd ${buildDir} 36 | cmake .. 37 | cmake --build . 38 | 39 | (cd src-test/${buildSubDir} && ${testPrepCmd} && ./objectbox-c-test) 40 | (cd src-test-gen/${buildSubDir} && ${testPrepCmd} && ./objectbox-c-gen-test) 41 | 42 | echo "Done. All looks good. Welcome to ObjectBox! :)" 43 | -------------------------------------------------------------------------------- /external/flatbuffers/flex_flat_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_FLEX_FLAT_UTIL_H_ 18 | #define FLATBUFFERS_FLEX_FLAT_UTIL_H_ 19 | 20 | #include "flatbuffers/flatbuffers.h" 21 | #include "flatbuffers/flexbuffers.h" 22 | 23 | namespace flexbuffers { 24 | 25 | // Verifies the `nested` flexbuffer within a flatbuffer vector is valid. 26 | inline bool VerifyNestedFlexBuffer( 27 | const flatbuffers::Vector *const nested, 28 | flatbuffers::Verifier &verifier) { 29 | if (!nested) return true; 30 | return verifier.Check(flexbuffers::VerifyBuffer( 31 | nested->data(), nested->size(), verifier.GetFlexReuseTracker())); 32 | } 33 | 34 | } // namespace flexbuffers 35 | 36 | #endif // FLATBUFFERS_FLEX_FLAT_UTIL_H_ 37 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_assert.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_ASSERT_H 2 | #define FLATCC_ASSERT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * This assert abstraction is only used for the flatcc runtime library. 10 | * The flatcc compiler uses Posix assert routines regardless of how this 11 | * file is configured. 12 | * 13 | * This header makes it possible to use systems where assert is not 14 | * valid to use. Note that `` may remain a dependency for static 15 | * assertions. 16 | * 17 | * `FLATCC_ASSERT` is designed to handle errors which cannot be ignored 18 | * and could lead to crash. The portable library may use assertions that 19 | * are not affected by this macro. 20 | * 21 | * `FLATCC_ASSERT` defaults to POSIX assert but can be overrided by a 22 | * preprocessor definition. 23 | * 24 | * Runtime assertions can be entirely disabled by defining 25 | * `FLATCC_NO_ASSERT`. 26 | */ 27 | 28 | #ifdef FLATCC_NO_ASSERT 29 | /* NOTE: This will not affect inclusion of for static assertions. */ 30 | #undef FLATCC_ASSERT 31 | #define FLATCC_ASSERT(x) ((void)0) 32 | /* Grisu3 is used for floating point conversion in JSON processing. */ 33 | #define GRISU3_NO_ASSERT 34 | #endif 35 | 36 | #ifndef FLATCC_ASSERT 37 | #include 38 | #define FLATCC_ASSERT assert 39 | #endif 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* FLATCC_ASSERT_H */ 46 | -------------------------------------------------------------------------------- /external/flatcc/support/readfile.h: -------------------------------------------------------------------------------- 1 | #ifndef READFILE_H 2 | #define READFILE_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | static char *readfile(const char *filename, size_t max_size, size_t *size_out) 12 | { 13 | FILE *fp; 14 | long k; 15 | size_t size, pos, n, _out; 16 | char *buf; 17 | 18 | size_out = size_out ? size_out : &_out; 19 | 20 | fp = fopen(filename, "rb"); 21 | size = 0; 22 | buf = 0; 23 | 24 | if (!fp) { 25 | goto fail; 26 | } 27 | fseek(fp, 0L, SEEK_END); 28 | k = ftell(fp); 29 | if (k < 0) goto fail; 30 | size = (size_t)k; 31 | *size_out = size; 32 | if (max_size > 0 && size > max_size) { 33 | goto fail; 34 | } 35 | rewind(fp); 36 | buf = (char *)malloc(size ? size : 1); 37 | if (!buf) { 38 | goto fail; 39 | } 40 | pos = 0; 41 | while ((n = fread(buf + pos, 1, size - pos, fp))) { 42 | pos += n; 43 | } 44 | if (pos != size) { 45 | goto fail; 46 | } 47 | fclose(fp); 48 | *size_out = size; 49 | return buf; 50 | 51 | fail: 52 | if (fp) { 53 | fclose(fp); 54 | } 55 | if (buf) { 56 | free(buf); 57 | } 58 | *size_out = size; 59 | return 0; 60 | } 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* READFILE_H */ 67 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(PROJECT_NAME objectbox-examples-c-tasks-lowlevel) 4 | 5 | project(${PROJECT_NAME} C) 6 | 7 | add_executable(${PROJECT_NAME} 8 | main.c 9 | # Note: the flatcc sources are embedded into this project for convenience: 10 | ../../external/flatcc-src/builder.c 11 | ../../external/flatcc-src/emitter.c 12 | ../../external/flatcc-src/refmap.c 13 | ) 14 | 15 | if (NOT TARGET objectbox) # Using "if" in case a (potential) parent project already defined "objectbox" 16 | include(FetchContent) 17 | FetchContent_Declare( 18 | objectbox 19 | GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git 20 | GIT_TAG v5.0.0 # For latest versions, check https://github.com/objectbox/objectbox-c/releases 21 | ) 22 | FetchContent_MakeAvailable(objectbox) 23 | 24 | # Note: ObjectBox generator is not used in this low-level example 25 | endif () 26 | 27 | target_link_libraries(${PROJECT_NAME} objectbox) 28 | 29 | IF (CMAKE_ANDROID) 30 | target_link_libraries(${PROJECT_NAME} log) 31 | ENDIF () 32 | 33 | # Print the executable path after build, so user can run it easily 34 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 35 | COMMAND ${CMAKE_COMMAND} -E echo "Built executable at \"$\"" 36 | VERBATIM 37 | ) 38 | -------------------------------------------------------------------------------- /external/flatcc/portable/pdiagnostic_push.h: -------------------------------------------------------------------------------- 1 | /* 2 | * See also comment in "pdiagnostic.h" 3 | * 4 | * e.g. 5 | * #define PDIAGNOSTIC_IGNORE_USED_FUNCTION 6 | * #define PDIAGNOSTIC_IGNORE_USED_VARIABLE 7 | * #include "pdiagnostic_push" 8 | * ... 9 | * #include "pdiagnostic_pop.h" 10 | * 11 | * 12 | * or if push pop isn't desired: 13 | * #define PDIAGNOSTIC_IGNORE_USED_FUNCTION 14 | * #define PDIAGNOSTIC_IGNORE_USED_VARIABLE 15 | * #include "pdiagnostic.h" 16 | * ... 17 | * 18 | * 19 | * 20 | * Some if these warnings cannot be ignored 21 | * at the #pragma level, but might in the future. 22 | * Use compiler switches like -Wno-unused-function 23 | * to work around this. 24 | */ 25 | 26 | #if defined(_MSC_VER) 27 | #pragma warning( push ) 28 | #define PDIAGNOSTIC_PUSHED_MSVC 1 29 | #else 30 | #define PDIAGNOSTIC_PUSHED_MSVC 0 31 | #endif 32 | 33 | #if defined(__clang__) 34 | #pragma clang diagnostic push 35 | #define PDIAGNOSTIC_PUSHED_CLANG 1 36 | #else 37 | #define PDIAGNOSTIC_PUSHED_CLANG 0 38 | #endif 39 | 40 | #if defined(__GNUC__) && !defined(__clang__) 41 | #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) 42 | #pragma GCC diagnostic push 43 | #define PDIAGNOSTIC_PUSHED_GCC 1 44 | #else 45 | #define PDIAGNOSTIC_PUSHED_GCC 0 46 | #endif // GNUC >= 4.6 47 | #else 48 | #define PDIAGNOSTIC_PUSHED_GCC 0 49 | #endif // defined(__GNUC__) && !defined(__clang__) 50 | 51 | #include "pdiagnostic.h" 52 | -------------------------------------------------------------------------------- /examples/tasks/objectbox-model.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:6645479796472661392", 8 | "lastPropertyId": "5:6240065879507520219", 9 | "name": "Task", 10 | "properties": [ 11 | { 12 | "id": "1:9211738071025439652", 13 | "name": "id", 14 | "type": 6, 15 | "flags": 1 16 | }, 17 | { 18 | "id": "2:8804670454579230281", 19 | "name": "text", 20 | "type": 9 21 | }, 22 | { 23 | "id": "4:1260602348787983453", 24 | "name": "date_created", 25 | "type": 10 26 | }, 27 | { 28 | "id": "5:6240065879507520219", 29 | "name": "date_finished", 30 | "type": 10 31 | } 32 | ] 33 | } 34 | ], 35 | "lastEntityId": "1:6645479796472661392", 36 | "lastIndexId": "", 37 | "lastRelationId": "", 38 | "modelVersion": 5, 39 | "modelVersionParserMinimum": 5, 40 | "retiredEntityUids": [], 41 | "retiredIndexUids": [], 42 | "retiredPropertyUids": [ 43 | 6707341922395832766 44 | ], 45 | "retiredRelationUids": [], 46 | "version": 1 47 | } -------------------------------------------------------------------------------- /external/flatbuffers/bfbs_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_BFBS_GENERATOR_H_ 18 | #define FLATBUFFERS_BFBS_GENERATOR_H_ 19 | 20 | #include 21 | 22 | namespace flatbuffers { 23 | 24 | enum GeneratorStatus { 25 | OK, 26 | FAILED, 27 | FAILED_VERIFICATION, 28 | }; 29 | 30 | // A Flatbuffer Code Generator that receives a binary serialized reflection.fbs 31 | // and generates code from it. 32 | class BfbsGenerator { 33 | public: 34 | virtual ~BfbsGenerator() {} 35 | 36 | // Generate code from the provided `buffer` of given `length`. The buffer is 37 | // a serialized reflection.fbs. 38 | virtual GeneratorStatus Generate(const uint8_t *buffer, int64_t length) = 0; 39 | }; 40 | 41 | } // namespace flatbuffers 42 | 43 | #endif // FLATBUFFERS_BFBS_GENERATOR_H_ 44 | -------------------------------------------------------------------------------- /examples/c-tasks/objectbox-model.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:1139978622395651407", 8 | "lastPropertyId": "4:8036043269103161827", 9 | "name": "Task", 10 | "properties": [ 11 | { 12 | "id": "1:6052852175666615421", 13 | "name": "id", 14 | "type": 6, 15 | "flags": 1 16 | }, 17 | { 18 | "id": "2:2217803131116660471", 19 | "name": "text", 20 | "type": 9 21 | }, 22 | { 23 | "id": "3:7901967683818986922", 24 | "name": "date_created", 25 | "type": 10, 26 | "flags": 8192 27 | }, 28 | { 29 | "id": "4:8036043269103161827", 30 | "name": "date_finished", 31 | "type": 10, 32 | "flags": 8192 33 | } 34 | ] 35 | } 36 | ], 37 | "lastEntityId": "1:1139978622395651407", 38 | "lastIndexId": "", 39 | "lastRelationId": "", 40 | "modelVersion": 5, 41 | "modelVersionParserMinimum": 5, 42 | "retiredEntityUids": [], 43 | "retiredIndexUids": [], 44 | "retiredPropertyUids": [], 45 | "retiredRelationUids": [], 46 | "version": 1 47 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | :rotating_light: First, please check: 11 | - existing issues, 12 | - Docs https://cpp.objectbox.io/ 13 | 14 | **Describe the bug** 15 | A clear and concise description in English of what the bug is. 16 | 17 | **Basic info (please complete the following information):** 18 | - ObjectBox version: [e.g. 0.10.0, latest version?] 19 | - C or C++ version: [e.g. C++11] 20 | - Reproducibility: [e.g. occurred once only | occasionally without visible pattern | always] 21 | - OS: [e.g. Ubuntu 20.04] 22 | 23 | **To Reproduce** 24 | Steps to reproduce the behavior: 25 | 1. Put '...' 26 | 2. Make changes to '....' 27 | 3. See error 28 | 29 | **Expected behavior** 30 | A clear and concise description of what you expected to happen. 31 | 32 | **Code** 33 | If applicable, add code to help explain your problem. 34 | - Include affected entity code. 35 | - Please remove any unnecessary or confidential parts. 36 | - At best, link to or attach a project with a failing test. 37 | 38 | **Logs, stack traces** 39 | If applicable, add relevant logs, or a stack trace. 40 | 41 | **Additional context** 42 | Add any other context about the problem here. 43 | - Is there anything special about your code? 44 | - May transactions or multi-threading play a role? 45 | - Did you find any workarounds to prevent the issue? 46 | -------------------------------------------------------------------------------- /examples/c-tasks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(PROJECT_NAME objectbox-examples-c-tasks) 4 | 5 | project(${PROJECT_NAME} C) 6 | 7 | add_executable(${PROJECT_NAME} 8 | main.c 9 | # Note: the flatcc sources are embedded into this project for convenience: 10 | ../../external/flatcc-src/builder.c 11 | ../../external/flatcc-src/emitter.c 12 | ../../external/flatcc-src/refmap.c 13 | ) 14 | 15 | if (NOT TARGET objectbox) # Using "if" in case a (potential) parent project already defined "objectbox" 16 | include(FetchContent) 17 | FetchContent_Declare( 18 | objectbox 19 | GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git 20 | GIT_TAG v5.0.0 # For latest versions, check https://github.com/objectbox/objectbox-c/releases 21 | ) 22 | FetchContent_MakeAvailable(objectbox) 23 | 24 | # TODO: fix generator error with C-only build: "Missing variable CMAKE_CXX_COMPILE_OBJECT/CMAKE_CXX_LINK_EXECUTABLE" 25 | #find_package(ObjectBoxGenerator REQUIRED) 26 | #add_obx_schema(TARGET ${PROJECT_NAME} SCHEMA_FILES tasklist.fbs INSOURCE) 27 | endif () 28 | 29 | target_link_libraries(${PROJECT_NAME} objectbox) 30 | 31 | # Print the executable path after build, so user can run it easily 32 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 33 | COMMAND ${CMAKE_COMMAND} -E echo "Built executable at \"$\"" 34 | VERBATIM 35 | ) 36 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/objectbox-model.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:607353604830599953", 8 | "lastPropertyId": "3:6028438376669885699", 9 | "name": "City", 10 | "properties": [ 11 | { 12 | "id": "1:3289333370985535139", 13 | "name": "id", 14 | "type": 6, 15 | "flags": 1 16 | }, 17 | { 18 | "id": "2:8840693632700366740", 19 | "name": "name", 20 | "type": 9 21 | }, 22 | { 23 | "id": "3:6028438376669885699", 24 | "name": "location", 25 | "indexId": "1:4616869581890712534", 26 | "type": 28, 27 | "flags": 8, 28 | "hnswParams": { 29 | "dimensions": 2, 30 | "distance-type": "Geo" 31 | } 32 | } 33 | ] 34 | } 35 | ], 36 | "lastEntityId": "1:607353604830599953", 37 | "lastIndexId": "1:4616869581890712534", 38 | "lastRelationId": "", 39 | "modelVersion": 5, 40 | "modelVersionParserMinimum": 5, 41 | "retiredEntityUids": [], 42 | "retiredIndexUids": [], 43 | "retiredPropertyUids": [], 44 | "retiredRelationUids": [], 45 | "version": 1 46 | } -------------------------------------------------------------------------------- /external/flatbuffers/file_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_FILE_MANAGER_H_ 18 | #define FLATBUFFERS_FILE_MANAGER_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "flatbuffers/util.h" 24 | 25 | namespace flatbuffers { 26 | 27 | // A File interface to write data to file by default or 28 | // save only file names 29 | class FileManager { 30 | public: 31 | FileManager() = default; 32 | virtual ~FileManager() = default; 33 | 34 | virtual bool SaveFile(const std::string &absolute_file_name, 35 | const std::string &content) = 0; 36 | 37 | virtual bool LoadFile(const std::string &absolute_file_name, 38 | std::string *buf) = 0; 39 | 40 | private: 41 | // Copying is not supported. 42 | FileManager(const FileManager &) = delete; 43 | FileManager &operator=(const FileManager &) = delete; 44 | }; 45 | 46 | } // namespace flatbuffers 47 | 48 | #endif // FLATBUFFERS_FILE_MANAGER_H_ 49 | -------------------------------------------------------------------------------- /examples/tasks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(PROJECT_NAME objectbox-examples-tasks) 4 | project(${PROJECT_NAME} CXX) 5 | add_executable(${PROJECT_NAME} 6 | main.cpp 7 | tasklist.obx.cpp 8 | ) 9 | 10 | set_target_properties(${PROJECT_NAME} PROPERTIES 11 | CXX_STANDARD 14 12 | CXX_STANDARD_REQUIRED YES 13 | ) 14 | 15 | if (NOT TARGET objectbox) # Using "if" in case a (potential) parent project already defined "objectbox" 16 | include(FetchContent) 17 | FetchContent_Declare( 18 | objectbox 19 | GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git 20 | GIT_TAG v5.0.0 # For latest versions, check https://github.com/objectbox/objectbox-c/releases 21 | ) 22 | FetchContent_MakeAvailable(objectbox) 23 | 24 | if ((WIN32 OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") 25 | AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64|ARM|AARCH64)") 26 | message(STATUS "Skipping ObjectBox Generator integration, which is not yet supported on this platform (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR})") 27 | else () 28 | find_package(ObjectBoxGenerator REQUIRED) 29 | add_obx_schema(TARGET ${PROJECT_NAME} SCHEMA_FILES tasklist.fbs INSOURCE) 30 | endif () 31 | endif () 32 | 33 | target_link_libraries(${PROJECT_NAME} objectbox) 34 | 35 | # Print the executable path after build, so user can run it easily 36 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 37 | COMMAND ${CMAKE_COMMAND} -E echo "Built executable at \"$\"" 38 | VERBATIM 39 | ) 40 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_flatbuffers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Even C11 compilers depend on clib support for `static_assert` which 3 | * isn't always present, so we deal with this here for all compilers. 4 | * 5 | * Outside include guard to handle scope counter. 6 | */ 7 | #include "flatcc/portable/pstatic_assert.h" 8 | 9 | #ifndef FLATCC_FLATBUFFERS_H 10 | #define FLATCC_FLATBUFFERS_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #ifndef flatcc_flatbuffers_defined 17 | #define flatcc_flatbuffers_defined 18 | 19 | #ifdef FLATCC_PORTABLE 20 | #include "flatcc/flatcc_portable.h" 21 | #endif 22 | #include "flatcc/portable/pwarnings.h" 23 | /* Needed by C99 compilers without FLATCC_PORTABLE. */ 24 | #include "flatcc/portable/pstdalign.h" 25 | 26 | /* Handle fallthrough attribute in switch statements. */ 27 | #include "flatcc/portable/pattributes.h" 28 | 29 | #include "flatcc/flatcc_alloc.h" 30 | #include "flatcc/flatcc_assert.h" 31 | 32 | #define __FLATBUFFERS_PASTE2(a, b) a ## b 33 | #define __FLATBUFFERS_PASTE3(a, b, c) a ## b ## c 34 | #define __FLATBUFFERS_CONCAT(a, b) __FLATBUFFERS_PASTE2(a, b) 35 | 36 | /* 37 | * "flatcc_endian.h" requires the preceeding include files, 38 | * or compatible definitions. 39 | */ 40 | #include "flatcc/portable/pendian.h" 41 | #include "flatcc/flatcc_types.h" 42 | #include "flatcc/flatcc_endian.h" 43 | #include "flatcc/flatcc_identifier.h" 44 | 45 | #ifndef FLATBUFFERS_WRAP_NAMESPACE 46 | #define FLATBUFFERS_WRAP_NAMESPACE(ns, x) ns ## _ ## x 47 | #endif 48 | 49 | #endif /* flatcc_flatbuffers_defined */ 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* FLATCC_FLATBUFFERS_H */ 56 | -------------------------------------------------------------------------------- /examples/tasks/tasklist.obx.hpp: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include "flatbuffers/flatbuffers.h" 9 | #include "objectbox.h" 10 | #include "objectbox.hpp" 11 | 12 | 13 | struct Task_; 14 | 15 | /// A task with a description, a creation and completion date. 16 | struct Task { 17 | obx_id id; 18 | std::string text; 19 | int64_t date_created; 20 | /// If not set (zero value), the task is not finished. 21 | int64_t date_finished; 22 | 23 | struct _OBX_MetaInfo { 24 | static constexpr obx_schema_id entityId() { return 1; } 25 | 26 | static void setObjectId(Task& object, obx_id newId) { object.id = newId; } 27 | 28 | /// Write given object to the FlatBufferBuilder 29 | static void toFlatBuffer(flatbuffers::FlatBufferBuilder& fbb, const Task& object); 30 | 31 | /// Read an object from a valid FlatBuffer 32 | static Task fromFlatBuffer(const void* data, size_t size); 33 | 34 | /// Read an object from a valid FlatBuffer 35 | static std::unique_ptr newFromFlatBuffer(const void* data, size_t size); 36 | 37 | /// Read an object from a valid FlatBuffer 38 | static void fromFlatBuffer(const void* data, size_t size, Task& outObject); 39 | }; 40 | }; 41 | 42 | struct Task_ { 43 | static const obx::Property id; 44 | static const obx::Property text; 45 | static const obx::Property date_created; 46 | static const obx::Property date_finished; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/city.obx.hpp: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include "flatbuffers/flatbuffers.h" 9 | #include "objectbox.h" 10 | #include "objectbox.hpp" 11 | 12 | 13 | struct City_; 14 | 15 | /// A city with a 2D location vector for vector search. 16 | struct City { 17 | obx_id id; 18 | std::string name; 19 | /// A 2D vector representing the city's location with latitude and longitude. 20 | /// Using the "Geo" distance type, which specializes in geospatial search (haversine distance). 21 | std::vector location; 22 | 23 | struct _OBX_MetaInfo { 24 | static constexpr obx_schema_id entityId() { return 1; } 25 | 26 | static void setObjectId(City& object, obx_id newId) { object.id = newId; } 27 | 28 | /// Write given object to the FlatBufferBuilder 29 | static void toFlatBuffer(flatbuffers::FlatBufferBuilder& fbb, const City& object); 30 | 31 | /// Read an object from a valid FlatBuffer 32 | static City fromFlatBuffer(const void* data, size_t size); 33 | 34 | /// Read an object from a valid FlatBuffer 35 | static std::unique_ptr newFromFlatBuffer(const void* data, size_t size); 36 | 37 | /// Read an object from a valid FlatBuffer 38 | static void fromFlatBuffer(const void* data, size_t size, City& outObject); 39 | }; 40 | }; 41 | 42 | struct City_ { 43 | static const obx::Property id; 44 | static const obx::Property name; 45 | static const obx::Property location; 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build:ubuntu18: 2 | stage: build 3 | tags: [x64, docker ] 4 | image: objectboxio/cbuild-ubuntu18.04:2023-08-23 # Uses non-default CMake 3.11 5 | script: 6 | - ./test.sh 7 | 8 | build:ubuntu20: 9 | extends: build:ubuntu18 10 | image: objectboxio/cbuild-ubuntu20.04:2023-08-23 11 | 12 | build:ubuntu24: 13 | extends: build:ubuntu18 14 | image: objectboxio/cbuild-ubuntu24.04:2025-09-30 15 | 16 | build:rocky8: 17 | extends: build:ubuntu18 18 | image: objectboxio/cbuild-rocky8:2023-08-23 19 | 20 | build:linux-aarch64: 21 | extends: build:ubuntu18 22 | tags: [ armv8, shell, linux ] 23 | image: null 24 | 25 | build:examples: 26 | stage: build 27 | tags: [x64, docker ] 28 | image: objectboxio/cbuild-ubuntu20.04:2023-08-23 # CMake 3.16; examples need at least CMake 3.14 29 | before_script: 30 | - apt-get update && apt-get install -y --no-install-recommends git 31 | script: 32 | - cd examples/c-tasks && ./build.sh 33 | - build/objectbox-examples-c-tasks "Buy raspberries" 34 | - build/objectbox-examples-c-tasks 35 | - cd ../c-tasks-lowlevel && ./build.sh 36 | - build/objectbox-examples-c-tasks-lowlevel "Buy blueberries" 37 | - build/objectbox-examples-c-tasks-lowlevel 38 | - cd ../tasks && ./build.sh 39 | - printf "new \"Buy apples\"\nls\nexit" | build/objectbox-examples-tasks 40 | - cd ../vectorsearch-cities && ./build.sh 41 | - printf "name berlin\nexit" | build/objectbox-examples-vectorsearch-cities 42 | 43 | build:examples-ubuntu24: 44 | extends: build:examples 45 | image: objectboxio/cbuild-ubuntu24.04:2025-09-30 46 | before_script: [] 47 | 48 | build:examples-linux-aarch64: 49 | extends: build:examples 50 | tags: [ armv8, shell, linux ] 51 | image: null 52 | -------------------------------------------------------------------------------- /external/flatbuffers/buffer_ref.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_BUFFER_REF_H_ 18 | #define FLATBUFFERS_BUFFER_REF_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/verifier.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // Convenient way to bundle a buffer and its length, to pass it around 26 | // typed by its root. 27 | // A BufferRef does not own its buffer. 28 | struct BufferRefBase {}; // for std::is_base_of 29 | 30 | template struct BufferRef : BufferRefBase { 31 | BufferRef() : buf(nullptr), len(0), must_free(false) {} 32 | BufferRef(uint8_t *_buf, uoffset_t _len) 33 | : buf(_buf), len(_len), must_free(false) {} 34 | 35 | ~BufferRef() { 36 | if (must_free) free(buf); 37 | } 38 | 39 | const T *GetRoot() const { return flatbuffers::GetRoot(buf); } 40 | 41 | bool Verify() { 42 | Verifier verifier(buf, len); 43 | return verifier.VerifyBuffer(nullptr); 44 | } 45 | 46 | uint8_t *buf; 47 | uoffset_t len; 48 | bool must_free; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_BUFFER_REF_H_ 54 | -------------------------------------------------------------------------------- /external/flatbuffers/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_STRUCT_H_ 18 | #define FLATBUFFERS_STRUCT_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // "structs" are flat structures that do not have an offset table, thus 25 | // always have all members present and do not support forwards/backwards 26 | // compatible extensions. 27 | 28 | class Struct FLATBUFFERS_FINAL_CLASS { 29 | public: 30 | template T GetField(uoffset_t o) const { 31 | return ReadScalar(&data_[o]); 32 | } 33 | 34 | template T GetStruct(uoffset_t o) const { 35 | return reinterpret_cast(&data_[o]); 36 | } 37 | 38 | const uint8_t *GetAddressOf(uoffset_t o) const { return &data_[o]; } 39 | uint8_t *GetAddressOf(uoffset_t o) { return &data_[o]; } 40 | 41 | private: 42 | // private constructor & copy constructor: you obtain instances of this 43 | // class by pointing to existing data only 44 | Struct(); 45 | Struct(const Struct &); 46 | Struct &operator=(const Struct &); 47 | 48 | uint8_t data_[1]; 49 | }; 50 | 51 | } // namespace flatbuffers 52 | 53 | #endif // FLATBUFFERS_STRUCT_H_ 54 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | set(PROJECT_NAME objectbox-examples-vectorsearch-cities) 4 | project(${PROJECT_NAME} CXX) 5 | add_executable(${PROJECT_NAME} 6 | main.cpp 7 | city.obx.cpp 8 | ) 9 | set_target_properties(${PROJECT_NAME} PROPERTIES 10 | CXX_STANDARD 14 11 | CXX_STANDARD_REQUIRED YES 12 | ) 13 | target_link_libraries(${PROJECT_NAME} objectbox) 14 | 15 | if (NOT TARGET objectbox) # Using "if" in case a (potential) parent project already defined "objectbox" 16 | include(FetchContent) 17 | FetchContent_Declare( 18 | objectbox 19 | GIT_REPOSITORY https://github.com/objectbox/objectbox-c.git 20 | GIT_TAG v5.0.0 # For latest versions, check https://github.com/objectbox/objectbox-c/releases 21 | ) 22 | FetchContent_MakeAvailable(objectbox) 23 | 24 | if ((WIN32 OR CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") 25 | AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64|ARM|AARCH64)") 26 | message(STATUS "Skipping ObjectBox Generator integration, which is not yet supported on this platform (${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR})") 27 | else () 28 | find_package(ObjectBoxGenerator REQUIRED) 29 | add_obx_schema(TARGET ${PROJECT_NAME} SCHEMA_FILES city.fbs INSOURCE) 30 | endif () 31 | endif () 32 | 33 | configure_file(cities.csv ${CMAKE_CURRENT_BINARY_DIR}/cities.csv COPYONLY) 34 | add_custom_target(copy_csv_file ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/cities.csv) 35 | add_dependencies(${PROJECT_NAME} copy_csv_file) 36 | 37 | # Print the executable path after build, so user can run it easily 38 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 39 | COMMAND ${CMAKE_COMMAND} -E echo "Built executable at \"$\"" 40 | VERBATIM 41 | ) 42 | -------------------------------------------------------------------------------- /external/flatcc/portable/pwarnings.h: -------------------------------------------------------------------------------- 1 | #ifndef PWARNINGS_H 2 | #define PWARNINGS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * See also pdiagnostics.h headers for per file control of common 10 | * warnings. 11 | * 12 | * This file is intended for global disabling of warnings that shouldn't 13 | * be present in C11 or perhaps C99, or a generally just noise where 14 | * recent clang / gcc compile cleanly with high warning levels. 15 | */ 16 | 17 | #if defined(_MSC_VER) 18 | /* Needed when flagging code in or out and more. */ 19 | #pragma warning(disable: 4127) /* conditional expression is constant */ 20 | /* happens also in MS's own headers. */ 21 | #pragma warning(disable: 4668) /* preprocessor name not defined */ 22 | /* MSVC does not respect double parenthesis for intent */ 23 | #pragma warning(disable: 4706) /* assignment within conditional expression */ 24 | /* `inline` only advisory anyway. */ 25 | #pragma warning(disable: 4710) /* function not inlined */ 26 | /* Well, we don't intend to add the padding manually. */ 27 | #pragma warning(disable: 4820) /* x bytes padding added in struct */ 28 | 29 | /* 30 | * Don't warn that fopen etc. are unsafe 31 | * 32 | * Define a compiler flag like `-D_CRT_SECURE_NO_WARNINGS` in the build. 33 | * For some reason it doesn't work when defined here. 34 | * 35 | * #define _CRT_SECURE_NO_WARNINGS 36 | */ 37 | 38 | /* 39 | * Anonymous union in struct is valid in C11 and has been supported in 40 | * GCC and Clang for a while, but it is not C99. MSVC also handles it, 41 | * but warns. Truly portable code should perhaps not use this feature, 42 | * but this is not the place to complain about it. 43 | */ 44 | #pragma warning(disable: 4201) /* nonstandard extension used: nameless struct/union */ 45 | 46 | #endif /* _MSV_VER */ 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* PWARNINGS_H */ 53 | -------------------------------------------------------------------------------- /examples/tasks/objectbox-model.h: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #ifdef __cplusplus 6 | #include 7 | #include 8 | extern "C" { 9 | #else 10 | #include 11 | #include 12 | #endif 13 | #include "objectbox.h" 14 | 15 | /// Initializes an ObjectBox model for all entities. 16 | /// The returned pointer may be NULL if the allocation failed. If the returned model is not NULL, you should check if 17 | /// any error occurred by calling obx_model_error_code() and/or obx_model_error_message(). If an error occurred, you're 18 | /// responsible for freeing the resources by calling obx_model_free(). 19 | /// In case there was no error when setting the model up (i.e. obx_model_error_code() returned 0), you may configure 20 | /// OBX_store_options with the model by calling obx_opt_model() and subsequently opening a store with obx_store_open(). 21 | /// As soon as you call obx_store_open(), the model pointer is consumed and MUST NOT be freed manually. 22 | static inline OBX_model* create_obx_model() { 23 | OBX_model* model = obx_model(); 24 | if (!model) return NULL; 25 | 26 | obx_model_entity(model, "Task", 1, 6645479796472661392); 27 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 9211738071025439652); 28 | obx_model_property_flags(model, OBXPropertyFlags_ID); 29 | obx_model_property(model, "text", OBXPropertyType_String, 2, 8804670454579230281); 30 | obx_model_property(model, "date_created", OBXPropertyType_Date, 4, 1260602348787983453); 31 | obx_model_property(model, "date_finished", OBXPropertyType_Date, 5, 6240065879507520219); 32 | obx_model_entity_last_property_id(model, 5, 6240065879507520219); 33 | 34 | obx_model_last_entity_id(model, 1, 6645479796472661392); 35 | return model; // NOTE: the returned model will contain error information if an error occurred. 36 | } 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/task_reader.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_READER_H 2 | #define TASK_READER_H 3 | 4 | /* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ 5 | 6 | #ifndef FLATBUFFERS_COMMON_READER_H 7 | #include "flatbuffers_common_reader.h" 8 | #endif 9 | #include "flatcc/flatcc_flatbuffers.h" 10 | #ifndef __alignas_is_defined 11 | #include 12 | #endif 13 | #include "flatcc/flatcc_prologue.h" 14 | #ifndef flatbuffers_identifier 15 | #define flatbuffers_identifier 0 16 | #endif 17 | #ifndef flatbuffers_extension 18 | #define flatbuffers_extension "bin" 19 | #endif 20 | 21 | 22 | typedef const struct Task_table *Task_table_t; 23 | typedef struct Task_table *Task_mutable_table_t; 24 | typedef const flatbuffers_uoffset_t *Task_vec_t; 25 | typedef flatbuffers_uoffset_t *Task_mutable_vec_t; 26 | #ifndef Task_file_identifier 27 | #define Task_file_identifier 0 28 | #endif 29 | /* deprecated, use Task_file_identifier */ 30 | #ifndef Task_identifier 31 | #define Task_identifier 0 32 | #endif 33 | #define Task_type_hash ((flatbuffers_thash_t)0x76ef3d8c) 34 | #define Task_type_identifier "\x8c\x3d\xef\x76" 35 | #ifndef Task_file_extension 36 | #define Task_file_extension "bin" 37 | #endif 38 | 39 | 40 | 41 | struct Task_table { uint8_t unused__; }; 42 | 43 | static inline size_t Task_vec_len(Task_vec_t vec) 44 | __flatbuffers_vec_len(vec) 45 | static inline Task_table_t Task_vec_at(Task_vec_t vec, size_t i) 46 | __flatbuffers_offset_vec_at(Task_table_t, vec, i, 0) 47 | __flatbuffers_table_as_root(Task) 48 | 49 | __flatbuffers_define_scalar_field(0, Task, id, flatbuffers_uint64, uint64_t, UINT64_C(0)) 50 | __flatbuffers_define_string_field(1, Task, text, 0) 51 | __flatbuffers_define_scalar_field(2, Task, date_created, flatbuffers_uint64, uint64_t, UINT64_C(0)) 52 | __flatbuffers_define_scalar_field(3, Task, date_finished, flatbuffers_uint64, uint64_t, UINT64_C(0)) 53 | 54 | 55 | #include "flatcc/flatcc_epilogue.h" 56 | #endif /* TASK_READER_H */ 57 | -------------------------------------------------------------------------------- /examples/tasks/tasklist.obx.cpp: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #include "tasklist.obx.hpp" 4 | 5 | const obx::Property Task_::id(1); 6 | const obx::Property Task_::text(2); 7 | const obx::Property Task_::date_created(4); 8 | const obx::Property Task_::date_finished(5); 9 | 10 | void Task::_OBX_MetaInfo::toFlatBuffer(flatbuffers::FlatBufferBuilder& fbb, const Task& object) { 11 | fbb.Clear(); 12 | auto offsettext = fbb.CreateString(object.text); 13 | flatbuffers::uoffset_t fbStart = fbb.StartTable(); 14 | fbb.AddElement(4, object.id); 15 | fbb.AddOffset(6, offsettext); 16 | fbb.AddElement(10, object.date_created); 17 | fbb.AddElement(12, object.date_finished); 18 | flatbuffers::Offset offset; 19 | offset.o = fbb.EndTable(fbStart); 20 | fbb.Finish(offset); 21 | } 22 | 23 | Task Task::_OBX_MetaInfo::fromFlatBuffer(const void* data, size_t size) { 24 | Task object; 25 | fromFlatBuffer(data, size, object); 26 | return object; 27 | } 28 | 29 | std::unique_ptr Task::_OBX_MetaInfo::newFromFlatBuffer(const void* data, size_t size) { 30 | auto object = std::make_unique(); 31 | fromFlatBuffer(data, size, *object); 32 | return object; 33 | } 34 | 35 | void Task::_OBX_MetaInfo::fromFlatBuffer(const void* data, size_t, Task& outObject) { 36 | const auto* table = flatbuffers::GetRoot(data); 37 | assert(table); 38 | outObject.id = table->GetField(4, 0); 39 | { 40 | auto* ptr = table->GetPointer(6); 41 | if (ptr) { 42 | outObject.text.assign(ptr->c_str(), ptr->size()); 43 | } else { 44 | outObject.text.clear(); 45 | } 46 | } 47 | outObject.date_created = table->GetField(10, 0); 48 | outObject.date_finished = table->GetField(12, 0); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /examples/c-tasks/objectbox-model.h: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #ifdef __cplusplus 6 | #include 7 | #include 8 | extern "C" { 9 | #else 10 | #include 11 | #include 12 | #endif 13 | #include "objectbox.h" 14 | 15 | /// Initializes an ObjectBox model for all entities. 16 | /// The returned pointer may be NULL if the allocation failed. If the returned model is not NULL, you should check if 17 | /// any error occurred by calling obx_model_error_code() and/or obx_model_error_message(). If an error occurred, you're 18 | /// responsible for freeing the resources by calling obx_model_free(). 19 | /// In case there was no error when setting the model up (i.e. obx_model_error_code() returned 0), you may configure 20 | /// OBX_store_options with the model by calling obx_opt_model() and subsequently opening a store with obx_store_open(). 21 | /// As soon as you call obx_store_open(), the model pointer is consumed and MUST NOT be freed manually. 22 | static inline OBX_model* create_obx_model() { 23 | OBX_model* model = obx_model(); 24 | if (!model) return NULL; 25 | 26 | obx_model_entity(model, "Task", 1, 1139978622395651407); 27 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 6052852175666615421); 28 | obx_model_property_flags(model, OBXPropertyFlags_ID); 29 | obx_model_property(model, "text", OBXPropertyType_String, 2, 2217803131116660471); 30 | obx_model_property(model, "date_created", OBXPropertyType_Date, 3, 7901967683818986922); 31 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 32 | obx_model_property(model, "date_finished", OBXPropertyType_Date, 4, 8036043269103161827); 33 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 34 | obx_model_entity_last_property_id(model, 4, 8036043269103161827); 35 | 36 | obx_model_last_entity_id(model, 1, 1139978622395651407); 37 | return model; // NOTE: the returned model will contain error information if an error occurred. 38 | } 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/city.obx.cpp: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #include "city.obx.hpp" 4 | 5 | const obx::Property City_::id(1); 6 | const obx::Property City_::name(2); 7 | const obx::Property City_::location(3); 8 | 9 | void City::_OBX_MetaInfo::toFlatBuffer(flatbuffers::FlatBufferBuilder& fbb, const City& object) { 10 | fbb.Clear(); 11 | auto offsetname = fbb.CreateString(object.name); 12 | auto offsetlocation = fbb.CreateVector(object.location); 13 | flatbuffers::uoffset_t fbStart = fbb.StartTable(); 14 | fbb.AddElement(4, object.id); 15 | fbb.AddOffset(6, offsetname); 16 | fbb.AddOffset(8, offsetlocation); 17 | flatbuffers::Offset offset; 18 | offset.o = fbb.EndTable(fbStart); 19 | fbb.Finish(offset); 20 | } 21 | 22 | City City::_OBX_MetaInfo::fromFlatBuffer(const void* data, size_t size) { 23 | City object; 24 | fromFlatBuffer(data, size, object); 25 | return object; 26 | } 27 | 28 | std::unique_ptr City::_OBX_MetaInfo::newFromFlatBuffer(const void* data, size_t size) { 29 | auto object = std::make_unique(); 30 | fromFlatBuffer(data, size, *object); 31 | return object; 32 | } 33 | 34 | void City::_OBX_MetaInfo::fromFlatBuffer(const void* data, size_t, City& outObject) { 35 | const auto* table = flatbuffers::GetRoot(data); 36 | assert(table); 37 | outObject.id = table->GetField(4, 0); 38 | { 39 | auto* ptr = table->GetPointer(6); 40 | if (ptr) { 41 | outObject.name.assign(ptr->c_str(), ptr->size()); 42 | } else { 43 | outObject.name.clear(); 44 | } 45 | } 46 | { 47 | auto* ptr = table->GetPointer*>(8); 48 | if (ptr) { 49 | outObject.location.assign(ptr->begin(), ptr->end()); 50 | } else { 51 | outObject.location.clear(); 52 | } 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /external/flatcc/portable/pstatic_assert.h: -------------------------------------------------------------------------------- 1 | #ifndef PSTATIC_ASSERT_H 2 | #define PSTATIC_ASSERT_H 3 | 4 | #include 5 | 6 | /* Handle clang */ 7 | #ifndef __has_feature 8 | #define __has_feature(x) 0 9 | #endif 10 | 11 | #if defined(static_assert) 12 | #ifndef __static_assert_is_defined 13 | #define __static_assert_is_defined 1 14 | #endif 15 | #endif 16 | 17 | /* Handle static_assert as a keyword in C++ and compiler specifics. */ 18 | #if !defined(__static_assert_is_defined) 19 | 20 | #if defined(__cplusplus) 21 | 22 | #if __cplusplus >= 201103L 23 | #define __static_assert_is_defined 1 24 | #elif __has_feature(cxx_static_assert) 25 | #define __static_assert_is_defined 1 26 | #elif defined(_MSC_VER) && (_MSC_VER >= 1600) 27 | #define __static_assert_is_defined 1 28 | #endif 29 | 30 | #else 31 | 32 | #if defined(_MSC_VER) && (_MSC_VER >= 1600) 33 | #define __static_assert_is_defined 1 34 | #elif __has_feature(c_static_assert) 35 | #define static_assert(pred, msg) _Static_assert(pred, msg) 36 | #define __static_assert_is_defined 1 37 | #elif defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) 38 | /* In case the clib headers are not compliant. */ 39 | #define static_assert(pred, msg) _Static_assert(pred, msg) 40 | #define __static_assert_is_defined 1 41 | #endif 42 | 43 | #endif /* __cplusplus */ 44 | #endif /* __static_assert_is_defined */ 45 | 46 | 47 | #if !defined(__static_assert_is_defined) 48 | 49 | #define __PSTATIC_ASSERT_CONCAT_(a, b) static_assert_scope_##a##_line_##b 50 | #define __PSTATIC_ASSERT_CONCAT(a, b) __PSTATIC_ASSERT_CONCAT_(a, b) 51 | #ifdef __COUNTER__ 52 | #define static_assert(e, msg) enum { __PSTATIC_ASSERT_CONCAT(__COUNTER__, __LINE__) = 1/(!!(e)) } 53 | #else 54 | #include "pstatic_assert_scope.h" 55 | #define static_assert(e, msg) enum { __PSTATIC_ASSERT_CONCAT(__PSTATIC_ASSERT_COUNTER, __LINE__) = 1/(int)(!!(e)) } 56 | #endif 57 | 58 | #define __static_assert_is_defined 1 59 | 60 | #endif /* __static_assert_is_defined */ 61 | 62 | #endif /* PSTATIC_ASSERT_H */ 63 | 64 | /* Update scope counter outside of include guard. */ 65 | #ifdef __PSTATIC_ASSERT_COUNTER 66 | #include "pstatic_assert_scope.h" 67 | #endif 68 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/objectbox-model.h: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #ifdef __cplusplus 6 | #include 7 | #include 8 | extern "C" { 9 | #else 10 | #include 11 | #include 12 | #endif 13 | #include "objectbox.h" 14 | 15 | /// Initializes an ObjectBox model for all entities. 16 | /// The returned pointer may be NULL if the allocation failed. If the returned model is not NULL, you should check if 17 | /// any error occurred by calling obx_model_error_code() and/or obx_model_error_message(). If an error occurred, you're 18 | /// responsible for freeing the resources by calling obx_model_free(). 19 | /// In case there was no error when setting the model up (i.e. obx_model_error_code() returned 0), you may configure 20 | /// OBX_store_options with the model by calling obx_opt_model() and subsequently opening a store with obx_store_open(). 21 | /// As soon as you call obx_store_open(), the model pointer is consumed and MUST NOT be freed manually. 22 | static inline OBX_model* create_obx_model() { 23 | OBX_model* model = obx_model(); 24 | if (!model) return NULL; 25 | 26 | obx_model_entity(model, "City", 1, 607353604830599953); 27 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 3289333370985535139); 28 | obx_model_property_flags(model, OBXPropertyFlags_ID); 29 | obx_model_property(model, "name", OBXPropertyType_String, 2, 8840693632700366740); 30 | obx_model_property(model, "location", OBXPropertyType_FloatVector, 3, 6028438376669885699); 31 | obx_model_property_flags(model, OBXPropertyFlags_INDEXED); 32 | obx_model_property_index_hnsw_dimensions(model, 2); 33 | obx_model_property_index_hnsw_distance_type(model, OBXVectorDistanceType_Geo); 34 | obx_model_property_index_id(model, 1, 4616869581890712534); 35 | obx_model_entity_last_property_id(model, 3, 6028438376669885699); 36 | 37 | obx_model_last_entity_id(model, 1, 607353604830599953); 38 | obx_model_last_index_id(model, 1, 4616869581890712534); 39 | return model; // NOTE: the returned model will contain error information if an error occurred. 40 | } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /doxygen/main-page.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | Introduction 4 | ============ 5 | [ObjectBox](https://objectbox.io/) is a fast database for data objects. 6 | 7 | Installation and examples 8 | ------------------------- 9 | See [Installation docs](https://cpp.objectbox.io/installation) and check the [project's GitHub repository](https://github.com/objectbox/objectbox-c) for additional info and examples including the usage of flatcc. 10 | 11 | Headers 12 | ------------- 13 | * ObjectBox C99 support is provided by a single header file: **objectbox.h** 14 | * ObjectBox C++11 support is available in an additional header: **objectbox.hpp** 15 | 16 | Basic concepts 17 | -------------- 18 | * Objects are the entities persisted in the database 19 | * Objects are [FlatBuffers](https://google.github.io/flatbuffers/) 20 | * Objects are "grouped" by their type; e.g. there is a Box (or "Cursor") for each type 21 | * Objects are addressed using a 64 bit integer ID (`obx_id`) 22 | * There is no query language; queries are build using a [query builder](\ref OBX_query_builder) 23 | * Objects are stored on disk by default (ACID), or in-memory ("memory:" directory prefix) 24 | 25 | See [docs](https://cpp.objectbox.io) for more information on how to use ObjectBox in C and C++ 26 | 27 | API Naming conventions 28 | ---------------------- 29 | * C methods: obx_thing_action() 30 | * C structs: OBX_thing {} 31 | * C error codes: OBX_ERROR_REASON 32 | * C++ namespace: obx:: 33 | 34 | Essential types 35 | ----------------- 36 | Check the docs for the following types: 37 | 38 | * [OBX_store](\ref OBX_store) and [obx::Store](\ref obx::Store): the "database"; "opens" data files in a given directory 39 | * [OBX_box](\ref OBX_box) and [obx::Box](\ref obx::Box): object operations like put and get 40 | * [OBX_query_builder](\ref OBX_query_builder) and [obx::QueryBuilder](\ref obx::QueryBuilder): used to construct queries using "query conditions" 41 | * [OBX_query](\ref OBX_query) and [obx::Query](\ref obx::Query): the product of a query builder can be executed to find objects matching the previously defined conditions 42 | 43 | Essential Links/Readings 44 | ------------------------ 45 | * High-level docs and examples: https://cpp.objectbox.io 46 | * Entity (object) IDs: https://docs.objectbox.io/advanced/object-ids 47 | * Meta model and UIDs: https://docs.objectbox.io/advanced/meta-model-ids-and-uids 48 | -------------------------------------------------------------------------------- /examples/tasks/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2020 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define OBX_CPP_FILE // this "materializes" implementations from objectbox.hpp 18 | 19 | #include "TasklistCmdlineApp.hpp" 20 | 21 | int processArgs(int argc, char* argv[], obx::Options& outOptions) { 22 | // Remember, argv[0] is application path 23 | 24 | const char* directory = nullptr; 25 | if (argc == 2) { 26 | directory = argv[1]; 27 | } else if (argc == 3) { 28 | std::string paramName = argv[1]; 29 | if (paramName == "-d" || paramName == "--directory") { 30 | directory = argv[2]; 31 | } else { 32 | std::cerr << "Unknown argument " << paramName << ". Expected -d or --directory." << std::endl; 33 | return 1; 34 | } 35 | } else if (argc > 3) { 36 | std::cerr << "This app only takes zero, one or two arguments" << std::endl; 37 | return 1; 38 | } 39 | 40 | if (directory) { 41 | outOptions.directory(directory); 42 | std::cout << "Using DB directory " << directory << std::endl; 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | int main(int argc, char* argv[]) { 49 | std::cout << "** ObjectBox database (https://objectbox.io/) C++ example (tasks). **\n" 50 | "C++ docs: https://cpp.objectbox.io/\n" 51 | << std::endl; 52 | 53 | // create_obx_model() provided by objectbox-model.h 54 | // obx interface contents provided by objectbox.hpp 55 | obx::Options options(create_obx_model()); 56 | 57 | if (int err = processArgs(argc, argv, options)) { 58 | return err; 59 | } 60 | 61 | obx::Store store(options); 62 | TasklistCmdlineApp app(store); 63 | return app.run(); 64 | } -------------------------------------------------------------------------------- /src-test/c_test_reader.h: -------------------------------------------------------------------------------- 1 | #ifndef C_TEST_READER_H 2 | #define C_TEST_READER_H 3 | 4 | /* Generated by flatcc 0.5.2 FlatBuffers schema compiler for C by dvide.com */ 5 | 6 | #ifndef FLATBUFFERS_COMMON_READER_H 7 | #include "flatbuffers_common_reader.h" 8 | #endif 9 | #include "flatcc/flatcc_flatbuffers.h" 10 | #ifndef __alignas_is_defined 11 | #include 12 | #endif 13 | #include "flatcc/flatcc_prologue.h" 14 | #ifndef flatbuffers_identifier 15 | #define flatbuffers_identifier 0 16 | #endif 17 | #ifndef flatbuffers_extension 18 | #define flatbuffers_extension ".bin" 19 | #endif 20 | 21 | 22 | typedef const struct Foo_table *Foo_table_t; 23 | typedef const flatbuffers_uoffset_t *Foo_vec_t; 24 | typedef flatbuffers_uoffset_t *Foo_mutable_vec_t; 25 | typedef const struct Bar_table *Bar_table_t; 26 | typedef const flatbuffers_uoffset_t *Bar_vec_t; 27 | typedef flatbuffers_uoffset_t *Bar_mutable_vec_t; 28 | #ifndef Foo_identifier 29 | #define Foo_identifier flatbuffers_identifier 30 | #endif 31 | #define Foo_type_hash ((flatbuffers_thash_t)0xc7e1677) 32 | #define Foo_type_identifier "\x77\x16\x7e\x0c" 33 | #ifndef Bar_identifier 34 | #define Bar_identifier flatbuffers_identifier 35 | #endif 36 | #define Bar_type_hash ((flatbuffers_thash_t)0xdbbc7dba) 37 | #define Bar_type_identifier "\xba\x7d\xbc\xdb" 38 | 39 | 40 | 41 | struct Foo_table { uint8_t unused__; }; 42 | 43 | static inline size_t Foo_vec_len(Foo_vec_t vec) 44 | __flatbuffers_vec_len(vec) 45 | static inline Foo_table_t Foo_vec_at(Foo_vec_t vec, size_t i) 46 | __flatbuffers_offset_vec_at(Foo_table_t, vec, i, 0) 47 | __flatbuffers_table_as_root(Foo) 48 | 49 | __flatbuffers_define_scalar_field(0, Foo, id, flatbuffers_uint64, uint64_t, UINT64_C(0)) 50 | __flatbuffers_define_string_field(1, Foo, text, 0) 51 | 52 | struct Bar_table { uint8_t unused__; }; 53 | 54 | static inline size_t Bar_vec_len(Bar_vec_t vec) 55 | __flatbuffers_vec_len(vec) 56 | static inline Bar_table_t Bar_vec_at(Bar_vec_t vec, size_t i) 57 | __flatbuffers_offset_vec_at(Bar_table_t, vec, i, 0) 58 | __flatbuffers_table_as_root(Bar) 59 | 60 | __flatbuffers_define_scalar_field(0, Bar, id, flatbuffers_uint64, uint64_t, UINT64_C(0)) 61 | __flatbuffers_define_string_field(1, Bar, text, 0) 62 | __flatbuffers_define_scalar_field(2, Bar, fooId, flatbuffers_uint64, uint64_t, UINT64_C(0)) 63 | 64 | #include "flatcc/flatcc_epilogue.h" 65 | #endif /* C_TEST_READER_H */ 66 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/task_builder.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_BUILDER_H 2 | #define TASK_BUILDER_H 3 | 4 | /* Generated by flatcc 0.6.2 FlatBuffers schema compiler for C by dvide.com */ 5 | 6 | #ifndef TASK_READER_H 7 | #include "task_reader.h" 8 | #endif 9 | #ifndef FLATBUFFERS_COMMON_BUILDER_H 10 | #include "flatbuffers_common_builder.h" 11 | #endif 12 | #include "flatcc/flatcc_prologue.h" 13 | #ifndef flatbuffers_identifier 14 | #define flatbuffers_identifier 0 15 | #endif 16 | #ifndef flatbuffers_extension 17 | #define flatbuffers_extension "bin" 18 | #endif 19 | 20 | static const flatbuffers_voffset_t __Task_required[] = { 0 }; 21 | typedef flatbuffers_ref_t Task_ref_t; 22 | static Task_ref_t Task_clone(flatbuffers_builder_t *B, Task_table_t t); 23 | __flatbuffers_build_table(flatbuffers_, Task, 4) 24 | 25 | #define __Task_formal_args , uint64_t v0, flatbuffers_string_ref_t v1, uint64_t v2, uint64_t v3 26 | #define __Task_call_args , v0, v1, v2, v3 27 | static inline Task_ref_t Task_create(flatbuffers_builder_t *B __Task_formal_args); 28 | __flatbuffers_build_table_prolog(flatbuffers_, Task, Task_file_identifier, Task_type_identifier) 29 | 30 | __flatbuffers_build_scalar_field(0, flatbuffers_, Task_id, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Task) 31 | __flatbuffers_build_string_field(1, flatbuffers_, Task_text, Task) 32 | __flatbuffers_build_scalar_field(2, flatbuffers_, Task_date_created, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Task) 33 | __flatbuffers_build_scalar_field(3, flatbuffers_, Task_date_finished, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Task) 34 | 35 | static inline Task_ref_t Task_create(flatbuffers_builder_t *B __Task_formal_args) 36 | { 37 | if (Task_start(B) 38 | || Task_id_add(B, v0) 39 | || Task_date_created_add(B, v2) 40 | || Task_date_finished_add(B, v3) 41 | || Task_text_add(B, v1)) { 42 | return 0; 43 | } 44 | return Task_end(B); 45 | } 46 | 47 | static Task_ref_t Task_clone(flatbuffers_builder_t *B, Task_table_t t) 48 | { 49 | __flatbuffers_memoize_begin(B, t); 50 | if (Task_start(B) 51 | || Task_id_pick(B, t) 52 | || Task_date_created_pick(B, t) 53 | || Task_date_finished_pick(B, t) 54 | || Task_text_pick(B, t)) { 55 | return 0; 56 | } 57 | __flatbuffers_memoize_end(B, t, Task_end(B)); 58 | } 59 | 60 | #include "flatcc/flatcc_epilogue.h" 61 | #endif /* TASK_BUILDER_H */ 62 | -------------------------------------------------------------------------------- /external/flatcc/support/elapsed.h: -------------------------------------------------------------------------------- 1 | #ifndef ELAPSED_H 2 | #define ELAPSED_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | /* Based on http://stackoverflow.com/a/8583395 */ 11 | #if !defined(_WIN32) 12 | #include 13 | static double elapsed_realtime(void) { // returns 0 seconds first time called 14 | static struct timeval t0; 15 | struct timeval tv; 16 | gettimeofday(&tv, 0); 17 | if (!t0.tv_sec) 18 | t0 = tv; 19 | return (double)(tv.tv_sec - t0.tv_sec) + (double)(tv.tv_usec - t0.tv_usec) / 1e6; 20 | } 21 | #else 22 | #include 23 | #ifndef FatalError 24 | #define FatalError(s) do { perror(s); exit(-1); } while(0) 25 | #endif 26 | static double elapsed_realtime(void) { // granularity about 50 microsecs on my machine 27 | static LARGE_INTEGER freq, start; 28 | LARGE_INTEGER count; 29 | if (!QueryPerformanceCounter(&count)) 30 | FatalError("QueryPerformanceCounter"); 31 | if (!freq.QuadPart) { // one time initialization 32 | if (!QueryPerformanceFrequency(&freq)) 33 | FatalError("QueryPerformanceFrequency"); 34 | start = count; 35 | } 36 | return (double)(count.QuadPart - start.QuadPart) / freq.QuadPart; 37 | } 38 | #endif 39 | 40 | /* end Based on stackoverflow */ 41 | 42 | static int show_benchmark(const char *descr, double t1, double t2, size_t size, int rep, const char *reptext) 43 | { 44 | double tdiff = t2 - t1; 45 | double nstime; 46 | 47 | printf("operation: %s\n", descr); 48 | printf("elapsed time: %.3f (s)\n", tdiff); 49 | printf("iterations: %d\n", rep); 50 | printf("size: %lu (bytes)\n", (unsigned long)size); 51 | printf("bandwidth: %.3f (MB/s)\n", (double)rep * (double)size / 1e6 / tdiff); 52 | printf("throughput in ops per sec: %.3f\n", rep / tdiff); 53 | if (reptext && rep != 1) { 54 | printf("throughput in %s ops per sec: %.3f\n", reptext, 1 / tdiff); 55 | } 56 | nstime = tdiff * 1e9 / rep; 57 | if (nstime < 1000) { 58 | printf("time per op: %.3f (ns)\n", nstime); 59 | } else if (nstime < 1e6) { 60 | printf("time per op: %.3f (us)\n", nstime / 1000); 61 | } else if (nstime < 1e9) { 62 | printf("time per op: %.3f (ms)\n", nstime / 1e6); 63 | } else { 64 | printf("time per op: %.3f (s)\n", nstime / 1e9); 65 | } 66 | return 0; 67 | } 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* ELAPSED_H */ 74 | -------------------------------------------------------------------------------- /external/flatbuffers/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_STRING_H_ 18 | #define FLATBUFFERS_STRING_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/vector.h" 22 | 23 | namespace flatbuffers { 24 | 25 | struct String : public Vector { 26 | const char *c_str() const { return reinterpret_cast(Data()); } 27 | std::string str() const { return std::string(c_str(), size()); } 28 | 29 | // clang-format off 30 | #ifdef FLATBUFFERS_HAS_STRING_VIEW 31 | flatbuffers::string_view string_view() const { 32 | return flatbuffers::string_view(c_str(), size()); 33 | } 34 | 35 | /* implicit */ 36 | operator flatbuffers::string_view() const { 37 | return flatbuffers::string_view(c_str(), size()); 38 | } 39 | #endif // FLATBUFFERS_HAS_STRING_VIEW 40 | // clang-format on 41 | 42 | bool operator<(const String &o) const { 43 | return StringLessThan(this->data(), this->size(), o.data(), o.size()); 44 | } 45 | }; 46 | 47 | // Convenience function to get std::string from a String returning an empty 48 | // string on null pointer. 49 | static inline std::string GetString(const String *str) { 50 | return str ? str->str() : ""; 51 | } 52 | 53 | // Convenience function to get char* from a String returning an empty string on 54 | // null pointer. 55 | static inline const char *GetCstring(const String *str) { 56 | return str ? str->c_str() : ""; 57 | } 58 | 59 | #ifdef FLATBUFFERS_HAS_STRING_VIEW 60 | // Convenience function to get string_view from a String returning an empty 61 | // string_view on null pointer. 62 | static inline flatbuffers::string_view GetStringView(const String *str) { 63 | return str ? str->string_view() : flatbuffers::string_view(); 64 | } 65 | #endif // FLATBUFFERS_HAS_STRING_VIEW 66 | 67 | } // namespace flatbuffers 68 | 69 | #endif // FLATBUFFERS_STRING_H_ 70 | -------------------------------------------------------------------------------- /external/flatbuffers/default_allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 18 | #define FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 19 | 20 | #include "flatbuffers/allocator.h" 21 | #include "flatbuffers/base.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // DefaultAllocator uses new/delete to allocate memory regions 26 | class DefaultAllocator : public Allocator { 27 | public: 28 | uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE { 29 | return new uint8_t[size]; 30 | } 31 | 32 | void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE { delete[] p; } 33 | 34 | static void dealloc(void *p, size_t) { delete[] static_cast(p); } 35 | }; 36 | 37 | // These functions allow for a null allocator to mean use the default allocator, 38 | // as used by DetachedBuffer and vector_downward below. 39 | // This is to avoid having a statically or dynamically allocated default 40 | // allocator, or having to move it between the classes that may own it. 41 | inline uint8_t *Allocate(Allocator *allocator, size_t size) { 42 | return allocator ? allocator->allocate(size) 43 | : DefaultAllocator().allocate(size); 44 | } 45 | 46 | inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) { 47 | if (allocator) 48 | allocator->deallocate(p, size); 49 | else 50 | DefaultAllocator().deallocate(p, size); 51 | } 52 | 53 | inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p, 54 | size_t old_size, size_t new_size, 55 | size_t in_use_back, size_t in_use_front) { 56 | return allocator ? allocator->reallocate_downward(old_p, old_size, new_size, 57 | in_use_back, in_use_front) 58 | : DefaultAllocator().reallocate_downward( 59 | old_p, old_size, new_size, in_use_back, in_use_front); 60 | } 61 | 62 | } // namespace flatbuffers 63 | 64 | #endif // FLATBUFFERS_DEFAULT_ALLOCATOR_H_ 65 | -------------------------------------------------------------------------------- /external/flatcc/portable/pattributes.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * C23 introduces an attribute syntax `[[]]`. Prior to that 4 | * other non-standard syntaxes such as `__attribute__(())` 5 | * and `__declspec()` have been supported by some compiler 6 | * versions. 7 | * 8 | * See also: 9 | * https://en.cppreference.com/w/c/language/attributes 10 | * 11 | * There is no portable way to use C23 attributes in older C standards 12 | * so in order to use these portably, some macro name needs to be 13 | * defined for each attribute that either maps to the older supported 14 | * syntax, or ignores the attribute as appropriate. 15 | * 16 | * The Linux kernel defines certain attributes as macros, such as 17 | * `fallthrough`. When adding attributes it seems reasonable to follow 18 | * the Linux conventions in lack of any official standard. However, it 19 | * is not the intention that this file should mirror the Linux 20 | * attributes 1 to 1. 21 | * 22 | * See also: 23 | * https://github.com/torvalds/linux/blob/master/include/linux/compiler_attributes.h 24 | * 25 | * There is a risk that exposed attribute names may lead to name 26 | * conflicts. A conflicting name can be undefined and if necessary used 27 | * using `pattribute()`. All attributes can be hidden by 28 | * defining `PORTABLE_EXPOSE_ATTRIBUTES=0` in which case 29 | * `pattribute()` can still be used and then if a specific 30 | * attribute name still needs to be exposed, it can be defined manually 31 | * like `#define fallthrough pattribute(fallthrough)`. 32 | */ 33 | 34 | 35 | #ifndef PATTRIBUTES_H 36 | #define PATTRIBUTES_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #ifndef PORTABLE_EXPOSE_ATTRIBUTES 43 | #define PORTABLE_EXPOSE_ATTRIBUTES 0 44 | #endif 45 | 46 | #ifdef __has_c_attribute 47 | # define PORTABLE_HAS_C_ATTRIBUTE(x) __has_c_attribute(x) 48 | #else 49 | # define PORTABLE_HAS_C_ATTRIBUTE(x) 0 50 | #endif 51 | 52 | #ifdef __has_attribute 53 | # define PORTABLE_HAS_ATTRIBUTE(x) __has_attribute(x) 54 | #else 55 | # define PORTABLE_HAS_ATTRIBUTE(x) 0 56 | #endif 57 | 58 | 59 | /* https://en.cppreference.com/w/c/language/attributes/fallthrough */ 60 | #if PORTABLE_HAS_C_ATTRIBUTE(__fallthrough__) 61 | # define pattribute_fallthrough [[__fallthrough__]] 62 | #elif PORTABLE_HAS_ATTRIBUTE(__fallthrough__) 63 | # define pattribute_fallthrough __attribute__((__fallthrough__)) 64 | #else 65 | # define pattribute_fallthrough ((void)0) 66 | #endif 67 | 68 | 69 | #define pattribute(x) pattribute_##x 70 | 71 | #if PORTABLE_EXPOSE_ATTRIBUTES 72 | 73 | #ifndef fallthrough 74 | # define fallthrough pattribute(fallthrough) 75 | #endif 76 | 77 | #endif 78 | 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* PATTRIBUTES_H */ 85 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2024 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #define OBX_CPP_FILE // this "materializes" implementations from objectbox.hpp 18 | 19 | #include "VectorSearchCitiesApp.hpp" 20 | #include "objectbox.hpp" 21 | 22 | using namespace obx; 23 | 24 | int processArgs(int argc, char* argv[], obx::Options& outOptions) { 25 | // Remember, argv[0] is application path 26 | 27 | const char* directory = nullptr; 28 | if (argc == 2) { 29 | directory = argv[1]; 30 | } else if (argc == 3) { 31 | std::string paramName = argv[1]; 32 | if (paramName == "-d" || paramName == "--directory") { 33 | directory = argv[2]; 34 | } else { 35 | std::cerr << "Unknown argument " << paramName << ". Expected -d or --directory." << std::endl; 36 | return 1; 37 | } 38 | } else if (argc > 3) { 39 | std::cerr << "This app only takes zero, one or two arguments" << std::endl; 40 | return 1; 41 | } 42 | 43 | if (directory) { 44 | outOptions.directory(directory); 45 | std::cout << "Using DB directory " << directory << std::endl; 46 | } 47 | 48 | return 0; 49 | } 50 | 51 | int main(int argc, char* argv[]) { 52 | std::cout << "** ObjectBox database (https://objectbox.io/) C++ vector search example (cities). **\n" 53 | "C++ docs: https://cpp.objectbox.io/ | https://docs.objectbox.io/on-device-vector-search\n" 54 | << std::endl; 55 | 56 | if (!obx_has_feature(OBXFeature_VectorSearch)) { 57 | std::cerr << "Vector search is not supported in this edition.\n" 58 | "Please ensure to get ObjectBox with vector search enabled." 59 | << std::endl; 60 | return 1; 61 | } 62 | 63 | // Hint: create_obx_model() is provided by objectbox-model.h, which is a (pre)generated source file 64 | Options options(create_obx_model()); 65 | 66 | if (int err = processArgs(argc, argv, options)) { 67 | return err; 68 | } 69 | 70 | Store store(options); 71 | VectorSearchCitiesApp app(store); 72 | app.checkImportData(); 73 | return app.run(); 74 | } 75 | -------------------------------------------------------------------------------- /external/flatbuffers/allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_ALLOCATOR_H_ 18 | #define FLATBUFFERS_ALLOCATOR_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | 22 | namespace flatbuffers { 23 | 24 | // Allocator interface. This is flatbuffers-specific and meant only for 25 | // `vector_downward` usage. 26 | class Allocator { 27 | public: 28 | virtual ~Allocator() {} 29 | 30 | // Allocate `size` bytes of memory. 31 | virtual uint8_t *allocate(size_t size) = 0; 32 | 33 | // Deallocate `size` bytes of memory at `p` allocated by this allocator. 34 | virtual void deallocate(uint8_t *p, size_t size) = 0; 35 | 36 | // Reallocate `new_size` bytes of memory, replacing the old region of size 37 | // `old_size` at `p`. In contrast to a normal realloc, this grows downwards, 38 | // and is intended specifcally for `vector_downward` use. 39 | // `in_use_back` and `in_use_front` indicate how much of `old_size` is 40 | // actually in use at each end, and needs to be copied. 41 | virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, 42 | size_t new_size, size_t in_use_back, 43 | size_t in_use_front) { 44 | FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows 45 | uint8_t *new_p = allocate(new_size); 46 | memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, 47 | in_use_front); 48 | deallocate(old_p, old_size); 49 | return new_p; 50 | } 51 | 52 | protected: 53 | // Called by `reallocate_downward` to copy memory from `old_p` of `old_size` 54 | // to `new_p` of `new_size`. Only memory of size `in_use_front` and 55 | // `in_use_back` will be copied from the front and back of the old memory 56 | // allocation. 57 | void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p, 58 | size_t new_size, size_t in_use_back, 59 | size_t in_use_front) { 60 | memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back, 61 | in_use_back); 62 | memcpy(new_p, old_p, in_use_front); 63 | } 64 | }; 65 | 66 | } // namespace flatbuffers 67 | 68 | #endif // FLATBUFFERS_ALLOCATOR_H_ 69 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | ObjectBox C and C++ examples 2 | ============================ 3 | 4 | These are examples for ObjectBox C and C++. 5 | 6 | Each example is self-contained in its own subdirectory and can be built using CMake. 7 | For convenience, a `build.sh` script is provided in each example directory, 8 | which puts all build files into a separate directory ("build/"). 9 | See the [build and run](#build-and-run) section below for details. 10 | 11 | ## Tasks Examples 12 | 13 | There are four examples console applications that implement a simple task list. 14 | Tasks can be added, viewed, and marked as finished to demonstrate typical ObjectBox database operations. 15 | 16 | The examples for C++ are: 17 | 18 | - `tasks`: C++ application 19 | - `tasks-sync`: C++ application with sync enabled (requires a ObjectBox Sync server) 20 | 21 | The examples for C are: 22 | 23 | - `c-tasks`: C application 24 | - `c-tasks-lowlevel`: C application, but with lesser used lower-level APIs; not the best to start with 25 | 26 | ## Vector Search Example 27 | 28 | There's a C++ example for vector search in the [vectorsearch-cities](vectorsearch-cities/README.md) directory. 29 | 30 | ## Build and run 31 | 32 | Prerequisites are CMake 3.14+ and a C/C++ compiler. 33 | All examples follow the same setup, and thus we document it only once here. 34 | 35 | ### Build with the provided shell script 36 | 37 | This is the simplest way on Linux and macOS from the command line. 38 | 39 | * Typically, you `cd` into an example directory and run `./build.sh` (each example has its own `build.sh`). 40 | * Once the build is done, you can run the example: the executable is in the `build/` directory and its path is printed to the console during the build. 41 | * Run `./build.sh run` to build and run the example in one step. 42 | * The `./build.sh` also accepts `--clean` as the first argument to clear the build directory before building. 43 | 44 | ### Build within IDEs (CMake) 45 | 46 | If you work with a IDE, you can typically just open each example as a CMake project. 47 | The IDE will setup everything for you. 48 | 49 | ### Build with CMake 50 | 51 | If you prefer to use CMake directly (e.g. on a Windows terminal), you can do so as follows: 52 | 53 | ``` 54 | cmake -S . -B build 55 | cmake --build build 56 | ``` 57 | 58 | And then run the built executable: 59 | 60 | ``` 61 | build/objectbox-examples-... # replace ... with the example name 62 | ``` 63 | 64 | ## Next steps 65 | 66 | If you want, you can copy an example as a starting point for your own project. 67 | Pick the directory of the example that fits best for your needs. 68 | 69 | Links and documentation: 70 | 71 | * [ObjectBox homepage](https://objectbox.io/) 72 | * [ObjectBox C and C++ docs](https://cpp.objectbox.io/) 73 | * [ObjectBox Sync docs](https://sync.objectbox.io/) 74 | * [ObjectBox vector search docs](https://docs.objectbox.io/on-device-vector-search) 75 | 76 | -------------------------------------------------------------------------------- /external/flatcc/portable/pdiagnostic.h: -------------------------------------------------------------------------------- 1 | /* There is intentionally no include guard in this file. */ 2 | 3 | 4 | /* 5 | * Usage: optionally disable any of these before including. 6 | * 7 | * #define PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION 8 | * #define PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE 9 | * #define PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER 10 | * #define PDIAGNOSTIC_IGNORE_UNUSED // all of the above 11 | * 12 | * #include "pdiagnostic.h" 13 | * 14 | * Alternatively use #include "pdiagnostic_push/pop.h" 15 | */ 16 | 17 | #ifdef _MSC_VER 18 | #pragma warning(disable: 4668) /* preprocessor name not defined */ 19 | #endif 20 | 21 | #if !defined(PDIAGNOSTIC_AWARE_MSVC) && defined(_MSC_VER) 22 | #define PDIAGNOSTIC_AWARE_MSVC 1 23 | #elif !defined(PDIAGNOSTIC_AWARE_MSVC) 24 | #define PDIAGNOSTIC_AWARE_MSVC 0 25 | #endif 26 | 27 | #if !defined(PDIAGNOSTIC_AWARE_CLANG) && defined(__clang__) 28 | #define PDIAGNOSTIC_AWARE_CLANG 1 29 | #elif !defined(PDIAGNOSTIC_AWARE_CLANG) 30 | #define PDIAGNOSTIC_AWARE_CLANG 0 31 | #endif 32 | 33 | #if !defined(PDIAGNOSTIC_AWARE_GCC) && defined(__GNUC__) && !defined(__clang__) 34 | /* Can disable some warnings even if push is not available (gcc-4.2 vs gcc-4.7) */ 35 | #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) 36 | #define PDIAGNOSTIC_AWARE_GCC 1 37 | #endif 38 | #endif 39 | 40 | #if !defined(PDIAGNOSTIC_AWARE_GCC) 41 | #define PDIAGNOSTIC_AWARE_GCC 0 42 | #endif 43 | 44 | #if defined(PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION) || defined(PDIAGNOSTIC_IGNORE_UNUSED) 45 | #if PDIAGNOSTIC_AWARE_CLANG 46 | #pragma clang diagnostic ignored "-Wunused-function" 47 | #elif PDIAGNOSTIC_AWARE_GCC 48 | #pragma GCC diagnostic ignored "-Wunused-function" 49 | #endif 50 | #endif 51 | #undef PDIAGNOSTIC_IGNORE_UNUSED_FUNCTION 52 | 53 | #if defined(PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE) || defined(PDIAGNOSTIC_IGNORE_UNUSED) 54 | #if PDIAGNOSTIC_AWARE_MSVC 55 | #pragma warning(disable: 4101) /* unused local variable */ 56 | #elif PDIAGNOSTIC_AWARE_CLANG 57 | #pragma clang diagnostic ignored "-Wunused-variable" 58 | #elif PDIAGNOSTIC_AWARE_GCC 59 | #pragma GCC diagnostic ignored "-Wunused-variable" 60 | #endif 61 | #endif 62 | #undef PDIAGNOSTIC_IGNORE_UNUSED_VARIABLE 63 | 64 | #if defined(PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER) || defined(PDIAGNOSTIC_IGNORE_UNUSED) 65 | #if PDIAGNOSTIC_AWARE_CLANG 66 | #pragma clang diagnostic ignored "-Wunused-parameter" 67 | #elif PDIAGNOSTIC_AWARE_GCC 68 | #pragma GCC diagnostic ignored "-Wunused-parameter" 69 | #endif 70 | #endif 71 | #undef PDIAGNOSTIC_IGNORE_UNUSED_PARAMETER 72 | 73 | #undef PDIAGNOSTIC_IGNORE_UNUSED 74 | 75 | #if defined (__cplusplus) && __cplusplus < 201103L 76 | #if PDIAGNOSTIC_AWARE_CLANG 77 | /* Needed for < C++11 clang C++ static_assert */ 78 | #pragma clang diagnostic ignored "-Wc11-extensions" 79 | /* Needed for empty macro arguments. */ 80 | #pragma clang diagnostic ignored "-Wc99-extensions" 81 | /* Needed for trailing commas. */ 82 | #pragma clang diagnostic ignored "-Wc++11-extensions" 83 | #endif 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /external/flatcc/portable/README.md: -------------------------------------------------------------------------------- 1 | A small library for adding C11 compatibility to older C compilers, but 2 | only a small highly useful subset such as static assertions, inline 3 | functions and alignment. 4 | 5 | C++ is not a primary target, but the library has been updated to be more 6 | C++ friendly based on user feedback. 7 | 8 | Many compilers already have the required functionality but with slightly 9 | different names and arguments. 10 | 11 | In addition, compatibility with the Linux `` system file is 12 | provided, and "punaligned.h" is provided for unaligned memory reads 13 | which in part depends on endian support. 14 | 15 | The library also provides fast integer printing and floating point 16 | printing and parsing optionally using the grisu3 algorithm, but can fall 17 | back to strtod and related. The `pgrisu3` folder is header only and 18 | excludes test cases found in the main grisu3 project the files were 19 | extracted from. Base64 conversion is also provided. 20 | 21 | Integer conversion is not just an optimization. It is more difficult 22 | than it would appear to portably parse an integer of known size such as 23 | `uint64_t` up to at most n bytes which is needed for safe parsing. At 24 | the same time, the sometimes significant performance gains warrants 25 | custom implementations that might as well be done once and for all. 26 | 27 | Files can be included individually, or portable.h may be included to get 28 | all functionality. If the compiler is C11 compliant, portable.h will not 29 | include anything, except: it will provide a patch for static assertions 30 | which clang does not fully support in all versions even with C11 flagged. 31 | 32 | The grisu3 header files are the runtime files for the Grisu3 floating 33 | point conversion to/from text C port. Test coverage is provided separately. 34 | This library can be used indirectly via pparsefp.h and pprintfp.h. 35 | 36 | The `pstatic_assert.h` file is often needed on C11 systems because the 37 | compiler and standard library may support `_Static_assert` without 38 | `static_assert`. For compilers without `_Static_assert`, a unique 39 | identifier is needed for each assertion. This is done non-standard with 40 | the `__COUNTER__` macro, but has a fallback to `pstatic_assert_scope.h` 41 | for systems witout the `__COUNTER__` macro. Because of this fallback, 42 | `pstatic_assert.h` needs to be included in every file using 43 | `static_assert` in order to increment a scope counter, otherwise there 44 | is a risk of assert identifier conflicts when `static_assert` happen on 45 | the same line in different files. 46 | 47 | The `paligned_alloc.h` file implements the non-standard `aligned_free` 48 | to match the C11 standard `aligned_alloc` call. `aligned_free` is 49 | normally equivalent to `free`, but not on systems where `aligned_free` 50 | cannot be implemented using a system provived `free` call. Use of 51 | `aligned_free` is thus optional on some systems, but using it increases 52 | general portablity at the cost of pure C11 compatibility. 53 | 54 | IMPORTANT NOTE: this library has been used on various platforms and 55 | updated with user feedback but it is impossibly to systematically test 56 | all platforms so please test for specific uses cases and report 57 | any issues upstream. 58 | -------------------------------------------------------------------------------- /external/flatbuffers/code_generator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_CODE_GENERATOR_H_ 18 | #define FLATBUFFERS_CODE_GENERATOR_H_ 19 | 20 | #include 21 | 22 | #include "flatbuffers/idl.h" 23 | 24 | namespace flatbuffers { 25 | 26 | struct CodeGenOptions { 27 | std::string output_path; 28 | }; 29 | 30 | // A code generator interface for producing converting flatbuffer schema into 31 | // code. 32 | class CodeGenerator { 33 | public: 34 | virtual ~CodeGenerator() = default; 35 | 36 | enum Status { 37 | OK = 0, 38 | ERROR = 1, 39 | FAILED_VERIFICATION = 2, 40 | NOT_IMPLEMENTED = 3 41 | }; 42 | 43 | std::string status_detail; 44 | 45 | // Generate code from the provided `parser`. 46 | // 47 | // DEPRECATED: prefer using the other overload of GenerateCode for bfbs. 48 | virtual Status GenerateCode(const Parser &parser, const std::string &path, 49 | const std::string &filename) = 0; 50 | 51 | // Generate code from the provided `parser` and place it in the output. 52 | virtual Status GenerateCodeString(const Parser &parser, 53 | const std::string &filename, 54 | std::string &output) { 55 | (void)parser; 56 | (void)filename; 57 | (void)output; 58 | return Status::NOT_IMPLEMENTED; 59 | } 60 | 61 | // Generate code from the provided `buffer` of given `length`. The buffer is a 62 | // serialized reflection.fbs. 63 | virtual Status GenerateCode(const uint8_t *buffer, int64_t length, 64 | const CodeGenOptions &options) = 0; 65 | 66 | virtual Status GenerateMakeRule(const Parser &parser, const std::string &path, 67 | const std::string &filename, 68 | std::string &output) = 0; 69 | 70 | virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path, 71 | const std::string &filename) = 0; 72 | 73 | virtual Status GenerateRootFile(const Parser &parser, 74 | const std::string &path) = 0; 75 | 76 | virtual bool IsSchemaOnly() const = 0; 77 | 78 | virtual bool SupportsBfbsGeneration() const = 0; 79 | 80 | virtual bool SupportsRootFileGeneration() const = 0; 81 | 82 | virtual IDLOptions::Language Language() const = 0; 83 | 84 | virtual std::string LanguageName() const = 0; 85 | 86 | protected: 87 | CodeGenerator() = default; 88 | 89 | private: 90 | // Copying is not supported. 91 | CodeGenerator(const CodeGenerator &) = delete; 92 | CodeGenerator &operator=(const CodeGenerator &) = delete; 93 | }; 94 | 95 | } // namespace flatbuffers 96 | 97 | #endif // FLATBUFFERS_CODE_GENERATOR_H_ 98 | -------------------------------------------------------------------------------- /src-test/c_test_builder.h: -------------------------------------------------------------------------------- 1 | #ifndef C_TEST_BUILDER_H 2 | #define C_TEST_BUILDER_H 3 | 4 | /* Generated by flatcc 0.5.2 FlatBuffers schema compiler for C by dvide.com */ 5 | 6 | #ifndef C_TEST_READER_H 7 | #include "c_test_reader.h" 8 | #endif 9 | #ifndef FLATBUFFERS_COMMON_BUILDER_H 10 | #include "flatbuffers_common_builder.h" 11 | #endif 12 | #include "flatcc/flatcc_prologue.h" 13 | #ifndef flatbuffers_identifier 14 | #define flatbuffers_identifier 0 15 | #endif 16 | #ifndef flatbuffers_extension 17 | #define flatbuffers_extension ".bin" 18 | #endif 19 | 20 | static const flatbuffers_voffset_t __Foo_required[] = { 0 }; 21 | typedef flatbuffers_ref_t Foo_ref_t; 22 | static Foo_ref_t Foo_clone(flatbuffers_builder_t *B, Foo_table_t t); 23 | __flatbuffers_build_table(flatbuffers_, Foo, 2) 24 | 25 | static const flatbuffers_voffset_t __Bar_required[] = { 0 }; 26 | typedef flatbuffers_ref_t Bar_ref_t; 27 | static Bar_ref_t Bar_clone(flatbuffers_builder_t *B, Bar_table_t t); 28 | __flatbuffers_build_table(flatbuffers_, Bar, 3) 29 | 30 | #define __Foo_formal_args , uint64_t v0, flatbuffers_string_ref_t v1 31 | #define __Foo_call_args , v0, v1 32 | static inline Foo_ref_t Foo_create(flatbuffers_builder_t *B __Foo_formal_args); 33 | __flatbuffers_build_table_prolog(flatbuffers_, Foo, Foo_identifier, Foo_type_identifier) 34 | 35 | #define __Bar_formal_args , uint64_t v0, flatbuffers_string_ref_t v1, uint64_t v2 36 | #define __Bar_call_args , v0, v1, v2 37 | static inline Bar_ref_t Bar_create(flatbuffers_builder_t *B __Bar_formal_args); 38 | __flatbuffers_build_table_prolog(flatbuffers_, Bar, Bar_identifier, Bar_type_identifier) 39 | 40 | __flatbuffers_build_scalar_field(0, flatbuffers_, Foo_id, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Foo) 41 | __flatbuffers_build_string_field(1, flatbuffers_, Foo_text, Foo) 42 | 43 | static inline Foo_ref_t Foo_create(flatbuffers_builder_t *B __Foo_formal_args) 44 | { 45 | if (Foo_start(B) 46 | || Foo_id_add(B, v0) 47 | || Foo_text_add(B, v1)) { 48 | return 0; 49 | } 50 | return Foo_end(B); 51 | } 52 | 53 | static Foo_ref_t Foo_clone(flatbuffers_builder_t *B, Foo_table_t t) 54 | { 55 | __flatbuffers_memoize_begin(B, t); 56 | if (Foo_start(B) 57 | || Foo_id_pick(B, t) 58 | || Foo_text_pick(B, t)) { 59 | return 0; 60 | } 61 | __flatbuffers_memoize_end(B, t, Foo_end(B)); 62 | } 63 | 64 | __flatbuffers_build_scalar_field(0, flatbuffers_, Bar_id, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Bar) 65 | __flatbuffers_build_string_field(1, flatbuffers_, Bar_text, Bar) 66 | __flatbuffers_build_scalar_field(2, flatbuffers_, Bar_fooId, flatbuffers_uint64, uint64_t, 8, 8, UINT64_C(0), Bar) 67 | 68 | static inline Bar_ref_t Bar_create(flatbuffers_builder_t *B __Bar_formal_args) 69 | { 70 | if (Bar_start(B) 71 | || Bar_id_add(B, v0) 72 | || Bar_fooId_add(B, v2) 73 | || Bar_text_add(B, v1)) { 74 | return 0; 75 | } 76 | return Bar_end(B); 77 | } 78 | 79 | static Bar_ref_t Bar_clone(flatbuffers_builder_t *B, Bar_table_t t) 80 | { 81 | __flatbuffers_memoize_begin(B, t); 82 | if (Bar_start(B) 83 | || Bar_id_pick(B, t) 84 | || Bar_fooId_pick(B, t) 85 | || Bar_text_pick(B, t)) { 86 | return 0; 87 | } 88 | __flatbuffers_memoize_end(B, t, Bar_end(B)); 89 | } 90 | 91 | #include "flatcc/flatcc_epilogue.h" 92 | #endif /* C_TEST_BUILDER_H */ 93 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | permissions: 8 | contents: read 9 | 10 | jobs: 11 | build: 12 | name: Build (${{ matrix.os }}) 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | # Available runners: https://docs.github.com/en/actions/reference/runners/github-hosted-runners 18 | os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-26, windows-latest, windows-11-arm ] 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v4 22 | - name: Build and Test 23 | shell: bash 24 | run: | 25 | ./test.sh 26 | 27 | examples: 28 | name: Examples (${{ matrix.os }}) 29 | runs-on: ${{ matrix.os }} 30 | strategy: 31 | fail-fast: false 32 | matrix: 33 | os: [ ubuntu-latest, ubuntu-24.04-arm, macos-latest, macos-26, windows-latest, windows-11-arm ] 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v4 37 | - name: Build and run examples 38 | shell: bash 39 | run: | 40 | set -e 41 | 42 | # Only needed on Windows runners: copy required DLL next to the executable 43 | copy_dll_to_dir() { 44 | local bin_dir="$1" 45 | local src 46 | for src in \ 47 | build/_deps/objectbox-sync-download-src/lib/objectbox.dll \ 48 | build/_deps/objectbox-download-src/lib/objectbox.dll; do 49 | if [ -f "$src" ]; then 50 | cp -f "$src" "$bin_dir/" 51 | return 0 52 | fi 53 | done 54 | return 1 55 | } 56 | 57 | # This is mainly useful for Windows, as it defaults to use Debug/Release sub-directories 58 | find_bin() { 59 | local base="$1" 60 | local candidate 61 | local exe_file="$base" 62 | if [ "${RUNNER_OS:-}" == "Windows" ]; then 63 | exe_file="$base.exe" 64 | fi 65 | 66 | for candidate in "build/$exe_file" "build/Debug/$exe_file" "build/Release/$exe_file"; do 67 | if [ -f "$candidate" ]; then 68 | if [ "${RUNNER_OS:-}" == "Windows" ]; then 69 | copy_dll_to_dir "$(dirname "$candidate")" 70 | fi 71 | echo "$candidate" 72 | return 0 73 | fi 74 | done 75 | return 1 76 | } 77 | 78 | echo "### c-tasks example ###" 79 | cd examples/c-tasks && ./build.sh 80 | bin=$(find_bin objectbox-examples-c-tasks) 81 | "$bin" "Buy raspberries" 82 | "$bin" 83 | 84 | echo "### c-tasks-lowlevel example ###" 85 | cd ../c-tasks-lowlevel && ./build.sh 86 | bin=$(find_bin objectbox-examples-c-tasks-lowlevel) 87 | "$bin" "Buy blueberries" 88 | "$bin" 89 | 90 | echo "### tasks example ###" 91 | cd ../tasks && ./build.sh 92 | bin=$(find_bin objectbox-examples-tasks) 93 | printf "new \"Buy apples\"\nls\nexit\n" | "$bin" 94 | 95 | echo "### vectorsearch-cities example ###" 96 | cd ../vectorsearch-cities && ./build.sh 97 | bin=$(find_bin objectbox-examples-vectorsearch-cities) 98 | printf "name berlin\nexit\n" | "$bin" 99 | -------------------------------------------------------------------------------- /src-test/c_test_objects.c: -------------------------------------------------------------------------------- 1 | #include "c_test_objects.h" 2 | 3 | int create_foo(flatcc_builder_t* B, uint64_t id, char* text) { 4 | int rc; 5 | if ((rc = flatcc_builder_init(B))) return rc; 6 | if ((rc = Foo_start_as_root(B))) return rc; 7 | if ((rc = Foo_id_add(B, id))) return rc; 8 | rc = Foo_text_create_str(B, text); 9 | if (rc) return rc; 10 | flatbuffers_buffer_ref_t root = Foo_end_as_root(B); 11 | return 0; 12 | } 13 | 14 | Foo_table_t get_foo(OBX_cursor* cursor, uint64_t id) { 15 | const void* data; 16 | size_t size; 17 | int rc = obx_cursor_get(cursor, id, &data, &size); 18 | if (rc == 404) return NULL; // No special treatment at the moment if not found 19 | if (rc) return NULL; 20 | assert(data); 21 | assert(size); 22 | 23 | Foo_table_t table = Foo_as_root(data); 24 | assert(table); 25 | return table; 26 | } 27 | 28 | int put_foo(OBX_cursor* cursor, uint64_t* idInOut, char* text) { 29 | flatcc_builder_t builder; 30 | uint64_t id = *idInOut; 31 | bool isNew = id == 0; 32 | 33 | id = obx_cursor_id_for_put(cursor, id); 34 | if (!id) { return -1; } 35 | 36 | int rc = create_foo(&builder, id, text); 37 | if (rc) goto err; 38 | 39 | size_t size; 40 | void* buffer = flatcc_builder_get_direct_buffer(&builder, &size); 41 | if (!buffer) goto err; 42 | rc = (isNew ? obx_cursor_put_new : obx_cursor_put)(cursor, id, buffer, size); 43 | if (rc) goto err; 44 | flatcc_builder_clear(&builder); 45 | *idInOut = id; 46 | return 0; 47 | 48 | err: 49 | flatcc_builder_clear(&builder); 50 | if (rc == 0) return -1; 51 | else return rc; 52 | } 53 | 54 | 55 | int create_bar(flatcc_builder_t* B, uint64_t id, char* text, uint64_t fooId) { 56 | int rc; 57 | if ((rc = flatcc_builder_init(B))) return rc; 58 | if ((rc = Bar_start_as_root(B))) return rc; 59 | if ((rc = Bar_id_add(B, id))) return rc; 60 | if ((rc = Bar_fooId_add(B, fooId))) return rc; 61 | if ((rc = Bar_text_create_str(B, text))) return rc; 62 | flatbuffers_buffer_ref_t root = Bar_end_as_root(B); 63 | return 0; 64 | } 65 | 66 | Bar_table_t get_bar(OBX_cursor* cursor, uint64_t id) { 67 | const void* data; 68 | size_t size; 69 | int rc = obx_cursor_get(cursor, id, &data, &size); 70 | if (rc == 404) return NULL; // No special treatment at the moment if not found 71 | if (rc) return NULL; 72 | assert(data); 73 | assert(size); 74 | 75 | Bar_table_t table = Bar_as_root(data); 76 | assert(table); 77 | return table; 78 | } 79 | 80 | int put_bar(OBX_cursor* cursor, uint64_t* idInOut, char* text, uint64_t fooId) { 81 | flatcc_builder_t builder; 82 | uint64_t id = *idInOut; 83 | bool isNew = id == 0; 84 | 85 | id = obx_cursor_id_for_put(cursor, id); 86 | if (!id) return -1; 87 | 88 | int rc = create_bar(&builder, id, text, fooId); 89 | if (rc) goto err; 90 | 91 | size_t size; 92 | void* buffer = flatcc_builder_get_direct_buffer(&builder, &size); 93 | if (!buffer) goto err; 94 | rc = (isNew ? obx_cursor_put_new : obx_cursor_put)(cursor, id, buffer, size); 95 | if (rc) goto err; 96 | flatcc_builder_clear(&builder); 97 | *idInOut = id; 98 | return 0; 99 | 100 | err: 101 | flatcc_builder_clear(&builder); 102 | if (rc == 0) return -1; 103 | else return rc; 104 | } 105 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_types.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_TYPES_H 2 | #define FLATCC_TYPES_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #ifndef UINT8_MAX 11 | #include 12 | #endif 13 | 14 | /* 15 | * This should match generated type declaratios in 16 | * `flatbuffers_common_reader.h` (might have different name prefix). 17 | * Read only generated code does not depend on library code, 18 | * hence the duplication. 19 | */ 20 | #ifndef flatbuffers_types_defined 21 | #define flatbuffers_types_defined 22 | 23 | /* 24 | * uoffset_t and soffset_t must be same integer type, except for sign. 25 | * They can be (u)int16_t, (u)int32_t, or (u)int64_t. 26 | * The default is (u)int32_t. 27 | * 28 | * voffset_t is expected to be uint16_t, but can experimentally be 29 | * compiled from uint8_t up to uint32_t. 30 | * 31 | * ID_MAX is the largest value that can index a vtable. The table size 32 | * is given as voffset value. Each id represents a voffset value index 33 | * from 0 to max inclusive. Space is required for two header voffset 34 | * fields and the unaddressible highest index (due to the table size 35 | * representation). For 16-bit voffsets this yields a max of 2^15 - 4, 36 | * or (2^16 - 1) / 2 - 3. 37 | */ 38 | 39 | #define flatbuffers_uoffset_t_defined 40 | #define flatbuffers_soffset_t_defined 41 | #define flatbuffers_voffset_t_defined 42 | #define flatbuffers_utype_t_defined 43 | #define flatbuffers_bool_t_defined 44 | #define flatbuffers_thash_t_defined 45 | #define flatbuffers_fid_t_defined 46 | 47 | /* uoffset_t is also used for vector and string headers. */ 48 | #define FLATBUFFERS_UOFFSET_MAX UINT32_MAX 49 | #define FLATBUFFERS_SOFFSET_MAX INT32_MAX 50 | #define FLATBUFFERS_SOFFSET_MIN INT32_MIN 51 | #define FLATBUFFERS_VOFFSET_MAX UINT16_MAX 52 | #define FLATBUFFERS_UTYPE_MAX UINT8_MAX 53 | /* Well - the max of the underlying type. */ 54 | #define FLATBUFFERS_BOOL_MAX UINT8_MAX 55 | #define FLATBUFFERS_THASH_MAX UINT32_MAX 56 | 57 | #define FLATBUFFERS_ID_MAX (FLATBUFFERS_VOFFSET_MAX / sizeof(flatbuffers_voffset_t) - 3) 58 | /* Vectors of empty structs can yield div by zero, so we must guard against this. */ 59 | #define FLATBUFFERS_COUNT_MAX(elem_size) (FLATBUFFERS_UOFFSET_MAX/((elem_size) == 0 ? 1 : (elem_size))) 60 | 61 | #define FLATBUFFERS_UOFFSET_WIDTH 32 62 | #define FLATBUFFERS_COUNT_WIDTH 32 63 | #define FLATBUFFERS_SOFFSET_WIDTH 32 64 | #define FLATBUFFERS_VOFFSET_WIDTH 16 65 | #define FLATBUFFERS_UTYPE_WIDTH 8 66 | #define FLATBUFFERS_BOOL_WIDTH 8 67 | #define FLATBUFFERS_THASH_WIDTH 32 68 | 69 | #define FLATBUFFERS_TRUE 1 70 | #define FLATBUFFERS_FALSE 0 71 | 72 | #define FLATBUFFERS_PROTOCOL_IS_LE 1 73 | #define FLATBUFFERS_PROTOCOL_IS_BE 0 74 | 75 | typedef uint32_t flatbuffers_uoffset_t; 76 | typedef int32_t flatbuffers_soffset_t; 77 | typedef uint16_t flatbuffers_voffset_t; 78 | typedef uint8_t flatbuffers_utype_t; 79 | typedef uint8_t flatbuffers_bool_t; 80 | typedef uint32_t flatbuffers_thash_t; 81 | /* Public facing type operations. */ 82 | typedef flatbuffers_utype_t flatbuffers_union_type_t; 83 | 84 | static const flatbuffers_bool_t flatbuffers_true = FLATBUFFERS_TRUE; 85 | static const flatbuffers_bool_t flatbuffers_false = FLATBUFFERS_FALSE; 86 | 87 | #define FLATBUFFERS_IDENTIFIER_SIZE (FLATBUFFERS_THASH_WIDTH / 8) 88 | 89 | typedef char flatbuffers_fid_t[FLATBUFFERS_IDENTIFIER_SIZE]; 90 | 91 | #endif /* flatbuffers_types_defined */ 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif /* FLATCC_TYPES_H */ 98 | -------------------------------------------------------------------------------- /examples/vectorsearch-cities/README.md: -------------------------------------------------------------------------------- 1 | VectorSearch-Cities ObjectBox C++ Example 2 | ========================================= 3 | 4 | This example demonstrates vector search in ObjectBox using capital cities. 5 | You can search cities according to their geolocations (latitude and longitude), 6 | e.g. find the closest cities to a given city or a given geolocation. 7 | It uses a simple command-line interface; see below for some example queries. 8 | 9 | ## 2D vs. high-dimensional vector search 10 | 11 | We chose this example as an intuitive way to demonstrate ObjectBox vector search; 12 | e.g. cities with 2D location vectors are relatively easy to understand and work with. 13 | While this is a perfectly valid use case, ObjectBox vector search is primarily built for high-dimensional vector data. 14 | Thus, ObjectBox vector search is typically used for embeddings produced by AI models, 15 | which have hundreds or thousands of dimensions (e.g. there's no limit on the number of dimensions). 16 | 17 | ## Build and run 18 | 19 | You need CMake 3.14+ and a C++14 compiler to build this example. 20 | Run `./build.sh run` is the simplest option; other options are described in the [build and run](../README.md#build-and-run) section of the parent directory. 21 | 22 | ## Usage examples 23 | 24 | Once you start the example, you will see something like this: 25 | 26 | ``` 27 | Welcome to the ObjectBox vectorsearch-cities app example 28 | Available commands are: 29 | import Import CSV data (try cities.csv) 30 | ls [] List cities (with common if set) 31 | name [,] Search cities to nearest to the given name/prefix 32 | ( defaults to 5; try `name Berlin` or `name berl`) 33 | geo ,[,] Search cities nearest to the given geo location 34 | ( defaults to 5; try `geo 50,10`) 35 | add ,, add location 36 | removeAll remove all existing data 37 | exit close the program 38 | help display this help 39 | ``` 40 | 41 | Now, you can interact with it by typing in commands. 42 | 43 | List all entries with `ls`: 44 | 45 | ``` 46 | ls 47 | [..] 48 | 207 Willemstad 12.11 -68.93 49 | 208 Windhoek -22.57 17.08 50 | 209 Yamoussoukro 6.83 -5.29 51 | 210 Yaoundé 3.85 11.50 52 | 211 Yaren -0.55 166.92 53 | 212 Yerevan 40.19 44.52 54 | ``` 55 | 56 | Search nearest neighbors to Berlin with `name Berlin, 10` (note that "Score" is the distance in kilometers): 57 | 58 | ``` 59 | name Berlin, 10 60 | ID Name Location Score 61 | 28 Berlin 52.52 13.40 0.00 62 | 147 Prague 50.08 14.44 281.13 63 | 49 Copenhagen 55.68 12.57 355.15 64 | 203 Warsaw 52.23 21.01 517.17 65 | 200 Vienna 48.21 16.37 523.55 66 | 34 Bratislava 48.15 17.11 552.40 67 | 6 Amsterdam 52.37 4.89 576.75 68 | 94 Luxembourg City 49.61 6.13 601.97 69 | 37 Brussels 50.85 4.35 650.65 70 | 196 Vaduz 47.14 9.52 659.56 71 | ``` 72 | 73 | Search nearest neighbors to Area 51 via latitude and longitude with `geo 37.23, -115.80` (note that "Score" is the distance in kilometers): 74 | 75 | ``` 76 | geo 37.23, -115.80 77 | ID Name Location Score 78 | 107 Mexico City 19.43 -99.13 2555.95 79 | 204 Washington D.C. 38.91 -77.04 3372.90 80 | 129 Ottawa 45.42 -75.70 3431.69 81 | 27 Belmopan 17.25 -88.76 3452.91 82 | 64 Guatemala City 14.63 -90.51 3542.07 83 | ``` 84 | -------------------------------------------------------------------------------- /external/flatbuffers/detached_buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_DETACHED_BUFFER_H_ 18 | #define FLATBUFFERS_DETACHED_BUFFER_H_ 19 | 20 | #include "flatbuffers/allocator.h" 21 | #include "flatbuffers/base.h" 22 | #include "flatbuffers/default_allocator.h" 23 | 24 | namespace flatbuffers { 25 | 26 | // DetachedBuffer is a finished flatbuffer memory region, detached from its 27 | // builder. The original memory region and allocator are also stored so that 28 | // the DetachedBuffer can manage the memory lifetime. 29 | class DetachedBuffer { 30 | public: 31 | DetachedBuffer() 32 | : allocator_(nullptr), 33 | own_allocator_(false), 34 | buf_(nullptr), 35 | reserved_(0), 36 | cur_(nullptr), 37 | size_(0) {} 38 | 39 | DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf, 40 | size_t reserved, uint8_t *cur, size_t sz) 41 | : allocator_(allocator), 42 | own_allocator_(own_allocator), 43 | buf_(buf), 44 | reserved_(reserved), 45 | cur_(cur), 46 | size_(sz) {} 47 | 48 | DetachedBuffer(DetachedBuffer &&other) noexcept 49 | : allocator_(other.allocator_), 50 | own_allocator_(other.own_allocator_), 51 | buf_(other.buf_), 52 | reserved_(other.reserved_), 53 | cur_(other.cur_), 54 | size_(other.size_) { 55 | other.reset(); 56 | } 57 | 58 | DetachedBuffer &operator=(DetachedBuffer &&other) noexcept { 59 | if (this == &other) return *this; 60 | 61 | destroy(); 62 | 63 | allocator_ = other.allocator_; 64 | own_allocator_ = other.own_allocator_; 65 | buf_ = other.buf_; 66 | reserved_ = other.reserved_; 67 | cur_ = other.cur_; 68 | size_ = other.size_; 69 | 70 | other.reset(); 71 | 72 | return *this; 73 | } 74 | 75 | ~DetachedBuffer() { destroy(); } 76 | 77 | const uint8_t *data() const { return cur_; } 78 | 79 | uint8_t *data() { return cur_; } 80 | 81 | size_t size() const { return size_; } 82 | 83 | uint8_t *begin() { return data(); } 84 | const uint8_t *begin() const { return data(); } 85 | uint8_t *end() { return data() + size(); } 86 | const uint8_t *end() const { return data() + size(); } 87 | 88 | // These may change access mode, leave these at end of public section 89 | FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other)); 90 | FLATBUFFERS_DELETE_FUNC( 91 | DetachedBuffer &operator=(const DetachedBuffer &other)); 92 | 93 | protected: 94 | Allocator *allocator_; 95 | bool own_allocator_; 96 | uint8_t *buf_; 97 | size_t reserved_; 98 | uint8_t *cur_; 99 | size_t size_; 100 | 101 | inline void destroy() { 102 | if (buf_) Deallocate(allocator_, buf_, reserved_); 103 | if (own_allocator_ && allocator_) { delete allocator_; } 104 | reset(); 105 | } 106 | 107 | inline void reset() { 108 | allocator_ = nullptr; 109 | own_allocator_ = false; 110 | buf_ = nullptr; 111 | reserved_ = 0; 112 | cur_ = nullptr; 113 | size_ = 0; 114 | } 115 | }; 116 | 117 | } // namespace flatbuffers 118 | 119 | #endif // FLATBUFFERS_DETACHED_BUFFER_H_ 120 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_ALLOC_H 2 | #define FLATCC_ALLOC_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * These allocation abstractions are __only__ for runtime libraries. 10 | * 11 | * The flatcc compiler uses Posix allocation routines regardless 12 | * of how this file is configured. 13 | * 14 | * This header makes it possible to use systems where malloc is not 15 | * valid to use. In this case the portable library will not help 16 | * because it implements Posix / C11 abstractions. 17 | * 18 | * Systems like FreeRTOS do not work with Posix memory calls and here it 19 | * can be helpful to override runtime allocation primitives. 20 | * 21 | * In general, it is better to customize the allocator and emitter via 22 | * flatcc_builder_custom_init and to avoid using the default emitter 23 | * specific high level calls the copy out a buffer that must later be 24 | * deallocated. This provides full control of allocation withou the need 25 | * for this file. 26 | * 27 | * 28 | * IMPORTANT 29 | * 30 | * If you override malloc, free, etc., make sure your applications 31 | * use the same allocation methods. For example, samples/monster.c 32 | * and several test cases are no longer guaranteed to work out of the 33 | * box. 34 | * 35 | * The changes must only affect target runtime compilation including the 36 | * the runtime library libflatccrt. 37 | * 38 | * The host system flatcc compiler and the compiler library libflatcc 39 | * should NOT be compiled with non-Posix allocation since the compiler 40 | * has a dependency on the runtime library and the wrong free operation 41 | * might be callled. The safest way to avoid this problem this is to 42 | * compile flatcc with the CMake script and the runtime files with a 43 | * dedicated build system for the target system. 44 | */ 45 | 46 | #include 47 | 48 | #ifndef FLATCC_ALLOC 49 | #define FLATCC_ALLOC(n) malloc(n) 50 | #endif 51 | 52 | #ifndef FLATCC_FREE 53 | #define FLATCC_FREE(p) free(p) 54 | #endif 55 | 56 | #ifndef FLATCC_REALLOC 57 | #define FLATCC_REALLOC(p, n) realloc(p, n) 58 | #endif 59 | 60 | #ifndef FLATCC_CALLOC 61 | #define FLATCC_CALLOC(nm, n) calloc(nm, n) 62 | #endif 63 | 64 | /* 65 | * Implements `aligned_alloc` and `aligned_free`. 66 | * Even with C11, this implements non-standard aligned_free needed for portable 67 | * aligned_alloc implementations. 68 | */ 69 | #ifndef FLATCC_USE_GENERIC_ALIGNED_ALLOC 70 | 71 | #ifndef FLATCC_NO_PALIGNED_ALLOC 72 | #include "flatcc/portable/paligned_alloc.h" 73 | #else 74 | #if !defined(__aligned_free_is_defined) || !__aligned_free_is_defined 75 | #define aligned_free free 76 | #endif 77 | #endif 78 | 79 | #else /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ 80 | 81 | #ifndef FLATCC_ALIGNED_ALLOC 82 | static inline void *__flatcc_aligned_alloc(size_t alignment, size_t size) 83 | { 84 | char *raw; 85 | void *buf; 86 | size_t total_size = (size + alignment - 1 + sizeof(void *)); 87 | 88 | if (alignment < sizeof(void *)) { 89 | alignment = sizeof(void *); 90 | } 91 | raw = (char *)(size_t)FLATCC_ALLOC(total_size); 92 | buf = raw + alignment - 1 + sizeof(void *); 93 | buf = (void *)(((size_t)buf) & ~(alignment - 1)); 94 | ((void **)buf)[-1] = raw; 95 | return buf; 96 | } 97 | #define FLATCC_ALIGNED_ALLOC(alignment, size) __flatcc_aligned_alloc(alignment, size) 98 | #endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ 99 | 100 | #ifndef FLATCC_ALIGNED_FREE 101 | static inline void __flatcc_aligned_free(void *p) 102 | { 103 | char *raw; 104 | 105 | if (!p) return; 106 | raw = ((void **)p)[-1]; 107 | 108 | FLATCC_FREE(raw); 109 | } 110 | #define FLATCC_ALIGNED_FREE(p) __flatcc_aligned_free(p) 111 | #endif 112 | 113 | #endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */ 114 | 115 | #ifndef FLATCC_ALIGNED_ALLOC 116 | #define FLATCC_ALIGNED_ALLOC(a, n) aligned_alloc(a, n) 117 | #endif 118 | 119 | #ifndef FLATCC_ALIGNED_FREE 120 | #define FLATCC_ALIGNED_FREE(p) aligned_free(p) 121 | #endif 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* FLATCC_ALLOC_H */ 128 | -------------------------------------------------------------------------------- /external/flatbuffers/hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_HASH_H_ 18 | #define FLATBUFFERS_HASH_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "flatbuffers/flatbuffers.h" 24 | 25 | namespace flatbuffers { 26 | 27 | template struct FnvTraits { 28 | static const T kFnvPrime; 29 | static const T kOffsetBasis; 30 | }; 31 | 32 | template<> struct FnvTraits { 33 | static const uint32_t kFnvPrime = 0x01000193; 34 | static const uint32_t kOffsetBasis = 0x811C9DC5; 35 | }; 36 | 37 | template<> struct FnvTraits { 38 | static const uint64_t kFnvPrime = 0x00000100000001b3ULL; 39 | static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL; 40 | }; 41 | 42 | template T HashFnv1(const char *input) { 43 | T hash = FnvTraits::kOffsetBasis; 44 | for (const char *c = input; *c; ++c) { 45 | hash *= FnvTraits::kFnvPrime; 46 | hash ^= static_cast(*c); 47 | } 48 | return hash; 49 | } 50 | 51 | template T HashFnv1a(const char *input) { 52 | T hash = FnvTraits::kOffsetBasis; 53 | for (const char *c = input; *c; ++c) { 54 | hash ^= static_cast(*c); 55 | hash *= FnvTraits::kFnvPrime; 56 | } 57 | return hash; 58 | } 59 | 60 | template<> inline uint16_t HashFnv1(const char *input) { 61 | uint32_t hash = HashFnv1(input); 62 | return (hash >> 16) ^ (hash & 0xffff); 63 | } 64 | 65 | template<> inline uint16_t HashFnv1a(const char *input) { 66 | uint32_t hash = HashFnv1a(input); 67 | return (hash >> 16) ^ (hash & 0xffff); 68 | } 69 | 70 | template struct NamedHashFunction { 71 | const char *name; 72 | 73 | typedef T (*HashFunction)(const char *); 74 | HashFunction function; 75 | }; 76 | 77 | const NamedHashFunction kHashFunctions16[] = { 78 | { "fnv1_16", HashFnv1 }, 79 | { "fnv1a_16", HashFnv1a }, 80 | }; 81 | 82 | const NamedHashFunction kHashFunctions32[] = { 83 | { "fnv1_32", HashFnv1 }, 84 | { "fnv1a_32", HashFnv1a }, 85 | }; 86 | 87 | const NamedHashFunction kHashFunctions64[] = { 88 | { "fnv1_64", HashFnv1 }, 89 | { "fnv1a_64", HashFnv1a }, 90 | }; 91 | 92 | inline NamedHashFunction::HashFunction FindHashFunction16( 93 | const char *name) { 94 | std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]); 95 | for (std::size_t i = 0; i < size; ++i) { 96 | if (std::strcmp(name, kHashFunctions16[i].name) == 0) { 97 | return kHashFunctions16[i].function; 98 | } 99 | } 100 | return nullptr; 101 | } 102 | 103 | inline NamedHashFunction::HashFunction FindHashFunction32( 104 | const char *name) { 105 | std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]); 106 | for (std::size_t i = 0; i < size; ++i) { 107 | if (std::strcmp(name, kHashFunctions32[i].name) == 0) { 108 | return kHashFunctions32[i].function; 109 | } 110 | } 111 | return nullptr; 112 | } 113 | 114 | inline NamedHashFunction::HashFunction FindHashFunction64( 115 | const char *name) { 116 | std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]); 117 | for (std::size_t i = 0; i < size; ++i) { 118 | if (std::strcmp(name, kHashFunctions64[i].name) == 0) { 119 | return kHashFunctions64[i].function; 120 | } 121 | } 122 | return nullptr; 123 | } 124 | 125 | } // namespace flatbuffers 126 | 127 | #endif // FLATBUFFERS_HASH_H_ 128 | -------------------------------------------------------------------------------- /external/flatcc/portable/pendian_detect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Uses various known flags to decide endianness and defines: 3 | * 4 | * __LITTLE_ENDIAN__ or __BIG_ENDIAN__ if not already defined 5 | * 6 | * and also defines 7 | * 8 | * __BYTE_ORDER__ to either __ORDER_LITTLE_ENDIAN__ or 9 | * __ORDER_BIG_ENDIAN__ if not already defined 10 | * 11 | * If none of these could be set, __UNKNOWN_ENDIAN__ is defined, 12 | * which is not a known flag. If __BYTE_ORDER__ is defined but 13 | * not big or little endian, __UNKNOWN_ENDIAN__ is also defined. 14 | * 15 | * Note: Some systems define __BYTE_ORDER without __ at the end 16 | * - this will be mapped to to __BYTE_ORDER__. 17 | */ 18 | 19 | #ifndef PENDIAN_DETECT 20 | #define PENDIAN_DETECT 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #ifndef __ORDER_LITTLE_ENDIAN__ 27 | #define __ORDER_LITTLE_ENDIAN__ 1234 28 | #endif 29 | 30 | #ifndef __ORDER_BIG_ENDIAN__ 31 | #define __ORDER_BIG_ENDIAN__ 4321 32 | #endif 33 | 34 | #ifdef __BYTE_ORDER__ 35 | 36 | #if defined(__LITTLE_ENDIAN__) && __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ 37 | #error __LITTLE_ENDIAN__ inconsistent with __BYTE_ORDER__ 38 | #endif 39 | 40 | #if defined(__BIG_ENDIAN__) && __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ 41 | #error __BIG_ENDIAN__ inconsistent with __BYTE_ORDER__ 42 | #endif 43 | 44 | #else /* __BYTE_ORDER__ */ 45 | 46 | 47 | #if \ 48 | defined(__LITTLE_ENDIAN__) || \ 49 | (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN) || \ 50 | defined(__ARMEL__) || defined(__THUMBEL__) || \ 51 | defined(__AARCH64EL__) || \ 52 | (defined(_MSC_VER) && defined(_M_ARM)) || \ 53 | defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ 54 | defined(_M_X64) || defined(_M_IX86) || defined(_M_I86) || \ 55 | defined(__i386__) || defined(__alpha__) || \ 56 | defined(__ia64) || defined(__ia64__) || \ 57 | defined(_M_IA64) || defined(_M_ALPHA) || \ 58 | defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || \ 59 | defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ 60 | defined(__bfin__) 61 | 62 | #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ 63 | 64 | #endif 65 | 66 | #if \ 67 | defined (__BIG_ENDIAN__) || \ 68 | (defined(__BYTE_ORDER) && __BYTE_ORDER == __ORDER_BIG_ENDIAN) || \ 69 | defined(__ARMEB__) || defined(THUMBEB__) || defined (__AARCH64EB__) || \ 70 | defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \ 71 | defined(__sparc) || defined(__sparc__) || \ 72 | defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || \ 73 | defined(__hpux) || defined(__hppa) || defined(__s390__) 74 | 75 | #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__ 76 | 77 | #endif 78 | 79 | #endif /* __BYTE_ORDER__ */ 80 | 81 | #ifdef __BYTE_ORDER__ 82 | 83 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 84 | 85 | #ifndef __LITTLE_ENDIAN__ 86 | #define __LITTLE_ENDIAN__ 1 87 | #endif 88 | 89 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 90 | 91 | #ifndef __BIG_ENDIAN__ 92 | #define __BIG_ENDIAN__ 1 93 | #endif 94 | 95 | #else 96 | 97 | /* 98 | * Custom extension - we only define __BYTE_ORDER__ if known big or little. 99 | * User code that understands __BYTE_ORDER__ may also assume unkown if 100 | * it is not defined by now - this will allow other endian formats than 101 | * big or little when supported by compiler. 102 | */ 103 | #ifndef __UNKNOWN_ENDIAN__ 104 | #define __UNKNOWN_ENDIAN__ 1 105 | #endif 106 | 107 | #endif 108 | #endif /* __BYTE_ORDER__ */ 109 | 110 | #if defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__) 111 | #error conflicting definitions of __LITTLE_ENDIAN__ and __BIG_ENDIAN__ 112 | #endif 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif /* PENDIAN_DETECT */ 119 | -------------------------------------------------------------------------------- /examples/c-tasks-lowlevel/README.md: -------------------------------------------------------------------------------- 1 | # Example: Tasks (low-level) 2 | 3 | **Deprecation warning:** This example is mostly deprecated. 4 | It's using the low-level cursor API and also the ObjectBox Generator approach is now the recommended way to use ObjectBox. 5 | Information here may be outdated. 6 | 7 | This example shows how to use the ObjectBox C API to create a simple console-based task-list application. 8 | 9 | To add a new task, simply enter the task text as arguments: 10 | 11 | ```bash 12 | ./objectbox-examples-c-tasks-lowlevel Buy milk 13 | ``` 14 | 15 | Now you can run `./objectbox-examples-c-tasks-lowlevel` without arguments to see the list of open tasks: 16 | 17 | ID Created Finished Text 18 | 1 2018-09-10 12:44:07 Buy milk 19 | 20 | To complete a task, you would run `./objectbox-examples-c-tasks-lowlevel --done 1` (1 is the ID of the task as shown above). 21 | And to show all complete tasks you can run `./objectbox-examples-c-tasks-lowlevel --done`. 22 | 23 | ### Code overview 24 | Files: 25 | 26 | * [main.c](main.c): actual example code 27 | * [task.fbs](task.fbs): FlatBuffers schema file to define a table "Task" with its properties 28 | * Other files are auto-generated by flatcc 29 | 30 | Code organization 31 | 32 | 1. In the `main()` parses arguments and sets up ObjectBox store based on a data model 33 | 1. Start a transaction and get a cursor for the `Task` entity type 34 | 1. Execute a requested action using the cursor 35 | 1. Gracefully close everything and clean it up 36 | 37 | The following methods demonstrate some of the API capabilities: 38 | 39 | * `task_list()` - iterates over the whole dataset 40 | * `task_create()` - insert (calls `task_put()`) 41 | * `task_done()` - select & update (calls `task_put()`) 42 | * `task_put()` - actual insert/update (overwrite) - builds flatbuffer and writes it to the store. 43 | 44 | ### Changing the data model 45 | For convenience, all FlatBuffer files for the `Task` entity are already generated. 46 | 47 | You may want to change the data model to expend the example or to start your own data model for a new app. 48 | Here's what you have to do: 49 | 50 | 1. Edit `task.fbs` 51 | 2. Generate FlatBuffers sources again using [flatcc](https://github.com/dvidelabs/flatcc) and the script `./flatcc-fbs.sh`. 52 | For the script to work, you need flatcc in the `$PATH` (or update the script with the file path of your compiled `bin/flatcc`). 53 | 3. Once the FlatBuffers model is changed, you need to adjust the ObjectBox model accordingly: 54 | The model defined in the `model_create()` method and in the `task.fbs` file should be kept in sync. 55 | 56 | Some quick notes on IDs and UIDs in the ObjectBox model: 57 | 58 | * Entity IDs need to be unique among themselves 59 | * Property IDs need to be unique inside their Entity 60 | * All UIDs need to be unique application-wide 61 | * See [Meta Model, IDs, and UIDs](https://docs.objectbox.io/advanced/meta-model-ids-and-uids) docs for more details. 62 | 63 | *Note:* We are using flatbuffers auxiliary methods to build the Task data. See Flatcc & FlatBuffers documentation for more details. 64 | 65 | ### Command line options 66 | 67 | Run `objectbox-examples-c-tasks-lowlevel --help` to see available options for the example application. 68 | The output looks like this: 69 | 70 | ```text 71 | usage: objectbox-examples-c-tasks-lowlevel 72 | text of a new task create a new task with the given text 73 | (default) lists active tasks 74 | --done lists active and done tasks 75 | --done ID marks the task with the given ID as done 76 | --help displays this help 77 | ``` 78 | 79 | 80 | ### License 81 | Copyright 2018 ObjectBox Ltd. All rights reserved. 82 | 83 | Licensed under the Apache License, Version 2.0 (the "License"); 84 | you may not use this file except in compliance with the License. 85 | You may obtain a copy of the License at 86 | 87 | http://www.apache.org/licenses/LICENSE-2.0 88 | 89 | Unless required by applicable law or agreed to in writing, software 90 | distributed under the License is distributed on an "AS IS" BASIS, 91 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 92 | See the License for the specific language governing permissions and 93 | limitations under the License. 94 | 95 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_endian.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_ENDIAN_H 2 | #define FLATCC_ENDIAN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * This file provides helper macros to define type-specific macros and 10 | * inline functions that convert between stored data and native data 11 | * indedpently of both native (host) endianness and protocol endianness 12 | * (i.e. the serialized endian format). 13 | * 14 | * To detect endianness correctly ensure one of the following is defined. 15 | * 16 | * __LITTLE_ENDIAN__ 17 | * __BIG_ENDIAN__ 18 | * FLATBUFFERS_LITTLEENDIAN=1 19 | * FLATBUFFERS_LITTLEENDIAN=0 20 | * 21 | * Note: the Clang compiler likely already does this, but other 22 | * compilers may have their own way, if at all. 23 | * 24 | * It is also necessary to include or a compatible 25 | * implementation in order to provide: 26 | * 27 | * le16toh, le32to, le64toh, be16toh, be32toh, be64toh, 28 | * htole16, htole32, htole64, htobe16, htobe32, htobe64. 29 | * 30 | * A simple way to ensure all of the above for most platforms is 31 | * to include the portable endian support file: 32 | * 33 | * #include "flatcc/portable/pendian.h" 34 | * 35 | * It is also necessary to include 36 | * 37 | * #include "flatcc/flatcc_types.h" 38 | * 39 | * or an equivalent file. This makes it possible to change the 40 | * endianness of the serialized data and the sizes of flatbuffer 41 | * specific types such as `uoffset_t`. 42 | * 43 | * Note: the mentioned include files are likely already included 44 | * by the file including this file, at least for the default 45 | * configuration. 46 | */ 47 | 48 | #ifndef UINT8_t 49 | #include 50 | #endif 51 | 52 | /* These are needed to simplify accessor macros and are not found in . */ 53 | #ifndef le8toh 54 | #define le8toh(n) (n) 55 | #endif 56 | 57 | #ifndef be8toh 58 | #define be8toh(n) (n) 59 | #endif 60 | 61 | #ifndef htole8 62 | #define htole8(n) (n) 63 | #endif 64 | 65 | #ifndef htobe8 66 | #define htobe8(n) (n) 67 | #endif 68 | 69 | #include "flatcc/flatcc_accessors.h" 70 | 71 | /* This is the binary encoding endianness, usually LE for flatbuffers. */ 72 | #if FLATBUFFERS_PROTOCOL_IS_LE 73 | #define flatbuffers_endian le 74 | #elif FLATBUFFERS_PROTOCOL_IS_BE 75 | #define flatbuffers_endian be 76 | #else 77 | #error "flatbuffers has no defined endiannesss" 78 | #endif 79 | 80 | __flatcc_define_basic_scalar_accessors(flatbuffers_, flatbuffers_endian) 81 | 82 | __flatcc_define_integer_accessors(flatbuffers_bool, flatbuffers_bool_t, 83 | FLATBUFFERS_BOOL_WIDTH, flatbuffers_endian) 84 | __flatcc_define_integer_accessors(flatbuffers_union_type, flatbuffers_union_type_t, 85 | FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian) 86 | 87 | __flatcc_define_integer_accessors(__flatbuffers_uoffset, flatbuffers_uoffset_t, 88 | FLATBUFFERS_UOFFSET_WIDTH, flatbuffers_endian) 89 | __flatcc_define_integer_accessors(__flatbuffers_soffset, flatbuffers_soffset_t, 90 | FLATBUFFERS_SOFFSET_WIDTH, flatbuffers_endian) 91 | __flatcc_define_integer_accessors(__flatbuffers_voffset, flatbuffers_voffset_t, 92 | FLATBUFFERS_VOFFSET_WIDTH, flatbuffers_endian) 93 | __flatcc_define_integer_accessors(__flatbuffers_utype, flatbuffers_utype_t, 94 | FLATBUFFERS_UTYPE_WIDTH, flatbuffers_endian) 95 | __flatcc_define_integer_accessors(__flatbuffers_thash, flatbuffers_thash_t, 96 | FLATBUFFERS_THASH_WIDTH, flatbuffers_endian) 97 | 98 | /* flatcc/portable/pendian.h sets LITTLE/BIG flags if possible, and always defines le16toh. */ 99 | #ifndef flatbuffers_is_native_pe 100 | #if defined(__LITTLE_ENDIAN__) || FLATBUFFERS_LITTLEENDIAN 101 | #undef FLATBUFFERS_LITTLEENDIAN 102 | #define FLATBUFFERS_LITTLEENDIAN 1 103 | #define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_LE) 104 | #elif defined(__BIG_ENDIAN__) || (defined(FLATBUFFERS_LITTLEENDIAN) && !FLATBUFFERS_LITTLEENDIAN) 105 | #undef FLATBUFFERS_LITTLEENDIAN 106 | #define FLATBUFFERS_LITTLEENDIAN 0 107 | #define flatbuffers_is_native_pe() (FLATBUFFERS_PROTOCOL_IS_BE) 108 | #else 109 | #define flatbuffers_is_native_pe() (__FLATBUFFERS_CONCAT(flatbuffers_endian, 16toh)(1) == 1) 110 | #endif 111 | #endif 112 | 113 | #ifndef flatbuffers_is_native_le 114 | #define flatbuffers_is_native_le() flatbuffers_is_native_pe() 115 | #endif 116 | 117 | #ifndef flatbuffers_is_native_be 118 | #define flatbuffers_is_native_be() (!flatbuffers_is_native_pe()) 119 | #endif 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif /* FLATCC_ENDIAN_H */ 126 | -------------------------------------------------------------------------------- /external/flatbuffers/flatc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_FLATC_H_ 18 | #define FLATBUFFERS_FLATC_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "flatbuffers/code_generator.h" 27 | #include "flatbuffers/flatbuffers.h" 28 | #include "flatbuffers/idl.h" 29 | #include "flatbuffers/util.h" 30 | 31 | namespace flatbuffers { 32 | 33 | extern void LogCompilerWarn(const std::string &warn); 34 | extern void LogCompilerError(const std::string &err); 35 | 36 | struct FlatCOptions { 37 | IDLOptions opts; 38 | 39 | std::string program_name; 40 | 41 | std::string output_path; 42 | 43 | std::vector filenames; 44 | 45 | std::list include_directories_storage; 46 | std::vector include_directories; 47 | std::vector conform_include_directories; 48 | std::vector generator_enabled; 49 | size_t binary_files_from = std::numeric_limits::max(); 50 | std::string conform_to_schema; 51 | std::string annotate_schema; 52 | bool annotate_include_vector_contents = true; 53 | bool any_generator = false; 54 | bool print_make_rules = false; 55 | bool raw_binary = false; 56 | bool schema_binary = false; 57 | bool grpc_enabled = false; 58 | bool requires_bfbs = false; 59 | bool file_names_only = false; 60 | 61 | std::vector> generators; 62 | }; 63 | 64 | struct FlatCOption { 65 | std::string short_opt; 66 | std::string long_opt; 67 | std::string parameter; 68 | std::string description; 69 | }; 70 | 71 | class FlatCompiler { 72 | public: 73 | typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, 74 | bool show_exe_name); 75 | 76 | typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, 77 | bool usage, bool show_exe_name); 78 | 79 | // Parameters required to initialize the FlatCompiler. 80 | struct InitParams { 81 | InitParams() : warn_fn(nullptr), error_fn(nullptr) {} 82 | 83 | WarnFn warn_fn; 84 | ErrorFn error_fn; 85 | }; 86 | 87 | explicit FlatCompiler(const InitParams ¶ms) : params_(params) {} 88 | 89 | bool RegisterCodeGenerator(const FlatCOption &option, 90 | std::shared_ptr code_generator); 91 | 92 | int Compile(const FlatCOptions &options); 93 | 94 | std::string GetShortUsageString(const std::string &program_name) const; 95 | std::string GetUsageString(const std::string &program_name) const; 96 | 97 | // Parse the FlatC options from command line arguments. 98 | FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv); 99 | 100 | private: 101 | void ParseFile(flatbuffers::Parser &parser, const std::string &filename, 102 | const std::string &contents, 103 | const std::vector &include_directories) const; 104 | 105 | void LoadBinarySchema(Parser &parser, const std::string &filename, 106 | const std::string &contents); 107 | 108 | void Warn(const std::string &warn, bool show_exe_name = true) const; 109 | 110 | void Error(const std::string &err, bool usage = true, 111 | bool show_exe_name = true) const; 112 | 113 | void AnnotateBinaries(const uint8_t *binary_schema, 114 | uint64_t binary_schema_size, 115 | const FlatCOptions &options); 116 | 117 | void ValidateOptions(const FlatCOptions &options); 118 | 119 | Parser GetConformParser(const FlatCOptions &options); 120 | 121 | std::unique_ptr GenerateCode(const FlatCOptions &options, 122 | Parser &conform_parser); 123 | 124 | std::map> code_generators_; 125 | 126 | InitParams params_; 127 | }; 128 | 129 | } // namespace flatbuffers 130 | 131 | #endif // FLATBUFFERS_FLATC_H_ 132 | -------------------------------------------------------------------------------- /src-test-gen/objectbox-model.h: -------------------------------------------------------------------------------- 1 | // Code generated by ObjectBox; DO NOT EDIT. 2 | 3 | #pragma once 4 | 5 | #ifdef __cplusplus 6 | #include 7 | #include 8 | extern "C" { 9 | #else 10 | #include 11 | #include 12 | #endif 13 | #include "objectbox.h" 14 | 15 | /// Initializes an ObjectBox model for all entities. 16 | /// The returned pointer may be NULL if the allocation failed. If the returned model is not NULL, you should check if 17 | /// any error occurred by calling obx_model_error_code() and/or obx_model_error_message(). If an error occurred, you're 18 | /// responsible for freeing the resources by calling obx_model_free(). 19 | /// In case there was no error when setting the model up (i.e. obx_model_error_code() returned 0), you may configure 20 | /// OBX_store_options with the model by calling obx_opt_model() and subsequently opening a store with obx_store_open(). 21 | /// As soon as you call obx_store_open(), the model pointer is consumed and MUST NOT be freed manually. 22 | static inline OBX_model* create_obx_model() { 23 | OBX_model* model = obx_model(); 24 | if (!model) return NULL; 25 | 26 | obx_model_entity(model, "Bar", 1, 4238748172040711863); 27 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 8899753625016606063); 28 | obx_model_property_flags(model, OBXPropertyFlags_ID); 29 | obx_model_property(model, "text", OBXPropertyType_String, 2, 8817565853152409613); 30 | obx_model_property(model, "fooId", OBXPropertyType_Long, 3, 8289563594193508940); 31 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 32 | obx_model_entity_last_property_id(model, 3, 8289563594193508940); 33 | 34 | obx_model_entity(model, "Foo", 2, 3681320287511818591); 35 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 1727382257942252770); 36 | obx_model_property_flags(model, OBXPropertyFlags_ID); 37 | obx_model_property(model, "text", OBXPropertyType_String, 2, 4580216775980296323); 38 | obx_model_entity_last_property_id(model, 2, 4580216775980296323); 39 | 40 | obx_model_entity(model, "Typeful", 3, 1679870369785090036); 41 | obx_model_property(model, "id", OBXPropertyType_Long, 1, 2357716816519717741); 42 | obx_model_property_flags(model, OBXPropertyFlags_ID); 43 | obx_model_property(model, "int", OBXPropertyType_Int, 2, 7787106383907421892); 44 | obx_model_property(model, "int8", OBXPropertyType_Byte, 3, 6626668244087952726); 45 | obx_model_property(model, "int16", OBXPropertyType_Short, 4, 2311989977658529302); 46 | obx_model_property(model, "int32", OBXPropertyType_Int, 5, 4449626101884999513); 47 | obx_model_property(model, "int64", OBXPropertyType_Long, 6, 6878925028725243346); 48 | obx_model_property(model, "uint", OBXPropertyType_Int, 7, 6993200619804101647); 49 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 50 | obx_model_property(model, "uint8", OBXPropertyType_Byte, 8, 2723131825781050497); 51 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 52 | obx_model_property(model, "uint16", OBXPropertyType_Short, 9, 1317433661165132830); 53 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 54 | obx_model_property(model, "uint32", OBXPropertyType_Int, 10, 408806406362957694); 55 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 56 | obx_model_property(model, "uint64", OBXPropertyType_Long, 11, 7911223144937033489); 57 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 58 | obx_model_property(model, "bool", OBXPropertyType_Bool, 12, 5102252532293057263); 59 | obx_model_property(model, "string", OBXPropertyType_String, 13, 1210918154342857444); 60 | obx_model_property(model, "stringvector", OBXPropertyType_StringVector, 14, 2211039980163256942); 61 | obx_model_property(model, "byte", OBXPropertyType_Byte, 15, 8283195889592016512); 62 | obx_model_property(model, "ubyte", OBXPropertyType_Byte, 16, 2204379929217582908); 63 | obx_model_property_flags(model, OBXPropertyFlags_UNSIGNED); 64 | obx_model_property(model, "bytevector", OBXPropertyType_ByteVector, 17, 8640208185566146332); 65 | obx_model_property(model, "ubytevector", OBXPropertyType_ByteVector, 18, 7744667429633222761); 66 | obx_model_property(model, "float32", OBXPropertyType_Float, 19, 8432942845376480737); 67 | obx_model_property(model, "float64", OBXPropertyType_Double, 20, 8918992376217400744); 68 | obx_model_property(model, "float", OBXPropertyType_Float, 21, 1569262633269218436); 69 | obx_model_property(model, "double", OBXPropertyType_Double, 22, 1844447541348929615); 70 | obx_model_entity_last_property_id(model, 22, 1844447541348929615); 71 | 72 | obx_model_last_entity_id(model, 3, 1679870369785090036); 73 | return model; // NOTE: the returned model will contain error information if an error occurred. 74 | } 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /external/flatcc/portable/pstdalign.h: -------------------------------------------------------------------------------- 1 | #ifndef PSTDALIGN_H 2 | #define PSTDALIGN_H 3 | 4 | /* 5 | * NOTE: aligned_alloc is defined via paligned_alloc.h 6 | * and requires aligned_free to be fully portable although 7 | * free also works on C11 and platforms with posix_memalign. 8 | * 9 | * NOTE: C++11 defines alignas as a keyword but then also defines 10 | * __alignas_is_defined. 11 | * 12 | * C++14 does not define __alignas_is_defined, at least sometimes. 13 | * 14 | * GCC 8.3 reverts on this and makes C++11 behave the same as C++14 15 | * preventing a simple __cplusplus version check from working. 16 | * 17 | * Clang C++ without std=c++11 or std=c++14 does define alignas 18 | * but does so incorrectly wrt. C11 and C++11 semantics because 19 | * `alignas(4) float x;` is not recognized. 20 | * To fix such issues, either move to a std version, or 21 | * include a working stdalign.h for the given compiler before 22 | * this file. 23 | * 24 | * newlib defines _Alignas and _Alignof in sys/cdefs but rely on 25 | * gcc version for which can lead to conflicts if 26 | * stdalign is not included. 27 | * 28 | * newlibs need for conflicts with broken C++ stdalign 29 | * but this can be fixed be using std=C++11 or newer. 30 | * 31 | * MSVC does not support at least up to MSVC 2015, 32 | * but does appear to support alignas and alignof keywords in 33 | * recent standard C++. 34 | * 35 | * TCC only supports alignas with a numeric argument like 36 | * `alignas(4)`, but not `alignas(float)`. 37 | * 38 | * If stdalign.h is supported but heuristics in this file are 39 | * insufficient to detect this, try including manually 40 | * or define HAVE_STDALIGN_H. 41 | */ 42 | 43 | /* https://github.com/dvidelabs/flatcc/issues/130 */ 44 | #ifndef __alignas_is_defined 45 | #if defined(__cplusplus) 46 | #if __cplusplus == 201103 && !defined(__clang__) && ((__GNUC__ > 8) || (__GNUC__ == 8 && __GNUC_MINOR__ >= 3)) 47 | #define __alignas_is_defined 1 48 | #define __alignof_is_defined 1 49 | #include 50 | #endif 51 | #endif 52 | #endif 53 | 54 | /* Allow for alternative solution to be included first. */ 55 | #ifndef __alignas_is_defined 56 | 57 | #ifdef __cplusplus 58 | #if defined(PORTABLE_PATCH_CPLUSPLUS_STDALIGN) 59 | #include 60 | #undef alignas 61 | #define alignas(t) __attribute__((__aligned__(t))) 62 | #endif 63 | #endif 64 | 65 | #if !defined(PORTABLE_HAS_INCLUDE_STDALIGN) 66 | #if defined(__has_include) 67 | #if __has_include() 68 | #define PORTABLE_HAS_INCLUDE_STDALIGN 1 69 | #else 70 | #define PORTABLE_HAS_INCLUDE_STDALIGN 0 71 | #endif 72 | #endif 73 | #endif 74 | 75 | /* https://lists.gnu.org/archive/html/bug-gnulib/2015-08/msg00003.html */ 76 | #if defined(__cplusplus) 77 | #if !defined(_MSC_VER) 78 | #include 79 | #endif 80 | #if __cplusplus > 201103 81 | #define __alignas_is_defined 1 82 | #define __alignof_is_defined 1 83 | #endif 84 | #elif PORTABLE_HAS_INCLUDE_STDALIGN 85 | #include 86 | #elif !defined(__clang__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) 87 | #include 88 | #elif defined(HAVE_STDALIGN_H) 89 | #include 90 | #endif 91 | 92 | #endif /* __alignas_is_defined */ 93 | 94 | #ifndef __alignas_is_defined 95 | 96 | #ifdef __cplusplus 97 | extern "C" { 98 | #endif 99 | 100 | #if (!defined(__clang__) && defined(__GNUC__) && \ 101 | ((__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 7))) 102 | #undef PORTABLE_C11_STDALIGN_MISSING 103 | #define PORTABLE_C11_STDALIGN_MISSING 104 | #endif 105 | 106 | #if defined(__IBMC__) 107 | #undef PORTABLE_C11_STDALIGN_MISSING 108 | #define PORTABLE_C11_STDALIGN_MISSING 109 | #endif 110 | 111 | #if ((defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) && \ 112 | !defined(PORTABLE_C11_STDALIGN_MISSING)) 113 | /* C11 or newer */ 114 | #include 115 | #else 116 | #if defined(__GNUC__) || defined(__IBM_ALIGNOF__) || defined(__clang__) 117 | 118 | #ifndef _Alignas 119 | #define _Alignas(t) __attribute__((__aligned__(t))) 120 | #endif 121 | 122 | #ifndef _Alignof 123 | #define _Alignof(t) __alignof__(t) 124 | #endif 125 | 126 | #elif defined(_MSC_VER) 127 | 128 | #define _Alignas(t) __declspec (align(t)) 129 | #define _Alignof(t) __alignof(t) 130 | 131 | #elif defined(__TINYC__) 132 | 133 | /* Supports `_Alignas(integer-expression)`, but not `_Alignas(type)`. */ 134 | #define _Alignas(t) __attribute__(aligned(t)) 135 | #define _Alignof(t) __alignof__(t) 136 | 137 | #else 138 | #error please update pstdalign.h with support for current compiler and library 139 | #endif 140 | 141 | #endif /* __STDC__ */ 142 | 143 | #ifndef alignas 144 | #define alignas _Alignas 145 | #endif 146 | 147 | #ifndef alignof 148 | #define alignof _Alignof 149 | #endif 150 | 151 | #define __alignas_is_defined 1 152 | #define __alignof_is_defined 1 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif /* __alignas__is_defined */ 159 | 160 | #include "paligned_alloc.h" 161 | 162 | #endif /* PSTDALIGN_H */ 163 | -------------------------------------------------------------------------------- /external/flatbuffers/registry.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Google Inc. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef FLATBUFFERS_REGISTRY_H_ 18 | #define FLATBUFFERS_REGISTRY_H_ 19 | 20 | #include "flatbuffers/base.h" 21 | #include "flatbuffers/idl.h" 22 | 23 | namespace flatbuffers { 24 | 25 | // Convenience class to easily parse or generate text for arbitrary FlatBuffers. 26 | // Simply pre-populate it with all schema filenames that may be in use, and 27 | // This class will look them up using the file_identifier declared in the 28 | // schema. 29 | class Registry { 30 | public: 31 | // Call this for all schemas that may be in use. The identifier has 32 | // a function in the generated code, e.g. MonsterIdentifier(). 33 | void Register(const char *file_identifier, const char *schema_path) { 34 | Schema schema; 35 | schema.path_ = schema_path; 36 | schemas_[file_identifier] = schema; 37 | } 38 | 39 | // Generate text from an arbitrary FlatBuffer by looking up its 40 | // file_identifier in the registry. 41 | bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest) { 42 | // Get the identifier out of the buffer. 43 | // If the buffer is truncated, exit. 44 | if (len < sizeof(uoffset_t) + kFileIdentifierLength) { 45 | lasterror_ = "buffer truncated"; 46 | return false; 47 | } 48 | std::string ident( 49 | reinterpret_cast(flatbuf) + sizeof(uoffset_t), 50 | kFileIdentifierLength); 51 | // Load and parse the schema. 52 | Parser parser; 53 | if (!LoadSchema(ident, &parser)) return false; 54 | // Now we're ready to generate text. 55 | auto err = GenText(parser, flatbuf, dest); 56 | if (err) { 57 | lasterror_ = 58 | "unable to generate text for FlatBuffer binary: " + std::string(err); 59 | return false; 60 | } 61 | return true; 62 | } 63 | 64 | // Converts a binary buffer to text using one of the schemas in the registry, 65 | // use the file_identifier to indicate which. 66 | // If DetachedBuffer::data() is null then parsing failed. 67 | DetachedBuffer TextToFlatBuffer(const char *text, 68 | const char *file_identifier) { 69 | // Load and parse the schema. 70 | Parser parser; 71 | if (!LoadSchema(file_identifier, &parser)) return DetachedBuffer(); 72 | // Parse the text. 73 | if (!parser.Parse(text)) { 74 | lasterror_ = parser.error_; 75 | return DetachedBuffer(); 76 | } 77 | // We have a valid FlatBuffer. Detach it from the builder and return. 78 | return parser.builder_.Release(); 79 | } 80 | 81 | // Modify any parsing / output options used by the other functions. 82 | void SetOptions(const IDLOptions &opts) { opts_ = opts; } 83 | 84 | // If schemas used contain include statements, call this function for every 85 | // directory the parser should search them for. 86 | void AddIncludeDirectory(const char *path) { include_paths_.push_back(path); } 87 | 88 | // Returns a human readable error if any of the above functions fail. 89 | const std::string &GetLastError() { return lasterror_; } 90 | 91 | private: 92 | bool LoadSchema(const std::string &ident, Parser *parser) { 93 | // Find the schema, if not, exit. 94 | auto it = schemas_.find(ident); 95 | if (it == schemas_.end()) { 96 | // Don't attach the identifier, since it may not be human readable. 97 | lasterror_ = "identifier for this buffer not in the registry"; 98 | return false; 99 | } 100 | auto &schema = it->second; 101 | // Load the schema from disk. If not, exit. 102 | std::string schematext; 103 | if (!LoadFile(schema.path_.c_str(), false, &schematext)) { 104 | lasterror_ = "could not load schema: " + schema.path_; 105 | return false; 106 | } 107 | // Parse schema. 108 | parser->opts = opts_; 109 | if (!parser->Parse(schematext.c_str(), include_paths_.data(), 110 | schema.path_.c_str())) { 111 | lasterror_ = parser->error_; 112 | return false; 113 | } 114 | return true; 115 | } 116 | 117 | struct Schema { 118 | std::string path_; 119 | // TODO(wvo) optionally cache schema file or parsed schema here. 120 | }; 121 | 122 | std::string lasterror_; 123 | IDLOptions opts_; 124 | std::vector include_paths_; 125 | std::map schemas_; 126 | }; 127 | 128 | } // namespace flatbuffers 129 | 130 | #endif // FLATBUFFERS_REGISTRY_H_ 131 | -------------------------------------------------------------------------------- /src-test-gen/objectbox-model.json: -------------------------------------------------------------------------------- 1 | { 2 | "_note1": "KEEP THIS FILE! Check it into a version control system (VCS) like git.", 3 | "_note2": "ObjectBox manages crucial IDs for your object model. See docs for details.", 4 | "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", 5 | "entities": [ 6 | { 7 | "id": "1:4238748172040711863", 8 | "lastPropertyId": "3:8289563594193508940", 9 | "name": "Bar", 10 | "properties": [ 11 | { 12 | "id": "1:8899753625016606063", 13 | "name": "id", 14 | "type": 6, 15 | "flags": 1 16 | }, 17 | { 18 | "id": "2:8817565853152409613", 19 | "name": "text", 20 | "type": 9 21 | }, 22 | { 23 | "id": "3:8289563594193508940", 24 | "name": "fooId", 25 | "type": 6, 26 | "flags": 8192 27 | } 28 | ] 29 | }, 30 | { 31 | "id": "2:3681320287511818591", 32 | "lastPropertyId": "2:4580216775980296323", 33 | "name": "Foo", 34 | "properties": [ 35 | { 36 | "id": "1:1727382257942252770", 37 | "name": "id", 38 | "type": 6, 39 | "flags": 1 40 | }, 41 | { 42 | "id": "2:4580216775980296323", 43 | "name": "text", 44 | "type": 9 45 | } 46 | ] 47 | }, 48 | { 49 | "id": "3:1679870369785090036", 50 | "lastPropertyId": "22:1844447541348929615", 51 | "name": "Typeful", 52 | "properties": [ 53 | { 54 | "id": "1:2357716816519717741", 55 | "name": "id", 56 | "type": 6, 57 | "flags": 1 58 | }, 59 | { 60 | "id": "2:7787106383907421892", 61 | "name": "int", 62 | "type": 5 63 | }, 64 | { 65 | "id": "3:6626668244087952726", 66 | "name": "int8", 67 | "type": 2 68 | }, 69 | { 70 | "id": "4:2311989977658529302", 71 | "name": "int16", 72 | "type": 3 73 | }, 74 | { 75 | "id": "5:4449626101884999513", 76 | "name": "int32", 77 | "type": 5 78 | }, 79 | { 80 | "id": "6:6878925028725243346", 81 | "name": "int64", 82 | "type": 6 83 | }, 84 | { 85 | "id": "7:6993200619804101647", 86 | "name": "uint", 87 | "type": 5, 88 | "flags": 8192 89 | }, 90 | { 91 | "id": "8:2723131825781050497", 92 | "name": "uint8", 93 | "type": 2, 94 | "flags": 8192 95 | }, 96 | { 97 | "id": "9:1317433661165132830", 98 | "name": "uint16", 99 | "type": 3, 100 | "flags": 8192 101 | }, 102 | { 103 | "id": "10:408806406362957694", 104 | "name": "uint32", 105 | "type": 5, 106 | "flags": 8192 107 | }, 108 | { 109 | "id": "11:7911223144937033489", 110 | "name": "uint64", 111 | "type": 6, 112 | "flags": 8192 113 | }, 114 | { 115 | "id": "12:5102252532293057263", 116 | "name": "bool", 117 | "type": 1 118 | }, 119 | { 120 | "id": "13:1210918154342857444", 121 | "name": "string", 122 | "type": 9 123 | }, 124 | { 125 | "id": "14:2211039980163256942", 126 | "name": "stringvector", 127 | "type": 30 128 | }, 129 | { 130 | "id": "15:8283195889592016512", 131 | "name": "byte", 132 | "type": 2 133 | }, 134 | { 135 | "id": "16:2204379929217582908", 136 | "name": "ubyte", 137 | "type": 2, 138 | "flags": 8192 139 | }, 140 | { 141 | "id": "17:8640208185566146332", 142 | "name": "bytevector", 143 | "type": 23 144 | }, 145 | { 146 | "id": "18:7744667429633222761", 147 | "name": "ubytevector", 148 | "type": 23 149 | }, 150 | { 151 | "id": "19:8432942845376480737", 152 | "name": "float32", 153 | "type": 7 154 | }, 155 | { 156 | "id": "20:8918992376217400744", 157 | "name": "float64", 158 | "type": 8 159 | }, 160 | { 161 | "id": "21:1569262633269218436", 162 | "name": "float", 163 | "type": 7 164 | }, 165 | { 166 | "id": "22:1844447541348929615", 167 | "name": "double", 168 | "type": 8 169 | } 170 | ] 171 | } 172 | ], 173 | "lastEntityId": "3:1679870369785090036", 174 | "lastIndexId": "", 175 | "lastRelationId": "", 176 | "modelVersion": 5, 177 | "modelVersionParserMinimum": 5, 178 | "retiredEntityUids": [], 179 | "retiredIndexUids": [], 180 | "retiredPropertyUids": [], 181 | "retiredRelationUids": [], 182 | "version": 1 183 | } -------------------------------------------------------------------------------- /include/objectbox-dart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021-2023 ObjectBox Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef OBJECTBOX_DART_H 18 | #define OBJECTBOX_DART_H 19 | 20 | #include 21 | 22 | #include "dart_api.h" 23 | #include "objectbox-sync.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | //---------------------------------------------- 30 | // Dart-specific binding 31 | // 32 | // Following section provides [Dart](https://dart.dev) specific async callbacks integration. 33 | // These functions are only used internally by [objectbox-dart](https://github.com/objectbox/objectbox-dart) binding. 34 | // In short - instead of issuing callbacks from background threads, their messages are sent to Dart over NativePorts. 35 | //---------------------------------------------- 36 | 37 | /// Initializes Dart API - call before any other obx_dart_* functions. 38 | OBX_C_API obx_err obx_dart_init_api(void* data); 39 | 40 | /// @see obx_observe() 41 | /// Note: use obx_observer_close() to free unassign the observer and free resources after you're done with it 42 | OBX_C_API OBX_observer* obx_dart_observe(OBX_store* store, int64_t native_port); 43 | 44 | // @see obx_observe_single_type() 45 | OBX_C_API OBX_observer* obx_dart_observe_single_type(OBX_store* store, obx_schema_id type_id, int64_t native_port); 46 | 47 | // Note: use OBX_dart_sync_listener_close() to unassign the listener and free native resources 48 | struct OBX_dart_sync_listener; 49 | typedef struct OBX_dart_sync_listener OBX_dart_sync_listener; 50 | 51 | /// @param listener may be NULL 52 | OBX_C_API obx_err obx_dart_sync_listener_close(OBX_dart_sync_listener* listener); 53 | 54 | // @see obx_sync_listener_connect() 55 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_connect(OBX_sync* sync, int64_t native_port); 56 | 57 | /// @see obx_sync_listener_disconnect() 58 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_disconnect(OBX_sync* sync, int64_t native_port); 59 | 60 | /// @see obx_sync_listener_login() 61 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_login(OBX_sync* sync, int64_t native_port); 62 | 63 | /// @see obx_sync_listener_login_failure() 64 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_login_failure(OBX_sync* sync, int64_t native_port); 65 | 66 | /// @see obx_sync_listener_complete() 67 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_complete(OBX_sync* sync, int64_t native_port); 68 | 69 | /// @see obx_sync_listener_change() 70 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_change(OBX_sync* sync, int64_t native_port); 71 | 72 | /// @see obx_sync_listener_server_time() 73 | OBX_C_API OBX_dart_sync_listener* obx_dart_sync_listener_server_time(OBX_sync* sync, int64_t native_port); 74 | 75 | /// @see obx_async_put_object() 76 | OBX_C_API obx_id obx_dart_async_put_object(OBX_async* async, int64_t native_port, void* data, size_t size, 77 | OBXPutMode mode); 78 | 79 | struct OBX_dart_stream; 80 | typedef struct OBX_dart_stream OBX_dart_stream; 81 | 82 | OBX_C_API obx_err obx_dart_stream_close(OBX_dart_stream* stream); 83 | 84 | /// @see obx_dart_stream_query_find 85 | OBX_C_API OBX_dart_stream* obx_dart_query_find(OBX_query* query, int64_t native_port); 86 | 87 | OBX_C_API OBX_dart_stream* obx_dart_query_find_ptr(OBX_query* query, int64_t native_port); 88 | 89 | struct OBX_dart_finalizer; 90 | typedef struct OBX_dart_finalizer OBX_dart_finalizer; 91 | 92 | /// A function to clean up native resources. Must be a c-function (non-throwing). The returned error is ignored. 93 | /// e.g. obx_query_close(), obx_store_close(), ... 94 | typedef obx_err obx_dart_closer(void* native_object); 95 | 96 | /// Attaches a finalizer (destructor) to be called when the given object is garbage-collected. 97 | /// @param dart_object marks the object owning the native pointer 98 | /// @param native_object is the native pointer to be freed 99 | /// @param closer is the function that frees native_object 100 | /// @param native_object_size is an allocated size estimate - can be used by a the Dart garbage collector to prioritize 101 | /// @return a finalizer freed automatically when the GC finalizer runs (or manually by obx_dart_detach_finalizer()) 102 | /// @return NULL if the finalizer couldn't be attached, in which case the caller is responsible for running the closer 103 | OBX_C_API OBX_dart_finalizer* obx_dart_attach_finalizer(Dart_Handle dart_object, obx_dart_closer* closer, 104 | void* native_object, size_t native_object_size); 105 | 106 | /// Detach the finalizer preliminarily, without executing its "closer" 107 | OBX_C_API obx_err obx_dart_detach_finalizer(OBX_dart_finalizer* finalizer, Dart_Handle dart_object); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif // OBJECTBOX_DART_H 114 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_identifier.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_IDENTIFIER_H 2 | #define FLATCC_IDENTIFIER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #ifndef FLATCC_FLATBUFFERS_H 9 | #error "include via flatcc/flatcc_flatbuffers.h" 10 | #endif 11 | 12 | #ifndef UINT8_MAX 13 | #include 14 | #endif 15 | 16 | /* 17 | * FlatBuffers identifiers are normally specified by "file_identifer" in 18 | * the schema, but a standard hash of the fully qualified type name can 19 | * also be used. This file implements such a mapping, but the generated 20 | * headers also contain the necessary information for known types. 21 | */ 22 | 23 | 24 | /* 25 | * Returns the type hash of a given name in native endian format. 26 | * Generated code already provides these, but if a name was changed 27 | * in the schema it may be relevant to recompute the hash manually. 28 | * 29 | * The wire-format of this value should always be little endian. 30 | * 31 | * Note: this must be the fully qualified name, e.g. in the namespace 32 | * "MyGame.Example": 33 | * 34 | * flatbuffers_type_hash_from_name("MyGame.Example.Monster"); 35 | * 36 | * or, in the global namespace just: 37 | * 38 | * flatbuffers_type_hash_from_name("MyTable"); 39 | * 40 | * This assumes 32 bit hash type. For other sizes, other FNV-1a 41 | * constants would be required. 42 | * 43 | * Note that we reserve hash value 0 for missing or ignored value. 44 | */ 45 | static inline flatbuffers_thash_t flatbuffers_type_hash_from_name(const char *name) 46 | { 47 | uint32_t hash = UINT32_C(2166136261); 48 | while (*name) { 49 | hash ^= (unsigned char)*name; 50 | hash = hash * UINT32_C(16777619); 51 | ++name; 52 | } 53 | if (hash == 0) { 54 | hash = UINT32_C(2166136261); 55 | } 56 | return hash; 57 | } 58 | 59 | /* 60 | * Type hash encoded as little endian file identifier string. 61 | * Note: if type hash is 0, the identifier should be null which 62 | * we cannot return in this interface. 63 | */ 64 | static inline void flatbuffers_identifier_from_type_hash(flatbuffers_thash_t type_hash, flatbuffers_fid_t out_identifier) 65 | { 66 | out_identifier[0] = (char)(type_hash & 0xff); 67 | type_hash >>= 8; 68 | out_identifier[1] = (char)(type_hash & 0xff); 69 | type_hash >>= 8; 70 | out_identifier[2] = (char)(type_hash & 0xff); 71 | type_hash >>= 8; 72 | out_identifier[3] = (char)(type_hash & 0xff); 73 | } 74 | 75 | /* Native integer encoding of file identifier. */ 76 | static inline flatbuffers_thash_t flatbuffers_type_hash_from_identifier(const flatbuffers_fid_t identifier) 77 | { 78 | uint8_t *p = (uint8_t *)identifier; 79 | 80 | return identifier ? 81 | (uint32_t)p[0] + (((uint32_t)p[1]) << 8) + (((uint32_t)p[2]) << 16) + (((uint32_t)p[3]) << 24) : 0; 82 | } 83 | 84 | /* 85 | * Convert a null terminated string identifier like "MONS" or "X" into a 86 | * native type hash identifier, usually for comparison. This will not 87 | * work with type hash strings because they can contain null bytes. 88 | */ 89 | static inline flatbuffers_thash_t flatbuffers_type_hash_from_string(const char *identifier) 90 | { 91 | flatbuffers_thash_t h = 0; 92 | const uint8_t *p = (const uint8_t *)identifier; 93 | 94 | if (!p[0]) return h; 95 | h += ((flatbuffers_thash_t)p[0]); 96 | if (!p[1]) return h; 97 | h += ((flatbuffers_thash_t)p[1]) << 8; 98 | if (!p[2]) return h; 99 | h += ((flatbuffers_thash_t)p[2]) << 16; 100 | /* No need to test for termination here. */ 101 | h += ((flatbuffers_thash_t)p[3]) << 24; 102 | return h; 103 | } 104 | 105 | /* 106 | * Computes the little endian wire format of the type hash. It can be 107 | * used as a file identifer argument to various flatcc buffer calls. 108 | * 109 | * `flatbuffers_fid_t` is just `char [4]` for the default flatbuffers 110 | * type system defined in `flatcc/flatcc_types.h`. 111 | */ 112 | static inline void flatbuffers_identifier_from_name(const char *name, flatbuffers_fid_t out_identifier) 113 | { 114 | flatbuffers_identifier_from_type_hash(flatbuffers_type_hash_from_name(name), out_identifier); 115 | } 116 | 117 | /* 118 | * This is a collision free hash (a permutation) of the type hash to 119 | * provide better distribution for use in hash tables. It is likely not 120 | * necessary in praxis, and for uniqueness of identifiers it provides no 121 | * advantage over just using the FNV-1a type hash, except when truncating 122 | * the identifier to less than 32-bits. 123 | * 124 | * Note: the output should not be used in transmission. It provides no 125 | * additional information and just complicates matters. Furthermore, the 126 | * unmodified type hash has the benefit that it can seed a child namespace. 127 | */ 128 | static inline uint32_t flatbuffers_disperse_type_hash(flatbuffers_thash_t type_hash) 129 | { 130 | /* http://stackoverflow.com/a/12996028 */ 131 | uint32_t x = type_hash; 132 | 133 | x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); 134 | x = ((x >> 16) ^ x) * UINT32_C(0x45d9f3b); 135 | x = ((x >> 16) ^ x); 136 | return x; 137 | } 138 | 139 | 140 | /* We have hardcoded assumptions about identifier size. */ 141 | static_assert(sizeof(flatbuffers_fid_t) == 4, "unexpected file identifier size"); 142 | static_assert(sizeof(flatbuffers_thash_t) == 4, "unexpected type hash size"); 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* FLATCC_IDENTIFIER_H */ 149 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_refmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The flatcc builder supports storing a pointer to a refmap 3 | * and wraps some operations to make them work as a dummy 4 | * even if no refmap has been set. This enables optional 5 | * DAG preservation possible during clone operations. 6 | * 7 | * A refmap maps a source address to a builder reference. 8 | * 9 | * This is just a map, but the semantics are important: 10 | * 11 | * The map thus preserves identity of the source. It is not a 12 | * cache because cache eviction would fail to properly track 13 | * identity. 14 | * 15 | * The map is used for memoization during object cloning are and 16 | * may also be used by user logic doing similar operations. 17 | * This ensures that identity is preserved so a source object is 18 | * not duplicated which could lead to either loss of semantic 19 | * information, or an explosion in size, or both. In some, or 20 | * even most, cases this concern may not be important, but when 21 | * it is important, it is important. 22 | * 23 | * The source address must not be reused for different content 24 | * for the lifetime of the map, although the content doest not 25 | * have to be valid or event exist at that location since source 26 | * address is just used as a key. 27 | * 28 | * The lifetime may be a single clone operation which then 29 | * tracks child object references as well, or it may be the 30 | * lifetime of the buffer builder. 31 | * 32 | * The map may be flushed explicitly when the source addresses 33 | * are no longer unique, such as when reusing a memory buffer, 34 | * and when identity preservation is no longer important. 35 | * Flushing a map is esentially the same as ending a lifetime. 36 | * 37 | * Multiple maps may exist concurrently for example if cloning 38 | * an object twice into two new objects that should have 39 | * separate identities. This is especially true and necessary 40 | * when creating a new nested buffer because the nested buffer 41 | * cannot share references with the parent. Cloning and object 42 | * that contains a nested buffer does not require multiple maps 43 | * because the nested buffer is then opaque. 44 | */ 45 | 46 | #ifndef FLATCC_REFMAP_H 47 | #define FLATCC_REFMAP_H 48 | 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | #include "flatcc/flatcc_types.h" 54 | 55 | #ifndef FLATCC_REFMAP_MIN_BUCKETS 56 | /* 8 buckets gives us 5 useful initial entries with a load factor of 0.7 */ 57 | #define FLATCC_REFMAP_MIN_BUCKETS 8 58 | #endif 59 | 60 | #define FLATCC_REFMAP_LOAD_FACTOR 0.7f 61 | 62 | typedef struct flatcc_refmap flatcc_refmap_t; 63 | typedef flatbuffers_soffset_t flatcc_refmap_ref_t; 64 | 65 | static const flatcc_refmap_ref_t flatcc_refmap_not_found = 0; 66 | 67 | struct flatcc_refmap_item { 68 | const void *src; 69 | flatcc_refmap_ref_t ref; 70 | }; 71 | 72 | struct flatcc_refmap { 73 | size_t count; 74 | size_t buckets; 75 | struct flatcc_refmap_item *table; 76 | /* Use stack allocation for small maps. */ 77 | struct flatcc_refmap_item min_table[FLATCC_REFMAP_MIN_BUCKETS]; 78 | }; 79 | 80 | /* 81 | * Fast zero initialization - does not allocate any memory. 82 | * May be replaced by memset 0, but `init` avoids clearing the 83 | * stack allocated initial hash table until it is needed. 84 | */ 85 | static inline int flatcc_refmap_init(flatcc_refmap_t *refmap) 86 | { 87 | refmap->count = 0; 88 | refmap->buckets = 0; 89 | refmap->table = 0; 90 | return 0; 91 | } 92 | 93 | /* 94 | * Removes all items and deallocates memory. 95 | * Not required unless `insert` or `resize` took place. The map can be 96 | * reused subsequently without calling `init`. 97 | */ 98 | void flatcc_refmap_clear(flatcc_refmap_t *refmap); 99 | 100 | /* 101 | * Keeps allocated memory as is, but removes all items. The map 102 | * must intialized first. 103 | */ 104 | void flatcc_refmap_reset(flatcc_refmap_t *refmap); 105 | 106 | /* 107 | * Returns the inserted reference if the `src` pointer was found, 108 | * without inspecting the content of the `src` pointer. 109 | * 110 | * Returns flatcc_refmap_not_found (default 0) if the `src` pointer was 111 | * not found. 112 | */ 113 | flatcc_refmap_ref_t flatcc_refmap_find(flatcc_refmap_t *refmap, const void *src); 114 | 115 | /* 116 | * Inserts a `src` source pointer and its associated `ref` reference 117 | * into the refmap without inspecting the `src` pointer content. The 118 | * `ref` value will be replaced if the the `src` pointer already exists. 119 | * 120 | * Inserting null will just return the ref without updating the map. 121 | * 122 | * There is no delete operation which simplifies an open 123 | * addressing hash table, and it isn't needed for this use case. 124 | * 125 | * Returns the input ref or not_found on allocation error. 126 | */ 127 | flatcc_refmap_ref_t flatcc_refmap_insert(flatcc_refmap_t *refmap, const void *src, flatcc_refmap_ref_t ref); 128 | 129 | /* 130 | * Set the hash table to accommodate at least `count` items while staying 131 | * within the predefined load factor. 132 | * 133 | * Resize is primarily an internal operation, but the user may resize 134 | * ahead of a large anticipated load, or after a large load to shrink 135 | * the table using 0 as the `count` argument. The table never shrinks 136 | * on its own account. 137 | */ 138 | int flatcc_refmap_resize(flatcc_refmap_t *refmap, size_t count); 139 | 140 | #ifdef __cplusplus 141 | } 142 | #endif 143 | 144 | #endif /* FLATCC_REFMAP_H */ 145 | -------------------------------------------------------------------------------- /external/flatcc/flatcc_rtconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef FLATCC_RTCONFIG_H 2 | #define FLATCC_RTCONFIG_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | 9 | /* Include portability layer here since all other files depend on it. */ 10 | #ifdef FLATCC_PORTABLE 11 | #include "flatcc/portable/portable.h" 12 | #endif 13 | 14 | /* 15 | * Fast printing and parsing of double. 16 | * 17 | * This requires the grisu3/grisu3_* files to be in the include path, 18 | * otherwise strod and sprintf will be used (these needed anyway 19 | * as fallback for cases not supported by grisu3). 20 | */ 21 | #ifndef FLATCC_USE_GRISU3 22 | #define FLATCC_USE_GRISU3 1 23 | #endif 24 | 25 | /* 26 | * This requires compiler that has enabled marc=native or similar so 27 | * __SSE4_2__ flag is defined. Otherwise it will have no effect. 28 | * 29 | * While SSE may be used for different purposes, it has (as of this 30 | * writing) only be used to test the effect on JSON whitespace handling 31 | * which improved, but not by a lot, assuming 64-bit unligned access is 32 | * otherwise available: 33 | * 34 | * With 8 space indentation, the JSON benchmark handles 308K parse ops/sec 35 | * while SSE ups that to 333 parse ops/sec or 336 if \r\n is also 36 | * consumed by SSE. Disabling indentation leaves SSE spacing handling 37 | * ineffective, and performance reaches 450K parse ops/sec and can 38 | * improve further to 500+K parse ops/sec if inexact GRISU3 numbers are 39 | * allowed (they are pretty accurate anyway, just not exact). This 40 | * feature requires hacking a flag direct in the grisu3 double parsing 41 | * lib directly and only mentioned for comparison. 42 | * 43 | * In conclusion SSE doesn't add a lot to JSON space handling at least. 44 | * 45 | * Disabled by default, but can be overriden by build system. 46 | */ 47 | #ifndef FLATCC_USE_SSE4_2 48 | #define FLATCC_USE_SSE4_2 0 49 | #endif 50 | 51 | /* 52 | * The verifier only reports yes and no. The following setting 53 | * enables assertions in debug builds. It must be compiled into 54 | * the runtime library and is not normally the desired behavior. 55 | * 56 | * NOTE: enabling this can break test cases so use with build, not test. 57 | */ 58 | #if !defined(FLATCC_DEBUG_VERIFY) && !defined(NDEBUG) 59 | #define FLATCC_DEBUG_VERIFY 0 60 | #endif 61 | 62 | #if !defined(FLATCC_TRACE_VERIFY) 63 | #define FLATCC_TRACE_VERIFY 0 64 | #endif 65 | 66 | 67 | /* 68 | * Limit recursion level for tables. Actual level may be deeper 69 | * when structs are deeply nested - but these are limited by the 70 | * schema compiler. 71 | */ 72 | #ifndef FLATCC_JSON_PRINT_MAX_LEVELS 73 | #define FLATCC_JSON_PRINT_MAX_LEVELS 100 74 | #endif 75 | 76 | /* Maximum length of names printed exluding _type suffix. */ 77 | #ifndef FLATCC_JSON_PRINT_NAME_LEN_MAX 78 | #define FLATCC_JSON_PRINT_NAME_LEN_MAX 100 79 | #endif 80 | 81 | /* 82 | * Print float and double values with C99 hexadecimal floating point 83 | * notation. This option is not valid JSON but it avoids precision 84 | * loss, correctly handles NaN, +/-Infinity and is significantly faster 85 | * to parse and print. Some JSON parsers rely on strtod which does 86 | * support hexadecimal floating points when C99 compliant. 87 | */ 88 | #ifndef FLATCC_JSON_PRINT_HEX_FLOAT 89 | #define FLATCC_JSON_PRINT_HEX_FLOAT 0 90 | #endif 91 | 92 | /* 93 | * Always print multipe enum flags like `color: "Red Green"` 94 | * even when unquote is selected as an option for single 95 | * value like `color: Green`. Otherwise multiple values 96 | * are printed as `color: Red Green`, but this could break 97 | * some flatbuffer json parser. 98 | */ 99 | #ifndef FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS 100 | #define FLATCC_JSON_PRINT_ALWAYS_QUOTE_MULTIPLE_FLAGS 1 101 | #endif 102 | 103 | /* 104 | * The general nesting limit may be lower, but for skipping 105 | * JSON we do not need to - we can set this high as it only 106 | * costs a single char per level in a stack array. 107 | */ 108 | #ifndef FLATCC_JSON_PARSE_GENERIC_MAX_NEST 109 | #define FLATCC_JSON_PARSE_GENERIC_MAX_NEST 512 110 | #endif 111 | 112 | /* Store value even if it is default. */ 113 | #ifndef FLATCC_JSON_PARSE_FORCE_DEFAULTS 114 | #define FLATCC_JSON_PARSE_FORCE_DEFAULTS 0 115 | #endif 116 | 117 | #ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED 118 | #define FLATCC_JSON_PARSE_ALLOW_UNQUOTED 1 119 | #endif 120 | 121 | /* 122 | * Multiple enum values are by default not permitted unless 123 | * quoted like `color: "Red Green" as per Googles flatc JSON 124 | * parser while a single value like `color: Red` can be 125 | * unquoted. Enabling this setting will allow `color: Red 126 | * Green`, but only if FLATCC_JSON_PARSE_ALLOW_UNQUOTED is 127 | * also enabled. 128 | */ 129 | #ifndef FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST 130 | #define FLATCC_JSON_PARSE_ALLOW_UNQUOTED_LIST 0 131 | #endif 132 | 133 | #ifndef FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD 134 | #define FLATCC_JSON_PARSE_ALLOW_UNKNOWN_FIELD 1 135 | #endif 136 | 137 | #ifndef FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA 138 | #define FLATCC_JSON_PARSE_ALLOW_TRAILING_COMMA 1 139 | #endif 140 | 141 | /* 142 | * Just parse to the closing bracket '}' if set. 143 | * Otherwise parse to end by consuming space and 144 | * fail if anything but space follows. 145 | */ 146 | #ifndef FLATCC_PARSE_IGNORE_TRAILING_DATA 147 | #define FLATCC_PARSE_IGNORE_TRAILING_DATA 0 148 | #endif 149 | 150 | /* 151 | * Optimize to parse a lot of white space, but 152 | * in most cases it probably slows parsing down. 153 | */ 154 | #ifndef FLATCC_JSON_PARSE_WIDE_SPACE 155 | #define FLATCC_JSON_PARSE_WIDE_SPACE 0 156 | #endif 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* FLATCC_RTCONFIG_H */ 163 | -------------------------------------------------------------------------------- /external/flatcc/portable/pendian.h: -------------------------------------------------------------------------------- 1 | #ifndef PENDIAN_H 2 | #define PENDIAN_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* 9 | * Defines platform optimized (as per linux 10 | * 11 | * le16toh, le32to, le64toh, be16toh, be32toh, be64toh 12 | * htole16, htole32, htole64, htobe16, htobe32, htobe64 13 | * 14 | * Falls back to auto-detect endian conversion which is also fast 15 | * if fast byteswap operation was detected. 16 | * 17 | * Also defines platform optimized: 18 | * 19 | * bswap16, bswap32, bswap64, 20 | * 21 | * with fall-back to shift-or implementation. 22 | * 23 | * For convenience also defines: 24 | * 25 | * le8to, be8toh, htole8, htobe8 26 | * bswap8 27 | * 28 | * The convience functions makes is simpler to define conversion macros 29 | * based on type size. 30 | * 31 | * NOTE: this implementation expects arguments with no side-effects and 32 | * with appropriately sized unsigned arguments. These are expected to be 33 | * used with typesafe wrappers. 34 | */ 35 | 36 | #ifndef UINT8_MAX 37 | #include "pstdint.h" 38 | #endif 39 | 40 | #if defined(__linux__) 41 | #include 42 | #elif defined(__OpenBSD__) || defined(__FreeBSD__) 43 | #include 44 | #endif 45 | 46 | #include "pendian_detect.h" 47 | 48 | #if defined(_MSC_VER) 49 | #if _MSC_VER >= 1300 50 | #include 51 | #define bswap16 _byteswap_ushort 52 | #define bswap32 _byteswap_ulong 53 | #define bswap64 _byteswap_uint64 54 | #endif 55 | #elif defined(__clang__) 56 | #if __has_builtin(__builtin_bswap16) 57 | #ifndef bswap16 58 | #define bswap16 __builtin_bswap16 59 | #endif 60 | #endif 61 | #if __has_builtin(__builtin_bswap32) 62 | #ifndef bswap32 63 | #define bswap32 __builtin_bswap32 64 | #endif 65 | #endif 66 | #if __has_builtin(__builtin_bswap64) 67 | #ifndef bswap64 68 | #define bswap64 __builtin_bswap64 69 | #endif 70 | #endif 71 | #elif defined(__OpenBSD__) || defined(__FreeBSD__) 72 | #ifndef bswap16 73 | #define bswap16 swap16 74 | #endif 75 | #ifndef bswap32 76 | #define bswap32 swap32 77 | #endif 78 | #ifndef bswap64 79 | #define bswap64 swap64 80 | #endif 81 | #elif defined(__GNUC__) /* Supported since at least GCC 4.4 */ 82 | #ifndef bswap32 83 | #define bswap32 __builtin_bswap32 84 | #endif 85 | #ifndef bswap64 86 | #define bswap64 __builtin_bswap64 87 | #endif 88 | #endif 89 | 90 | #ifndef bswap16 91 | #define bswap16(v) \ 92 | (((uint16_t)(v) << 8) | ((uint16_t)(v) >> 8)) 93 | #endif 94 | 95 | #ifndef bswap32 96 | #define bswap32(v) \ 97 | ((((uint32_t)(v) << 24)) \ 98 | | (((uint32_t)(v) << 8) & UINT32_C(0x00FF0000)) \ 99 | | (((uint32_t)(v) >> 8) & UINT32_C(0x0000FF00)) \ 100 | | (((uint32_t)(v) >> 24))) 101 | #endif 102 | 103 | #ifndef bswap64 104 | #define bswap64(v) \ 105 | ((((uint64_t)(v) << 56)) \ 106 | | (((uint64_t)(v) << 40) & UINT64_C(0x00FF000000000000)) \ 107 | | (((uint64_t)(v) << 24) & UINT64_C(0x0000FF0000000000)) \ 108 | | (((uint64_t)(v) << 8) & UINT64_C(0x000000FF00000000)) \ 109 | | (((uint64_t)(v) >> 8) & UINT64_C(0x00000000FF000000)) \ 110 | | (((uint64_t)(v) >> 24) & UINT64_C(0x0000000000FF0000)) \ 111 | | (((uint64_t)(v) >> 40) & UINT64_C(0x000000000000FF00)) \ 112 | | (((uint64_t)(v) >> 56))) 113 | #endif 114 | 115 | #ifndef bswap8 116 | #define bswap8(v) ((uint8_t)(v)) 117 | #endif 118 | 119 | #if !defined(le16toh) && defined(letoh16) 120 | #define le16toh letoh16 121 | #define le32toh letoh32 122 | #define le64toh letoh64 123 | #endif 124 | 125 | #if !defined(be16toh) && defined(betoh16) 126 | #define be16toh betoh16 127 | #define be32toh betoh32 128 | #define be64toh betoh64 129 | #endif 130 | 131 | /* Assume it goes for all. */ 132 | #if !defined(le16toh) 133 | 134 | #if defined(__LITTLE_ENDIAN__) 135 | 136 | #define le16toh(v) (v) 137 | #define le32toh(v) (v) 138 | #define le64toh(v) (v) 139 | 140 | #define htole16(v) (v) 141 | #define htole32(v) (v) 142 | #define htole64(v) (v) 143 | 144 | #define be16toh(v) bswap16(v) 145 | #define be32toh(v) bswap32(v) 146 | #define be64toh(v) bswap64(v) 147 | 148 | #define htobe16(v) bswap16(v) 149 | #define htobe32(v) bswap32(v) 150 | #define htobe64(v) bswap64(v) 151 | 152 | #elif defined(__BIG_ENDIAN__) 153 | 154 | #define le16toh(v) bswap16(v) 155 | #define le32toh(v) bswap32(v) 156 | #define le64toh(v) bswap64(v) 157 | 158 | #define htole16(v) bswap16(v) 159 | #define htole32(v) bswap32(v) 160 | #define htole64(v) bswap64(v) 161 | 162 | #define be16toh(v) (v) 163 | #define be32toh(v) (v) 164 | #define be64toh(v) (v) 165 | 166 | #define htobe16(v) (v) 167 | #define htobe32(v) (v) 168 | #define htobe64(v) (v) 169 | 170 | #else 171 | 172 | static const int __pendian_test = 1; 173 | 174 | #define le16toh(v) (*(char *)&__pendian_test ? (v) : bswap16(v)) 175 | #define le32toh(v) (*(char *)&__pendian_test ? (v) : bswap32(v)) 176 | #define le64toh(v) (*(char *)&__pendian_test ? (v) : bswap64(v)) 177 | 178 | #define htole16(v) (*(char *)&__pendian_test ? (v) : bswap16(v)) 179 | #define htole32(v) (*(char *)&__pendian_test ? (v) : bswap32(v)) 180 | #define htole64(v) (*(char *)&__pendian_test ? (v) : bswap64(v)) 181 | 182 | #define be16toh(v) (*(char *)&__pendian_test ? bswap16(v) : (v)) 183 | #define be32toh(v) (*(char *)&__pendian_test ? bswap32(v) : (v)) 184 | #define be64toh(v) (*(char *)&__pendian_test ? bswap64(v) : (v)) 185 | 186 | #define htobe16(v) (*(char *)&__pendian_test ? bswap16(v) : (v)) 187 | #define htobe32(v) (*(char *)&__pendian_test ? bswap32(v) : (v)) 188 | #define htobe64(v) (*(char *)&__pendian_test ? bswap64(v) : (v)) 189 | 190 | #endif 191 | 192 | #endif /* le16toh */ 193 | 194 | /* Helpers not part of Linux */ 195 | #if !defined(le8toh) 196 | #define le8toh(n) (n) 197 | #define htole8(n) (n) 198 | #define be8toh(n) (n) 199 | #define htobe8(n) (n) 200 | #endif 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif /* PENDIAN_H */ 207 | -------------------------------------------------------------------------------- /src-test-gen/plain-c-test-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "c_test.obx.h" 5 | #include "objectbox-model.h" 6 | 7 | obx_err printError() { 8 | printf("Unexpected error: %d, %d (%s)\n", obx_last_error_code(), obx_last_error_secondary(), 9 | obx_last_error_message()); 10 | return obx_last_error_code(); 11 | } 12 | 13 | int put_foo(OBX_cursor* cursor, uint64_t* idInOut, char* text) { 14 | flatcc_builder_t builder; 15 | flatcc_builder_init(&builder); 16 | 17 | uint64_t id = *idInOut; 18 | bool isNew = id == 0; 19 | 20 | id = obx_cursor_id_for_put(cursor, id); 21 | if (!id) { 22 | return -1; 23 | } 24 | 25 | int rc = 0; 26 | size_t size; 27 | void* buffer; 28 | 29 | Foo foo = {.id = id, .text = text}; 30 | if (!Foo_to_flatbuffer(&builder, &foo, &buffer, &size)) goto err; 31 | 32 | rc = (isNew ? obx_cursor_put_new : obx_cursor_put)(cursor, id, buffer, size); 33 | if (rc) goto err; 34 | flatcc_builder_clear(&builder); 35 | *idInOut = id; 36 | return 0; 37 | 38 | err: 39 | flatcc_builder_clear(&builder); 40 | if (rc == 0) { 41 | return -1; 42 | } else { 43 | return rc; 44 | } 45 | } 46 | 47 | Foo* get_foo(OBX_cursor* cursor, uint64_t id) { 48 | const void* data; 49 | size_t size; 50 | int rc = obx_cursor_get(cursor, id, &data, &size); 51 | if (rc == OBX_NOT_FOUND) return NULL; // No special treatment at the moment if not found 52 | if (rc) return NULL; 53 | return Foo_new_from_flatbuffer(data, size); 54 | } 55 | 56 | obx_err testCursorStuff(OBX_cursor* cursor) { 57 | obx_id id = 0; 58 | int rc; 59 | 60 | if ((rc = put_foo(cursor, &id, "bar"))) return rc; 61 | 62 | const void* dataRead; 63 | size_t sizeRead; 64 | if (obx_cursor_get(cursor, id, &dataRead, &sizeRead)) return printError(); 65 | printf("%zu data bytes read from ID %ld\n", sizeRead, (long) id); 66 | 67 | rc = obx_cursor_get(cursor, id + 1, &dataRead, &sizeRead); 68 | if (rc != OBX_NOT_FOUND) { 69 | printf("Get expected OBX_NOT_FOUND, but got %d\n", rc); 70 | return 1; 71 | } 72 | 73 | OBX_bytes_array* bytesArray = obx_cursor_get_all(cursor); 74 | if (bytesArray == NULL || bytesArray->count != 1) { 75 | printf("obx_cursor_get_all did not return one result: %d\n", rc); 76 | return 1; 77 | } 78 | obx_bytes_array_free(bytesArray); 79 | 80 | uint64_t count = 0; 81 | if (obx_cursor_count(cursor, &count)) return printError(); 82 | printf("Count: %ld\n", (long) count); 83 | if (obx_cursor_remove(cursor, id)) return printError(); 84 | if (obx_cursor_count(cursor, &count)) return printError(); 85 | printf("Count after remove: %ld\n", (long) count); 86 | 87 | rc = obx_cursor_remove(cursor, id); 88 | if (rc != OBX_NOT_FOUND) { 89 | printf("Remove expected OBX_NOT_FOUND, but got %d\n", rc); 90 | return 1; 91 | } 92 | 93 | return OBX_SUCCESS; 94 | } 95 | 96 | obx_err testPutAndGetFlatObjects(OBX_cursor* cursor) { 97 | obx_id id = 0; 98 | if (put_foo(cursor, &id, "bar")) return -1; 99 | 100 | Foo* foo = get_foo(cursor, id); 101 | if (!foo) return -1; 102 | 103 | assert(foo->id == id); 104 | assert(strcmp(foo->text, "bar") == 0); 105 | 106 | Foo_free(foo); 107 | return 0; 108 | } 109 | 110 | int main(int argc, char* args[]) { 111 | printf("Testing libobjectbox version %s, core version: %s\n", obx_version_string(), obx_version_core_string()); 112 | printf("Result array support: %d\n", obx_has_feature(OBXFeature_ResultArray)); 113 | 114 | if (argc >= 2 && strcmp(args[1], "--in-memory-wal") == 0) { 115 | printf("Enable in-memory WAL\n"); 116 | obx_store_type_id_register_default(OBXStoreTypeId_InMemoryWal); 117 | } else 118 | #ifdef OBX_Feature_Lmdb // If LMDB is unavailable, always register in-memory as default 119 | if (argc >= 2 && strcmp(args[1], "--in-memory") == 0) 120 | #endif 121 | { 122 | printf("Enable in-memory\n"); 123 | obx_store_type_id_register_default(OBXStoreTypeId_InMemory); 124 | } 125 | 126 | OBX_store* store = NULL; 127 | OBX_txn* txn = NULL; 128 | OBX_cursor* cursor = NULL; 129 | OBX_cursor* cursor_bar = NULL; 130 | int rc = 0; 131 | 132 | // Firstly, we need to create a model for our data and the store 133 | { 134 | OBX_model* model = create_obx_model(); 135 | if (!model) goto handle_error; 136 | if (obx_model_error_code(model)) goto handle_error; 137 | 138 | OBX_store_options* opt = obx_opt(); 139 | obx_opt_model(opt, model); 140 | store = obx_store_open(opt); 141 | if (!store) goto handle_error; 142 | 143 | // model is freed by the obx_store_open(), we can't access it anymore 144 | } 145 | 146 | txn = obx_txn_write(store); 147 | if (!txn) goto handle_error; 148 | 149 | cursor = obx_cursor(txn, Foo_ENTITY_ID); 150 | if (!cursor) goto handle_error; 151 | cursor_bar = obx_cursor(txn, Bar_ENTITY_ID); 152 | if (!cursor_bar) goto handle_error; 153 | 154 | // Clear any existing data 155 | if (obx_cursor_remove_all(cursor_bar)) goto handle_error; 156 | if (obx_cursor_remove_all(cursor)) goto handle_error; 157 | 158 | if ((rc = testCursorStuff(cursor))) goto handle_error; 159 | 160 | if ((rc = testPutAndGetFlatObjects(cursor))) goto handle_error; 161 | 162 | // TODO fix double close in handle_error if a close returns an error 163 | if (obx_cursor_close(cursor)) goto handle_error; 164 | if (obx_cursor_close(cursor_bar)) goto handle_error; 165 | if (obx_txn_success(txn)) goto handle_error; 166 | if (!obx_store_await_async_completion(store)) goto handle_error; 167 | if (obx_store_close(store)) goto handle_error; 168 | 169 | return 0; 170 | 171 | // print error and cleanup on error 172 | handle_error: 173 | if (!rc) rc = -1; 174 | printError(); 175 | 176 | // cleanup anything remaining 177 | if (cursor) { 178 | obx_cursor_close(cursor); 179 | } 180 | if (txn) { 181 | obx_txn_close(txn); 182 | } 183 | if (store) { 184 | obx_store_await_async_completion(store); 185 | obx_store_close(store); 186 | } 187 | return rc; 188 | } --------------------------------------------------------------------------------