Skip to content

Commit 9e0d32b

Browse files
committed
Update headers
Various minor improvements, e.g. comply with strict compiler checks
1 parent 846b598 commit 9e0d32b

File tree

4 files changed

+80
-52
lines changed

4 files changed

+80
-52
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
ObjectBox Embedded Database for C and C++
22
=========================================
3-
4-
**Your opinion matters to us!** 👉 Please fill in this 2-minute [Anonymous Feedback Form](https://forms.gle/LvVjN6jfFHuivxZX6) 🙏
5-
6-
[ObjectBox](https://objectbox.io) is a superfast C and C++ database for embedded devices (Mobile and IoT), desktop and server apps.
7-
The out-of-the-box [Data Sync](https://objectbox.io/sync/) keeps data harmonized across devices and any kind of backend/cloud reliably. ObjectBox Database and Sync is ideal for reliable resource-efficiency and speed on restricted devices and out-of-the-box differential sync of data in offline settings or scenarios including occasionally connected devices.
3+
[ObjectBox](https://objectbox.io) is a superfast C and C++ database for embedded devices (mobile and IoT), desktop and server apps.
4+
The out-of-the-box [Data Sync](https://objectbox.io/sync/) keeps data in sync across devices and any kind of backend/cloud reliably for occasionally connected devices.
85
ObjectBox Data Persistence and Data Sync follows an offline-first approach and can be used on-premise as well as with a cloud setup.
96

10-
This is the **ObjectBox runtime library** to run ObjectBox as an [embedded database](https://objectbox.io/embedded-database/) in your C or C++ application.
7+
This is the **ObjectBox runtime library** to run ObjectBox as an embedded database in your C or C++ application.
118

129
Here's a C++ example that inserts a `Task` data object (a plain user defined `struct`) into the database:
1310
```c++
@@ -123,7 +120,7 @@ Besides C/C++, ObjectBox also offers:
123120
124121
How can I help ObjectBox?
125122
---------------------------
126-
Let us know what you love, what you don’t like, and what you'd want to see next ❤️
123+
Let us know what you love, what you don’t, what do you want to see next?
127124
128125
**We're looking forward to receiving your comments and requests:**
129126

include/objectbox-sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "objectbox.h"
3535

3636
#if defined(static_assert) || defined(__cplusplus)
37-
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0,
37+
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0, // NOLINT
3838
"Versions of objectbox.h and objectbox-sync.h files do not match, please update");
3939
#endif
4040

include/objectbox-sync.hpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
#include "objectbox-sync.h"
2020
#include "objectbox.hpp"
2121

22-
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0,
22+
static_assert(OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 17 && OBX_VERSION_PATCH == 0, // NOLINT
2323
"Versions of objectbox.h and objectbox-sync.hpp files do not match, please update");
2424

25-
static_assert(sizeof(obx_id) == sizeof(OBX_id_array::ids[0]),
26-
"Can't directly link OBX_id_array.ids to std::vector<obx_id>::data()");
27-
2825
namespace obx {
2926

3027
class SyncCredentials {
@@ -61,6 +58,8 @@ class SyncCredentials {
6158
/// Listens to login events on a sync client.
6259
class SyncClientLoginListener {
6360
public:
61+
virtual ~SyncClientLoginListener() {}
62+
6463
/// Called on a successful login.
6564
/// At this point the connection to the sync destination was established and
6665
/// entered an operational state, in which data can be sent both ways.
@@ -73,6 +72,8 @@ class SyncClientLoginListener {
7372
/// Listens to sync client connection events.
7473
class SyncClientConnectionListener {
7574
public:
75+
virtual ~SyncClientConnectionListener() {}
76+
7677
/// Called when connection is established (on first connect or after a reconnection).
7778
virtual void connected() noexcept = 0;
7879

@@ -85,6 +86,8 @@ class SyncClientConnectionListener {
8586
/// Listens to sync complete event on a sync client.
8687
class SyncClientCompletionListener {
8788
public:
89+
virtual ~SyncClientCompletionListener() {}
90+
8891
/// Called each time a sync completes, in the sense that the client has caught up with the current server state.
8992
/// Or in other words, when the client is "up-to-date".
9093
virtual void updatesCompleted() noexcept = 0;
@@ -95,6 +98,8 @@ class SyncClientTimeListener {
9598
public:
9699
using TimePoint = std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>;
97100

101+
virtual ~SyncClientTimeListener() {}
102+
98103
/// Called when a server time information is received on the client.
99104
/// @param time - current server timestamp since Unix epoch
100105
virtual void serverTime(TimePoint time) noexcept = 0;
@@ -103,7 +108,7 @@ class SyncClientTimeListener {
103108
/// A collection of changes made to one entity type during a sync transaction. Delivered via SyncClientChangeListener.
104109
/// IDs of changed objects are available via `puts` and those of removed objects via `removals`.
105110
struct SyncChange {
106-
obx_schema_id entityId;
111+
obx_schema_id entityId = 0;
107112
std::vector<obx_id> puts;
108113
std::vector<obx_id> removals;
109114
};
@@ -112,6 +117,8 @@ struct SyncChange {
112117
/// @note this may affect performance. Use SyncClientCompletionListener for the general synchronization-finished check.
113118
class SyncChangeListener {
114119
public:
120+
virtual ~SyncChangeListener() {}
121+
115122
/// Called each time when data `changes` from sync were applied locally.
116123
virtual void changed(const std::vector<SyncChange>& changes) noexcept = 0;
117124

@@ -134,12 +141,11 @@ class SyncChangeListener {
134141
}
135142

136143
void copyIdVector(const OBX_id_array* in, std::vector<obx_id>& out) {
137-
static_assert(sizeof(in->ids[0]) == sizeof(out[0]), "Can't directly copy OBX_id_array to std::vector<obx_id>");
138-
if (!in) {
139-
out.clear();
140-
} else {
144+
if (in) {
141145
out.resize(in->count);
142146
memcpy(out.data(), in->ids, sizeof(out[0]) * out.size());
147+
} else {
148+
out.clear();
143149
}
144150
}
145151
};
@@ -153,6 +159,8 @@ class SyncClientListener : public SyncClientLoginListener,
153159

154160
class SyncObjectsMessageListener {
155161
public:
162+
virtual ~SyncObjectsMessageListener() {}
163+
156164
// TODO do we want to transform to a more c++ friendly representation, like in other listeners?
157165
virtual void received(const OBX_sync_msg_objects* cObjects) noexcept = 0;
158166
};
@@ -204,7 +212,7 @@ class SyncClient : public Closable {
204212
/// Can't be copied, single owner of C resources is required (to avoid double-free during destruction)
205213
SyncClient(const SyncClient&) = delete;
206214

207-
virtual ~SyncClient() {
215+
~SyncClient() override {
208216
try {
209217
closeNonVirtual();
210218
} catch (...) {
@@ -243,7 +251,7 @@ class SyncClient : public Closable {
243251
/// @param interval default value is 25 minutes (1 500 000 milliseconds), which is also the allowed maximum.
244252
/// @throws if value is not in the allowed range, e.g. larger than the maximum (1 500 000).
245253
void setHeartbeatInterval(std::chrono::milliseconds interval) {
246-
internal::checkErrOrThrow(obx_sync_heartbeat_interval(cPtr(), interval.count()));
254+
internal::checkErrOrThrow(obx_sync_heartbeat_interval(cPtr(), static_cast<uint64_t>(interval.count())));
247255
}
248256

249257
/// Triggers the heartbeat sending immediately.
@@ -420,7 +428,7 @@ class SyncClient : public Closable {
420428
Guard lock(listeners_.mutex);
421429

422430
// if it was previously set, unassign in the core before (potentially) destroying the object
423-
bool forceRemove = listeners_.combined.get() != nullptr;
431+
bool forceRemove = listeners_.combined != nullptr;
424432
removeLoginListener(forceRemove);
425433
removeCompletionListener(forceRemove);
426434
removeConnectionListener(forceRemove);
@@ -607,7 +615,8 @@ class SyncServer : public Closable {
607615
}
608616

609617
/// Rvalue variant of SyncServer(Options& storeOptions, const std::string& uri) that works equivalently.
610-
explicit SyncServer(Options&& storeOptions, const std::string& uri) : SyncServer((Options&) storeOptions, uri) {}
618+
explicit SyncServer(Options&& storeOptions, const std::string& uri)
619+
: SyncServer(static_cast<Options&>(storeOptions), uri) {}
611620

612621
SyncServer(SyncServer&& source) noexcept : cPtr_(source.cPtr_) {
613622
source.cPtr_ = nullptr;
@@ -676,7 +685,7 @@ class SyncServer : public Closable {
676685
/// specified "0" port (i.e. automatic assignment).
677686
uint16_t port() {
678687
uint16_t result = obx_sync_server_port(cPtr());
679-
if (!result) internal::throwLastError();
688+
if (result == 0) internal::throwLastError();
680689
return result;
681690
}
682691

0 commit comments

Comments
 (0)