Merge branch 'master' of ssh://git.axiodl.com:6431/libAthena/athena

This commit is contained in:
Jack Andersen 2019-08-31 10:36:20 -10:00
commit 132c7def65
43 changed files with 792 additions and 744 deletions

View File

@ -184,22 +184,22 @@ class ATDNAEmitVisitor : public clang::RecursiveASTVisitor<ATDNAEmitVisitor> {
static std::string GetOpString(const std::string& fieldName, const std::string& propIdExpr,
const std::string& endianExpr) {
return "<Op, "s + endianExpr + ">({" + propIdExpr + "}, " + fieldName + ", s)";
return "<Op, "s + endianExpr + ">(athena::io::PropId(" + propIdExpr + "), " + fieldName + ", s)";
}
static std::string GetOpString(const std::string& fieldName, const std::string& propIdExpr) {
return "<Op>({" + propIdExpr + "}, " + fieldName + ", s)";
return "<Op>(athena::io::PropId(" + propIdExpr + "), " + fieldName + ", s)";
}
static std::string GetVectorOpString(const std::string& fieldName, const std::string& propIdExpr,
const std::string& sizeExpr, const std::string& endianExpr) {
return "<Op, "s + endianExpr + ">({" + propIdExpr + "}, " + fieldName + ", " + sizeExpr + ", s)";
return "<Op, "s + endianExpr + ">(athena::io::PropId(" + propIdExpr + "), " + fieldName + ", " + sizeExpr + ", s)";
}
static std::string GetVectorOpString(const std::string& fieldName, const std::string& propIdExpr,
const std::string& sizeExpr) {
return "<Op>({" + propIdExpr + "}, " + fieldName + ", " + sizeExpr + ", s)";
return "<Op>(athena::io::PropId(" + propIdExpr + "), " + fieldName + ", " + sizeExpr + ", s)";
}
static void RecurseNestedTypeName(const clang::DeclContext* decl, std::string& templateStmt, std::string& qualType) {

View File

@ -1,35 +1,29 @@
#pragma once
#include <string>
#include "LZ77/LZLookupTable.hpp"
class LZBase {
public:
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3,
atInt32 blockSize = 8);
virtual ~LZBase() {}
virtual ~LZBase();
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
atInt32 slidingWindow() const;
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
atInt32 readAheadBuffer() const;
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
atInt32 minMatch() const;
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
atInt32 blockSize() const;
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
private:
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr,
atUint8* startLBPtr);
atUint32 minimumOffset() const;
protected:
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
LZLengthOffset search(const atUint8* posPtr, const atUint8* dataBegin, const atUint8* dataEnd) const;
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;

View File

@ -1,30 +1,30 @@
#pragma once
#include <map>
#include <deque>
#include <vector>
#include <cstdint>
#include <map>
#include <vector>
#include <athena/Types.hpp>
struct LZLengthOffset {
atUint32 length; // The number of bytes compressed
atUint16 offset; // How far back in sliding window where bytes that match the lookAheadBuffer is located
bool compare_equal(const LZLengthOffset& lo_pair) { return length == lo_pair.length && offset == lo_pair.offset; }
bool operator==(const LZLengthOffset& lo_pair) const { return length == lo_pair.length && offset == lo_pair.offset; }
bool operator!=(const LZLengthOffset& lo_pair) const { return !operator==(lo_pair); }
};
class LZLookupTable {
public:
LZLookupTable();
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
explicit LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
~LZLookupTable();
LZLengthOffset search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
LZLengthOffset search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
void setLookAheadWindow(atInt32 lookAheadWindow);
private:
typedef std::multimap<std::vector<uint8_t>, int32_t> LookupTable;
using LookupTable = std::multimap<std::vector<uint8_t>, int32_t>;
LookupTable table;
atInt32 m_minimumMatch;
atInt32 m_slidingWindow;
atInt32 m_lookAheadWindow;
atInt32 m_minimumMatch = 3;
atInt32 m_slidingWindow = 4096;
atInt32 m_lookAheadWindow = 18;
std::vector<uint8_t> m_buffer;
};

View File

@ -1,11 +1,11 @@
#pragma once
#include "LZBase.hpp"
#include "LZ77/LZBase.hpp"
class LZType10 : public LZBase {
public:
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen);
atUint32 compress(const atUint8* src, atUint8** dstBuf, atUint32 srcLength) override;
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen) override;
};

View File

@ -1,11 +1,11 @@
#pragma once
#include "LZBase.hpp"
#include "LZ77/LZBase.hpp"
class LZType11 : public LZBase {
public:
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 compress(const atUint8* src, atUint8** dst, atUint32 srcLength) override;
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLength) override;
};

View File

@ -1,6 +1,6 @@
#pragma once
#include "athena/Global.hpp"
#include "athena/Types.hpp"
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF,

View File

