<commit_before>#ifndef HOFFSETS_H_INCLUDED
#define HOFFSETS_H_INCLUDED
#include "endian.h"
#include <cstdint>
#include <stdexcept>
#include <cstddef>

namespace HedgeLib::IO
{
	template<typename OffsetType>
	struct DataOffset
	{
	protected:
		OffsetType o = 0;

	public:
		constexpr DataOffset() = default;
		constexpr DataOffset(const OffsetType offset) : o(offset) {}
		constexpr DataOffset(std::nullptr_t) : o(0) {}

		constexpr operator OffsetType() const noexcept
		{
			return o;
		}
	};

	template<typename DataType>
	struct DataOffset32 : public DataOffset<std::uint32_t>
	{
		constexpr DataOffset32() = default;
		constexpr DataOffset32(const std::uint32_t offset) :
			DataOffset<std::uint32_t>(offset) {}
		constexpr DataOffset32(std::nullptr_t) :
			DataOffset<std::uint32_t>(nullptr) {}

		DataOffset32(const DataType* ptr) { Set(ptr); }

		ENDIAN_SWAP(o);

		template<typename CastedType>
		inline CastedType* GetAs() const noexcept
		{
			return reinterpret_cast<CastedType*>(Get());
		}

		inline DataType* Get() const noexcept
		{
#ifdef x86
			return reinterpret_cast<DataType*>(o);
#elif x64
			return reinterpret_cast<DataType*>(reinterpret_cast
				<const std::uintptr_t>(this) + o);
#endif
		}

		inline operator DataType*() const noexcept
		{
			return Get();
		}

		inline DataType& operator* () const noexcept
		{
			return *Get();
		}

		inline DataType* operator-> () const noexcept
		{
			return Get();
		}

		inline DataType& operator[] (const int index) const noexcept
		{
    		return Get()[index];
		}

		constexpr void Fix(const std::uintptr_t origin) noexcept
		{
#ifdef x86
			o += origin;
#elif x64
			o = static_cast<std::uint32_t>(((origin + o) -
				reinterpret_cast<std::uintptr_t>(this)));
#endif
		}

		constexpr void Set(const DataType* ptr)
		{
#ifdef x86
			o = static_cast<std::uint32_t>(
				reinterpret_cast<std::uintptr_t>(ptr));
#elif x64
			std::uintptr_t t = reinterpret_cast<std::uintptr_t>(this);
			std::uintptr_t p = reinterpret_cast<std::uintptr_t>(ptr);

			if (p < t) // TODO: There has to be some better way to do this?
				throw std::runtime_error("Cannot store negative values in offset!");

			o = static_cast<std::uint32_t>(p - t);
#endif
		}
	};

	template<typename DataType>
	struct DataOffset64 : public DataOffset<std::uint64_t>
	{
		constexpr DataOffset64() = default;
		constexpr DataOffset64(const std::uint64_t offset) :
			DataOffset<std::uint64_t>(offset) {}
		constexpr DataOffset64(std::nullptr_t) :
			DataOffset<std::uint64_t>(nullptr) {}

		DataOffset64(const DataType* ptr) { Set(ptr); }

		template<typename CastedType>
		inline CastedType* GetAs() const noexcept
		{
			return reinterpret_cast<CastedType*>(o);
		}

		inline DataType* Get() const noexcept
		{
			return reinterpret_cast<DataType*>(o);
		}

		inline operator DataType*() const noexcept
		{
			return Get();
		}

		inline DataType& operator* () const noexcept
		{
			return *Get();
		}

		inline DataType* operator-> () const noexcept
		{
			return Get();
		}

		inline DataType& operator[] (const int index) const noexcept
		{
    		return Get()[index];
		}

		constexpr void Fix(const std::uintptr_t origin) noexcept
		{
			o += origin;
		}

		constexpr void Set(const DataType* ptr)
		{
			o = static_cast<std::uint64_t>(
				reinterpret_cast<std::uintptr_t>(ptr));
		}
	};

	template<typename DataType>
	struct ArrOffset32 : public DataOffset<std::uint32_t>
	{
		constexpr ArrOffset32() = default;
		constexpr ArrOffset32(const std::uint32_t offset) :
			DataOffset<std::uint32_t>(offset) {}
		constexpr ArrOffset32(std::nullptr_t) :
			DataOffset<std::uint32_t>(nullptr) {}

		inline DataType* Get() const noexcept
		{
#ifdef x86
			return reinterpret_cast<DataType*>(o);
#elif x64
			return reinterpret_cast<DataType*>(reinterpret_cast
				<const std::uintptr_t>(this) + o);
#endif
		}
		
		inline operator DataType*() const noexcept
		{
			return &(Get()[0]);
		}

		inline DataType& operator* () const noexcept
		{
			return Get()[0];
		}

		inline DataType* operator-> () const noexcept
		{
			return &(Get()[0]);
		}<commit_msg>Made DataOffset also swap endianness of object itself<commit_after>#ifndef HOFFSETS_H_INCLUDED
#define HOFFSETS_H_INCLUDED
#include "endian.h"
#include <cstdint>
#include <stdexcept>
#include <cstddef>

namespace HedgeLib::IO
{
	template<typename OffsetType>
	struct DataOffset
	{
	protected:
		OffsetType o = 0;

