[ox/fs] Add model definition for FileAddress
This commit is contained in:
parent
d0f5819072
commit
ed0bf268ba
31
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
31
deps/ox/src/ox/fs/filesystem/filelocation.hpp
vendored
@ -29,15 +29,17 @@ class FileAddress {
|
|||||||
friend ox::Error modelWrite(T*, FileAddress*);
|
friend ox::Error modelWrite(T*, FileAddress*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static constexpr auto TypeName = "ox::FileAddress";
|
||||||
static constexpr auto Fields = 2;
|
static constexpr auto Fields = 2;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FileAddressType m_type = FileAddressType::None;
|
union Data {
|
||||||
union {
|
|
||||||
char *path;
|
char *path;
|
||||||
const char *constPath;
|
const char *constPath;
|
||||||
uint64_t inode;
|
uint64_t inode;
|
||||||
} m_data;
|
};
|
||||||
|
FileAddressType m_type = FileAddressType::None;
|
||||||
|
Data m_data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileAddress();
|
FileAddress();
|
||||||
@ -94,9 +96,9 @@ class FileAddress {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error modelRead(T *io, FileAddress *fa) {
|
ox::Error modelRead(T *io, FileAddress *fa) {
|
||||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
io->template setTypeInfo<FileAddress>();
|
||||||
decltype(fa->m_data.inode) inode = 0;
|
decltype(fa->m_data.inode) inode = 0;
|
||||||
const auto strSize = io->stringLength() + 1;
|
const auto strSize = io->stringLength("path") + 1;
|
||||||
auto path = new char[strSize];
|
auto path = new char[strSize];
|
||||||
oxReturnError(io->field("path", SerStr(path, strSize - 1)));
|
oxReturnError(io->field("path", SerStr(path, strSize - 1)));
|
||||||
oxReturnError(io->field("inode", &inode));
|
oxReturnError(io->field("inode", &inode));
|
||||||
@ -113,7 +115,7 @@ ox::Error modelRead(T *io, FileAddress *fa) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ox::Error modelWrite(T *io, FileAddress *fa) {
|
ox::Error modelWrite(T *io, FileAddress *fa) {
|
||||||
io->setTypeInfo("ox::FileAddress", FileAddress::Fields);
|
io->template setTypeInfo<FileAddress>();
|
||||||
switch (fa->m_type) {
|
switch (fa->m_type) {
|
||||||
case FileAddressType::Path:
|
case FileAddressType::Path:
|
||||||
case FileAddressType::ConstPath:
|
case FileAddressType::ConstPath:
|
||||||
@ -145,4 +147,21 @@ ox::Error modelWrite(T *io, FileAddress *fa) {
|
|||||||
return OxError(0);
|
return OxError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ox::Error modelWriteDefinition(T *io, FileAddress::Data *obj) {
|
||||||
|
io->template setTypeInfo<FileAddress::Data>();
|
||||||
|
oxReturnError(io->field("path", &obj->path));
|
||||||
|
oxReturnError(io->field("constPath", &obj->constPath));
|
||||||
|
oxReturnError(io->field("inode", &obj->inode));
|
||||||
|
return OxError(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
ox::Error modelWriteDefinition(T *io, FileAddress *fa) {
|
||||||
|
io->template setTypeInfo<FileAddress>();
|
||||||
|
oxReturnError(io->field("type", &fa->m_type));
|
||||||
|
oxReturnError(io->field("data", UnionView(&fa->m_data, fa->m_type)));
|
||||||
|
return OxError(0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user