1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-11 15:49:38 +00:00

Use std::once in preference to home-rolled solution.

This commit is contained in:
Thomas Harte 2024-12-08 22:35:41 -05:00
parent aecd7f9283
commit b0158ed7ce
3 changed files with 14 additions and 11 deletions

View File

@ -40,6 +40,10 @@ struct ArchimedesTarget: public ::Analyser::Static::Target, public Reflection::S
std::string main_program;
ArchimedesTarget() : Analyser::Static::Target(Machine::Archimedes) {}
private:
friend Reflection::StructImpl<ArchimedesTarget>;
void declare_fields() {}
};
}

View File

@ -24,8 +24,8 @@
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
disableMainThreadChecker = "YES"
codeCoverageEnabled = "YES">

View File

@ -13,6 +13,7 @@
#include <cstring>
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <string>
#include <typeindex>
#include <typeinfo>
@ -150,6 +151,13 @@ template <typename Type> Type get(const Struct &target, const std::string &name,
template <typename Owner> class StructImpl: public Struct {
public:
StructImpl<Owner>() {
static std::once_flag once;
std::call_once(once, [this] {
static_cast<Owner *>(this)->declare_fields();
});
}
/*!
@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.
@ -344,15 +352,6 @@ private:
};
static inline std::unordered_map<std::string, Field> contents_;
static inline std::unordered_map<std::string, std::vector<bool>> permitted_enum_values_;
// Ensure fields are declared at startup.
struct Declarer {
Declarer() {
Owner o;
o.declare_fields();
}
};
static Declarer declarer;
};