mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-22 08:16:42 +00:00
Adds safety asserts.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#ifndef Struct_hpp
|
||||
#define Struct_hpp
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
@@ -113,6 +114,15 @@ struct Serialisable {
|
||||
|
||||
template <typename Owner> class StructImpl: public Struct {
|
||||
public:
|
||||
#ifndef NDEBUG
|
||||
StructImpl() {
|
||||
// Protect against declarations that nominate the wrong Owner; this isn't
|
||||
// a static assert because that wouldn't catch all invalid cases.
|
||||
const auto owner = static_cast<Owner *>(this);
|
||||
assert(owner != nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@returns the value of type @c Type that is loaded from the offset registered for the field @c name.
|
||||
It is the caller's responsibility to provide an appropriate type of data.
|
||||
|
||||
Reference in New Issue
Block a user