-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/integration/cmake: update project changes
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
|
||
project(objectbox-generator-cmake-cpp-flat CXX) | ||
|
||
include(../common.cmake) | ||
|
||
add_executable(objectbox-test main.cpp) | ||
target_link_libraries(objectbox-test objectbox) | ||
|
||
set_target_properties(objectbox-test PROPERTIES | ||
CXX_STANDARD 14 | ||
CXX_STANDARD_REQUIRED YES | ||
) | ||
|
||
# Variants: | ||
# - multiple add_obx_schema calls on same target | ||
# - single add_obx_schema call adding two schemas | ||
# - use OUTPUT_DIR_HEADERS (without OUTPUT_DIR) | ||
if (DO_INSOURCE) | ||
add_obx_schema( | ||
TARGET | ||
objectbox-test | ||
SCHEMA_FILES | ||
task.fbs | ||
monster.fbs | ||
person.fbs | ||
INSOURCE | ||
OUTPUT_DIR_MODEL_JSON model | ||
OUTPUT_DIR_HEADERS | ||
include2 | ||
) | ||
target_include_directories(objectbox-test PRIVATE include2) | ||
else() | ||
add_obx_schema( | ||
TARGET | ||
objectbox-test | ||
SCHEMA_FILES | ||
task.fbs | ||
monster.fbs | ||
person.fbs | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#define OBX_CPP_FILE | ||
|
||
|
||
#include "objectbox.hpp" | ||
|
||
#include "objectbox-model.h" | ||
#include "task.obx.hpp" | ||
#include "monster.obx.hpp" | ||
#include "person.obx.hpp" | ||
|
||
#include <cinttypes> | ||
|
||
int main(int argc, char* args[]) | ||
{ | ||
// create_obx_model() provided by objectbox-model.h | ||
// obx interface contents provided by objectbox.hpp | ||
obx::Store store(create_obx_model()); | ||
obx::Box<Task> box(store); | ||
|
||
Task my_task{}; | ||
my_task.text = "Buy milk"; | ||
obx_id id = box.put(my_task); // Create | ||
|
||
std::unique_ptr<Task> task = box.get(id); // Read | ||
if (task) { | ||
task->text += " & some bread"; | ||
box.put(*task); // Update | ||
} | ||
|
||
printf("Your task has ID=%" PRIu64 ", text=%s\n, text2=%s\n", | ||
id, | ||
box.get(id)->text.c_str(), | ||
box.get(id)->text2.c_str()); | ||
|
||
obx::Box<Person> person_box(store); | ||
Person my_person{}; | ||
obx_id person_id = person_box.put(my_person); // Create | ||
|
||
printf("Your person has ID=%" PRIu64, person_id); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
table Person { | ||
id: ulong; | ||
name: string; | ||
age: int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
table Task { | ||
id: ulong; | ||
text: string; | ||
text2: string; | ||
date_created: ulong; | ||
date_finished: ulong; | ||
} |