2021-06-15 11:01:56 +00:00
|
|
|
#pragma once
|
2022-07-20 10:56:33 +00:00
|
|
|
#include <core/record.h>
|
2021-06-15 11:01:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Class for opening, casting, holding and closing records
|
|
|
|
*
|
|
|
|
* @tparam TRecordClass record class
|
|
|
|
*/
|
2022-09-14 16:11:38 +00:00
|
|
|
template <typename TRecordClass>
|
|
|
|
class RecordController {
|
2021-06-15 11:01:56 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Construct a new Record Controller object for record with record name
|
|
|
|
*
|
|
|
|
* @param record_name record name
|
|
|
|
*/
|
|
|
|
RecordController(const char* record_name) {
|
|
|
|
name = record_name;
|
|
|
|
value = static_cast<TRecordClass*>(furi_record_open(name));
|
|
|
|
};
|
|
|
|
|
|
|
|
~RecordController() {
|
|
|
|
furi_record_close(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Record getter
|
|
|
|
*
|
|
|
|
* @return TRecordClass* record value
|
|
|
|
*/
|
|
|
|
TRecordClass* get() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Record getter (by cast)
|
|
|
|
*
|
|
|
|
* @return TRecordClass* record value
|
|
|
|
*/
|
|
|
|
operator TRecordClass*() const {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const char* name;
|
|
|
|
TRecordClass* value;
|
2022-05-06 13:37:10 +00:00
|
|
|
};
|