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:
parent
aecd7f9283
commit
b0158ed7ce
@ -40,6 +40,10 @@ struct ArchimedesTarget: public ::Analyser::Static::Target, public Reflection::S
|
|||||||
std::string main_program;
|
std::string main_program;
|
||||||
|
|
||||||
ArchimedesTarget() : Analyser::Static::Target(Machine::Archimedes) {}
|
ArchimedesTarget() : Analyser::Static::Target(Machine::Archimedes) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend Reflection::StructImpl<ArchimedesTarget>;
|
||||||
|
void declare_fields() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
</BuildAction>
|
</BuildAction>
|
||||||
<TestAction
|
<TestAction
|
||||||
buildConfiguration = "Debug"
|
buildConfiguration = "Debug"
|
||||||
selectedDebuggerIdentifier = ""
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
disableMainThreadChecker = "YES"
|
disableMainThreadChecker = "YES"
|
||||||
codeCoverageEnabled = "YES">
|
codeCoverageEnabled = "YES">
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
#include <typeinfo>
|
#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 {
|
template <typename Owner> class StructImpl: public Struct {
|
||||||
public:
|
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.
|
@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.
|
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, Field> contents_;
|
||||||
static inline std::unordered_map<std::string, std::vector<bool>> permitted_enum_values_;
|
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user