@ -1,6 +1,6 @@
#pragma once
#include "athena/Global.hpp"
#include "athena/Types.hpp"
namespace athena::io::Compression {
// Zlib compression

View File

@ -6,12 +6,16 @@
* Any changes to the types or namespacing must be reflected in 'atdna/main.cpp'
*/
#include "Global.hpp"
#include "IStreamReader.hpp"
#include "IStreamWriter.hpp"
#include "DNAOp.hpp"
#include <vector>
#include <memory>
#include <string>
#include <vector>
#include <sys/types.h>
#include "athena/DNAOp.hpp"
#include "athena/Global.hpp"
#include "athena/IStreamReader.hpp"
#include "athena/IStreamWriter.hpp"
namespace athena::io {
@ -129,9 +133,9 @@ struct DNAV : DNA<DNAE> {
template <Endian DNAE>
struct DNAVYaml : DNAV<DNAE> {
virtual ~DNAVYaml() = default;
virtual void read(athena::io::IStreamReader& r) = 0;
virtual void write(athena::io::IStreamWriter& w) const = 0;
virtual void binarySize(size_t& s) const = 0;
void read(athena::io::IStreamReader& r) override = 0;
void write(athena::io::IStreamWriter& w) const override = 0;
void binarySize(size_t& s) const override = 0;
virtual void read(athena::io::YAMLDocReader& r) = 0;
virtual void write(athena::io::YAMLDocWriter& w) const = 0;
};

View File

@ -1,11 +1,16 @@
#pragma once
#include "IStreamReader.hpp"
#include "IStreamWriter.hpp"
#include "YAMLDocReader.hpp"
#include "YAMLDocWriter.hpp"
#include "ChecksumsLiterals.hpp"
#include <cstddef>
#include <cstdint>
#include <string>
#include <type_traits>
#include <vector>
#include "athena/ChecksumsLiterals.hpp"
#include "athena/IStreamReader.hpp"
#include "athena/IStreamWriter.hpp"
#include "athena/YAMLDocReader.hpp"
#include "athena/YAMLDocWriter.hpp"
namespace athena::io {
@ -16,8 +21,9 @@ struct PropId {
template <class T>
constexpr T opget() const;
constexpr PropId() = default;
constexpr PropId(const char* name, uint32_t rcrc32, uint64_t crc64) : name(name), rcrc32(rcrc32), crc64(crc64) {}
constexpr PropId(const char* name)
constexpr explicit PropId(const char* name, uint32_t rcrc32, uint64_t crc64)
: name(name), rcrc32(rcrc32), crc64(crc64) {}
constexpr explicit PropId(const char* name)
: name(name)
, rcrc32(athena::checksums::literals::rcrc32_rec(0xFFFFFFFF, name))
, crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {}
@ -36,7 +42,7 @@ constexpr uint64_t PropId::opget<uint64_t>() const {
}
namespace literals {
constexpr PropId operator"" _propid(const char* s, size_t len) { return {s}; }
constexpr PropId operator"" _propid(const char* s, size_t len) { return PropId{s}; }
} // namespace literals
#define AT_PROP_CASE(...) case athena::io::PropId(__VA_ARGS__).opget<typename Op::PropT>()
@ -56,16 +62,16 @@ constexpr PropId operator"" _propid(const char* s, size_t len) { return {s}; }
enum class PropType { None, CRC32, CRC64 };
template <class T>
using __IsPODType = typename std::disjunction<
using __IsPODType = std::disjunction<
std::is_arithmetic<std::remove_cv_t<T>>, std::is_convertible<std::remove_cv_t<T>&, atVec2f&>,
std::is_convertible<std::remove_cv_t<T>&, atVec3f&>, std::is_convertible<std::remove_cv_t<T>&, atVec4f&>,
std::is_convertible<std::remove_cv_t<T>&, atVec2d&>, std::is_convertible<std::remove_cv_t<T>&, atVec3d&>,
std::is_convertible<std::remove_cv_t<T>&, atVec4d&>>;
template <class T>
inline constexpr bool __IsPODType_v = __IsPODType<T>::value;
constexpr bool __IsPODType_v = __IsPODType<T>::value;
template <class T>
using __CastPODType = typename std::conditional_t<
using __CastPODType = std::conditional_t<
std::is_convertible_v<std::remove_cv_t<T>&, atVec2f&>, atVec2f,
std::conditional_t<
std::is_convertible_v<std::remove_cv_t<T>&, atVec3f&>, atVec3f,
@ -78,32 +84,32 @@ using __CastPODType = typename std::conditional_t<
std::remove_cv_t<T>>>>>>>;
template <Endian DNAE>
inline uint16_t __Read16(IStreamReader& r) {
uint16_t __Read16(IStreamReader& r) {
return DNAE == Endian::Big ? r.readUint16Big() : r.readUint16Little();
}
template <Endian DNAE>
inline void __Write16(IStreamWriter& w, uint16_t v) {
void __Write16(IStreamWriter& w, uint16_t v) {
DNAE == Endian::Big ? w.writeUint16Big(v) : w.writeUint16Little(v);
}
template <Endian DNAE>
inline uint32_t __Read32(IStreamReader& r) {
uint32_t __Read32(IStreamReader& r) {
return DNAE == Endian::Big ? r.readUint32Big() : r.readUint32Little();
}
template <Endian DNAE>
inline void __Write32(IStreamWriter& w, uint32_t v) {
void __Write32(IStreamWriter& w, uint32_t v) {
DNAE == Endian::Big ? w.writeUint32Big(v) : w.writeUint32Little(v);
}
template <Endian DNAE>
inline uint64_t __Read64(IStreamReader& r) {
uint64_t __Read64(IStreamReader& r) {
return DNAE == Endian::Big ? r.readUint64Big() : r.readUint64Little();
}
template <Endian DNAE>
inline void __Write64(IStreamWriter& w, uint64_t v) {
void __Write64(IStreamWriter& w, uint64_t v) {
DNAE == Endian::Big ? w.writeUint64Big(v) : w.writeUint64Little(v);
}
@ -112,7 +118,7 @@ struct BinarySize {
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
using StreamT = size_t;
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& s) {
static std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& s) {
if (PropOp != PropType::None) {
/* Accessed via Enumerate, header */
s += 6;
@ -121,7 +127,7 @@ struct BinarySize {
BinarySize<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& s) {
static std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& s) {
if (PropOp != PropType::None) {
/* Accessed via Enumerate, header */
s += 6;
@ -130,19 +136,17 @@ struct BinarySize {
BinarySize<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(const_cast<std::remove_cv_t<T>&>(var)), s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp != PropType::None> Do(const PropId& id, T& var,
StreamT& s) {
static std::enable_if_t<__IsDNARecord_v<T> && PropOp != PropType::None> Do(const PropId& id, T& var, StreamT& s) {
/* Accessed via Enumerate, header */
s += 6;
var.template Enumerate<BinarySize<PropOp>>(s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord_v<T> && PropOp == PropType::None> Do(const PropId& id, T& var,
StreamT& s) {
static std::enable_if_t<__IsDNARecord_v<T> && PropOp == PropType::None> Do(const PropId& id, T& var, StreamT& s) {
var.template Enumerate<BinarySize<PropType::None>>(s);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
BinarySize<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
@ -151,14 +155,14 @@ struct BinarySize {
BinarySize<PropOp>::Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector,
const S& count, StreamT& s) {
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& s) {
for (T& v : vector)
BinarySize<PropOp>::Do<T, DNAE>(id, v, s);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& s) {
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& s) {
/* libc++ specializes vector<bool> as a bitstream */
s += vector.size();
}
@ -167,7 +171,7 @@ struct BinarySize {
s += count;
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& s) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& s) {
s += str.size() + 1;
}
static void Do(const PropId& id, std::string& str, atInt32 count, StreamT& s) {
@ -177,7 +181,7 @@ struct BinarySize {
s += count;
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& s) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& s) {
s += str.size() * 2 + 2;
}
template <Endian DNAE>
@ -263,7 +267,7 @@ struct PropCount {
s += 1;
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& s) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& s) {
/* Only reports one level of properties */
s += 1;
}
@ -272,7 +276,7 @@ struct PropCount {
s += 1;
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& s) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& s) {
/* Only reports one level of properties */
s += 1;
}
@ -290,23 +294,21 @@ struct Read {
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
using StreamT = IStreamReader;
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& r) {
using PODType = std::underlying_type_t<T>;
Read<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& r) {
using CastT = __CastPODType<T>;
Read<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None> Do(const PropId& id, T& var,
StreamT& r) {
static std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None> Do(const PropId& id, T& var, StreamT& r) {
var.template Enumerate<Read<PropType::None>>(r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None> Do(const PropId& id, T& var,
StreamT& r) {
static std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None> Do(const PropId& id, T& var, StreamT& r) {
/* Accessed via Lookup, no header */
atUint16 propCount = __Read16<T::DNAEndian>(r);
for (atUint32 i = 0; i < propCount; ++i) {
@ -324,7 +326,7 @@ struct Read {
}
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
Read<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
@ -333,8 +335,8 @@ struct Read {
Read<PropOp>::Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector,
const S& count, StreamT& r) {
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < static_cast<size_t>(count); ++i) {
@ -343,8 +345,8 @@ struct Read {
}
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
/* libc++ specializes vector<bool> as a bitstream */
vector.clear();
vector.reserve(count);
@ -356,12 +358,12 @@ struct Read {
r.readUBytesToBuf(buf.get(), count);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& r) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& r) {
str = r.readString();
}
static void Do(const PropId& id, std::string& str, atInt32 count, StreamT& r) { str = r.readString(count); }
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& r) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& r) {
Read<PropType::None>::Do<DNAE>(id, str, r);
}
template <Endian DNAE>
@ -429,7 +431,7 @@ struct Write {
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
using StreamT = IStreamWriter;
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& w) {
if (PropOp != PropType::None) {
/* Accessed via Enumerate, header */
if (PropOp == PropType::CRC64)
@ -444,7 +446,7 @@ struct Write {
Write<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& w) {
using CastT = __CastPODType<T>;
if (PropOp != PropType::None) {
/* Accessed via Enumerate, header */
@ -460,8 +462,7 @@ struct Write {
Write<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(const_cast<std::remove_cv_t<T>&>(var)), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None> Do(const PropId& id, T& var,
StreamT& w) {
static std::enable_if_t<__IsDNARecord<T>() && PropOp != PropType::None> Do(const PropId& id, T& var, StreamT& w) {
/* Accessed via Enumerate, header */
if (PropOp == PropType::CRC64)
__Write64<T::DNAEndian>(w, id.crc64);
@ -477,12 +478,11 @@ struct Write {
var.template Enumerate<Write<PropOp>>(w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None> Do(const PropId& id, T& var,
StreamT& w) {
static std::enable_if_t<__IsDNARecord<T>() && PropOp == PropType::None> Do(const PropId& id, T& var, StreamT& w) {
var.template Enumerate<Write<PropType::None>>(w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& s) {
for (auto& v : var)
Write<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>(id, v, s);
}
@ -491,14 +491,14 @@ struct Write {
Write<PropOp>::Do<T, DNAE>(id, var, s);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector,
const S& count, StreamT& w) {
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
for (T& v : vector)
Write<PropOp>::Do<T, DNAE>(id, v, w);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
/* libc++ specializes vector<bool> as a bitstream */
for (const T& v : vector)
w.writeBool(v);
@ -508,13 +508,12 @@ struct Write {
w.writeUBytes(buf.get(), count);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, std::string& str, StreamT& w) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, std::string& str, StreamT& w) {
w.writeString(str);
}
static void Do(const PropId& id, std::string& str, atInt32 count, StreamT& w) { w.writeString(str, count); }
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, std::wstring& str,
StreamT& w) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, std::wstring& str, StreamT& w) {
Write<PropType::None>::Do<DNAE>(id, str, w);
}
template <Endian DNAE>
@ -580,22 +579,22 @@ struct ReadYaml {
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
using StreamT = YAMLDocReader;
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& r) {
using PODType = std::underlying_type_t<T>;
ReadYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& r) {
using CastT = __CastPODType<T>;
ReadYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(var), r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<__IsDNARecord_v<T>> Do(const PropId& id, T& var, StreamT& r) {
if (auto rec = r.enterSubRecord(id.name))
var.template Enumerate<ReadYaml<PropOp>>(r);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& r) {
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& r) {
size_t _count;
if (auto __v = r.enterSubVector(id.name, _count))
for (size_t i = 0; i < _count && i < std::extent_v<T>; ++i)
@ -606,8 +605,8 @@ struct ReadYaml {
/* Squelch size field access */
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector,
const S& count, StreamT& r) {
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
size_t _count;
vector.clear();
if (auto __v = r.enterSubVector(id.name, _count)) {
@ -621,8 +620,8 @@ struct ReadYaml {
const_cast<S&>(count) = vector.size();
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& r) {
/* libc++ specializes vector<bool> as a bitstream */
size_t _count;
vector.clear();
@ -638,12 +637,12 @@ struct ReadYaml {
buf = r.readUBytes(id.name);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& r) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& r) {
str = r.readString(id.name);
}
static void Do(const PropId& id, std::string& str, atInt32 count, StreamT& r) { str = r.readString(id.name); }
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& r) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& r) {
str = r.readWString(id.name);
}
template <Endian DNAE>
@ -697,22 +696,22 @@ struct WriteYaml {
using PropT = std::conditional_t<PropOp == PropType::CRC64, uint64_t, uint32_t>;
using StreamT = YAMLDocWriter;
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<std::is_enum_v<T>> Do(const PropId& id, T& var, StreamT& w) {
using PODType = std::underlying_type_t<T>;
WriteYaml<PropType::None>::Do<PODType, DNAE>(id, *reinterpret_cast<PODType*>(&var), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<__IsPODType_v<T>> Do(const PropId& id, T& var, StreamT& w) {
using CastT = __CastPODType<T>;
WriteYaml<PropType::None>::Do<CastT, DNAE>(id, static_cast<CastT&>(const_cast<std::remove_cv_t<T>&>(var)), w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<__IsDNARecord_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<__IsDNARecord_v<T>> Do(const PropId& id, T& var, StreamT& w) {
if (auto rec = w.enterSubRecord(id.name))
var.template Enumerate<WriteYaml<PropOp>>(w);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& w) {
static std::enable_if_t<std::is_array_v<T>> Do(const PropId& id, T& var, StreamT& w) {
if (auto __v = w.enterSubVector(id.name))
for (auto& v : var)
WriteYaml<PropOp>::Do<std::remove_reference_t<decltype(v)>, DNAE>({}, v, w);
@ -722,15 +721,15 @@ struct WriteYaml {
/* Squelch size field access */
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector,
const S& count, StreamT& w) {
static std::enable_if_t<!std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
if (auto __v = w.enterSubVector(id.name))
for (T& v : vector)
WriteYaml<PropOp>::Do<T, DNAE>(id, v, w);
}
template <class T, class S, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
static std::enable_if_t<std::is_same_v<T, bool>> Do(const PropId& id, std::vector<T>& vector, const S& count,
StreamT& w) {
/* libc++ specializes vector<bool> as a bitstream */
if (auto __v = w.enterSubVector(id.name))
for (const T& v : vector)
@ -740,12 +739,12 @@ struct WriteYaml {
w.writeUBytes(id.name, buf, count);
}
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& w) {
static std::enable_if_t<std::is_same_v<T, std::string>> Do(const PropId& id, T& str, StreamT& w) {
w.writeString(id.name, str);
}
static void Do(const PropId& id, std::string& str, atInt32 count, StreamT& w) { w.writeString(id.name, str); }
template <class T, Endian DNAE>
static typename std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& w) {
static std::enable_if_t<std::is_same_v<T, std::wstring>> Do(const PropId& id, T& str, StreamT& w) {
w.writeWString(id.name, str);
}
template <Endian DNAE>
@ -795,77 +794,77 @@ __WRITE_YAML_S(atVec4f, Endian::Little) { w.writeVec4f(id.name, var); }
__WRITE_YAML_S(atVec4d, Endian::Little) { w.writeVec4d(id.name, var); }
template <class Op, class T, Endian DNAE>
inline void __Do(const PropId& id, T& var, typename Op::StreamT& s) {
void __Do(const PropId& id, T& var, typename Op::StreamT& s) {
Op::template Do<T, DNAE>(id, var, s);
}
template <class Op, class T, Endian DNAE>
inline void __DoSize(const PropId& id, T& var, typename Op::StreamT& s) {
void __DoSize(const PropId& id, T& var, typename Op::StreamT& s) {
Op::template DoSize<T, DNAE>(id, var, s);
}
template <class Op, class T, class S, Endian DNAE>
inline void __Do(const PropId& id, std::vector<T>& vector, const S& count, typename Op::StreamT& s) {
void __Do(const PropId& id, std::vector<T>& vector, const S& count, typename Op::StreamT& s) {
Op::template Do<T, S, DNAE>(id, vector, count, s);
}
template <class Op>
inline void __Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, typename Op::StreamT& s) {
void __Do(const PropId& id, std::unique_ptr<atUint8[]>& buf, size_t count, typename Op::StreamT& s) {
Op::Do(id, buf, count, s);
}
template <class Op>
inline void __Do(const PropId& id, std::string& str, atInt32 count, typename Op::StreamT& s) {
void __Do(const PropId& id, std::string& str, atInt32 count, typename Op::StreamT& s) {
Op::Do(id, str, count, s);
}
template <class Op, Endian DNAE>
inline void __Do(const PropId& id, std::wstring& str, atInt32 count, typename Op::StreamT& s) {
void __Do(const PropId& id, std::wstring& str, atInt32 count, typename Op::StreamT& s) {
Op::template Do<DNAE>(id, str, count, s);
}
template <class Op>
inline void __DoSeek(atInt64 delta, athena::SeekOrigin whence, typename Op::StreamT& s) {
void __DoSeek(atInt64 delta, athena::SeekOrigin whence, typename Op::StreamT& s) {
Op::DoSeek(delta, whence, s);
}
template <class Op>
inline void __DoAlign(atInt64 amount, typename Op::StreamT& s) {
void __DoAlign(atInt64 amount, typename Op::StreamT& s) {
Op::DoAlign(amount, s);
}
template <class T>
inline void __Read(T& obj, athena::io::IStreamReader& r) {
void __Read(T& obj, athena::io::IStreamReader& r) {
__Do<Read<PropType::None>, T, T::DNAEndian>({}, obj, r);
}
template <class T>
inline void __Write(const T& obj, athena::io::IStreamWriter& w) {
void __Write(const T& obj, athena::io::IStreamWriter& w) {
__Do<Write<PropType::None>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
}
template <class T>
inline void __BinarySize(const T& obj, size_t& s) {
void __BinarySize(const T& obj, size_t& s) {
__Do<BinarySize<PropType::None>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
}
template <class T>
inline void __PropCount(const T& obj, size_t& s) {
void __PropCount(const T& obj, size_t& s) {
const_cast<T&>(obj).template Enumerate<PropCount<PropType::None>>(s);
}
template <class T>
inline void __ReadYaml(T& obj, athena::io::YAMLDocReader& r) {
void __ReadYaml(T& obj, athena::io::YAMLDocReader& r) {
obj.template Enumerate<ReadYaml<PropType::None>>(r);
}
template <class T>
inline void __WriteYaml(const T& obj, athena::io::YAMLDocWriter& w) {
void __WriteYaml(const T& obj, athena::io::YAMLDocWriter& w) {
const_cast<T&>(obj).template Enumerate<WriteYaml<PropType::None>>(w);
}
template <class T>
inline void __ReadProp(T& obj, athena::io::IStreamReader& r) {
void __ReadProp(T& obj, athena::io::IStreamReader& r) {
/* Read root 0xffffffff hash (hashed empty string) */
T::DNAEndian == Endian::Big ? r.readUint32Big() : r.readUint32Little();
atInt64 size = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
@ -877,17 +876,17 @@ inline void __ReadProp(T& obj, athena::io::IStreamReader& r) {
}
template <class T>
inline void __WriteProp(const T& obj, athena::io::IStreamWriter& w) {
void __WriteProp(const T& obj, athena::io::IStreamWriter& w) {
__Do<Write<PropType::CRC32>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
}
template <class T>
inline void __BinarySizeProp(const T& obj, size_t& s) {
void __BinarySizeProp(const T& obj, size_t& s) {
__Do<BinarySize<PropType::CRC32>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
}
template <class T>
inline void __ReadProp64(T& obj, athena::io::IStreamReader& r) {
void __ReadProp64(T& obj, athena::io::IStreamReader& r) {
/* Read root 0x0 hash (hashed empty string) */
T::DNAEndian == Endian::Big ? r.readUint64Big() : r.readUint64Little();
atInt64 size = T::DNAEndian == Endian::Big ? r.readUint16Big() : r.readUint16Little();
@ -899,18 +898,18 @@ inline void __ReadProp64(T& obj, athena::io::IStreamReader& r) {
}
template <class T>
inline void __WriteProp64(const T& obj, athena::io::IStreamWriter& w) {
void __WriteProp64(const T& obj, athena::io::IStreamWriter& w) {
__Do<Write<PropType::CRC64>, T, T::DNAEndian>({}, const_cast<T&>(obj), w);
}
template <class T>
inline void __BinarySizeProp64(const T& obj, size_t& s) {
void __BinarySizeProp64(const T& obj, size_t& s) {
__Do<BinarySize<PropType::CRC64>, T, T::DNAEndian>({}, const_cast<T&>(obj), s);
}
} // namespace athena::io
#define AT_DECL_DNA \
#define AT_DECL_DNA_DO \
template <class Op, athena::Endian DNAE = DNAEndian, class T> \
void Do(const athena::io::PropId& _id, T& var, typename Op::StreamT& s) { \
athena::io::__Do<Op, T, DNAE>(_id, var, s); \
@ -945,7 +944,10 @@ inline void __BinarySizeProp64(const T& obj, size_t& s) {
} \
template <class Op> \
void Enumerate(typename Op::StreamT& s); \
static const char* DNAType(); \
static const char* DNAType();
#define AT_DECL_DNA \
AT_DECL_DNA_DO \
void read(athena::io::IStreamReader& r) { athena::io::__Read(*this, r); } \
void write(athena::io::IStreamWriter& w) const { athena::io::__Write(*this, w); } \
void binarySize(size_t& s) const { athena::io::__BinarySize(*this, s); }
@ -959,12 +961,47 @@ inline void __BinarySizeProp64(const T& obj, size_t& s) {
AT_DECL_DNA \
Delete __d;
#define AT_DECL_EXPLICIT_DNAV \
AT_DECL_DNAV \
Delete __d;
#define AT_DECL_EXPLICIT_DNAV_NO_TYPE \
AT_DECL_DNAV_NO_TYPE \
Delete __d;
#define AT_DECL_EXPLICIT_DNA_YAML \
AT_DECL_DNA_YAML \
Delete __d;
#define AT_DECL_EXPLICIT_DNA_YAMLV \
AT_DECL_DNA_YAMLV \
Delete __d;
#define AT_DECL_EXPLICIT_DNA_YAMLV_NO_TYPE \
AT_DECL_DNA_YAMLV_NO_TYPE \
Delete __d;
#define AT_DECL_DNAV \
const char* DNATypeV() const { return DNAType(); }
AT_DECL_DNA_DO \
void read(athena::io::IStreamReader& r) override { athena::io::__Read(*this, r); } \
void write(athena::io::IStreamWriter& w) const override { athena::io::__Write(*this, w); } \
void binarySize(size_t& s) const override { athena::io::__BinarySize(*this, s); } \
const char* DNATypeV() const override { return DNAType(); }
#define AT_DECL_DNAV_NO_TYPE \
AT_DECL_DNA_DO \
void read(athena::io::IStreamReader& r) override { athena::io::__Read(*this, r); } \
void write(athena::io::IStreamWriter& w) const override { athena::io::__Write(*this, w); } \
void binarySize(size_t& s) const override { athena::io::__BinarySize(*this, s); }
#define AT_DECL_DNA_YAMLV \
AT_DECL_DNAV \
void read(athena::io::YAMLDocReader& r) override { athena::io::__ReadYaml(*this, r); } \
void write(athena::io::YAMLDocWriter& w) const override { athena::io::__WriteYaml(*this, w); }
#define AT_DECL_DNA_YAMLV_NO_TYPE \
AT_DECL_DNAV_NO_TYPE \
void read(athena::io::YAMLDocReader& r) override { athena::io::__ReadYaml(*this, r); } \
void write(athena::io::YAMLDocWriter& w) const override { athena::io::__WriteYaml(*this, w); }
#define AT_SPECIALIZE_DNA(...) \
template void __VA_ARGS__::Enumerate<athena::io::Read<athena::io::PropType::None>>( \

View File

@ -1,25 +1,28 @@
#pragma once
#include "YAMLDocReader.hpp"
#include "YAMLDocWriter.hpp"
#include "DNA.hpp"
#include "FileReader.hpp"
#include "FileWriter.hpp"
#include <string>
#include <type_traits>
#include "athena/DNA.hpp"
#include "athena/FileReader.hpp"
#include "athena/FileWriter.hpp"
#include "athena/YAMLDocReader.hpp"
#include "athena/YAMLDocWriter.hpp"
namespace athena::io {
template <class T>
inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = 0) {
const char* __GetDNAName(const T& dna, std::enable_if_t<athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
return dna.DNATypeV();
}
template <class T>
inline const char* __GetDNAName(const T& dna, typename std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = 0) {
const char* __GetDNAName(const T& dna, std::enable_if_t<!athena::io::__IsDNAVRecord_v<T>>* = nullptr) {
return dna.DNAType();
}
template <class T>
inline std::string ToYAMLString(const T& dna) {
std::string ToYAMLString(const T& dna) {
YAMLDocWriter docWriter(__GetDNAName(dna));
std::string res;
@ -35,7 +38,7 @@ inline std::string ToYAMLString(const T& dna) {
}
template <class T>
inline bool FromYAMLString(T& dna, std::string_view str) {
bool FromYAMLString(T& dna, std::string_view str) {
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
@ -46,7 +49,7 @@ inline bool FromYAMLString(T& dna, std::string_view str) {
}
template <class DNASubtype>
inline bool ValidateFromYAMLString(std::string_view str) {
bool ValidateFromYAMLString(std::string_view str) {
YAMLStdStringViewReaderState reader(str);
YAMLDocReader docReader;
yaml_parser_set_input(docReader.getParser(), (yaml_read_handler_t*)YAMLStdStringReader, &reader);
@ -55,7 +58,7 @@ inline bool ValidateFromYAMLString(std::string_view str) {
}
template <class T>
inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
YAMLDocWriter docWriter(__GetDNAName(dna));
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
@ -66,8 +69,7 @@ inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout) {
}
template <class T>
inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
void (T::*fn)(YAMLDocWriter& out) const) {
bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout, void (T::*fn)(YAMLDocWriter& out) const) {
YAMLDocWriter docWriter(__GetDNAName(dna));
yaml_emitter_set_unicode(docWriter.getEmitter(), true);
@ -78,7 +80,7 @@ inline bool ToYAMLStream(const T& dna, athena::io::IStreamWriter& fout,
}
template <class T>
inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
@ -87,7 +89,7 @@ inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin) {
}
template <class T>
inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)(YAMLDocReader& in)) {
bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)(YAMLDocReader& in)) {
YAMLDocReader docReader;
if (!docReader.parse(&fin))
return false;
@ -96,7 +98,7 @@ inline bool FromYAMLStream(T& dna, athena::io::IStreamReader& fin, void (T::*fn)
}
template <class T, typename NameT>
inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
bool MergeToYAMLFile(const T& dna, const NameT& filename) {
athena::io::FileReader r(filename);
YAMLDocWriter docWriter(__GetDNAName(dna), r.isOpen() ? &r : nullptr);
r.close();
@ -109,7 +111,7 @@ inline bool MergeToYAMLFile(const T& dna, const NameT& filename) {
}
template <class DNASubtype>
inline bool ValidateFromYAMLStream(athena::io::IStreamReader& fin) {
bool ValidateFromYAMLStream(athena::io::IStreamReader& fin) {
YAMLDocReader reader;
atUint64 pos = fin.position();
yaml_parser_set_input(reader.getParser(), (yaml_read_handler_t*)YAMLAthenaReader, &fin);

View File

@ -1,11 +1,9 @@
#pragma once
#include "athena/FileInfo.hpp"
#include <cstdio>
#include <vector>
#include <string>
#if _WIN32
typedef int mode_t;
using mode_t = int;
#endif
namespace athena {
@ -14,13 +12,11 @@ public:
explicit Dir(std::string_view path);
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view path) { return Dir(path).absolutePath(); }
static std::string absolutePath(std::string_view path) { return Dir(path).absolutePath(); }
bool isDir() const;
static bool isDir(std::string_view dir) { return Dir(dir).isDir(); }
std::vector<FileInfo> files() const;
bool cd(std::string_view path);
bool rm(std::string_view path);
bool touch();

View File

@ -2,7 +2,7 @@
#include <string>
#include "athena/Global.hpp"
#include "athena/Types.hpp"
namespace athena {
class FileInfo {
@ -10,33 +10,33 @@ public:
explicit FileInfo(std::string_view path = {});
std::string absolutePath() const;
static inline std::string absolutePath(std::string_view lnk) { return FileInfo(lnk).absolutePath(); }
static std::string absolutePath(std::string_view lnk) { return FileInfo(lnk).absolutePath(); }
std::string absoluteFilePath() const;
static inline std::string absoluteFilePath(std::string_view path) { return FileInfo(path).absoluteFilePath(); }
static std::string absoluteFilePath(std::string_view path) { return FileInfo(path).absoluteFilePath(); }
std::string filename() const;
static inline std::string filename(std::string_view path) { return FileInfo(path).filename(); }
static std::string filename(std::string_view path) { return FileInfo(path).filename(); }
std::string path() const { return m_path; }
static inline std::string path(std::string_view path) { return FileInfo(path).path(); }
static std::string path(std::string_view path) { return FileInfo(path).path(); }
std::string extension() const;
static inline std::string extension(std::string_view path) { return FileInfo(path).extension(); }
static std::string extension(std::string_view path) { return FileInfo(path).extension(); }
atUint64 size() const;
static inline atUint64 size(std::string_view path) { return FileInfo(path).size(); }
static atUint64 size(std::string_view path) { return FileInfo(path).size(); }
bool exists() const;
static inline bool exists(std::string_view path) { return FileInfo(path).exists(); }
static bool exists(std::string_view path) { return FileInfo(path).exists(); }
bool isLink() const;
static inline bool isLink(std::string_view lnk) { return FileInfo(lnk).isLink(); }
static bool isLink(std::string_view lnk) { return FileInfo(lnk).isLink(); }
bool isFile() const;
static inline bool isFile(std::string_view path) { return FileInfo(path).isFile(); }
static bool isFile(std::string_view path) { return FileInfo(path).isFile(); }
bool touch() const;
static inline bool touch(std::string_view path) { return FileInfo(path).touch(); }
static bool touch(std::string_view path) { return FileInfo(path).touch(); }
private:
std::string m_path;

View File

@ -9,18 +9,20 @@
#include <cstdio>
#endif
#include <string>
#include <memory>
#include <string>
#include "athena/IStreamReader.hpp"
#include "athena/Types.hpp"
namespace athena::io {
class FileReader : public IStreamReader {
public:
FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
virtual ~FileReader();
explicit FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
explicit FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true);
~FileReader() override;
inline std::string filename() const {
std::string filename() const {
#if _WIN32
return utility::wideToUtf8(m_filename);
#else
@ -28,7 +30,7 @@ public:
#endif
}
inline std::wstring wfilename() const {
std::wstring wfilename() const {
#if _WIN32
return m_filename;
#else
@ -38,12 +40,12 @@ public:
void open();
void close();
inline bool isOpen() const { return m_fileHandle != 0; }
bool isOpen() const { return m_fileHandle != 0; }
bool save();
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
atUint64 readUBytesToBuf(void* buf, atUint64 len);
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
atUint64 position() const override;
atUint64 length() const override;
atUint64 readUBytesToBuf(void* buf, atUint64 len) override;
void setCacheSize(const atInt32 blockSize);
@ -69,10 +71,3 @@ protected:
bool m_globalErr;
};
} // namespace athena::io
#ifndef FILEREADER_BASE
#define FILEREADER_BASE() \
private: \
typedef athena::io::FileReader base
#endif // FILEREADER_BASE

View File

@ -8,23 +8,25 @@
#else
#include <cstdio>
#endif
#include "athena/IStreamWriter.hpp"
#include "athena/Types.hpp"
namespace athena::io {
class FileWriter : public IStreamWriter {
public:
FileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true);
FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true);
virtual ~FileWriter();
explicit FileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true);
explicit FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true);
~FileWriter() override;
inline std::string filename() const {
std::string filename() const {
#if _WIN32
return utility::wideToUtf8(m_filename);
#else
return m_filename;
#endif
}
inline std::wstring wfilename() const {
std::wstring wfilename() const {
#if _WIN32
return m_filename;
#else
@ -34,11 +36,11 @@ public:
void open(bool overwrite = true);
void close();
inline bool isOpen() const { return m_fileHandle != 0; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
atUint64 position() const;
atUint64 length() const;
void writeUBytes(const atUint8* data, atUint64 len);
bool isOpen() const { return m_fileHandle != 0; }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
atUint64 position() const override;
atUint64 length() const override;
void writeUBytes(const atUint8* data, atUint64 len) override;
#if _WIN32
using HandleType = HANDLE;
@ -69,7 +71,7 @@ class TransactionalFileWriter : public IStreamWriter {
atUint64 m_position = 0;
public:
TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
m_filename = utility::utf8ToWide(filename);
@ -77,7 +79,7 @@ public:
m_filename = filename;
#endif
}
TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true)
explicit TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true)
: m_overwrite(overwrite), m_globalErr(globalErr) {
#if _WIN32
m_filename = filename;
@ -99,18 +101,11 @@ public:
m_position = 0;
}
inline atUint64 position() const { return m_position; }
inline atUint64 length() const { return m_deferredBuffer.size(); }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void writeUBytes(const atUint8* data, atUint64 len);
atUint64 position() const override { return m_position; }
atUint64 length() const override { return m_deferredBuffer.size(); }
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) override;
void writeUBytes(const atUint8* data, atUint64 len) override;
~TransactionalFileWriter() { flush(); }
~TransactionalFileWriter() override { flush(); }
};
} // namespace athena::io
#ifndef FILEWRITER_BASE
#define FILEWRITER_BASE() \
private: \
typedef athena::io::FileWriter base;
#endif // FILEWRITER_BASE

View File

@ -1,6 +1,6 @@
#pragma once
#include <iostream>
#include <ostream>
#include "athena/Types.hpp"
#define FMT_STRING_ALIAS 1
@ -134,16 +134,15 @@ template <Endian DNAE>
struct DNAV;
template <class T>
using __IsDNARecord =
typename std::disjunction<std::is_base_of<DNA<Endian::Big>, T>, std::is_base_of<DNA<Endian::Little>, T>>;
using __IsDNARecord = std::disjunction<std::is_base_of<DNA<Endian::Big>, T>, std::is_base_of<DNA<Endian::Little>, T>>;
template <class T>
inline constexpr bool __IsDNARecord_v = __IsDNARecord<T>::value;
constexpr bool __IsDNARecord_v = __IsDNARecord<T>::value;
template <class T>
using __IsDNAVRecord =
typename std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>, std::is_base_of<DNAV<Endian::Little>, T>>;
std::disjunction<std::is_base_of<DNAV<Endian::Big>, T>, std::is_base_of<DNAV<Endian::Little>, T>>;
template <class T>
inline constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
constexpr bool __IsDNAVRecord_v = __IsDNAVRecord<T>::value;
} // namespace io
} // namespace athena
@ -163,7 +162,7 @@ std::ostream& operator<<(std::ostream& os, const athena::Endian& endian);
template <typename First, typename... Rest>
constexpr auto __FIRST_ARG__(First first, Rest...) { return first; }
template <typename S, typename... Args>
inline auto __make_args_checked__(const S& format_str, Args&&... args) {
auto __make_args_checked__(const S& format_str, Args&&... args) {
return fmt::internal::make_args_checked<Args...>(format_str, std::forward<Args>(args)...);
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "Global.hpp"
#include "athena/Global.hpp"
namespace athena::io {
std::ostream& operator<<(std::ostream& os, Endian& endian);

View File

@ -1,28 +1,30 @@
#pragma once
#include <memory>
#include <functional>
#include "utf8proc.h"
#include "Utility.hpp"
#include "IStream.hpp"
#include <memory>
#include <type_traits>
#include <vector>
#include "athena/IStream.hpp"
#include "athena/Utility.hpp"
namespace athena::io {
/** @brief The IStreamReader class defines a basic API for reading from streams, Implementors are provided with one pure
* virtual function that must be implemented in order to interact with the stream.
*
* Most implementing classes will only need to implement IStreamReader::readUBytesToBuf(void*, atUint64) for basic
* stream intearaction
* stream interaction
*/
class IStreamReader : public IStream {
public:
virtual ~IStreamReader() = default;
~IStreamReader() override = default;
/** @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek relative to
*/
virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) = 0;
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override = 0;
/** @brief Sets the buffer's position relative to the next 64-byte aligned position.<br />
*/
@ -44,19 +46,19 @@ public:
*
* @return True if at end; False otherwise.
*/
bool atEnd() const { return position() >= length(); }
bool atEnd() const override { return position() >= length(); }
/** @brief Returns the current position in the stream.
*
* @return The current position in the stream.
*/
virtual atUint64 position() const = 0;
atUint64 position() const override = 0;
/** @brief Returns the length of the file.
*
* @return True length of the file.
*/
virtual atUint64 length() const = 0;
atUint64 length() const override = 0;
/** @brief Reads a byte at the current position and advances the current position
*
@ -68,15 +70,15 @@ public:
return val;
}
template <class T>
atInt8 readVal(typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0) {
atInt8 readVal(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
return readByte();
}
template <class T>
atInt8 readValLittle(typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0) {
atInt8 readValLittle(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
return readByte();
}
template <class T>
atInt8 readValBig(typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0) {
atInt8 readValBig(std::enable_if_t<std::is_same_v<T, atInt8>>* = nullptr) {
return readByte();
}
@ -86,15 +88,15 @@ public:
*/
atUint8 readUByte() { return readByte(); }
template <class T>
atUint8 readVal(typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0) {
atUint8 readVal(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
return readUByte();
}
template <class T>
atUint8 readValLittle(typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0) {
atUint8 readValLittle(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
return readUByte();
}
template <class T>
atUint8 readValBig(typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0) {
atUint8 readValBig(std::enable_if_t<std::is_same_v<T, atUint8>>* = nullptr) {
return readUByte();
}
@ -103,10 +105,9 @@ public:
* @return The buffer at the current position from the given length.
*/
std::unique_ptr<atInt8[]> readBytes(atUint64 length) {
atInt8* buf = new atInt8[length];
memset(buf, 0, length);
readUBytesToBuf(buf, length);
return std::unique_ptr<atInt8[]>(buf);
auto buf = std::make_unique<atInt8[]>(length);
readUBytesToBuf(buf.get(), length);
return buf;
}
/** @brief Reads a byte at the current position and advances the current position.
@ -114,10 +115,9 @@ public:
* @return The buffer at the current position from the given length.
*/
std::unique_ptr<atUint8[]> readUBytes(atUint64 length) {
atUint8* buf = new atUint8[length];
memset(buf, 0, length);
readUBytesToBuf(buf, length);
return std::unique_ptr<atUint8[]>(buf);
auto buf = std::make_unique<atUint8[]>(length);
readUBytesToBuf(buf.get(), length);
return buf;
}
/** @brief Attempts to read a fixed length of data into a pre-allocated buffer.
@ -146,7 +146,7 @@ public:
return m_endian == Big ? utility::BigInt16(val) : utility::LittleInt16(val);
}
template <class T>
atInt16 readVal(typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0) {
atInt16 readVal(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
return readInt16();
}
@ -161,7 +161,7 @@ public:
return utility::LittleInt16(val);
}
template <class T>
atInt16 readValLittle(typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0) {
atInt16 readValLittle(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
return readInt16Little();
}
@ -176,7 +176,7 @@ public:
return utility::BigInt16(val);
}
template <class T>
atInt16 readValBig(typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0) {
atInt16 readValBig(std::enable_if_t<std::is_same_v<T, atInt16>>* = nullptr) {
return readInt16Big();
}
@ -187,7 +187,7 @@ public:
*/
atUint16 readUint16() { return readInt16(); }
template <class T>
atUint16 readVal(typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0) {
atUint16 readVal(std::enable_if_t<std::is_same_v<T, atUint16>>* = 0) {
return readUint16();
}
@ -202,7 +202,7 @@ public:
return utility::LittleUint16(val);
}
template <class T>
atUint16 readValLittle(typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0) {
atUint16 readValLittle(std::enable_if_t<std::is_same_v<T, atUint16>>* = nullptr) {
return readUint16Little();
}
@ -217,7 +217,7 @@ public:
return utility::BigUint16(val);
}
template <class T>
atUint16 readValBig(typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0) {
atUint16 readValBig(std::enable_if_t<std::is_same_v<T, atUint16>>* = nullptr) {
return readUint16Big();
}
@ -232,7 +232,7 @@ public:
return m_endian == Big ? utility::BigInt32(val) : utility::LittleInt32(val);
}
template <class T>
atInt32 readVal(typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0) {
atInt32 readVal(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
return readInt32();
}
@ -247,7 +247,7 @@ public:
return utility::LittleInt32(val);
}
template <class T>
atInt32 readValLittle(typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0) {
atInt32 readValLittle(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
return readInt32Little();
}
@ -262,7 +262,7 @@ public:
return utility::BigInt32(val);
}
template <class T>
atInt32 readValBig(typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0) {
atInt32 readValBig(std::enable_if_t<std::is_same_v<T, atInt32>>* = nullptr) {
return readInt32Big();
}
@ -273,7 +273,7 @@ public:
*/
atUint32 readUint32() { return readInt32(); }
template <class T>
atUint32 readVal(typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0) {
atUint32 readVal(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
return readUint32();
}
@ -288,7 +288,7 @@ public:
return utility::LittleUint32(val);
}
template <class T>
atInt32 readValLittle(typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0) {
atInt32 readValLittle(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
return readUint32Little();
}
@ -303,7 +303,7 @@ public:
return utility::BigUint32(val);
}
template <class T>
atUint32 readValBig(typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0) {
atUint32 readValBig(std::enable_if_t<std::is_same_v<T, atUint32>>* = nullptr) {
return readUint32Big();
}
@ -318,7 +318,7 @@ public:
return m_endian == Big ? utility::BigInt64(val) : utility::LittleInt64(val);
}
template <class T>
atInt64 readVal(typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0) {
atInt64 readVal(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
return readInt64();
}
@ -333,7 +333,7 @@ public:
return utility::LittleInt64(val);
}
template <class T>
atInt64 readValLittle(typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0) {
atInt64 readValLittle(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
return readInt64Little();
}
@ -348,7 +348,7 @@ public:
return utility::BigInt64(val);
}
template <class T>
atInt64 readValBig(typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0) {
atInt64 readValBig(std::enable_if_t<std::is_same_v<T, atInt64>>* = nullptr) {
return readInt64Big();
}
@ -359,7 +359,7 @@ public:
*/
atUint64 readUint64() { return readInt64(); }
template <class T>
atUint64 readVal(typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0) {
atUint64 readVal(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
return readUint64();
}
@ -374,7 +374,7 @@ public:
return utility::LittleUint64(val);
}
template <class T>
atUint64 readValLittle(typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0) {
atUint64 readValLittle(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
return readUint64Little();
}
@ -389,7 +389,7 @@ public:
return utility::BigUint64(val);
}
template <class T>
atUint64 readValBig(typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0) {
atUint64 readValBig(std::enable_if_t<std::is_same_v<T, atUint64>>* = nullptr) {
return readUint64Big();
}
@ -404,7 +404,7 @@ public:
return m_endian == Big ? utility::BigFloat(val) : utility::LittleFloat(val);
}
template <class T>
float readVal(typename std::enable_if<std::is_same<T, float>::value>::type* = 0) {
float readVal(std::enable_if_t<std::is_same_v<T, float>>* = nullptr) {
return readFloat();
}
@ -419,7 +419,7 @@ public:
return utility::LittleFloat(val);
}
template <class T>
float readValLittle(typename std::enable_if<std::is_same<T, float>::value>::type* = 0) {
float readValLittle(std::enable_if_t<std::is_same_v<T, float>>* = nullptr) {
return readFloatLittle();
}
@ -434,7 +434,7 @@ public:
return utility::BigFloat(val);
}
template <class T>
float readValBig(typename std::enable_if<std::is_same<T, float>::value>::type* = 0) {
float readValBig(std::enable_if_t<std::is_same_v<T, float>>* = nullptr) {
return readFloatBig();
}
@ -449,7 +449,7 @@ public:
return m_endian == Big ? utility::BigDouble(val) : utility::LittleDouble(val);
}
template <class T>
double readVal(typename std::enable_if<std::is_same<T, double>::value>::type* = 0) {
double readVal(std::enable_if_t<std::is_same_v<T, double>>* = nullptr) {
return readDouble();
}
@ -464,7 +464,7 @@ public:
return utility::LittleDouble(val);
}
template <class T>
double readValLittle(typename std::enable_if<std::is_same<T, double>::value>::type* = 0) {
double readValLittle(std::enable_if_t<std::is_same_v<T, double>>* = nullptr) {
return readDoubleLittle();
}
@ -479,7 +479,7 @@ public:
return utility::BigDouble(val);
}
template <class T>
double readValBig(typename std::enable_if<std::is_same<T, double>::value>::type* = 0) {
double readValBig(std::enable_if_t<std::is_same_v<T, double>>* = nullptr) {
return readDoubleBig();
}
@ -493,15 +493,15 @@ public:
return val != 0;
}
template <class T>
bool readVal(typename std::enable_if<std::is_same<T, bool>::value>::type* = 0) {
bool readVal(std::enable_if_t<std::is_same_v<T, bool>>* = nullptr) {
return readBool();
}
template <class T>
bool readValLittle(typename std::enable_if<std::is_same<T, bool>::value>::type* = 0) {
bool readValLittle(std::enable_if_t<std::is_same_v<T, bool>>* = nullptr) {
return readBool();
}
template <class T>
bool readValBig(typename std::enable_if<std::is_same<T, bool>::value>::type* = 0) {
bool readValBig(std::enable_if_t<std::is_same_v<T, bool>>* = nullptr) {
return readBool();
}
@ -527,7 +527,7 @@ public:
return s;
}
template <class T>
atVec2f readVal(typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0) {
atVec2f readVal(std::enable_if_t<std::is_same_v<T, atVec2f>>* = nullptr) {
return readVec2f();
}
@ -548,7 +548,7 @@ public:
return s;
}
template <class T>
atVec2f readValLittle(typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0) {
atVec2f readValLittle(std::enable_if_t<std::is_same_v<T, atVec2f>>* = nullptr) {
return readVec2fLittle();
}
@ -569,7 +569,7 @@ public:
return s;
}
template <class T>
atVec2f readValBig(typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0) {
atVec2f readValBig(std::enable_if_t<std::is_same_v<T, atVec2f>>* = nullptr) {
return readVec2fBig();
}
@ -596,7 +596,7 @@ public:
return s;
}
template <class T>
atVec3f readVal(typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0) {
atVec3f readVal(std::enable_if_t<std::is_same_v<T, atVec3f>>* = nullptr) {
return readVec3f();
}
@ -617,7 +617,7 @@ public:
return s;
}
template <class T>
atVec3f readValLittle(typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0) {
atVec3f readValLittle(std::enable_if_t<std::is_same_v<T, atVec3f>>* = nullptr) {
return readVec3fLittle();
}
@ -638,7 +638,7 @@ public:
return s;
}
template <class T>
atVec3f readValBig(typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0) {
atVec3f readValBig(std::enable_if_t<std::is_same_v<T, atVec3f>>* = nullptr) {
return readVec3fBig();
}
@ -666,7 +666,7 @@ public:
return s;
}
template <class T>
atVec4f readVal(typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0) {
atVec4f readVal(std::enable_if_t<std::is_same_v<T, atVec4f>>* = nullptr) {
return readVec4f();
}
@ -687,7 +687,7 @@ public:
return s;
}
template <class T>
atVec4f readValLittle(typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0) {
atVec4f readValLittle(std::enable_if_t<std::is_same_v<T, atVec4f>>* = nullptr) {
return readVec4fLittle();
}
@ -708,7 +708,7 @@ public:
return s;
}
template <class T>
atVec4f readValBig(typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0) {
atVec4f readValBig(std::enable_if_t<std::is_same_v<T, atVec4f>>* = nullptr) {
return readVec4fBig();
}
@ -734,7 +734,7 @@ public:
return s;
}
template <class T>
atVec2d readVal(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0) {
atVec2d readVal(std::enable_if_t<std::is_same_v<T, atVec2d>>* = nullptr) {
return readVec2d();
}
@ -755,7 +755,7 @@ public:
return s;
}
template <class T>
atVec2d readValLittle(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0) {
atVec2d readValLittle(std::enable_if_t<std::is_same_v<T, atVec2d>>* = nullptr) {
return readVec2dLittle();
}
@ -776,7 +776,7 @@ public:
return s;
}
template <class T>
atVec2d readValBig(typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0) {
atVec2d readValBig(std::enable_if_t<std::is_same_v<T, atVec2d>>* = nullptr) {
return readVec2dBig();
}
@ -803,7 +803,7 @@ public:
return s;
}
template <class T>
atVec3d readVal(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0) {
atVec3d readVal(std::enable_if_t<std::is_same_v<T, atVec3d>>* = nullptr) {
return readVec3d();
}
@ -824,7 +824,7 @@ public:
return s;
}
template <class T>
atVec3d readValLittle(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0) {
atVec3d readValLittle(std::enable_if_t<std::is_same_v<T, atVec3d>>* = nullptr) {
return readVec3dLittle();
}
@ -845,7 +845,7 @@ public:
return s;
}
template <class T>
atVec3d readValBig(typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0) {
atVec3d readValBig(std::enable_if_t<std::is_same_v<T, atVec3d>>* = nullptr) {
return readVec3dBig();
}
@ -873,7 +873,7 @@ public:
return s;
}
template <class T>
atVec4d readVal(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0) {
atVec4d readVal(std::enable_if_t<std::is_same_v<T, atVec4d>>* = nullptr) {
return readVec4d();
}
@ -894,7 +894,7 @@ public:
return s;
}
template <class T>
atVec4d readValLittle(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0) {
atVec4d readValLittle(std::enable_if_t<std::is_same_v<T, atVec4d>>* = nullptr) {
return readVec4dLittle();
}
@ -915,13 +915,16 @@ public:
return s;
}
template <class T>
atVec4d readValBig(typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0) {
atVec4d readValBig(std::enable_if_t<std::is_same_v<T, atVec4d>>* = nullptr) {
return readVec4dBig();
}
/** @brief Reads a string and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param fixedLen If non-negative, this is a fixed-length string read.
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read string
*/
std::string readString(atInt32 fixedLen = -1, bool doSeek = true) {
@ -946,13 +949,16 @@ public:
return ret;
}
template <class T>
std::string readVal(typename std::enable_if<std::is_same<T, std::string>::value>::type* = 0) {
std::string readVal(std::enable_if_t<std::is_same_v<T, std::string>>* = nullptr) {
return readString();
}
/** @brief Reads a wstring and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param fixedLen If non-negative, this is a fixed-length string read.
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read wstring
*/
std::wstring readWString(atInt32 fixedLen = -1, bool doSeek = true) {
@ -978,14 +984,17 @@ public:
return ret;
}
template <class T>
std::wstring readVal(typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0) {
std::wstring readVal(std::enable_if_t<std::is_same_v<T, std::wstring>>* = nullptr) {
return readWString();
}
/** @brief Reads a wstring assuming little-endian characters
* and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param fixedLen If non-negative, this is a fixed-length string read.
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read wstring
*/
std::wstring readWStringLittle(atInt32 fixedLen = -1, bool doSeek = true) {
@ -1011,7 +1020,7 @@ public:
return ret;
}
template <class T>
std::wstring readValLittle(typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0) {
std::wstring readValLittle(std::enable_if_t<std::is_same_v<T, std::wstring>>* = nullptr) {
return readWStringLittle();
}
@ -1019,6 +1028,9 @@ public:
* and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read wstring
*/
std::wstring readWStringBig(atInt32 fixedLen = -1, bool doSeek = true) {
@ -1043,14 +1055,17 @@ public:
return ret;
}
template <class T>
std::wstring readValBig(typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0) {
std::wstring readValBig(std::enable_if_t<std::is_same_v<T, std::wstring>>* = nullptr) {
return readWStringBig();
}
/** @brief Reads a u16string assuming big-endian characters
* and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param fixedLen If non-negative, this is a fixed-length string read.
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read wstring
*/
std::u16string readU16StringBig(atInt32 fixedLen = -1, bool doSeek = true) {
@ -1075,14 +1090,17 @@ public:
return ret;
}
template <class T>
std::u16string readValBig(typename std::enable_if<std::is_same<T, std::u16string>::value>::type* = 0) {
std::u16string readValBig(std::enable_if_t<std::is_same_v<T, std::u16string>>* = nullptr) {
return readU16StringBig();
}
/** @brief Reads a u32string assuming big-endian characters
* and advances the position in the file
*
* @param fixedLen If non-negative, this is a fixed-length string read
* @param fixedLen If non-negative, this is a fixed-length string read.
* @param doSeek Whether or not to reset the advanced position of the file.
* This is ignored if fixedLen is less than or equal to zero.
*
* @return The read wstring
*/
std::u32string readU32StringBig(atInt32 fixedLen = -1, bool doSeek = true) {
@ -1107,7 +1125,7 @@ public:
return ret;
}
template <class T>
std::u32string readValBig(typename std::enable_if<std::is_same<T, std::u32string>::value>::type* = 0) {
std::u32string readValBig(std::enable_if_t<std::is_same_v<T, std::u32string>>* = nullptr) {
return readU32StringBig();
}
@ -1119,10 +1137,9 @@ public:
* Endianness is set with setEndian
*/
template <class T>
void
enumerate(std::vector<T>& vector, size_t count,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerate(std::vector<T>& vector, size_t count,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> || std::is_same_v<T, atVec3f> ||
std::is_same_v<T, atVec4f>>* = nullptr) {
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < count; ++i)
@ -1137,10 +1154,9 @@ public:
* Endianness is little
*/
template <class T>
void enumerateLittle(
std::vector<T>& vector, size_t count,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerateLittle(std::vector<T>& vector, size_t count,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < count; ++i)
@ -1155,10 +1171,9 @@ public:
* Endianness is big
*/
template <class T>
void
enumerateBig(std::vector<T>& vector, size_t count,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerateBig(std::vector<T>& vector, size_t count,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < count; ++i)
@ -1171,10 +1186,9 @@ public:
* @param count The number of elements to read into vector
*/
template <class T>
void
enumerate(std::vector<T>& vector, size_t count,
typename std::enable_if<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerate(std::vector<T>& vector, size_t count,
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> &&
!std::is_same_v<T, atVec3f> && !std::is_same_v<T, atVec4f>>* = nullptr) {
vector.clear();
vector.reserve(count);
for (size_t i = 0; i < count; ++i) {

View File

@ -1,22 +1,25 @@
#pragma once
#include "utf8proc.h"
#include "IStream.hpp"
#include "Utility.hpp"
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include "utf8proc.h"
#include "athena/IStream.hpp"
#include "athena/Utility.hpp"
namespace athena::io {
class IStreamWriter : public IStream {
public:
virtual ~IStreamWriter() = default;
~IStreamWriter() override = default;
/** @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The location to seek relative to
*/
virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current) = 0;
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override = 0;
/** @brief Sets the buffers position relative to the next 32-byte aligned position.<br />
*/
@ -36,19 +39,19 @@ public:
*
* @return True if at end; False otherwise.
*/
bool atEnd() const { return position() >= length(); }
bool atEnd() const override { return position() >= length(); }
/** @brief Returns the current position in the stream.
*
* @return The current position in the stream.
*/
virtual atUint64 position() const = 0;
atUint64 position() const override = 0;
/** @brief Returns whether or not the stream is at the end.
*
* @return True if at end; False otherwise.
*/
virtual atUint64 length() const = 0;
atUint64 length() const override = 0;
/** @brief Writes a byte at the current position and advances the position by one byte.
* @param val The value to write
@ -72,7 +75,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
virtual void writeUBytes(const atUint8* data, atUint64 len) = 0;
virtual void writeUBytes(const atUint8* data, atUint64 length) = 0;
/** @brief Writes the given buffer with the specified length, buffers can be bigger than the length
* however it's undefined behavior to try and write a buffer which is smaller than the given length.
@ -80,7 +83,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeBytes(const void* data, atUint64 len) { writeUBytes((atUint8*)data, len); }
void writeBytes(const void* data, atUint64 length) { writeUBytes((atUint8*)data, length); }
/** @brief Writes an Int16 to the buffer and advances the buffer.
* It also swaps the bytes depending on the platform and Stream settings.
@ -977,9 +980,8 @@ public:
if (length == 0)
return;
std::unique_ptr<atUint8[]> tmp(new atUint8[length]);
memset(tmp.get(), val, length);
writeUBytes(tmp.get(), length);
const std::vector<atUint8> tmp(length, val);
writeUBytes(tmp.data(), length);
}
void fill(atInt8 val, atUint64 length) { fill((atUint8)val, length); }
@ -990,10 +992,9 @@ public:
* Endianness is set with setEndian
*/
template <class T>
void
enumerate(const std::vector<T>& vector,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerate(const std::vector<T>& vector,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> || std::is_same_v<T, atVec3f> ||
std::is_same_v<T, atVec4f>>* = nullptr) {
for (const T& item : vector)
writeVal(item);
}
@ -1004,10 +1005,9 @@ public:
* Endianness is little
*/
template <class T>
void enumerateLittle(
const std::vector<T>& vector,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerateLittle(const std::vector<T>& vector,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
for (const T& item : vector)
writeValLittle(item);
}
@ -1018,10 +1018,9 @@ public:
* Endianness is big
*/
template <class T>
void
enumerateBig(const std::vector<T>& vector,
typename std::enable_if<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerateBig(const std::vector<T>& vector,
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
for (const T& item : vector)
writeValBig(item);
}
@ -1030,10 +1029,9 @@ public:
* @param vector The std::vector read from when writing data
*/
template <class T>
void
enumerate(const std::vector<T>& vector,
typename std::enable_if<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value>::type* = 0) {
void enumerate(const std::vector<T>& vector,
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> &&
!std::is_same_v<T, atVec3f> && !std::is_same_v<T, atVec4f>>* = nullptr) {
for (const T& item : vector)
item.write(*this);
}

View File

@ -19,34 +19,35 @@ protected:
MemoryReader() = default;
public:
virtual ~MemoryReader();
~MemoryReader() override;
/*! \brief This constructor references an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
* \param takeOwnership Memory will be freed with the reader if set
* \param data The existing buffer.
* \param length The length of the existing buffer.
* \param takeOwnership Memory will be freed with the reader if set.
* \param globalErr Whether or not global errors are enabled.
*/
MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true);
explicit MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true);
/*! \brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* \param position where in the buffer to seek
* \param origin The Origin to seek \sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
/*! \brief Returns the current position in the stream.
*
* \return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
atUint64 position() const override { return m_position; }
/*! \brief Returns whether or not the stream is at the end.
*
* \return bool True if at end; False otherwise.
*/
inline atUint64 length() const { return m_length; }
atUint64 length() const override { return m_length; }
/*! \brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
@ -74,7 +75,7 @@ public:
* \param len Length to read
* \return Number of bytes read
*/
atUint64 readUBytesToBuf(void* buf, atUint64 len);
atUint64 readUBytesToBuf(void* buf, atUint64 len) override;
protected:
const void* m_data = nullptr;
@ -91,13 +92,13 @@ public:
* \param data The existing buffer
* \param length The length of the existing buffer
*/
MemoryCopyReader(const void* data, atUint64 length);
explicit MemoryCopyReader(const void* data, atUint64 length);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); }
explicit MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); }
void setData(const atUint8* data, atUint64 length);

View File

@ -1,8 +1,8 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include <string>
#include "athena/IStreamWriter.hpp"
namespace athena::io {
@ -17,12 +17,14 @@ namespace athena::io {
*/
class MemoryWriter : public IStreamWriter {
public:
virtual ~MemoryWriter();
~MemoryWriter() override;
/*! @brief This constructor references an existing buffer to write to in-place.
*
* @param data The existing buffer
* @param length The length of the existing buffer
* @param data The existing buffer.
* @param length The length of the existing buffer.
* @param takeOwnership Whether or not this writer takes ownership of the supplied data buffer.
* If true, the buffer will be deleted by this when the destructor executes.
*/
explicit MemoryWriter(atUint8* data, atUint64 length, bool takeOwnership = false);
@ -31,21 +33,21 @@ public:
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
atUint64 position() const override { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_length; }
atUint64 length() const override { return m_length; }
inline bool isOpen() const { return true; }
bool isOpen() const { return true; }
/** @brief Sets the buffer to the given one, deleting the current one if it owns it.<br />
* @param data The new buffer.
@ -65,12 +67,12 @@ public:
*
* @param filepath The path to write to.
*/
inline void setFilepath(const std::string& filepath) { m_filepath = filepath; }
void setFilepath(const std::string& filepath) { m_filepath = filepath; }
/*! @brief
* Returns the target file
*/
inline std::string filepath() const { return m_filepath; }
std::string filepath() const { return m_filepath; }
/*! @brief Saves the file to the specified file.
*
@ -85,7 +87,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
void writeUBytes(const atUint8* data, atUint64 length) override;
protected:
MemoryWriter() {}
@ -109,14 +111,14 @@ public:
*
* @param filename The file to create the stream from
*/
MemoryCopyWriter(std::string_view filename);
explicit MemoryCopyWriter(std::string_view filename);
/*! @brief Sets the buffers position relative to the specified position.<br />
* It seeks relative to the current position by default.
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Sets the buffer to the given one, deleting the current one.<br />
* <b>BEWARE:</b> As this deletes the current buffer it WILL cause a loss of data
@ -135,7 +137,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
void writeUBytes(const atUint8* data, atUint64 length) override;
protected:
std::unique_ptr<atUint8[]> m_dataCopy;

View File

@ -48,8 +48,5 @@ private:
};
} // namespace athena::io
#ifndef PHYSFSFILEREADER_BASE
#define PHYSFSFILEREADER_BASE() typedef athena::io::PHYSFSFileReader base
#endif
#endif // PHYSFSSTREAM_HPP
#endif // ATHENA_ENABLE_PHYSFS

View File

@ -1,15 +1,12 @@
#pragma once
#include <sys/types.h>
#include <fcntl.h>
#include <cstddef>
#include <cstdint>
#include <string>
#include <memory.h>
#include "Global.hpp"
#ifdef _WIN32
#include <BaseTsd.h>
typedef UINT_PTR SOCKET;
using SOCKET = UINT_PTR;
#endif
struct sockaddr_in;
@ -24,7 +21,7 @@ class IPAddress {
void resolve(const std::string& address);
public:
IPAddress(const std::string& address) { resolve(address); }
explicit IPAddress(const std::string& address) { resolve(address); }
uint32_t toInteger() const;
operator bool() const { return m_valid; }
@ -50,7 +47,7 @@ public:
static EResult LastWSAError();
#endif
Socket(bool blocking) : m_isBlocking(blocking) {}
explicit Socket(bool blocking) : m_isBlocking(blocking) {}
~Socket() { close(); }
Socket(const Socket& other) = delete;

View File

@ -1,46 +1,34 @@
#pragma once
#include <cstdint>
#include <cinttypes>
using atInt8 = int8_t;
using atUint8 = uint8_t;
using atInt16 = int16_t;
using atUint16 = uint16_t;
using atInt32 = int32_t;
using atUint32 = uint32_t;
using atInt64 = int64_t;
using atUint64 = uint64_t;
#include <cinttypes>
#include <cstdint>
using atInt8 = std::int8_t;
using atUint8 = std::uint8_t;
using atInt16 = std::int16_t;
using atUint16 = std::uint16_t;
using atInt32 = std::int32_t;
using atUint32 = std::uint32_t;
using atInt64 = std::int64_t;
using atUint64 = std::uint64_t;
// Vector types
#include "simd/simd.hpp"
typedef struct {
struct atVec2f {
athena::simd<float> simd;
} atVec2f;
typedef struct {
};
struct atVec3f {
athena::simd<float> simd;
} atVec3f;
typedef struct {
};
struct atVec4f {
athena::simd<float> simd;
} atVec4f;
typedef struct {
};
struct atVec2d {
athena::simd<double> simd;
} atVec2d;
typedef struct {
};
struct atVec3d {
athena::simd<double> simd;
} atVec3d;
typedef struct {
};
struct atVec4d {
athena::simd<double> simd;
} atVec4d;
#ifndef UNUSED
#define UNUSED(x) ((void)x)
#endif // UNUSED
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif
};

View File

@ -1,11 +1,11 @@
#ifndef __UTILITY_H__
#define __UTILITY_H__
#include <cstring>
#include <string>
#include <string_view>
#include <vector>
#include <cstdarg>
#include <cstring>
#include "athena/Global.hpp"
#include "athena/Types.hpp"
@ -181,9 +181,9 @@ atUint64 rand64();
std::string join(const std::vector<std::string>& elems, std::string_view delims);
void tolower(std::string& str);
void toupper(std::string& str);
bool parseBool(std::string_view boolean, bool* valid = NULL);
bool parseBool(std::string_view boolean, bool* valid = nullptr);
int countChar(std::string_view str, const char chr, int* lastOccur = NULL);
int countChar(std::string_view str, char chr, int* lastOccur = nullptr);
// trim from start
std::string& ltrim(std::string& s);

View File

@ -1,10 +1,10 @@
#pragma once
#include <string>
#include <memory>
#include <functional>
#include <cstdint>
#include <vector>
#include "athena/IStreamWriter.hpp"
#include "athena/Types.hpp"
namespace athena::io {
@ -22,21 +22,21 @@ public:
* @param position where in the buffer to seek
* @param origin The Origin to seek @sa SeekOrigin
*/
void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current);
void seek(atInt64 position, SeekOrigin origin = SeekOrigin::Current) override;
/*! @brief Returns the current position in the stream.
*
* @return Int64 The current position in the stream.
*/
inline atUint64 position() const { return m_position; }
atUint64 position() const override { return m_position; }
/*! @brief Returns the length of the stream.
*
* @return Int64 The length of the stream.
*/
inline atUint64 length() const { return m_data.size(); }
atUint64 length() const override { return m_data.size(); }
inline bool isOpen() const { return true; }
bool isOpen() const { return true; }
/*! @brief Obtains reference to underlying std::vector store */
const std::vector<uint8_t>& data() const { return m_data; }
@ -48,7 +48,7 @@ public:
* @param data The buffer to write
* @param length The amount to write
*/
void writeUBytes(const atUint8* data, atUint64 len);
void writeUBytes(const atUint8* data, atUint64 length) override;
protected:
std::vector<uint8_t> m_data;

View File

@ -4,13 +4,13 @@
#pragma once
#include <cstring>
#include <yaml.h>
#include <utf8proc.h>
#include <vector>
#include <memory>
#include <functional>
#include "Global.hpp"
#include <string>
#include <vector>
#include <yaml.h>
#include "athena/Types.hpp"
namespace athena::io {
class IStreamReader;
@ -27,14 +27,14 @@ struct YAMLNode {
YAMLNode(yaml_node_type_t type) : m_type(type) {}
inline const YAMLNode* findMapChild(std::string_view key) const {
const YAMLNode* findMapChild(std::string_view key) const {
for (const auto& item : m_mapChildren)
if (!item.first.compare(key))
return item.second.get();
return nullptr;
}
inline void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node) {
void assignMapChild(std::string_view key, std::unique_ptr<YAMLNode>&& node) {
for (auto& item : m_mapChildren)
if (!item.first.compare(key)) {
item.second = std::move(node);
@ -166,13 +166,13 @@ struct YAMLStdStringViewReaderState {
std::string_view::const_iterator begin;
std::string_view::const_iterator end;
YAMLStdStringViewReaderState(std::string_view str) {
explicit YAMLStdStringViewReaderState(std::string_view str) {
begin = str.begin();
end = str.end();
}
};
int YAMLStdStringReader(YAMLStdStringViewReaderState* str, unsigned char* buffer, size_t size, size_t* size_read);
int YAMLStdStringReader(YAMLStdStringViewReaderState* reader, unsigned char* buffer, size_t size, size_t* size_read);
int YAMLStdStringWriter(std::string* str, unsigned char* buffer, size_t size);

View File

@ -1,6 +1,14 @@
#pragma once
#include "YAMLCommon.hpp"
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include "athena/Types.hpp"
#include "athena/YAMLCommon.hpp"
namespace athena::io {
@ -19,21 +27,21 @@ public:
void reset();
inline yaml_parser_t* getParser() { return &m_parser; }
yaml_parser_t* getParser() { return &m_parser; }
bool parse(athena::io::IStreamReader* reader);
bool ClassTypeOperation(std::function<bool(const char* dnaType)> func);
bool ValidateClassType(const char* expectedType);
inline const YAMLNode* getRootNode() const { return m_rootNode.get(); }
inline const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
const YAMLNode* getRootNode() const { return m_rootNode.get(); }
const YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
std::unique_ptr<YAMLNode> releaseRootNode() { return std::move(m_rootNode); }
class RecordRAII {
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
RecordRAII(YAMLDocReader* r) : m_r(r) {}
explicit RecordRAII(YAMLDocReader* r) : m_r(r) {}
RecordRAII() = default;
public:
@ -54,7 +62,7 @@ public:
RecordRAII enterSubRecord(const char* name);
template <class T>
void enumerate(const char* name, T& record, typename std::enable_if_t<__IsDNARecord_v<T>>* = 0) {
void enumerate(const char* name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
if (auto rec = enterSubRecord(name))
record.read(*this);
}
@ -62,11 +70,11 @@ public:
class VectorRAII {
friend class YAMLDocReader;
YAMLDocReader* m_r = nullptr;
VectorRAII(YAMLDocReader* r) : m_r(r) {}
explicit VectorRAII(YAMLDocReader* r) : m_r(r) {}
VectorRAII() = default;
public:
operator bool() const { return m_r != nullptr; }
explicit operator bool() const { return m_r != nullptr; }
~VectorRAII() {
if (m_r)
m_r->_leaveSubVector();
@ -77,10 +85,9 @@ public:
VectorRAII enterSubVector(const char* name, size_t& countOut);
template <class T>
size_t
enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value>* = 0) {
size_t enumerate(const char* name, std::vector<T>& vector,
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> &&
!std::is_same_v<T, atVec3f> && !std::is_same_v<T, atVec4f>>* = nullptr) {
size_t countOut;
if (auto v = enterSubVector(name, countOut)) {
vector.clear();
@ -96,8 +103,8 @@ public:
template <class T>
size_t enumerate(const char* name, std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value>* = 0) {
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> ||
std::is_same_v<T, atVec3f> || std::is_same_v<T, atVec4f>>* = nullptr) {
size_t countOut;
if (auto v = enterSubVector(name, countOut)) {
vector.clear();

View File

@ -1,6 +1,13 @@
#pragma once
#include "YAMLCommon.hpp"
#include <cstddef>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>
#include "athena/Types.hpp"
#include "athena/YAMLCommon.hpp"
namespace athena::io {
@ -13,19 +20,19 @@ class YAMLDocWriter {
void _leaveSubVector();
public:
YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
explicit YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr);
~YAMLDocWriter();
yaml_emitter_t* getEmitter() { return &m_emitter; }
bool finish(athena::io::IStreamWriter* fout);
inline YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
YAMLNode* getCurNode() const { return m_subStack.empty() ? nullptr : m_subStack.back(); }
class RecordRAII {
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
RecordRAII(YAMLDocWriter* w) : m_w(w) {}
explicit RecordRAII(YAMLDocWriter* w) : m_w(w) {}
RecordRAII() = default;
public:
@ -40,7 +47,7 @@ public:
RecordRAII enterSubRecord(const char* name);
template <class T>
void enumerate(const char* name, T& record, typename std::enable_if_t<__IsDNARecord_v<T>>* = 0) {
void enumerate(const char* name, T& record, std::enable_if_t<__IsDNARecord_v<T>>* = nullptr) {
if (auto rec = enterSubRecord(name))
record.write(*this);
}
@ -48,7 +55,7 @@ public:
class VectorRAII {
friend class YAMLDocWriter;
YAMLDocWriter* m_w = nullptr;
VectorRAII(YAMLDocWriter* w) : m_w(w) {}
explicit VectorRAII(YAMLDocWriter* w) : m_w(w) {}
VectorRAII() = default;
public:
@ -63,11 +70,11 @@ public:
VectorRAII enterSubVector(const char* name);
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<!std::is_arithmetic<T>::value && !std::is_same<T, atVec2f>::value &&
!std::is_same<T, atVec3f>::value && !std::is_same<T, atVec4f>::value &&
!std::is_same<T, atVec2d>::value && !std::is_same<T, atVec3d>::value &&
!std::is_same<T, atVec4d>::value>* = 0) {
void
enumerate(const char* name, const std::vector<T>& vector,
std::enable_if_t<!std::is_arithmetic_v<T> && !std::is_same_v<T, atVec2f> && !std::is_same_v<T, atVec3f> &&
!std::is_same_v<T, atVec4f> && !std::is_same_v<T, atVec2d> &&
!std::is_same_v<T, atVec3d> && !std::is_same_v<T, atVec4d>>* = nullptr) {
if (auto v = enterSubVector(name))
for (const T& item : vector)
if (auto rec = enterSubRecord(nullptr))
@ -76,10 +83,9 @@ public:
template <class T>
void enumerate(const char* name, const std::vector<T>& vector,
typename std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<T, atVec2f>::value ||
std::is_same<T, atVec3f>::value || std::is_same<T, atVec4f>::value ||
std::is_same<T, atVec2d>::value || std::is_same<T, atVec3d>::value ||
std::is_same<T, atVec4d>::value>* = 0) {
std::enable_if_t<std::is_arithmetic_v<T> || std::is_same_v<T, atVec2f> || std::is_same_v<T, atVec3f> ||
std::is_same_v<T, atVec4f> || std::is_same_v<T, atVec2d> ||
std::is_same_v<T, atVec3d> || std::is_same_v<T, atVec4d>>* = nullptr) {
if (auto v = enterSubVector(name))
for (T item : vector)
writeVal<T>(nullptr, item);

View File

@ -1,75 +1,10 @@
#include "LZ77/LZLookupTable.hpp"
#include "LZ77/LZBase.hpp"
LZBase::LZBase(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimumMatch, atInt32 blockSize)
: m_slidingWindow(slidingWindow)
, m_readAheadBuffer(minimumMatch)
, m_minMatch(minimumMatch)
, m_blockSize(blockSize)
, m_minOffset(minimumOffset) {}
void LZBase::setSlidingWindow(atInt32 slidingWindow) { m_slidingWindow = slidingWindow; }
atInt32 LZBase::slidingWindow() { return m_slidingWindow; }
void LZBase::setReadAheadBuffer(atInt32 readAheadBuffer) { m_readAheadBuffer = readAheadBuffer; }
atInt32 LZBase::readAheadBuffer() { return m_readAheadBuffer; }
void LZBase::setMinMatch(atInt32 minimumMatch) { m_minMatch = minimumMatch; }
atInt32 LZBase::minMatch() { return m_minMatch; }
void LZBase::setBlockSize(atInt32 blockSize) { m_blockSize = blockSize; }
atInt32 LZBase::blockSize() { return m_blockSize; }
void LZBase::setMinimumOffset(atUint32 minimumOffset) { m_minOffset = minimumOffset; }
atUint32 LZBase::minimumOffset() { return m_minOffset; }
/*
DerricMc:
This search function is my own work and is no way affilated with any one else
I use the my own window_search function to drastically speed up the search function
Normally a search for one byte is matched, then two, then three, all the way up
to the size of the LookAheadBuffer. So I decided to skip the incremental search
and search for the entire LookAheadBuffer and if I don't find the bytes are equal I return
the next best match(which means if I look for 18 bytes and they are not found 18 bytess did not match,
and 17 bytes did match then 17 bytes match is return).
*/
LZLengthOffset LZBase::search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd) {
LZLengthOffset results = {0, 0};
// Returns negative 1 for Search failures since the current position is passed the size to be compressed
if (posPtr >= dataEnd) {
results.length = -1;
return results;
}
atUint8* searchWindow;
// LookAheadBuffer is ReadAheadBuffer Size if there are more bytes than ReadAheadBufferSize waiting
// to be compressed else the number of remaining bytes is the LookAheadBuffer
int lookAheadBuffer_len = ((int)(dataEnd - posPtr) < m_readAheadBuffer) ? (int)(dataEnd - posPtr) : m_readAheadBuffer;
int slidingBuffer = (int)(posPtr - dataBegin) - m_slidingWindow;
if (slidingBuffer > 0)
searchWindow = dataBegin + slidingBuffer;
else
searchWindow = dataBegin;
atUint8* endPos = posPtr + lookAheadBuffer_len;
if (!((posPtr - dataBegin < 1) || (dataEnd - posPtr < m_minMatch)))
results = windowSearch(searchWindow, posPtr, endPos, posPtr - m_minOffset);
return results;
}
namespace {
// Returns the full length of string2 if they are equal else
// Return the number of characters that were equal before they weren't equal
int LZBase::subMatch(const uint8_t* str1, const uint8_t* str2, const int len) {
int subMatch(const uint8_t* str1, const uint8_t* str2, const int len) {
for (int i = 0; i < len; ++i)
if (str1[i] != str2[i])
return i;
@ -77,24 +12,22 @@ int LZBase::subMatch(const uint8_t* str1, const uint8_t* str2, const int len) {
return len;
}
/*
Normally a search for one byte is matched, then two, then three, all the way up
to the size of the LookAheadBuffer. So I decided to skip the incremental search
and search for the entire LookAheadBuffer and if the function doesn't find the bytes are
equal the function return the next best match(which means if the function look for 18 bytes and they are not found,
return the number of bytes that did match before it failed to match. The submatch is function returns the number of
bytes that were equal, which can result up to the bytes total length if both byte strings are equal.
...[][][][][][][][][][][][]|[][][][][][][][][][][][][][]
|
Search Window Current Pos LookAheadBuffer
Up to 4096 bytes Up to 18 bytes
Sliding Window
Up to 4114 bytes
*/
LZLengthOffset LZBase::windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr,
atUint8* startLBPtr) {
// Normally a search for one byte is matched, then two, then three, all the way up
// to the size of the LookAheadBuffer. So I decided to skip the incremental search
// and search for the entire LookAheadBuffer and if the function doesn't find the bytes are
// equal the function return the next best match(which means if the function look for 18 bytes and they are not found,
// return the number of bytes that did match before it failed to match. The submatch is function returns the number of
// bytes that were equal, which can result up to the bytes total length if both byte strings are equal.
//
//
// ...[][][][][][][][][][][][]|[][][][][][][][][][][][][][]
// |
// Search Window Current Pos LookAheadBuffer
// Up to 4096 bytes Up to 18 bytes
// Sliding Window
// Up to 4114 bytes
LZLengthOffset windowSearch(const atUint8* beginSearchPtr, const atUint8* searchPosPtr, const atUint8* endLABufferPtr,
const atUint8* startLBPtr) {
atInt32 size = (atUint32)(endLABufferPtr - beginSearchPtr); // Size of the entire sliding window
atInt32 n = (atUint32)(endLABufferPtr - searchPosPtr);
LZLengthOffset result = {0, 0};
@ -103,10 +36,10 @@ LZLengthOffset LZBase::windowSearch(atUint8* beginSearchPtr, atUint8* searchPosP
if (n > size) // If the string that is being looked for is bigger than the string that is being searched
return result;
/*This makes sure that search for the searchPosPtr can be searched if an invalid position is given
An invalid position occurs if the amount of characters to search in_beginSearchPtr is less than the size
of searchPosPtr. In other words there has to be at least n characters left in the string
to have a chance to find n characters*/
// This makes sure that search for the searchPosPtr can be searched if an invalid position is given
// An invalid position occurs if the amount of characters to search in_beginSearchPtr is less than the size
// of searchPosPtr. In other words there has to be at least n characters left in the string
// to have a chance to find n characters
do {
temp = subMatch(startLBPtr, searchPosPtr, n);
@ -125,3 +58,74 @@ LZLengthOffset LZBase::windowSearch(atUint8* beginSearchPtr, atUint8* searchPosP
return result;
}
} // Anonymous namespace
LZBase::LZBase(atInt32 minimumOffset, atInt32 slidingWindow, atInt32 minimumMatch, atInt32 blockSize)
: m_slidingWindow(slidingWindow)
, m_readAheadBuffer(minimumMatch)
, m_minMatch(minimumMatch)
, m_blockSize(blockSize)
, m_minOffset(minimumOffset) {}
LZBase::~LZBase() = default;
void LZBase::setSlidingWindow(atInt32 slidingWindow) { m_slidingWindow = slidingWindow; }
atInt32 LZBase::slidingWindow() const { return m_slidingWindow; }
void LZBase::setReadAheadBuffer(atInt32 readAheadBuffer) { m_readAheadBuffer = readAheadBuffer; }
atInt32 LZBase::readAheadBuffer() const { return m_readAheadBuffer; }
void LZBase::setMinMatch(atInt32 minimumMatch) { m_minMatch = minimumMatch; }
atInt32 LZBase::minMatch() const { return m_minMatch; }
void LZBase::setBlockSize(atInt32 blockSize) { m_blockSize = blockSize; }
atInt32 LZBase::blockSize() const { return m_blockSize; }
void LZBase::setMinimumOffset(atUint32 minimumOffset) { m_minOffset = minimumOffset; }
atUint32 LZBase::minimumOffset() const { return m_minOffset; }
/*
DerricMc:
This search function is my own work and is no way affiliated with any one else
I use the my own window_search function to drastically speed up the search function
Normally a search for one byte is matched, then two, then three, all the way up
to the size of the LookAheadBuffer. So I decided to skip the incremental search
and search for the entire LookAheadBuffer and if I don't find the bytes are equal I return
the next best match(which means if I look for 18 bytes and they are not found 18 bytes did not match,
and 17 bytes did match then 17 bytes match is return).
*/
LZLengthOffset LZBase::search(const atUint8* posPtr, const atUint8* dataBegin, const atUint8* dataEnd) const {
LZLengthOffset results = {0, 0};
// Returns negative 1 for Search failures since the current position is passed the size to be compressed
if (posPtr >= dataEnd) {
results.length = -1;
return results;
}
const atUint8* searchWindow;
// LookAheadBuffer is ReadAheadBuffer Size if there are more bytes than ReadAheadBufferSize waiting
// to be compressed else the number of remaining bytes is the LookAheadBuffer
const int lookAheadBuffer_len =
((int)(dataEnd - posPtr) < m_readAheadBuffer) ? (int)(dataEnd - posPtr) : m_readAheadBuffer;
const int slidingBuffer = (int)(posPtr - dataBegin) - m_slidingWindow;
if (slidingBuffer > 0)
searchWindow = dataBegin + slidingBuffer;
else
searchWindow = dataBegin;
const atUint8* endPos = posPtr + lookAheadBuffer_len;
if (!((posPtr - dataBegin < 1) || (dataEnd - posPtr < m_minMatch)))
results = windowSearch(searchWindow, posPtr, endPos, posPtr - m_minOffset);
return results;
}

View File

@ -1,12 +1,7 @@
#include "LZ77/LZLookupTable.hpp"
#include <algorithm>
LZLookupTable::LZLookupTable() {
m_minimumMatch = 3;
m_slidingWindow = 4096;
m_lookAheadWindow = 18;
m_buffer.resize(m_minimumMatch);
}
LZLookupTable::LZLookupTable() : m_buffer(m_minimumMatch) {}
LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt32 lookAheadWindow) {
if (minimumMatch > 0)
@ -19,15 +14,12 @@ LZLookupTable::LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow, atInt3
else
m_slidingWindow = 4096;
if (lookAheadWindow > 0)
m_lookAheadWindow = lookAheadWindow;
else
m_lookAheadWindow = 18;
setLookAheadWindow(lookAheadWindow);
m_buffer.reserve(m_minimumMatch);
}
LZLookupTable::~LZLookupTable() {}
LZLookupTable::~LZLookupTable() = default;
void LZLookupTable::setLookAheadWindow(atInt32 lookAheadWindow) {
if (lookAheadWindow > 0)
@ -36,7 +28,7 @@ void LZLookupTable::setLookAheadWindow(atInt32 lookAheadWindow) {
m_lookAheadWindow = 18;
}
LZLengthOffset LZLookupTable::search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd) {
LZLengthOffset LZLookupTable::search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd) {
LZLengthOffset loPair = {0, 0};
// Returns negative 1 for search failures since the current position is passed the size to be compressed

View File

@ -106,7 +106,7 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt
}
delete[] compressedBytes;
compressedBytes = NULL;
compressedBytes = nullptr;
// Add zeros until the file is a multiple of 4
while ((outbuff.position() % 4) != 0)

View File

@ -1,7 +1,4 @@
#include "athena/Checksums.hpp"
#include "athena/FileReader.hpp"
#include <iostream>
#include <iomanip>
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed, atUint64 final) {

View File

@ -1,8 +1,9 @@
#include "athena/Compression.hpp"
#if AT_LZOKAY
#include <lzokay.hpp>
#endif
#include <iostream>
#include <zlib.h>
#include "LZ77/LZType10.hpp"
#include "LZ77/LZType11.hpp"
@ -10,7 +11,7 @@
namespace athena::io::Compression {
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
z_stream strm = {};
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef*)src;
@ -45,7 +46,7 @@ atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint
}
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
z_stream strm = {};
strm.total_in = strm.avail_in = srcLen;
strm.total_out = strm.avail_out = dstLen;
strm.next_in = (Bytef*)src;

View File

@ -1,5 +1,10 @@
#include "athena/DNAYaml.hpp"
#include <cctype>
#include <cstdlib>
#include "athena/YAMLCommon.hpp"
namespace athena::io {
template <>
@ -15,127 +20,119 @@ bool NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(bool val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = val ? "True" : "False";
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atInt8 NodeToVal(const YAMLNode* node) {
return strtol(node->m_scalarString.c_str(), NULL, 0);
return strtol(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atInt8 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atUint8 NodeToVal(const YAMLNode* node) {
return strtoul(node->m_scalarString.c_str(), NULL, 0);
return strtoul(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atUint8 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("0x{:02X}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atInt16 NodeToVal(const YAMLNode* node) {
return strtol(node->m_scalarString.c_str(), NULL, 0);
return strtol(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atInt16 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atUint16 NodeToVal(const YAMLNode* node) {
return strtoul(node->m_scalarString.c_str(), NULL, 0);
return strtoul(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atUint16 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("0x{:04X}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atInt32 NodeToVal(const YAMLNode* node) {
return strtol(node->m_scalarString.c_str(), NULL, 0);
return strtol(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atInt32 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), int(val));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atUint32 NodeToVal(const YAMLNode* node) {
return strtoul(node->m_scalarString.c_str(), NULL, 0);
return strtoul(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atUint32 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("0x{:08X}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atInt64 NodeToVal(const YAMLNode* node) {
#if _WIN32
return _strtoi64(node->m_scalarString.c_str(), NULL, 0);
#else
return strtoq(node->m_scalarString.c_str(), NULL, 0);
#endif
return std::strtoll(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atInt64 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
atUint64 NodeToVal(const YAMLNode* node) {
#if _WIN32
return _strtoui64(node->m_scalarString.c_str(), NULL, 0);
#else
return strtouq(node->m_scalarString.c_str(), NULL, 0);
#endif
return std::strtoull(node->m_scalarString.c_str(), nullptr, 0);
}
std::unique_ptr<YAMLNode> ValToNode(atUint64 val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("0x{:016X}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
float NodeToVal(const YAMLNode* node) {
return strtof(node->m_scalarString.c_str(), NULL);
return strtof(node->m_scalarString.c_str(), nullptr);
}
std::unique_ptr<YAMLNode> ValToNode(float val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
double NodeToVal(const YAMLNode* node) {
return strtod(node->m_scalarString.c_str(), NULL);
return strtod(node->m_scalarString.c_str(), nullptr);
}
std::unique_ptr<YAMLNode> ValToNode(double val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = fmt::format(fmt("{}"), val);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <typename RETURNTYPE>
@ -165,15 +162,15 @@ atVec2f NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec2f& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(2);
simd_floats f(val.simd);
for (size_t i = 0; i < 2; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -182,15 +179,15 @@ atVec3f NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec3f& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(3);
simd_floats f(val.simd);
for (size_t i = 0; i < 3; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -199,15 +196,15 @@ atVec4f NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec4f& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(4);
simd_floats f(val.simd);
for (size_t i = 0; i < 4; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -216,15 +213,15 @@ atVec2d NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec2d& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(2);
simd_doubles f(val.simd);
for (size_t i = 0; i < 2; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -233,15 +230,15 @@ atVec3d NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec3d& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(3);
simd_doubles f(val.simd);
for (size_t i = 0; i < 3; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -250,15 +247,15 @@ atVec4d NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const atVec4d& val) {
YAMLNode* ret = new YAMLNode(YAML_SEQUENCE_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SEQUENCE_NODE);
ret->m_seqChildren.reserve(4);
simd_doubles f(val.simd);
for (size_t i = 0; i < 4; ++i) {
YAMLNode* comp = new YAMLNode(YAML_SCALAR_NODE);
auto comp = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
comp->m_scalarString = fmt::format(fmt("{}"), f[i]);
ret->m_seqChildren.emplace_back(comp);
ret->m_seqChildren.emplace_back(std::move(comp));
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -267,10 +264,10 @@ std::unique_ptr<atUint8[]> NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(const std::unique_ptr<atUint8[]>& val, size_t byteCount) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
if (val)
ret->m_scalarString = base64_encode(val.get(), byteCount);
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -279,9 +276,9 @@ std::string NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(std::string_view val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString = val;
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
template <>
@ -303,48 +300,48 @@ std::wstring NodeToVal(const YAMLNode* node) {
}
std::unique_ptr<YAMLNode> ValToNode(std::wstring_view val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString.reserve(val.length());
for (wchar_t ch : val) {
utf8proc_uint8_t mb[4];
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
if (c < 0) {
atWarning(fmt("invalid UTF-8 character while encoding"));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
std::unique_ptr<YAMLNode> ValToNode(std::u16string_view val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString.reserve(val.length());
for (char16_t ch : val) {
utf8proc_uint8_t mb[4];
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
if (c < 0) {
atWarning(fmt("invalid UTF-8 character while encoding"));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
std::unique_ptr<YAMLNode> ValToNode(std::u32string_view val) {
YAMLNode* ret = new YAMLNode(YAML_SCALAR_NODE);
auto ret = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
ret->m_scalarString.reserve(val.length());
for (char32_t ch : val) {
utf8proc_uint8_t mb[4];
utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb);
if (c < 0) {
atWarning(fmt("invalid UTF-8 character while encoding"));
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
ret->m_scalarString.append(reinterpret_cast<char*>(mb), c);
}
return std::unique_ptr<YAMLNode>(ret);
return ret;
}
static const char* ErrorString(yaml_error_type_t errt) {
@ -426,40 +423,48 @@ YAMLDocWriter::YAMLDocWriter(const char* classType, athena::io::IStreamReader* r
m_subStack.emplace_back(m_rootNode.get());
if (classType) {
YAMLNode* classVal = new YAMLNode(YAML_SCALAR_NODE);
auto classVal = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
classVal->m_scalarString.assign(classType);
m_rootNode->assignMapChild("DNAType", std::unique_ptr<YAMLNode>(classVal));
m_rootNode->assignMapChild("DNAType", std::move(classVal));
}
}
YAMLDocWriter::~YAMLDocWriter() { yaml_emitter_delete(&m_emitter); }
bool YAMLDocWriter::finish(athena::io::IStreamWriter* fout) {
const auto error = [this] {
HandleYAMLEmitterError(&m_emitter);
return false;
};
yaml_event_t event = {};
if (fout)
if (fout) {
yaml_emitter_set_output(&m_emitter, (yaml_write_handler_t*)YAMLAthenaWriter, fout);
if (!yaml_emitter_open(&m_emitter))
goto err;
}
if (!yaml_emitter_open(&m_emitter)) {
return error();
}
event.type = YAML_DOCUMENT_START_EVENT;
event.data.document_start.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
if (!RecursiveFinish(&m_emitter, *m_rootNode))
if (!yaml_emitter_emit(&m_emitter, &event)) {
return error();
}
if (!RecursiveFinish(&m_emitter, *m_rootNode)) {
return false;
}
event.type = YAML_DOCUMENT_END_EVENT;
event.data.document_end.implicit = true;
if (!yaml_emitter_emit(&m_emitter, &event))
goto err;
if (!yaml_emitter_emit(&m_emitter, &event)) {
return error();
}
if (!yaml_emitter_close(&m_emitter) || !yaml_emitter_flush(&m_emitter))
goto err;
if (!yaml_emitter_close(&m_emitter) || !yaml_emitter_flush(&m_emitter)) {
return error();
}
return true;
err:
HandleYAMLEmitterError(&m_emitter);
return false;
}
YAMLDocWriter::RecordRAII YAMLDocWriter::enterSubRecord(const char* name) {
@ -633,7 +638,7 @@ std::unique_ptr<YAMLNode> YAMLDocReader::ParseEvents(athena::io::IStreamReader*
result = yaml_parser_parse(&m_parser, &event)) {
if (!result) {
HandleYAMLParserError(&m_parser);
return std::unique_ptr<YAMLNode>();
return nullptr;
}
switch (event.type) {
case YAML_SCALAR_EVENT: {
@ -641,7 +646,7 @@ std::unique_ptr<YAMLNode> YAMLDocReader::ParseEvents(athena::io::IStreamReader*
atWarning(fmt("YAML parser stack empty; skipping scalar node"));
break;
}
std::unique_ptr<YAMLNode> newScalar(new YAMLNode(YAML_SCALAR_NODE));
auto newScalar = std::make_unique<YAMLNode>(YAML_SCALAR_NODE);
newScalar->m_scalarString.assign((char*)event.data.scalar.value, event.data.scalar.length);
if (nodeStack.empty())
retVal = std::move(newScalar);
@ -957,48 +962,58 @@ static yaml_mapping_style_t MappingStyle(const YAMLNode& node) {
}
bool YAMLDocWriter::RecursiveFinish(yaml_emitter_t* doc, const YAMLNode& node) {
const auto handleError = [doc] {
HandleYAMLEmitterError(doc);
return false;
};
yaml_event_t event;
if (node.m_type == YAML_SCALAR_NODE) {
if (!yaml_scalar_event_initialize(&event, nullptr, nullptr, (yaml_char_t*)node.m_scalarString.c_str(),
node.m_scalarString.length(), true, true, ScalarStyle(node)) ||
!yaml_emitter_emit(doc, &event))
goto err;
!yaml_emitter_emit(doc, &event)) {
return handleError();
}
} else if (node.m_type == YAML_SEQUENCE_NODE) {
if (!yaml_sequence_start_event_initialize(&event, nullptr, nullptr, 1, SequenceStyle(node)) ||
!yaml_emitter_emit(doc, &event))
goto err;
for (const auto& item : node.m_seqChildren) {
if (!RecursiveFinish(doc, *item))
goto err;
!yaml_emitter_emit(doc, &event)) {
return handleError();
}
for (const auto& item : node.m_seqChildren) {
if (!RecursiveFinish(doc, *item)) {
return handleError();
}
}
if (!yaml_sequence_end_event_initialize(&event) || !yaml_emitter_emit(doc, &event)) {
return handleError();
}
if (!yaml_sequence_end_event_initialize(&event) || !yaml_emitter_emit(doc, &event))
goto err;
} else if (node.m_type == YAML_MAPPING_NODE) {
if (!yaml_mapping_start_event_initialize(&event, nullptr, nullptr, true, MappingStyle(node)) ||
!yaml_emitter_emit(doc, &event))
goto err;
!yaml_emitter_emit(doc, &event)) {
return handleError();
}
for (const auto& item : node.m_mapChildren) {
if (!EmitKeyScalar(doc, item.first.c_str()))
goto err;
if (!RecursiveFinish(doc, *item.second))
goto err;
if (!EmitKeyScalar(doc, item.first.c_str())) {
return handleError();
}
if (!RecursiveFinish(doc, *item.second)) {
return handleError();
}
}
event.type = YAML_MAPPING_END_EVENT;
if (!yaml_mapping_end_event_initialize(&event) || !yaml_emitter_emit(doc, &event))
goto err;
if (!yaml_mapping_end_event_initialize(&event) || !yaml_emitter_emit(doc, &event)) {
return handleError();
}
}
return true;
err:
HandleYAMLEmitterError(doc);
return false;
}
static const std::string base64_chars =
constexpr std::string_view base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
inline bool is_base64(unsigned char c) { return (isalnum(c) || (c == '+') || (c == '/')); }
static bool is_base64(unsigned char c) { return isalnum(c) || c == '+' || c == '/'; }
std::string base64_encode(const atUint8* bytes_to_encode, size_t in_len) {
std::string ret;

View File

@ -1,16 +1,20 @@
#include "athena/Dir.hpp"
#include <sys/stat.h>
#include <climits>
#include <cstdlib>
#include <limits.h>
#include <ctime>
#include <sys/stat.h>
#define __STDC_FORMAT_MACROS
#include <cinttypes>
#include "athena/FileInfo.hpp"
#include "athena/Utility.hpp"
#ifndef _WIN32
#include <dirent.h>
#include <unistd.h>
#else
#include <ctime>
#include <direct.h>
#endif
@ -45,7 +49,7 @@ bool Dir::cd(std::string_view path) {
bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data()).c_str()) < 0); }
bool Dir::touch() {
srand(time(NULL));
std::srand(std::time(nullptr));
atUint64 tmp = utility::rand64();
std::string tmpFile = fmt::format(fmt("{:016X}.tmp"), tmp);
bool ret = FileInfo(m_path + "/" + tmpFile).touch();

View File

@ -1,11 +1,13 @@
#include "athena/FileInfo.hpp"
#include "athena/Utility.hpp"
#include "athena/FileWriter.hpp"
#include "athena/FileReader.hpp"
#include <ctime>
#include <climits>
#include <cstdio>
#include <limits.h>
#include <cstdlib>
#include <ctime>
#include "athena/FileReader.hpp"
#include "athena/FileWriter.hpp"
#include "athena/Utility.hpp"
#ifndef _WIN32
#include <sys/time.h>
@ -104,7 +106,7 @@ bool FileInfo::touch() const {
(void)athena::io::FileWriter(m_path);
return true;
}
if (utimes(m_path.c_str(), NULL) < 0) {
if (utimes(m_path.c_str(), nullptr) < 0) {
return false;
}
#elif defined(_WIN32)
@ -114,7 +116,7 @@ bool FileInfo::touch() const {
wchar_t date[80], time[80];
#if !WINDOWS_STORE
fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL);
fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, nullptr, CREATE_NEW, 0, nullptr);
if (fh == INVALID_HANDLE_VALUE)
return false;
@ -122,14 +124,14 @@ bool FileInfo::touch() const {
/*
* Use GetFileTime() to get the file modification time.
*/
if (GetFileTime(fh, NULL, NULL, &modtime) == 0) {
if (GetFileTime(fh, nullptr, nullptr, &modtime) == 0) {
CloseHandle(fh);
return false;
}
FileTimeToSystemTime(&modtime, &st);
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) {
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) {
CloseHandle(fh);
return false;
}
@ -139,13 +141,13 @@ bool FileInfo::touch() const {
* to the current time.
*/
GetSystemTime(&st);
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) {
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 ||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) {
CloseHandle(fh);
return false;
}
SystemTimeToFileTime(&st, &modtime);
if (SetFileTime(fh, NULL, NULL, &modtime) == 0) {
if (SetFileTime(fh, nullptr, nullptr, &modtime) == 0) {
CloseHandle(fh);
return false;
}

View File

@ -1,5 +1,7 @@
#include "athena/FileWriter.hpp"
#include <cstring>
namespace athena::io {
void TransactionalFileWriter::seek(atInt64 pos, SeekOrigin origin) {
switch (origin) {

View File

@ -2,6 +2,7 @@
#include "athena/Utility.hpp"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define FMT_STRING_ALIAS 1
#define FMT_ENFORCE_COMPILE_STRING 1

View File

@ -1,11 +1,8 @@
#include "athena/MemoryReader.hpp"
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#ifdef HW_RVL
#include <malloc.h>

View File

@ -2,8 +2,6 @@
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#ifdef HW_RVL
#include <malloc.h>

View File

@ -1,18 +1,22 @@
#include "athena/Socket.hpp"
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <cerrno>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <unistd.h>
#include <cerrno>
#include <fcntl.h>
#else
#include <WinSock2.h>
#include <Ws2tcpip.h>
#endif
#include "athena/Global.hpp"
namespace athena::net {
/* Define the low-level send/receive flags, which depend on the OS */
@ -45,8 +49,8 @@ void IPAddress::resolve(const std::string& address) {
addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
addrinfo* result = NULL;
if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) {
addrinfo* result = nullptr;
if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) {
if (result) {
addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr;
freeaddrinfo(result);

View File

@ -1,15 +1,16 @@
#include "athena/Utility.hpp"
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <algorithm>
#include <cstdarg>
#include <iterator>
#include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <random>
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include "utf8proc.h"
#ifdef _MSC_VER
@ -100,7 +101,7 @@ int countChar(std::string_view str, const char chr, int* lastOccur) {
for (char c : str) {
if (c == chr) {
if (lastOccur != NULL)
if (lastOccur != nullptr)
*lastOccur = index;
ret++;

View File

@ -1,10 +1,8 @@
#include "athena/VectorWriter.hpp"
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
namespace athena::io {