	public:
		constexpr DataOffset() = default;
		constexpr DataOffset(const OffsetType offset) : o(offset) {}
		constexpr DataOffset(std::nullptr_t) : o(0) {}

		constexpr operator OffsetType() const noexcept
		{
			return o;
		}
	};

	template<typename DataType>
	struct DataOffset32 : public DataOffset<std::uint32_t>
	{
		constexpr DataOffset32() = default;
		constexpr DataOffset32(const std::uint32_t offset) :
			DataOffset<std::uint32_t>(offset) {}
		constexpr DataOffset32(std::nullptr_t) :
			DataOffset<std::uint32_t>(nullptr) {}

		DataOffset32(const DataType* ptr) { Set(ptr); }

		template<typename CastedType>
		inline CastedType* GetAs() const noexcept
		{
			return reinterpret_cast<CastedType*>(Get());
		}

		inline DataType* Get() const noexcept
		{
#ifdef x86
			return reinterpret_cast<DataType*>(o);
#elif x64
			return reinterpret_cast<DataType*>(reinterpret_cast
				<const std::uintptr_t>(this) + o);
#endif
		}

		inline operator DataType*() const noexcept
		{
			return Get();
		}

		inline DataType& operator* () const noexcept
		{
			return *Get();
		}

		inline DataType* operator-> () const noexcept
		{
			return Get();
		}

		inline DataType& operator[] (const int index) const noexcept
		{
    		return Get()[index];
		}

		constexpr void Fix(const std::uintptr_t origin) noexcept
		{
#ifdef x86
			o += origin;
#elif x64
			o = static_cast<std::uint32_t>(((origin + o) -
				reinterpret_cast<std::uintptr_t>(this)));
#endif
		}

		constexpr void Set(const DataType* ptr)
		{
#ifdef x86
			o = static_cast<std::uint32_t>(
				reinterpret_cast<std::uintptr_t>(ptr));
#elif x64
			std::uintptr_t t = reinterpret_cast<std::uintptr_t>(this);
			std::uintptr_t p = reinterpret_cast<std::uintptr_t>(ptr);

			if (p < t) // TODO: There has to be some better way to do this?
				throw std::runtime_error("Cannot store negative values in offset!");

			o = static_cast<std::uint32_t>(p - t);
#endif
		}

		inline void EndianSwap()
		{
			HedgeLib::IO::Endian::SwapRecursive(o, *Get());
		}
	};

	template<typename DataType>
	struct DataOffset64 : public DataOffset<std::uint64_t>
	{
		constexpr DataOffset64() = default;
		constexpr DataOffset64(const std::uint64_t offset) :
			DataOffset<std::uint64_t>(offset) {}
		constexpr DataOffset64(std::nullptr_t) :
			DataOffset<std::uint64_t>(nullptr) {}

		DataOffset64(const DataType* ptr) { Set(ptr); }

		template<typename CastedType>
		inline CastedType* GetAs() const noexcept
		{
			return reinterpret_cast<CastedType*>(o);
		}

		inline DataType* Get() const noexcept
		{
			return reinterpret_cast<DataType*>(o);
		}

		inline operator DataType*() const noexcept
		{
			return Get();
		}

		inline DataType& operator* () const noexcept
		{
			return *Get();
		}

		inline DataType* operator-> () const noexcept
		{
			return Get();
		}

		inline DataType& operator[] (const int index) const noexcept
		{
    		return Get()[index];
		}

		constexpr void Fix(const std::uintptr_t origin) noexcept
		{
			o += origin;
		}

		constexpr void Set(const DataType* ptr)
		{
			o = static_cast<std::uint64_t>(
				reinterpret_cast<std::uintptr_t>(ptr));
		}

		inline void EndianSwap()
		{
			HedgeLib::IO::Endian::SwapRecursive(o, *Get());
		}
	};

	template<typename DataType>
	struct ArrOffset32 : public DataOffset<std::uint32_t>
	{
		constexpr ArrOffset32() = default;
		constexpr ArrOffset32(const std::uint32_t offset) :
			DataOffset<std::uint32_t>(offset) {}
		constexpr ArrOffset32(std::nullptr_t) :
			DataOffset<std::uint32_t>(nullptr) {}

		ENDIAN_SWAP(o);

		inline DataType* Get() const noexcept
		{
#ifdef x86
			return reinterpret_cast<DataType*>(o);
#elif x64
			return reinterpret_cast<DataType*>(reinterpret_cast
				<const std::uintptr_t>(this) + o);
#endif
		}
		
		inline operator DataType*() const noexcept
		{
			return &(Get()[0]);
		}

		inline DataType& operator* () const noexcept
		{
			return Get()[0];
		}

		inline DataType* operator-> () const noexcept
		{
			return &(Get()[0]);
		}
{'fraction_non_alphanumeric': 0.13048664122137404, 'fraction_numerical': 0.019322519083969467, 'mean_word_length': 4.306962025316456, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6247868', 'n_tokens_mistral': 3374, 'n_tokens_neox': 2919, 'n_words': 655}