136 lines
2.8 KiB
C++
136 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "./storage.h"
|
|
|
|
namespace stfx { namespace storage {
|
|
|
|
template<class SubClassCRTP>
|
|
struct STFXStorageScanner : public signalsmith::storage::StorageScanner<SubClassCRTP> {
|
|
void info(const char *, const char *) {}
|
|
int version(int v) {
|
|
return v;
|
|
}
|
|
|
|
template<class V>
|
|
bool changed(const char *key, V &v) {
|
|
auto &sub = *(SubClassCRTP *)this;
|
|
sub(key, v);
|
|
return false;
|
|
}
|
|
void invalidate(const char *) {}
|
|
|
|
bool extra() {
|
|
return false;
|
|
}
|
|
template<class V>
|
|
void extra(const char *, V) {}
|
|
|
|
template<class PR>
|
|
RangeParamIgnore range(const char *key, PR ¶m) {
|
|
return {};
|
|
}
|
|
template<class PS>
|
|
SteppedParamIgnore stepped(const char *key, PS ¶m) {
|
|
return {};
|
|
}
|
|
};
|
|
|
|
template<class SubClassCRTP=void>
|
|
struct STFXStorageWriter : public signalsmith::storage::StorageCborWriter<SubClassCRTP> {
|
|
using signalsmith::storage::StorageCborWriter<SubClassCRTP>::StorageCborWriter;
|
|
|
|
void info(const char *name, const char *desc) {
|
|
sub().extra("name", name);
|
|
sub().extra("desc", desc);
|
|
}
|
|
|
|
template<class V>
|
|
bool changed(const char *key, V &v) {
|
|
sub()(key, v);
|
|
return false;
|
|
}
|
|
void invalidate(const char *) {}
|
|
|
|
int version(int v) {
|
|
sub()("version", v);
|
|
return v;
|
|
}
|
|
bool extra() {
|
|
return false;
|
|
}
|
|
template<class V>
|
|
void extra(const char *key, V v) {}
|
|
|
|
template<class PR>
|
|
RangeParamIgnore range(const char *key, PR ¶m) {
|
|
sub()(key, param);
|
|
return {};
|
|
}
|
|
template<class PS>
|
|
SteppedParamIgnore stepped(const char *key, PS ¶m) {
|
|
sub()(key, param);
|
|
return {};
|
|
}
|
|
|
|
private:
|
|
SubClassCRTP & sub() {
|
|
return *(SubClassCRTP *)this;
|
|
}
|
|
};
|
|
|
|
template<class SubClassCRTP=void>
|
|
struct STFXStorageReader : public signalsmith::storage::StorageCborReader<SubClassCRTP> {
|
|
using signalsmith::storage::StorageCborReader<SubClassCRTP>::StorageCborReader;
|
|
|
|
// This is supplemental
|
|
void info(const char *, const char *) {}
|
|
|
|
int version(int v) {
|
|
sub()("version", v);
|
|
return v;
|
|
}
|
|
bool extra() {
|
|
return false;
|
|
}
|
|
template<class V>
|
|
void extra(const char *key, V v) {}
|
|
|
|
template<class V>
|
|
bool changed(const char *key, V &v) {
|
|
V prev = v;
|
|
sub()(key, v);
|
|
return v != prev;
|
|
}
|
|
void invalidate(const char *invalidatedKey) {
|
|
LOG_EXPR(invalidatedKey);
|
|
}
|
|
|
|
template<class PR>
|
|
RangeParamIgnore range(const char *key, PR ¶m) {
|
|
sub()(key, param);
|
|
return {};
|
|
}
|
|
template<class PS>
|
|
SteppedParamIgnore stepped(const char *key, PS ¶m) {
|
|
sub()(key, param);
|
|
return {};
|
|
}
|
|
|
|
private:
|
|
SubClassCRTP & sub() {
|
|
return *(SubClassCRTP *)this;
|
|
}
|
|
};
|
|
|
|
// If void, use itself for CRTP
|
|
template<>
|
|
struct STFXStorageWriter<void> : public STFXStorageWriter<STFXStorageWriter<void>> {
|
|
using STFXStorageWriter<STFXStorageWriter<void>>::STFXStorageWriter;
|
|
};
|
|
template<>
|
|
struct STFXStorageReader<void> : public STFXStorageReader<STFXStorageReader<void>> {
|
|
using STFXStorageReader<STFXStorageReader<void>>::STFXStorageReader;
|
|
};
|
|
|
|
}} // namespace
|