[ox] Move NodeBuffer and Ptr to ptrarith package

This commit is contained in:
Gary Talent 2018-04-14 10:53:02 -05:00
parent b2245cc3b2
commit fc3ec47330
11 changed files with 58 additions and 23 deletions

View File

@ -7,4 +7,5 @@ endif(OX_USE_STDLIB STREQUAL "ON")
add_subdirectory(fs)
add_subdirectory(trace)
add_subdirectory(mc)
add_subdirectory(ptrarith)
add_subdirectory(std)

View File

@ -8,7 +8,7 @@
#pragma once
#include "nodebuffer.hpp"
#include <ox/ptrarith/nodebuffer.hpp>
namespace ox::fs {

View File

@ -8,20 +8,21 @@
#pragma once
#include <ox/ptrarith/nodebuffer.hpp>
#include "filestore.hpp"
#include "nodebuffer.hpp"
namespace ox::fs {
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<uint8_t> fileType = 0;
ox::LittleEndian<size_t> links = 0;
ox::LittleEndian<size_t> left = 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();
}
ox::fs::Ptr<uint8_t, size_t> data() {
return Ptr<uint8_t, size_t>(this, this->size(), sizeof(*this), this->size() - sizeof(*this));
ox::ptrarith::Ptr<uint8_t, size_t> data() {
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 {
private:
using ItemPtr = typename ox::fs::NodeBuffer<size_t, FileStoreItem<size_t>>::ItemPtr;
using Buffer = ox::fs::NodeBuffer<size_t, FileStoreItem<size_t>>;
using ItemPtr = typename ox::ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>::ItemPtr;
using Buffer = ox::ptrarith::NodeBuffer<size_t, FileStoreItem<size_t>>;
struct __attribute__((packed)) FileStoreData {
ox::LittleEndian<size_t> rootNode = 0;
@ -127,7 +128,7 @@ class FileStoreTemplate: public FileStore {
template<typename size_t>
FileStoreTemplate<size_t>::FileStoreTemplate(void *buff, size_t 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)) {
m_buffSize = 0;
m_buffer = nullptr;

View 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);
};
}

View File

@ -8,4 +8,5 @@
#pragma once
#include "filesystem/filesystemtemplate.hpp"
#include "filesystem/filesystemtemplate.hpp"
#include "filesystem2/directory.hpp"

View File

@ -337,7 +337,7 @@ map<string, int(*)(string)> tests = {
[](string) {
constexpr auto buffLen = 5000;
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.");
auto subPtr = p.subPtr<uint64_t>(50);
@ -351,7 +351,7 @@ map<string, int(*)(string)> tests = {
int err = 0;
constexpr auto buffLen = 5000;
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 2 failed");
auto first = list->firstItem();
@ -369,7 +369,7 @@ map<string, int(*)(string)> tests = {
constexpr auto str2 = "Hello, Moon!";
constexpr auto str2Len = ox_strlen(str2) + 1;
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);
oxAssert(fileStore.format() == 0, "FileStore::format failed.");
oxAssert(fileStore.write(4, const_cast<char*>(str1), str1Len, 1) == 0, "FileStore::write 1 failed.");

View File

@ -0,0 +1,7 @@
install(
FILES
nodebuffer.hpp
ptr.hpp
DESTINATION
include/ox/ptrarith
)

View File

@ -12,7 +12,7 @@
#include "ptr.hpp"
namespace ox::fs {
namespace ox::ptrarith {
template<typename size_t, typename Item>
class __attribute__((packed)) NodeBuffer {
@ -24,7 +24,7 @@ class __attribute__((packed)) NodeBuffer {
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;

View File

@ -10,7 +10,7 @@
#include <ox/std/std.hpp>
namespace ox::fs {
namespace ox::ptrarith {
template<typename T, typename size_t, size_t minOffset = 1>
class Ptr {

View File

@ -6,22 +6,23 @@
* 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 <ox/__buildinfo/defines.hpp>
#endif
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)
void _assert(const char *file, int line, bool pass, const char *msg) {
if (!pass) {
std::cerr << '(' << file << ':' << line << "): " << msg << std::endl;
std::abort();
}
}
#else
void _assert(const char*, int, bool, const char*) {
}
#endif
}
}

View File

@ -1,4 +1,3 @@
/*
* Copyright 2015 - 2018 gtalent2@gmail.com
*