[ox] Move NodeBuffer and Ptr to ptrarith package
This commit is contained in:
parent
b2245cc3b2
commit
fc3ec47330
1
deps/ox/src/ox/CMakeLists.txt
vendored
1
deps/ox/src/ox/CMakeLists.txt
vendored
@ -7,4 +7,5 @@ endif(OX_USE_STDLIB STREQUAL "ON")
|
|||||||
add_subdirectory(fs)
|
add_subdirectory(fs)
|
||||||
add_subdirectory(trace)
|
add_subdirectory(trace)
|
||||||
add_subdirectory(mc)
|
add_subdirectory(mc)
|
||||||
|
add_subdirectory(ptrarith)
|
||||||
add_subdirectory(std)
|
add_subdirectory(std)
|
||||||
|
2
deps/ox/src/ox/fs/filestore/filestore.hpp
vendored
2
deps/ox/src/ox/fs/filestore/filestore.hpp
vendored
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "nodebuffer.hpp"
|
#include <ox/ptrarith/nodebuffer.hpp>
|
||||||
|
|
||||||
namespace ox::fs {
|
namespace ox::fs {
|
||||||
|
|
||||||
|
@ -8,20 +8,21 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <ox/ptrarith/nodebuffer.hpp>
|
||||||
|
|
||||||
#include "filestore.hpp"
|
#include "filestore.hpp"
|
||||||
#include "nodebuffer.hpp"
|
|
||||||
|
|
||||||
namespace ox::fs {
|
namespace ox::fs {
|
||||||
|
|
||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
struct __attribute__((packed)) FileStoreItem: public Item<size_t> {
|
struct __attribute__((packed)) FileStoreItem: public ptrarith::Item<size_t> {
|
||||||
ox::LittleEndian<size_t> id = 0;
|
ox::LittleEndian<size_t> id = 0;
|
||||||
ox::LittleEndian<uint8_t> fileType = 0;
|
ox::LittleEndian<uint8_t> fileType = 0;
|
||||||
ox::LittleEndian<size_t> links = 0;
|
ox::LittleEndian<size_t> links = 0;
|
||||||
ox::LittleEndian<size_t> left = 0;
|
ox::LittleEndian<size_t> left = 0;
|
||||||
ox::LittleEndian<size_t> right = 0;
|
ox::LittleEndian<size_t> right = 0;
|
||||||
|
|
||||||
explicit FileStoreItem(size_t size): Item<size_t>(size) {
|
explicit FileStoreItem(size_t size): ptrarith::Item<size_t>(size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,8 +32,8 @@ struct __attribute__((packed)) FileStoreItem: public Item<size_t> {
|
|||||||
return sizeof(*this) + this->size();
|
return sizeof(*this) + this->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::fs::Ptr<uint8_t, size_t> data() {
|
ox::ptrarith::Ptr<uint8_t, size_t> data() {
|
||||||
return Ptr<uint8_t, size_t>(this, this->size(), sizeof(*this), this->size() - sizeof(*this));
|
return ptrarith::Ptr<uint8_t, size_t>(this, this->size(), sizeof(*this), this->size() - sizeof(*this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,8 +42,8 @@ template<typename size_t>
|
|||||||
class FileStoreTemplate: public FileStore {
|
class FileStoreTemplate: public FileStore {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using ItemPtr = typename ox::fs::NodeBuffer<size_t, FileStoreItem<size_t>>::ItemPtr;
|
using ItemPtr = typename ox::ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>::ItemPtr;
|
||||||
using Buffer = ox::fs::NodeBuffer<size_t, FileStoreItem<size_t>>;
|
using Buffer = ox::ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>;
|
||||||
|
|
||||||
struct __attribute__((packed)) FileStoreData {
|
struct __attribute__((packed)) FileStoreData {
|
||||||
ox::LittleEndian<size_t> rootNode = 0;
|
ox::LittleEndian<size_t> rootNode = 0;
|
||||||
@ -127,7 +128,7 @@ class FileStoreTemplate: public FileStore {
|
|||||||
template<typename size_t>
|
template<typename size_t>
|
||||||
FileStoreTemplate<size_t>::FileStoreTemplate(void *buff, size_t buffSize) {
|
FileStoreTemplate<size_t>::FileStoreTemplate(void *buff, size_t buffSize) {
|
||||||
m_buffSize = buffSize;
|
m_buffSize = buffSize;
|
||||||
m_buffer = reinterpret_cast<ox::fs::NodeBuffer<size_t, FileStoreItem<size_t>>*>(buff);
|
m_buffer = reinterpret_cast<ox::ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>*>(buff);
|
||||||
if (!m_buffer->valid(buffSize)) {
|
if (!m_buffer->valid(buffSize)) {
|
||||||
m_buffSize = 0;
|
m_buffSize = 0;
|
||||||
m_buffer = nullptr;
|
m_buffer = nullptr;
|
||||||
|
25
deps/ox/src/ox/fs/filesystem2/directory.hpp
vendored
Normal file
25
deps/ox/src/ox/fs/filesystem2/directory.hpp
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 - 2018 gtalent2@gmail.com
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ox/fs/filesystem/pathiterator.hpp>
|
||||||
|
#include <ox/fs/filestore.hpp>
|
||||||
|
|
||||||
|
namespace ox::fs {
|
||||||
|
|
||||||
|
struct DirectoryData {
|
||||||
|
};
|
||||||
|
|
||||||
|
class Directory {
|
||||||
|
|
||||||
|
Error add(const PathIterator &it, uint64_t inode);
|
||||||
|
|
||||||
|
Error rm(PathIterator &it);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
1
deps/ox/src/ox/fs/fs.hpp
vendored
1
deps/ox/src/ox/fs/fs.hpp
vendored
@ -9,3 +9,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "filesystem/filesystemtemplate.hpp"
|
#include "filesystem/filesystemtemplate.hpp"
|
||||||
|
#include "filesystem2/directory.hpp"
|
||||||
|
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
6
deps/ox/src/ox/fs/test/tests.cpp
vendored
@ -337,7 +337,7 @@ map<string, int(*)(string)> tests = {
|
|||||||
[](string) {
|
[](string) {
|
||||||
constexpr auto buffLen = 5000;
|
constexpr auto buffLen = 5000;
|
||||||
uint8_t buff[buffLen];
|
uint8_t buff[buffLen];
|
||||||
ox::fs::Ptr<uint8_t, uint32_t> p(buff, buffLen, 500, 500);
|
ox::ptrarith::Ptr<uint8_t, uint32_t> p(buff, buffLen, 500, 500);
|
||||||
oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid.");
|
oxAssert(p.valid(), "Ptr::subPtr: Ptr p is invalid.");
|
||||||
|
|
||||||
auto subPtr = p.subPtr<uint64_t>(50);
|
auto subPtr = p.subPtr<uint64_t>(50);
|
||||||
@ -351,7 +351,7 @@ map<string, int(*)(string)> tests = {
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
constexpr auto buffLen = 5000;
|
constexpr auto buffLen = 5000;
|
||||||
uint8_t buff[buffLen];
|
uint8_t buff[buffLen];
|
||||||
auto list = new (buff) ox::fs::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
auto list = new (buff) ox::ptrarith::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
||||||
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 1 failed");
|
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 1 failed");
|
||||||
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 2 failed");
|
oxAssert(list->malloc(50).valid(), "NodeBuffer::insert: malloc 2 failed");
|
||||||
auto first = list->firstItem();
|
auto first = list->firstItem();
|
||||||
@ -369,7 +369,7 @@ map<string, int(*)(string)> tests = {
|
|||||||
constexpr auto str2 = "Hello, Moon!";
|
constexpr auto str2 = "Hello, Moon!";
|
||||||
constexpr auto str2Len = ox_strlen(str2) + 1;
|
constexpr auto str2Len = ox_strlen(str2) + 1;
|
||||||
uint8_t buff[buffLen];
|
uint8_t buff[buffLen];
|
||||||
auto list = new (buff) ox::fs::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
auto list = new (buff) ox::ptrarith::NodeBuffer<uint32_t, ox::fs::FileStoreItem<uint32_t>>(buffLen);
|
||||||
ox::fs::FileStore32 fileStore(list, buffLen);
|
ox::fs::FileStore32 fileStore(list, buffLen);
|
||||||
oxAssert(fileStore.format() == 0, "FileStore::format failed.");
|
oxAssert(fileStore.format() == 0, "FileStore::format failed.");
|
||||||
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1) == 0, "FileStore::write 1 failed.");
|
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1) == 0, "FileStore::write 1 failed.");
|
||||||
|
7
deps/ox/src/ox/ptrarith/CMakeLists.txt
vendored
Normal file
7
deps/ox/src/ox/ptrarith/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
install(
|
||||||
|
FILES
|
||||||
|
nodebuffer.hpp
|
||||||
|
ptr.hpp
|
||||||
|
DESTINATION
|
||||||
|
include/ox/ptrarith
|
||||||
|
)
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "ptr.hpp"
|
#include "ptr.hpp"
|
||||||
|
|
||||||
namespace ox::fs {
|
namespace ox::ptrarith {
|
||||||
|
|
||||||
template<typename size_t, typename Item>
|
template<typename size_t, typename Item>
|
||||||
class __attribute__((packed)) NodeBuffer {
|
class __attribute__((packed)) NodeBuffer {
|
||||||
@ -24,7 +24,7 @@ class __attribute__((packed)) NodeBuffer {
|
|||||||
ox::LittleEndian<size_t> firstItem = 0;
|
ox::LittleEndian<size_t> firstItem = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ItemPtr = ox::fs::Ptr<Item, size_t, sizeof(Header)>;
|
using ItemPtr = ox::ptrarith::Ptr<Item, size_t, sizeof(Header)>;
|
||||||
|
|
||||||
Header m_header;
|
Header m_header;
|
||||||
|
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <ox/std/std.hpp>
|
#include <ox/std/std.hpp>
|
||||||
|
|
||||||
namespace ox::fs {
|
namespace ox::ptrarith {
|
||||||
|
|
||||||
template<typename T, typename size_t, size_t minOffset = 1>
|
template<typename T, typename size_t, size_t minOffset = 1>
|
||||||
class Ptr {
|
class Ptr {
|
13
deps/ox/src/ox/std/assert.cpp
vendored
13
deps/ox/src/ox/std/assert.cpp
vendored
@ -6,22 +6,23 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ox/__buildinfo/defines.hpp>
|
||||||
|
|
||||||
|
#if defined(OX_USE_STDLIB)
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <ox/__buildinfo/defines.hpp>
|
#endif
|
||||||
|
|
||||||
namespace ox {
|
namespace ox {
|
||||||
|
|
||||||
|
void _assert([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) {
|
||||||
#if defined(OX_USE_STDLIB)
|
#if defined(OX_USE_STDLIB)
|
||||||
void _assert(const char *file, int line, bool pass, const char *msg) {
|
|
||||||
if (!pass) {
|
if (!pass) {
|
||||||
std::cerr << '(' << file << ':' << line << "): " << msg << std::endl;
|
std::cerr << '(' << file << ':' << line << "): " << msg << std::endl;
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#else
|
|
||||||
void _assert(const char*, int, bool, const char*) {
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
1
deps/ox/src/ox/std/memops.cpp
vendored
1
deps/ox/src/ox/std/memops.cpp
vendored
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 - 2018 gtalent2@gmail.com
|
* Copyright 2015 - 2018 gtalent2@gmail.com
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user