This commit is contained in:
Isuru Samarathunga
2025-07-04 17:34:24 +05:30
parent 987e801797
commit 491342ad50
93 changed files with 6234 additions and 0 deletions

View File

@ -0,0 +1,4 @@
add_library(IACore STATIC imp/cpp/dummy.cpp)
target_include_directories(IACore PUBLIC inc/hpp imp/inl)

View File

View File

@ -0,0 +1,52 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/binary-search.interface.inl"
namespace ia
{
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
iterator_type BinarySearchLeft(IN iterator_type begin, IN iterator_type end, IN CONST typename iterator_type::value_type& v)
{
SSIZE_T l = 0, r = end - begin;
while(l < r)
{
const auto m = static_cast<SSIZE_T>((l+r)/2);
const auto t = *(begin + m) < v;
l = t ? m + 1 : l;
r = t ? r : m;
}
return begin + l;
}
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
iterator_type BinarySearchRight(IN iterator_type begin, IN iterator_type end, IN CONST typename iterator_type::value_type& v)
{
SSIZE_T l = 0, r = end - begin;
while(l < r)
{
const auto m = static_cast<SSIZE_T>((l+r)/2);
const auto t = *(begin + m) > v;
r = t ? m : r;
l = t ? l : m + 1;
}
return begin + (r - 1);
}
}

View File

@ -0,0 +1,30 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/iterator.hpp>
namespace ia
{
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
iterator_type BinarySearchLeft(IN iterator_type begin, IN iterator_type end, IN CONST typename iterator_type::value_type& v);
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
iterator_type BinarySearchRight(IN iterator_type begin, IN iterator_type end, IN CONST typename iterator_type::value_type& v);
}

View File

@ -0,0 +1,26 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/iterator.hpp>
namespace ia
{
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
VOID QuickSort(IN iterator_type begin, IN iterator_type end);
}

View File

@ -0,0 +1,68 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/quick-sort.interface.inl"
namespace ia::__internal
{
template<typename pointer_type>
VOID quick_sort_partition(IN pointer_type data, IN SSIZE_T l, IN SSIZE_T r, OUT SSIZE_T& p_left, OUT SSIZE_T& p_right)
{
auto m = l;
p_left = l, p_right = r;
const auto p = data[(l+r)/2];
while(m <= p_right)
{
const auto t = data[m];
if(t < p)
{
ia_swap(data[m], data[p_left]);
p_left++;
}
else if(t > p)
{
ia_swap(data[m], data[p_right]);
p_right--;
continue;
}
m++;
}
}
template<typename pointer_type>
VOID quick_sort_aux(IN pointer_type data, IN SSIZE_T start, IN SSIZE_T end)
{
SSIZE_T p_left { 0 }, p_right { 0 };
if(start >= 0 && start < end)
{
quick_sort_partition(data, start, end, p_left, p_right);
quick_sort_aux(data, start, p_left - 1);
quick_sort_aux(data, p_right + 1, end);
}
}
}
namespace ia
{
template<typename iterator_type>
requires valid_contiguous_iterator_type<iterator_type>
VOID QuickSort(IN iterator_type begin, IN iterator_type end)
{
__internal::quick_sort_aux(&(begin[0]), 0, end - begin - 1);
}
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/array.interface.inl"
namespace ia {}

View File

@ -0,0 +1,56 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/container.hpp>
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class Array: public FixedContainer<_value_type, _allocator_type, _alignment>
{
using Base = FixedContainer<_value_type, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
Array(): Base() {}
Array(IN size_type count): Base(count) {}
Array(IN initializer_list<value_type> v): Base(v) {}
Array(IN Array&& r): Base(r) {}
Array(IN CONST Array& r): Base(r) {}
~Array() {}
VOID operator=(IN CONST Array& r) { Base::copy_from(r); }
VOID operator=(IN Array&& r) { Base::take_from(IA_MOVE(r)); }
};
}

View File

@ -0,0 +1,247 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/bytestring.interface.inl"
namespace ia
{
template<SIZE_T _size>
ByteString FixedByteString<_size>::operator+(IN CONST IIByteString& other) CONST
{
ByteString res;
res.resize(length() + other.length());
ia_memcpy(res.data(), data(), length());
ia_memcpy(&res.data()[length()], other.data(), other.length());
return res;
}
ByteString ByteString::operator+(IN CONST IIByteString& other) CONST
{
ByteString res;
res.resize(length() + other.length());
ia_memcpy(res.data(), data(), length());
ia_memcpy(&res.data()[length()], other.data(), other.length());
return res;
}
ByteString& ByteString::operator+=(IN CONST IIByteString& other)
{
const auto l = length();
resize(l + other.length());
ia_memcpy(&data()[l], other.data(), other.length());
return *this;
}
}
namespace ia
{
UINT16 IIByteString::swapEndianness16(IN UINT16 v)
{
const auto t = reinterpret_cast<PUINT8>(&v);
std::swap(t[0], t[1]);
return v;
}
UINT32 IIByteString::swapEndianness32(IN UINT32 v)
{
const auto t = reinterpret_cast<PUINT8>(&v);
std::swap(t[0], t[3]);
std::swap(t[1], t[2]);
return v;
}
UINT64 IIByteString::swapEndianness64(IN UINT64 v)
{
const auto t = reinterpret_cast<PUINT8>(&v);
std::swap(t[0], t[7]);
std::swap(t[1], t[6]);
std::swap(t[2], t[5]);
std::swap(t[3], t[4]);
return v;
}
VOID IIByteString::swapEndianness16()
{
IA_ASSERT_MSG(!(length() % 2), "length must be 2-byte aligned");
const auto t = reinterpret_cast<PUINT16>(data());
const auto l = length() >> 1;
for(SIZE_T i = 0; i < l; i++)
t[i] = swapEndianness16(t[i]);
}
VOID IIByteString::swapEndianness32()
{
IA_ASSERT_MSG(!(length() % 4), "length must be 4-byte aligned");
const auto t = reinterpret_cast<PUINT32>(data());
const auto l = length() >> 2;
for(SIZE_T i = 0; i < l; i++)
t[i] = swapEndianness32(t[i]);
}
VOID IIByteString::swapEndianness64()
{
IA_ASSERT_MSG(!(length() % 8), "length must be 8-byte aligned");
const auto t = reinterpret_cast<PUINT64>(data());
const auto l = length() >> 3;
for(SIZE_T i = 0; i < l; i++)
t[i] = swapEndianness64(t[i]);
}
}
namespace ia
{
VOID IIByteString::fillFromHexString(IN CONST String& v)
{
STATIC CONSTEXPR UINT8 HEX_LUT[] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};
auto data = v.data();
const auto l = (v.length() >> 1) + (v.length() % 2);
if(l > length()) resize(l);
SIZE_T i { 0 };
for(CHAR c; (c = *data); data++)
{
auto t = HEX_LUT[c];
IAC_CHECK_SANITY(t < 16);
UINT8 byte = (t << 4);
data++;
c = *data;
if(!c) {
this->data()[i++] = byte;
break;
}
t = HEX_LUT[c];
IAC_CHECK_SANITY(t < 16);
byte |= (t & 0x0F);
this->data()[i++] = byte;
}
if(i < length()) ia_memset(&this->data()[i], 0, length() - i);
}
VOID IIByteString::fillFromUTF8String(IN CONST String& v)
{
fillFromMemory((PCUINT8)v.data(), v.length());
}
VOID IIByteString::fillFromMemory(IN PCUINT8 data, IN SIZE_T dataSize)
{
if(dataSize > length()) resize(dataSize);
else if(dataSize < length())
ia_memset(&this->data()[dataSize], 0, length() - dataSize);
ia_memcpy(this->data(), data, dataSize);
}
String IIByteString::toHexString() CONST
{
STATIC CONSTEXPR CHAR HEX_LUT[] = "0123456789ABCDEF";
String res;
for(SIZE_T i = 0; i < length(); i++)
{
res += HEX_LUT[(data()[i] >> 4) & 0x0F];
res += HEX_LUT[data()[i] & 0x0F];
}
return res;
}
String IIByteString::toBinString() CONST
{
String res; res.resize(8 * length());
for(SIZE_T i = 0; i < length(); i++)
{
auto byte = data()[i];
for(INT32 j = 0; j < 8; j++)
{
res[i * 8 + j] = (byte & 0x80) ? '1' : '0';
byte <<= 1;
}
}
return res;
}
}
namespace ia
{
VOID IIByteString::put(IN SIZE_T position, IN PCUINT8 data, IN SIZE_T dataLength)
{
IAC_CHECK_OVERFLOW(position + dataLength, length());
memcpy(&this->data()[position], data, dataLength);
}
VOID IIByteString::put8(IN SIZE_T position, IN UINT8 data)
{
IAC_CHECK_OVERFLOW(position + 1, length());
this->data()[position] = data;
}
VOID IIByteString::put16le(IN SIZE_T position, IN UINT16 data)
{
IAC_CHECK_OVERFLOW(position + 2, length());
this->data()[position + 0] = data;
this->data()[position + 1] = data >> 8;
}
VOID IIByteString::put32le(IN SIZE_T position, IN UINT32 data)
{
IAC_CHECK_OVERFLOW(position + 4, length());
this->data()[position + 0] = data;
this->data()[position + 1] = data >> 8;
this->data()[position + 2] = data >> 16;
this->data()[position + 3] = data >> 24;
}
VOID IIByteString::put64le(IN SIZE_T position, IN UINT64 data)
{
IAC_CHECK_OVERFLOW(position + 8, length());
this->data()[position + 0] = data;
this->data()[position + 1] = data >> 8;
this->data()[position + 2] = data >> 16;
this->data()[position + 3] = data >> 24;
this->data()[position + 4] = data >> 32;
this->data()[position + 5] = data >> 40;
this->data()[position + 6] = data >> 48;
this->data()[position + 7] = data >> 56;
}
VOID IIByteString::put16be(IN SIZE_T position, IN UINT16 data)
{
IAC_CHECK_OVERFLOW(position + 2, length());
this->data()[position + 1] = data;
this->data()[position + 0] = data >> 8;
}
VOID IIByteString::put32be(IN SIZE_T position, IN UINT32 data)
{
IAC_CHECK_OVERFLOW(position + 4, length());
this->data()[position + 3] = data;
this->data()[position + 2] = data >> 8;
this->data()[position + 1] = data >> 16;
this->data()[position + 0] = data >> 24;
}
VOID IIByteString::put64be(IN SIZE_T position, IN UINT64 data)
{
IAC_CHECK_OVERFLOW(position + 8, length());
this->data()[position + 7] = data;
this->data()[position + 6] = data >> 8;
this->data()[position + 5] = data >> 16;
this->data()[position + 4] = data >> 24;
this->data()[position + 3] = data >> 32;
this->data()[position + 2] = data >> 40;
this->data()[position + 1] = data >> 48;
this->data()[position + 0] = data >> 56;
}
}

View File

@ -0,0 +1,124 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/exception.hpp>
#include <iacore/vector.hpp>
namespace ia
{
class IIByteString
{
public:
PURE_VIRTUAL(PUINT8 data());
PURE_VIRTUAL(SIZE_T length() CONST);
PURE_VIRTUAL(CONST PCUINT8 data() CONST);
PURE_VIRTUAL(VOID resize(IN SIZE_T newSize));
PURE_VIRTUAL(UINT8& operator[](IN SIZE_T index));
PURE_VIRTUAL(CONST UINT8& operator[](IN SIZE_T index) CONST);
public:
INLINE VOID fillFromHexString(IN CONST String& v);
INLINE VOID fillFromUTF8String(IN CONST String& v);
INLINE VOID fillFromMemory(IN PCUINT8 data, IN SIZE_T dataSize);
INLINE String toHexString() CONST;
INLINE String toBinString() CONST;
public:
STATIC INLINE UINT16 swapEndianness16(IN UINT16 v);
STATIC INLINE UINT32 swapEndianness32(IN UINT32 v);
STATIC INLINE UINT64 swapEndianness64(IN UINT64 v);
public:
INLINE VOID swapEndianness16();
INLINE VOID swapEndianness32();
INLINE VOID swapEndianness64();
public:
INLINE VOID put8(IN SIZE_T position, IN UINT8 data);
INLINE VOID put(IN SIZE_T position, IN PCUINT8 data, IN SIZE_T dataLength);
INLINE VOID put16le(IN SIZE_T position, IN UINT16 data);
INLINE VOID put32le(IN SIZE_T position, IN UINT32 data);
INLINE VOID put64le(IN SIZE_T position, IN UINT64 data);
INLINE VOID put16be(IN SIZE_T position, IN UINT16 data);
INLINE VOID put32be(IN SIZE_T position, IN UINT32 data);
INLINE VOID put64be(IN SIZE_T position, IN UINT64 data);
public:
SIZE_T size() CONST { return length(); }
};
class ByteString;
template<SIZE_T _size>
class FixedByteString: public IIByteString
{
public:
STATIC FixedByteString<_size> fromHexString(IN CONST String& v) { FixedByteString<_size> res; res.fillFromHexString(v); return IA_MOVE(res); }
STATIC FixedByteString<_size> fromUTF8String(IN CONST String& v) { FixedByteString<_size> res; res.fillFromUTF8String(v); return IA_MOVE(res); }
STATIC FixedByteString<_size> fromMemory(IN PCUINT8 data, IN SIZE_T dataSize) { FixedByteString<_size> res; res.fillFromMemory(data, dataSize); return IA_MOVE(res); }
public:
VOID resize(IN SIZE_T newSize) { THROW_INVALID_USAGE("attempting to resize a fixed byte string"); }
PUINT8 data() { return m_data; }
SIZE_T length() CONST { return _size; }
CONST PCUINT8 data() CONST { return m_data; }
UINT8& operator[](IN SIZE_T index) { return m_data[index]; }
CONST UINT8& operator[](IN SIZE_T index) CONST { return m_data[index]; }
public:
INLINE ByteString operator+(IN CONST IIByteString& other) CONST;
private:
UINT8 m_data[_size];
};
class ByteString: public IIByteString
{
public:
STATIC ByteString fromHexString(IN CONST String& v) { ByteString res; res.fillFromHexString(v); return IA_MOVE(res); }
STATIC ByteString fromUTF8String(IN CONST String& v) { ByteString res; res.fillFromUTF8String(v); return IA_MOVE(res); }
STATIC ByteString fromMemory(IN PCUINT8 data, IN SIZE_T dataSize) { ByteString res; res.fillFromMemory(data, dataSize); return IA_MOVE(res); }
public:
ByteString() {}
ByteString(IN CONST IIByteString& v) { fillFromMemory(v.data(), v.length()); }
public:
VOID resize(IN SIZE_T newSize) { m_data.resize(newSize); }
PUINT8 data() { return m_data.data(); }
SIZE_T length() CONST { return m_data.size(); }
CONST PCUINT8 data() CONST { return m_data.data(); }
UINT8& operator[](IN SIZE_T index) { return m_data[index]; }
CONST UINT8& operator[](IN SIZE_T index) CONST { return m_data[index]; }
public:
INLINE ByteString operator+(IN CONST IIByteString& other) CONST;
INLINE ByteString& operator+=(IN CONST IIByteString& other);
private:
Vector<UINT8> m_data;
};
}

View File

@ -0,0 +1,350 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/dynamic.interface.inl"
#define put_element(start, element) new (&Base::m_data[start]) value_type(element);
#define move_element(start, element) new (&Base::m_data[start]) value_type(IA_MOVE(element));
#define move_elements(start, data, count) for(size_type i = 0; i < count; i++) new (&Base::m_data[start + i]) value_type(IA_MOVE((data)[i]));
#define __template_iterator template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, _value_type>
#define __ia__identifier DynamicContainer<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(, DynamicContainer)
{
}
define_member_function(, DynamicContainer, IN size_type count)
{
resize(count);
}
define_member_function(, DynamicContainer, IN initializer_list<value_type> v)
{
reserve(v.size());
for(const auto& value: v) new (&Base::m_data[Base::m_count++]) value_type(value);
}
define_member_function(, ~DynamicContainer,)
{
reset();
}
define_member_function(VOID, copy_from, IN CONST __ia__identifier& r)
{
Base::m_allocator = r.m_allocator.selectOnContainerCopy();
reserve(r.capacity());
for(Base::m_count = 0; Base::m_count < r.m_count; Base::m_count++)
new (&Base::m_data[Base::m_count]) value_type(r.m_data[Base::m_count]);
}
define_member_function(VOID, take_from, IN __ia__identifier&& r)
{
ia_swap(Base::m_data, r.m_data);
ia_swap(Base::m_count, r.m_count);
ia_swap(Base::m_allocator, r.m_allocator);
ia_swap(m_capacity, r.m_capacity);
}
define_member_function(VOID, reset,)
{
Base::reset();
m_capacity = 0;
}
define_member_function(__ia__identifier::pointer_type, take,)
{
auto res = Base::m_data;
Base::m_data = nullptr;
reset();
return res;
}
}
namespace ia
{
define_member_function(VOID, append, IN value_type&& v)
{
grow(1);
new (&Base::m_data[Base::m_count++]) value_type(IA_MOVE(v));
}
define_member_function(VOID, append, IN const_reference_type v)
{
grow(1);
new (&Base::m_data[Base::m_count++]) value_type(v);
}
define_member_function(VOID, append, IN size_type n, IN const_reference_type v)
{
grow(n);
for(size_type i = 0; i < n; i++)
new (&Base::m_data[Base::m_count++]) value_type(v);
}
define_member_function(VOID, append, IN size_type n, IN const_pointer_type v)
{
grow(n);
for(size_type i = 0; i < n; i++)
new (&Base::m_data[Base::m_count++]) value_type(v[i]);
}
define_member_function(VOID, append, IN initializer_list<value_type> v)
{
grow(v.size());
for(auto it = v.begin(); it != v.end(); it++)
new (&Base::m_data[Base::m_count++]) value_type(*it);
}
define_member_function(__template_iterator VOID, append, IN iterator_type first, IN iterator_type last)
{
grow(last - first);
for(auto it = first; it != last; it++)
new (&Base::m_data[Base::m_count++]) value_type(*it);
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN value_type&& v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
pointer_type oldData {};
if(grow(1, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + 1, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + 1, Base::m_data[i]);
}
move_element(insert_at, v);
Base::m_count++;
return { Base::m_data + insert_at + 1 };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN const_reference_type v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
pointer_type oldData {};
if(grow(1, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + 1, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + 1, Base::m_data[i]);
}
put_element(insert_at, v);
Base::m_count++;
return { Base::m_data + insert_at + 1 };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN size_type n, IN const_reference_type v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
for(size_type i = 0; i < n; i++) put_element(insert_at + i, v);
Base::m_count += n;
return { Base::m_data + insert_at + n };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN size_type n, IN const_pointer_type v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
for(size_type i = 0; i < n; i++) put_element(insert_at + i, v[i]);
Base::m_count += n;
return { Base::m_data + insert_at + n };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN initializer_list<value_type> v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
const auto n = v.size();
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
ssize_type i { insert_at };
for(auto it = v.begin(); it != v.end(); it++, i++) put_element(i, *it);
Base::m_count += n;
return { Base::m_data + insert_at + n };
}
define_member_function(__template_iterator __ia__identifier::iterator, insert, IN const_iterator p, IN iterator_type first, IN iterator_type last)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= Base::m_count);
const auto n = last - first;
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
ssize_type i { insert_at };
for(auto it = first; it != last; it++, i++) put_element(i, *it);
Base::m_count += n;
return { Base::m_data + insert_at + n };
}
define_member_function(__ia__identifier::iterator, erase, IN const_iterator p, IN size_type n)
{
const auto erase_at = p - Base::cbegin();
IA_ASSERT((erase_at + n) <= Base::m_count);
for(size_type i = 0; i < n; i++) Base::m_data[erase_at + i].~value_type();
for(size_type i = erase_at + n; i < Base::m_count; i++) move_element(i - n, Base::m_data[i]);
Base::m_count -= n;
shrink();
return { Base::m_data + erase_at + n };
}
define_member_function(__ia__identifier::iterator, erase, IN const_iterator first, IN const_iterator last)
{
const auto n = last - first;
const auto erase_at = first - Base::cbegin();
IA_ASSERT((erase_at + n) <= Base::m_count);
for(size_type i = 0; i < n; i++) Base::m_data[erase_at + i].~value_type();
for(size_type i = erase_at + n; i < Base::m_count; i++) move_element(i - n, Base::m_data[i]);
Base::m_count -= n;
shrink();
return { Base::m_data + erase_at + n };
}
define_member_function(BOOL, grow, IN size_type size)
{
// [IATODO]: [IMPL] [URGENT] Proper grow using reallocation counts
return reserve(Base::m_count + size);
}
define_member_function(BOOL, grow, IN size_type size, OUT pointer_type* oldData)
{
// [IATODO]: [IMPL] [URGENT] Proper grow using reallocation counts
return reserve(Base::m_count + size, oldData);
}
define_member_function(VOID, shrink)
{
}
}
namespace ia
{
define_member_function(BOOL, resize, IN size_type newCount)
{
const auto did_reallocate = reserve(newCount);
for(; Base::m_count < newCount; Base::m_count++) Base::m_allocator.construct(&Base::m_data[Base::m_count]);
return did_reallocate;
}
define_member_function(BOOL, reserve, IN size_type newCapacity)
{
const auto oldData = Base::m_data;
if(newCapacity <= m_capacity) return false;
Base::m_data = alloc<_alignment>(Base::m_allocator, newCapacity);
m_capacity = newCapacity;
if(!oldData) return true;
for(size_type i = 0; i < Base::m_count; i++)
new (&Base::m_data[i]) value_type(IA_MOVE(oldData[i]));
dealloc<_alignment>(Base::m_allocator, oldData);
return true;
}
define_member_function(BOOL, resize, IN size_type newCount, OUT pointer_type* oldData)
{
const auto did_reallocate = reserve(newCount, oldData);
Base::m_count = newCount;
return did_reallocate;
}
define_member_function(BOOL, reserve, IN size_type newCapacity, OUT pointer_type* oldData)
{
*oldData = Base::m_data;
if(newCapacity <= m_capacity) return false;
Base::m_data = alloc<_alignment>(Base::m_allocator, newCapacity);
m_capacity = newCapacity;
return true;
}
define_member_function(VOID, clear,)
{
if(Base::m_data) Base::m_allocator.destruct(Base::m_data, Base::m_count);
Base::m_count = 0;
}
}
#undef put_element
#undef move_element
#undef move_elements
#undef __template_iterator
#undef __template
#undef __ia__identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,230 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/fixed.interface.inl"
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, _value_type>
#define __ia__identifier FixedContainer<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(, FixedContainer)
{
}
define_member_function(, FixedContainer, IN size_type count)
{
m_count = count;
m_data = alloc<_alignment>(m_allocator, m_count);
m_allocator.construct(m_data, m_count);
}
define_member_function(, FixedContainer, IN initializer_list<value_type> v)
{
m_data = alloc<_alignment>(m_allocator, v.size());
for(const auto& value: v) new (&m_data[m_count++]) value_type(value);
}
define_member_function(, ~FixedContainer,)
{
reset();
}
define_member_function(VOID, reset,)
{
if(m_data)
{
m_allocator.destruct(m_data, m_count);
dealloc<_alignment>(m_allocator, m_data);
m_data = nullptr;
}
m_count = 0;
}
define_member_function(__ia__identifier::pointer_type, take,)
{
auto res = m_data;
m_data = nullptr;
reset();
return res;
}
define_member_function(VOID, copy_from, IN CONST __ia__identifier& r)
{
m_allocator = r.m_allocator.selectOnContainerCopy();
m_data = alloc<_alignment>(m_allocator, (m_count = r.m_count));
for(size_type i = 0; i < m_count; i++)
new (&m_data[i]) value_type(r.m_data[i]);
}
define_member_function(VOID, take_from, IN __ia__identifier&& r)
{
ia_swap(m_data, r.m_data);
ia_swap(m_count, r.m_count);
ia_swap(m_allocator, r.m_allocator);
}
}
namespace ia
{
define_member_function(__ia__identifier::iterator, find, IN comparator_type c, IN size_type offset)
{
return cfind(c, offset);
}
define_member_function(__ia__identifier::iterator, rfind, IN comparator_type c, IN size_type offset)
{
return crfind(c, offset);
}
define_member_function(template<typename compare_type> __ia__identifier::iterator, find, IN CONST compare_type& v, IN size_type offset)
{
return cfind(v, offset);
}
define_member_function(template<typename compare_type> __ia__identifier::iterator, rfind, IN CONST compare_type& v, IN size_type offset)
{
return crfind(v, offset);
}
define_const_member_function(__ia__identifier::const_iterator, cfind, IN comparator_type c, IN size_type offset)
{
for(size_type i = offset; i < m_count; i++)
if(!c(m_data[i])) return { &m_data[i] };
return end();
}
define_const_member_function(__ia__identifier::const_iterator, crfind, IN comparator_type c, IN size_type offset)
{
for(ssize_type i = m_count - 1; i >= offset; i--)
if(!c(m_data[i])) return { &m_data[i] };
return end();
}
define_const_member_function(template<typename compare_type> __ia__identifier::const_iterator, cfind, IN CONST compare_type& v, IN size_type offset)
{
for(size_type i = offset; i < m_count; i++)
if(v == m_data[i]) return { &m_data[i] };
return end();
}
define_const_member_function(template<typename compare_type> __ia__identifier::const_iterator, crfind, IN CONST compare_type& v, IN size_type offset)
{
for(ssize_type i = m_count - 1; i >= offset; i--)
if(v == m_data[i]) return { &m_data[i] };
return end();
}
define_const_member_function(BOOL, contains, IN comparator_type v)
{
for(size_type i = 0; i < m_count; i++)
if(!c(m_data[i])) return true;
return false;
}
define_const_member_function(template<typename compare_type> BOOL, contains, IN CONST compare_type& v)
{
for(size_type i = 0; i < m_count; i++)
if(v == m_data[i]) return true;
return false;
}
define_const_member_function(BOOL, operator==, IN CONST FixedContainer& o)
{
if(m_count != o.size()) return false;
const auto data = o.data();
for(size_type i = 0; i < o.size(); i++)
if(m_data[i] != data[i]) return false;
return true;
}
define_const_member_function(UINT64, hash,)
{
return IIHashable::fnv_1a((PCUINT8)m_data, m_count * sizeof(value_type));
}
}
namespace ia
{
define_member_function(__ia__identifier::iterator, begin,)
{
return cbegin();
}
define_member_function(__ia__identifier::iterator, end,)
{
return cend();
}
define_member_function(__ia__identifier::reverse_iterator, rbegin,)
{
return crbegin();
}
define_member_function(__ia__identifier::reverse_iterator, rend,)
{
return crend();
}
define_const_member_function(__ia__identifier::const_iterator, begin,)
{
return cbegin();
}
define_const_member_function(__ia__identifier::const_iterator, end,)
{
return cend();
}
define_const_member_function(__ia__identifier::const_iterator, cbegin,)
{
return { m_data };
}
define_const_member_function(__ia__identifier::const_iterator, cend,)
{
return { m_data + m_count };
}
define_const_member_function(__ia__identifier::reverse_const_iterator, rbegin,)
{
return crbegin();
}
define_const_member_function(__ia__identifier::reverse_const_iterator, rend,)
{
return crend();
}
define_const_member_function(__ia__identifier::reverse_const_iterator, crbegin,)
{
return { m_data + m_count - 1 };
}
define_const_member_function(__ia__identifier::reverse_const_iterator, crend,)
{
return { m_data - 1 };
}
}
#undef __template
#undef __ia__identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,101 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "fixed.interface.inl"
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class DynamicContainer: public FixedContainer<_value_type, _allocator_type, _alignment>
{
using Base = FixedContainer<_value_type, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
DynamicContainer();
DynamicContainer(IN size_type count);
DynamicContainer(IN initializer_list<value_type> v);
DynamicContainer(IN DynamicContainer&& r) { take_from(IA_MOVE(r)); }
DynamicContainer(IN CONST DynamicContainer& r) { copy_from(r); }
~DynamicContainer();
VOID operator=(IN DynamicContainer&& r) { take_from(IA_MOVE(r)); }
VOID operator=(IN CONST DynamicContainer& r) { copy_from(r); }
public:
VOID append(IN value_type&& v);
VOID append(IN const_reference_type v);
VOID append(IN size_type n, IN const_reference_type v);
VOID append(IN size_type n, IN const_pointer_type v);
VOID append(IN initializer_list<value_type> v);
template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
VOID append(IN iterator_type first, IN iterator_type last);
iterator insert(IN const_iterator p, IN value_type&& v);
iterator insert(IN const_iterator p, IN const_reference_type v);
iterator insert(IN const_iterator p, IN size_type n, IN const_reference_type v);
iterator insert(IN const_iterator p, IN size_type n, IN const_pointer_type v);
iterator insert(IN const_iterator p, IN initializer_list<value_type> v);
template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
iterator insert(IN const_iterator p, IN iterator_type first, IN iterator_type last);
iterator erase(IN const_iterator p, IN size_type n = 1);
iterator erase(IN const_iterator first, IN const_iterator last);
public:
BOOL resize(IN size_type newCount);
BOOL reserve(IN size_type newCapacity);
VOID clear();
VIRTUAL VOID reset();
VIRTUAL pointer_type take();
public:
VIRTUAL size_type capacity() CONST { return m_capacity; }
protected:
BOOL resize(IN size_type newCount, OUT pointer_type* oldData);
BOOL reserve(IN size_type newCapacity, OUT pointer_type* oldData);
BOOL grow(IN size_type size);
BOOL grow(IN size_type size, OUT pointer_type* oldData);
VOID shrink();
VIRTUAL VOID take_from(IN DynamicContainer&& r);
VIRTUAL VOID copy_from(IN CONST DynamicContainer& r);
protected:
size_type m_capacity { 0 };
};
}

View File

@ -0,0 +1,139 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/hashable.hpp>
#include <iacore/allocator.hpp>
#include <iacore/memory.hpp>
#include "iterator.interface.inl"
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class FixedContainer: public IIHashable
{
public:
using size_type = SIZE_T;
using ssize_type = SSIZE_T;
using value_type = _value_type;
using buffer_type = value_type*;
using pointer_type = value_type*;
using reference_type = value_type&;
using allocator_type = _allocator_type;
using const_pointer_type = CONST value_type*;
using const_reference_type = CONST value_type&;
using iterator = ContainerIterator<value_type>;
using const_iterator = ContainerConstIterator<value_type>;
using reverse_iterator = ContainerIterator<value_type, true>;
using reverse_const_iterator = ContainerConstIterator<value_type, true>;
using comparator_type = std::function<INT32(IN CONST value_type&)>;
STATIC CONSTEXPR size_type alignment = _alignment;
public:
FixedContainer();
FixedContainer(IN size_type count);
FixedContainer(IN initializer_list<value_type> v);
FixedContainer(IN FixedContainer&& r) { take_from(IA_MOVE(r)); }
FixedContainer(IN CONST FixedContainer& r) { copy_from(r); }
~FixedContainer();
VOID operator=(IN FixedContainer&& r) { take_from(IA_MOVE(r)); }
VOID operator=(IN CONST FixedContainer& r) { copy_from(r); }
public:
iterator begin();
iterator end();
const_iterator begin() CONST;
const_iterator end() CONST;
const_iterator cbegin() CONST;
const_iterator cend() CONST;
reverse_iterator rbegin();
reverse_iterator rend();
reverse_const_iterator rbegin() CONST;
reverse_const_iterator rend() CONST;
reverse_const_iterator crbegin() CONST;
reverse_const_iterator crend() CONST;
public:
value_type& front() { IA_ASSERT(m_count > 0); return m_data[0]; }
CONST value_type& front() CONST { IA_ASSERT(m_count > 0); return m_data[0]; }
value_type& back() { IA_ASSERT(m_count > 0); return m_data[m_count - 1]; }
CONST value_type& back() CONST { IA_ASSERT(m_count > 0); return m_data[m_count - 1]; }
value_type& operator[](IN size_type index) { IA_ASSERT(index < m_count); return m_data[index]; }
CONST value_type& operator[](IN size_type index) CONST { IA_ASSERT(index < m_count); return m_data[index]; }
public:
template<typename compare_type>
iterator find(IN CONST compare_type& v, IN size_type offset = 0);
iterator find(IN comparator_type c, IN size_type offset = 0);
template<typename compare_type>
iterator rfind(IN CONST compare_type& v, IN size_type offset = 0);
iterator rfind(IN comparator_type c, IN size_type offset = 0);
template<typename compare_type>
const_iterator find(IN CONST compare_type& v, IN size_type offset = 0) CONST { return cfind(v, offset); }
const_iterator find(IN comparator_type c, IN size_type offset = 0) CONST { return cfind(c, offset); }
template<typename compare_type>
const_iterator rfind(IN CONST compare_type& v, IN size_type offset = 0) CONST { return crfind(v, offset); }
const_iterator rfind(IN comparator_type c, IN size_type offset = 0) CONST { return crfind(c, offset); }
template<typename compare_type>
const_iterator cfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
const_iterator cfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type>
const_iterator crfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
const_iterator crfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type>
BOOL contains(IN CONST compare_type& v) CONST;
BOOL contains(IN CONST comparator_type c) CONST;
public:
UINT64 hash() CONST;
public:
BOOL operator==(IN CONST FixedContainer& o) CONST;
public:
pointer_type data() { return m_data; }
const_pointer_type CONST data() CONST { return m_data; }
VIRTUAL size_type size() CONST { return m_count; }
VIRTUAL BOOL empty() CONST { return !m_count; }
allocator_type& allocator() { return m_allocator; }
VOID allocator(IN CONST allocator_type& v) { m_allocator = v; }
public:
VIRTUAL VOID reset();
VIRTUAL pointer_type take();
VIRTUAL VOID take_from(IN FixedContainer&& r);
VIRTUAL VOID copy_from(IN CONST FixedContainer& r);
protected:
size_type m_count { 0 };
buffer_type m_data { nullptr };
protected:
allocator_type m_allocator {};
};
}

View File

@ -0,0 +1,133 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/iterator.hpp>
namespace ia
{
template<typename _value_type, BOOL _is_reverse = false>
class ContainerIterator;
template<typename _value_type, BOOL _is_reverse = false>
class ContainerConstIterator: public virtual ContiguousIterator<ContainerConstIterator<_value_type, _is_reverse>, _value_type, CONST _value_type&, CONST _value_type*>
{
using Base = ContiguousIterator<ContainerConstIterator<_value_type, _is_reverse>, _value_type, CONST _value_type&, CONST _value_type*>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = _value_type;
using pointer_type = CONST _value_type*;
using reference_type = CONST _value_type&;
using self_type = ContainerConstIterator<_value_type, _is_reverse>;
public:
ContainerConstIterator(IN pointer_type dataRef): m_dataPtr(dataRef) {}
ContainerConstIterator(IN CONST ContainerConstIterator& o): m_dataPtr(o.m_dataPtr) {}
ContainerConstIterator(IN CONST ContainerIterator<_value_type, _is_reverse>& o): m_dataPtr(o.m_dataPtr) {}
public:
pointer_type operator->() CONST { return m_dataPtr; }
reference_type operator*() CONST { return *m_dataPtr; }
reference_type operator[](IN ssize_type index) CONST { return m_dataPtr[index]; }
public:
self_type& operator++() { increment(); return *this; }
self_type operator++(IN INT32) { auto res = *this; increment(); return res; }
self_type& operator--() { decrement(); return *this; }
self_type operator--(IN INT32) { auto res = *this; decrement(); return res; }
self_type operator+(IN size_type off) CONST { if constexpr(_is_reverse) return { m_dataPtr - off }; else return { m_dataPtr + off }; }
self_type operator-(IN size_type off) CONST { if constexpr(_is_reverse) return { m_dataPtr + off }; else return { m_dataPtr - off }; }
self_type& operator+=(IN size_type off) { increment(off); return *this; }
self_type& operator-=(IN size_type off) { decrement(off); return *this; }
ssize_type operator-(IN CONST self_type& o) CONST { return m_dataPtr - o.m_dataPtr; }
public:
BOOL operator==(IN CONST self_type& o) CONST { return m_dataPtr == o.m_dataPtr; }
BOOL operator!=(IN CONST self_type& o) CONST { return m_dataPtr != o.m_dataPtr; }
BOOL operator<=(IN CONST self_type& o) CONST { return m_dataPtr <= o.m_dataPtr; }
BOOL operator>=(IN CONST self_type& o) CONST { return m_dataPtr >= o.m_dataPtr; }
BOOL operator<(IN CONST self_type& o) CONST { return m_dataPtr < o.m_dataPtr; }
BOOL operator>(IN CONST self_type& o) CONST { return m_dataPtr > o.m_dataPtr; }
protected:
pointer_type m_dataPtr { nullptr };
private:
ALWAYS_INLINE VOID increment(IN size_type count = 1) { if constexpr(_is_reverse) m_dataPtr-=count; else m_dataPtr+=count; }
ALWAYS_INLINE VOID decrement(IN size_type count = 1) { if constexpr(_is_reverse) m_dataPtr+=count; else m_dataPtr-=count; }
friend class ContainerIterator<_value_type, _is_reverse>;
};
template<typename _value_type, BOOL _is_reverse>
class ContainerIterator: public virtual ContiguousIterator<ContainerIterator<_value_type, _is_reverse>, _value_type, _value_type&, _value_type*>
{
using Base = ContiguousIterator<ContainerIterator<_value_type, _is_reverse>, _value_type, _value_type&, _value_type*>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = _value_type;
using pointer_type = _value_type*;
using reference_type = _value_type&;
using self_type = ContainerIterator<_value_type, _is_reverse>;
public:
ContainerIterator(IN pointer_type dataRef): m_dataPtr(dataRef) {}
ContainerIterator(IN CONST self_type& o): m_dataPtr(o.m_dataPtr) {}
ContainerIterator(IN CONST ContainerConstIterator<value_type, _is_reverse>& o): m_dataPtr(const_cast<pointer_type>(o.m_dataPtr)) {}
public:
pointer_type operator->() CONST { return m_dataPtr; }
reference_type operator*() CONST { return *m_dataPtr; }
reference_type operator[](IN ssize_type index) CONST { return m_dataPtr[index]; }
public:
self_type& operator++() { increment(); return *this; }
self_type operator++(IN INT32) { auto res = *this; increment(); return res; }
self_type& operator--() { decrement(); return *this; }
self_type operator--(IN INT32) { auto res = *this; decrement(); return res; }
self_type operator+(IN size_type off) CONST { if constexpr(_is_reverse) return { m_dataPtr - off }; else return { m_dataPtr + off }; }
self_type operator-(IN size_type off) CONST { if constexpr(_is_reverse) return { m_dataPtr + off }; else return { m_dataPtr - off }; }
self_type& operator+=(IN size_type off) { increment(off); return *this; }
self_type& operator-=(IN size_type off) { decrement(off); return *this; }
ssize_type operator-(IN CONST self_type& o) CONST { return m_dataPtr - o.m_dataPtr; }
public:
BOOL operator==(IN CONST self_type& o) CONST { return m_dataPtr == o.m_dataPtr; }
BOOL operator!=(IN CONST self_type& o) CONST { return m_dataPtr != o.m_dataPtr; }
BOOL operator<=(IN CONST self_type& o) CONST { return m_dataPtr <= o.m_dataPtr; }
BOOL operator>=(IN CONST self_type& o) CONST { return m_dataPtr >= o.m_dataPtr; }
BOOL operator<(IN CONST self_type& o) CONST { return m_dataPtr < o.m_dataPtr; }
BOOL operator>(IN CONST self_type& o) CONST { return m_dataPtr > o.m_dataPtr; }
protected:
pointer_type m_dataPtr { nullptr };
private:
ALWAYS_INLINE VOID increment(IN size_type count = 1) { if constexpr(_is_reverse) m_dataPtr-=count; else m_dataPtr+=count; }
ALWAYS_INLINE VOID decrement(IN size_type count = 1) { if constexpr(_is_reverse) m_dataPtr+=count; else m_dataPtr-=count; }
friend class ContainerConstIterator<_value_type, _is_reverse>;
};
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/iterator.interface.inl"
namespace ia {}

View File

@ -0,0 +1,37 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/iihashable.interface.inl"
namespace ia
{
template<typename _type>
concept hashable_type = std::derived_from<_type, IIHashable>;
INLINE UINT64 IIHashable::fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength)
{
// Implemented as described at http://isthe.com/chongo/tech/comp/fnv/#google_vignette
UINT64 hash = 14695981039346656037llu;
for(SIZE_T i = 0; i < dataLength; i++)
{
hash = hash ^ data[i];
hash = hash * 1099511628211ul;
}
return hash;
}
}

View File

@ -0,0 +1,31 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
namespace ia
{
class IIHashable
{
public:
PURE_VIRTUAL(UINT64 hash() CONST);
public:
STATIC INLINE UINT64 fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength);
};
}

View File

@ -0,0 +1,105 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
namespace ia
{
template<typename iterator_type, typename _value_type, typename _reference_type, typename _pointer_type>
class Iterator
{
public:
using size_type = SIZE_T;
using ssize_type = SSIZE_T;
using value_type = _value_type;
using reference_type = _reference_type;
using pointer_type = _pointer_type;
//public:
// PURE_VIRTUAL(iterator_type& operator=(IN CONST iterator_type&));
public:
PURE_VIRTUAL(pointer_type operator->() CONST);
PURE_VIRTUAL(reference_type operator*() CONST);
};
template<typename iterator_type, typename _value_type, typename _reference_type, typename _pointer_type>
class ForwardIterator: public virtual Iterator<iterator_type, _value_type, _reference_type, _pointer_type>
{
public:
using value_type = _value_type;
using reference_type = _reference_type;
using pointer_type = _pointer_type;
public:
PURE_VIRTUAL(iterator_type& operator++());
PURE_VIRTUAL(iterator_type operator++(IN INT32));
public:
PURE_VIRTUAL(BOOL operator==(IN CONST iterator_type&) CONST);
PURE_VIRTUAL(BOOL operator!=(IN CONST iterator_type&) CONST);
};
template<typename iterator_type, typename _value_type, typename _reference_type, typename _pointer_type>
class BidirectionalIterator: public virtual ForwardIterator<iterator_type, _value_type, _reference_type, _pointer_type>
{
public:
using value_type = _value_type;
using reference_type = _reference_type;
using pointer_type = _pointer_type;
public:
PURE_VIRTUAL(iterator_type& operator--());
PURE_VIRTUAL(iterator_type operator--(IN INT32));
};
template<typename iterator_type, typename _value_type, typename _reference_type, typename _pointer_type>
class RandomAccessIterator: public virtual BidirectionalIterator<iterator_type, _value_type, _reference_type, _pointer_type>
{
public:
using value_type = _value_type;
using reference_type = _reference_type;
using pointer_type = _pointer_type;
public:
PURE_VIRTUAL(iterator_type& operator+=(IN SIZE_T));
PURE_VIRTUAL(iterator_type& operator-=(IN SIZE_T));
public:
PURE_VIRTUAL(BOOL operator<(IN CONST iterator_type&) CONST);
PURE_VIRTUAL(BOOL operator>(IN CONST iterator_type&) CONST);
PURE_VIRTUAL(BOOL operator<=(IN CONST iterator_type&) CONST);
PURE_VIRTUAL(BOOL operator>=(IN CONST iterator_type&) CONST);
PURE_VIRTUAL(iterator_type operator+(IN SIZE_T) CONST);
PURE_VIRTUAL(iterator_type operator-(IN SIZE_T) CONST);
PURE_VIRTUAL(reference_type operator[](IN SSIZE_T) CONST);
};
template<typename iterator_type, typename _value_type, typename _reference_type, typename _pointer_type>
class ContiguousIterator: public virtual RandomAccessIterator<iterator_type, _value_type, _reference_type, _pointer_type>
{
public:
using value_type = _value_type;
using reference_type = _reference_type;
using pointer_type = _pointer_type;
public:
PURE_VIRTUAL(SSIZE_T operator-(IN CONST iterator_type&) CONST);
};
}

View File

@ -0,0 +1,42 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/iterator.interface.inl"
namespace ia
{
template<typename iterator_type>
concept valid_iterator_type =
std::derived_from<iterator_type, Iterator<iterator_type, typename iterator_type::value_type, typename iterator_type::reference_type, typename iterator_type::pointer_type>>;
template<typename iterator_type>
concept valid_forward_iterator_type =
std::derived_from<iterator_type, ForwardIterator<iterator_type, typename iterator_type::value_type, typename iterator_type::reference_type, typename iterator_type::pointer_type>>;
template<typename iterator_type>
concept valid_bidirectional_iterator_type =
std::derived_from<iterator_type, BidirectionalIterator<iterator_type, typename iterator_type::value_type, typename iterator_type::reference_type, typename iterator_type::pointer_type>>;
template<typename iterator_type>
concept valid_random_access_iterator_type =
std::derived_from<iterator_type, RandomAccessIterator<iterator_type, typename iterator_type::value_type, typename iterator_type::reference_type, typename iterator_type::pointer_type>>;
template<typename iterator_type>
concept valid_contiguous_iterator_type =
std::derived_from<iterator_type, ContiguousIterator<iterator_type, typename iterator_type::value_type, typename iterator_type::reference_type, typename iterator_type::pointer_type>>;
}

View File

@ -0,0 +1,34 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/types.hpp>
namespace ia
{
template<typename Tr, typename Tv>
Tr floor(IN Tv v);
template<typename Tr, typename Tv>
Tr ceil(IN Tv v);
template<typename Tr, typename Tv>
Tr round(IN Tv v);
template<typename T1, typename T2>
T1 min(IN T1 a, IN T2 b);
template<typename T1, typename T2>
T1 max(IN T1 a, IN T2 b);
}

View File

@ -0,0 +1,60 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/types.hpp>
/*
* -----------------------------------
* IMPORTANT
* -----------------------------------
* This code is an initial DRAFT and
* has not yet been IA reviewed.
*
* Till this notice is removed from here,
* DO NOT USE this code in production.
*
* [IATODO]: [URGENT] [REVIEW]
*/
namespace ia
{
INLINE PVOID memset_8(OUT PVOID dst, IN UINT8 v, IN SIZE_T n);
INLINE PVOID memset_16(OUT PVOID dst, IN UINT16 v, IN SIZE_T n);
INLINE PVOID memset_32(OUT PVOID dst, IN UINT32 v, IN SIZE_T n);
INLINE PVOID memset_64(OUT PVOID dst, IN UINT64 v, IN SIZE_T n);
INLINE PVOID memcpy(OUT PVOID dst, IN PCVOID src, IN SIZE_T n);
INLINE PVOID memcpy(OUT PVOID dst, IN SIZE_T dst_len, IN PCVOID src, IN SIZE_T src_len);
INLINE PVOID memmov(INOUT PVOID dst, INOUT PCVOID src, IN SIZE_T n);
INLINE PVOID memmov(INOUT PVOID dst, IN SIZE_T dst_len, INOUT PCVOID src, IN SIZE_T src_len);
INLINE PVOID memchr(IN PCVOID s, IN CHAR c, IN SIZE_T n);
INLINE PVOID memcchr(IN PCVOID s, IN CHAR _c, IN SIZE_T n);
INLINE PVOID memmem(IN PCVOID l, IN SIZE_T l_len, IN PCVOID s, IN SIZE_T s_len);
INLINE INT memcmp(IN PCVOID s1, IN PCVOID s2, IN SIZE_T n);
ALWAYS_INLINE PVOID memset(OUT PVOID dst, IN UINT8 v, IN SIZE_T n) { return memset_8(dst, v, n); }
ALWAYS_INLINE PVOID memzero(OUT PVOID dst, IN SIZE_T n) { return memset(dst, 0, n); }
ALWAYS_INLINE PVOID memmove(INOUT PVOID dst, INOUT PCVOID src, IN SIZE_T n) { return memmov(dst, src, n); }
ALWAYS_INLINE PVOID memmove(INOUT PVOID dst, IN SIZE_T dst_len, INOUT PCVOID src, IN SIZE_T src_len) { return memmov(dst, dst_len, src, src_len); }
template<typename T>
VOID swap(INOUT T& l, INOUT T& r);
}

View File

@ -0,0 +1,46 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/types.hpp>
/*
* -----------------------------------
* IMPORTANT
* -----------------------------------
* This code is an initial DRAFT and
* has not yet been IA reviewed.
*
* Till this notice is removed from here,
* DO NOT USE this code in production.
*
* [IATODO]: [URGENT] [REVIEW]
*/
namespace ia
{
INLINE SIZE_T strlen(IN PCCHAR str);
INLINE INT strcmp(IN PCCHAR s1, IN PCCHAR s2);
INLINE INT strncmp(IN PCCHAR s1, IN PCCHAR s2, IN SIZE_T n);
INLINE PCHAR stpcpy(OUT PCHAR dst, IN PCCHAR src);
INLINE PCHAR strcpy(OUT PCHAR dst, IN PCCHAR src);
INLINE PCHAR strcat(INOUT PCHAR s1, IN PCCHAR s2);
INLINE PCHAR strcat(OUT PCHAR dst, IN PCCHAR s1, IN PCCHAR s2);
}

View File

@ -0,0 +1,48 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/math.interface.inl"
namespace ia
{
template<typename Tr, typename Tv>
Tr floor(IN Tv v)
{
return static_cast<Tr>(v);
}
template<typename Tr, typename Tv>
Tr ceil(IN Tv v)
{
Tr res = v;
if(v == (Tv)res) return res;
return res + 1;
}
template<typename Tr, typename Tv>
Tr round(IN Tv v)
{
return ((v - static_cast<Tr>(v)) >= 0.5) ? v + 1 : v;
}
template<typename T1, typename T2>
T1 min(IN T1 a, IN T2 b) { return (a > b) ? b : a; }
template<typename T1, typename T2>
T1 max(IN T1 a, IN T2 b) { return (a < b) ? b : a; }
}

View File

@ -0,0 +1,177 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/mem.interface.inl"
namespace ia
{
PVOID memset_8(OUT PVOID dst, IN UINT8 v, IN SIZE_T n)
{
/* Implementation is based on the code found in FreeBSD libk repository */
auto d = static_cast<PUINT8>(dst);
while(n--) *d++ = v;
return dst;
}
PVOID memset_16(OUT PVOID dst, IN UINT16 v, IN SIZE_T n)
{
auto d = static_cast<PUINT16>(dst);
while(n--) *d++ = v;
return dst;
}
PVOID memset_32(OUT PVOID dst, IN UINT32 v, IN SIZE_T n)
{
auto d = static_cast<PINT32>(dst);
while(n--) *d++ = v;
return dst;
}
PVOID memset_64(OUT PVOID dst, IN UINT64 v, IN SIZE_T n)
{
auto d = static_cast<PUINT64>(dst);
while(n--) *d++ = v;
return dst;
}
PVOID memcpy(OUT PVOID dst, IN PCVOID src, IN SIZE_T n)
{
auto s = static_cast<PCUINT8>(src);
auto d = static_cast<PUINT8>(dst);
while(n--) *d++ = *s++;
return dst;
}
PVOID memcpy(OUT PVOID dst, IN SIZE_T dst_len, IN PCVOID src, IN SIZE_T src_len)
{
auto n = (dst_len > src_len) ? src_len : dst_len;
auto s = static_cast<PCUINT8>(src);
auto d = static_cast<PUINT8>(dst);
while(n--) *d++ = *s++;
return dst;
}
PVOID memmov(INOUT PVOID dst, INOUT PCVOID src, IN SIZE_T n)
{
const auto t = new UINT8[n];
auto s = static_cast<PCUINT8>(src);
auto tn = n;
auto tt = t;
while(tn--) *tt++ = *s++;
auto d = static_cast<PUINT8>(dst);
tt = t;
while(n--) *d++ = *tt++;
delete[] t;
return dst;
}
PVOID memmov(INOUT PVOID dst, IN SIZE_T dst_len, INOUT PCVOID src, IN SIZE_T src_len)
{
auto n = (dst_len > src_len) ? src_len : dst_len;
const auto t = new UINT8[n];
auto s = static_cast<PCUINT8>(src);
auto tn = n;
auto tt = t;
while(tn--) *tt++ = *s++;
auto d = static_cast<PUINT8>(dst);
tt = t;
while(n--) *d++ = *tt++;
delete[] t;
return dst;
}
PVOID memchr(IN PCVOID s, IN CHAR c, IN SIZE_T n)
{
/* Implementation is based on the code found in FreeBSD libk repository */
if B_UNLIKELY(!n) return nullptr;
auto p = static_cast<PCCHAR>(s);
do {
if (*p++ == c)
return ((PVOID)(PUINT)(p - 1));
} while (--n != 0);
return nullptr; // IATODO: URGENT Fix
}
PVOID memcchr(IN PCVOID s, IN CHAR _c, IN SIZE_T n)
{
/* Implementation is based on the code found in FreeBSD libk repository */
if B_UNLIKELY(!n) return nullptr;
auto c = static_cast<UINT8>(_c);
auto w = static_cast<UINT64>(_c);
w |= w << 8; w |= w << 16; w |= w << 32;
auto lp = reinterpret_cast<PCUINT64>(
reinterpret_cast<UINT64>(s) & ~(sizeof(long) - 1));
auto p = static_cast<PCUINT8>(s);
const auto e = reinterpret_cast<PCUINT8>((UINT64)(s) + n);
#define TEST_BYTE if(*p != c) goto done; p++;
if(*lp++ != w) while(p < reinterpret_cast<PCUINT8>(lp)) { TEST_BYTE; }
while(reinterpret_cast<PCUINT8>(lp) < e)
{
if(*lp++ != w)
{
p = reinterpret_cast<PCUINT8>(lp);
TEST_BYTE;
TEST_BYTE;
TEST_BYTE;
TEST_BYTE;
TEST_BYTE;
TEST_BYTE;
TEST_BYTE;
goto done;
}
}
return nullptr;
#undef TEST_BYTE
done:
return (p < e) ? DECONST(PVOID, static_cast<PCVOID>(p)) : nullptr;
}
PVOID memmem(IN PCVOID l, IN SIZE_T l_len, IN PCVOID s, IN SIZE_T s_len)
{
/* Implementation is based on the code found in FreeBSD libk repository */
if B_UNLIKELY(l_len == 0 || s_len == 0 || l_len < s_len) return nullptr;
auto cs = static_cast<PCCHAR>(s);
if B_UNLIKELY(s_len == 1) return memchr(l, (int)*cs, l_len);
auto cl = static_cast<PCCHAR>(l);
auto last = DECONST(PCHAR, cl) + l_len - s_len;
for (auto cur = DECONST(PCHAR, cl); cur <= last; cur++)
if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
return cur;
return nullptr;
}
INT memcmp(IN PCVOID s1, IN PCVOID s2, IN SIZE_T n)
{
/* Implementation is based on the code found in FreeBSD libk repository */
if B_UNLIKELY(!n) return 0;
auto p1 = static_cast<PCUINT8>(s1), p2 = static_cast<PCUINT8>(s2);
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
return 0;
}
template<typename T>
VOID swap(INOUT T& l, INOUT T& r)
{
T t = r;
r = l;
l = t;
}
}

View File

@ -0,0 +1,85 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/str.interface.inl"
namespace ia
{
SIZE_T strlen(IN PCCHAR str)
{
PCCHAR s = str;
while(*s++);
return s - str - 1;
}
INT strcmp(IN PCCHAR s1, IN PCCHAR s2)
{
// [IATODO]: [URGENT] [OPTIMIZE]
const auto a = strlen(s1), b = strlen(s2);
return strncmp(s1, s2, (a > b) ? a : b);
}
INT strncmp(IN PCCHAR s1, IN PCCHAR s2, IN SIZE_T n)
{
// [IATODO]: [URGENT] [VERIFY]
const auto a = reinterpret_cast<const unsigned char*>(s1),
b = reinterpret_cast<const unsigned char*>(s2);
for(SIZE_T i = 0; i < n; i++)
{
const auto d = a[i] - b[i];
if(d) return d;
}
return 0;
}
PCHAR stpcpy(OUT PCHAR dst, IN PCCHAR src)
{
for(CHAR c = 0; (c = *src); src++)
{
*dst++ = c;
}
*dst = 0;
return dst;
}
PCHAR strcpy(OUT PCHAR dst, IN PCCHAR src)
{
const auto originalDst = dst;
for(CHAR c = 0; (c = *src); src++)
{
*dst++ = c;
}
*dst = 0;
return originalDst;
}
PCHAR strcat(INOUT PCHAR s1, IN PCCHAR s2)
{
// [IATODO]: [URGENT] [OPTIMIZE]
return strcat(s1, s1, s2);
}
PCHAR strcat(OUT PCHAR dst, IN PCCHAR s1, IN PCCHAR s2)
{
// [IATODO]: [URGENT] [OPTIMIZE]
const auto originalDst = dst;
dst = stpcpy(dst, s1);
dst = stpcpy(dst, s2);
return originalDst;
}
}

View File

@ -0,0 +1,31 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/entry.interface.inl"
namespace ia
{
template<typename _value_type>
ListEntry<_value_type>::ListEntry() {}
template<typename _value_type>
ListEntry<_value_type>::ListEntry(IN _value_type&& v): m_value(IA_MOVE(v)) {}
template<typename _value_type>
ListEntry<_value_type>::ListEntry(IN CONST _value_type& v): m_value(v) {}
}

View File

@ -0,0 +1,59 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/allocator.hpp>
namespace ia
{
// [IATODO: IMPL] (Allocator must be fore _value_type, not ListEntry<_value_type>)
template<typename _value_type>
class ListEntry;
template<typename _value_type, typename _allocator_type = GeneralAllocator<ListEntry<_value_type>>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, ListEntry<_value_type>>
class List;
template<typename _value_type>
class ListEntry
{
public:
ListEntry();
ListEntry(IN _value_type&& v);
ListEntry(IN CONST _value_type& v);
public:
operator _value_type&() { return m_value; }
operator _value_type*() { return &m_value; }
operator CONST _value_type&() CONST { return m_value; }
operator CONST _value_type*() CONST { return &m_value; }
_value_type& operator*() { return m_value; }
_value_type* operator->() { return &m_value; }
CONST _value_type& operator*() CONST { return m_value; }
CONST _value_type* operator->() CONST { return &m_value; }
private:
ListEntry* m_next {};
ListEntry* m_prev {};
_value_type m_value;
friend class List<_value_type>;
};
}

View File

@ -0,0 +1,114 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/allocator.hpp>
//#include "iterator.interface.inl"
#include "entry.interface.inl"
namespace ia
{
template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment>
requires valid_allocator_type<_allocator_type, ListEntry<_value_type>>
class List
{
public:
using size_type = SIZE_T;
using ssize_type = SSIZE_T;
using value_type = ListEntry<_value_type>;
using pointer_type = value_type*;
using reference_type = value_type&;
using allocator_type = _allocator_type;
using const_pointer_type = CONST value_type*;
using const_reference_type = CONST value_type&;
STATIC CONSTEXPR size_type alignment = _alignment;
public:
List();
List(IN List&& o);
List(IN CONST List& o);
~List();
VOID operator=(IN List&& o);
VOID operator=(IN CONST List& o);
public:
STATIC ListEntry<_value_type>* next(IN ListEntry<_value_type>* e) { return e->m_next; }
STATIC ListEntry<_value_type>* prev(IN ListEntry<_value_type>* e) { return e->m_prev; }
STATIC CONST ListEntry<_value_type>* next(IN CONST ListEntry<_value_type>* e) { return e->m_next; }
STATIC CONST ListEntry<_value_type>* prev(IN CONST ListEntry<_value_type>* e) { return e->m_prev; }
public:
BOOL erase(IN SIZE_T index);
pointer_type append(IN _value_type&& v);
pointer_type append(IN const_reference_type v);
pointer_type insert(IN SIZE_T index, IN _value_type&& v);
pointer_type insert(IN SIZE_T index, IN const_reference_type v);
public:
template<typename compare_type>
pointer_type find(IN CONST compare_type& v, IN size_type offset = 0);
template<typename compare_type>
pointer_type rfind(IN CONST compare_type& v, IN size_type offset = 0);
template<typename compare_type>
const_pointer_type cfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
template<typename compare_type>
const_pointer_type crfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
template<typename compare_type>
const_pointer_type find(IN CONST compare_type& v, IN size_type offset = 0) CONST { return cfind(v, offset); }
template<typename compare_type>
const_pointer_type rfind(IN CONST compare_type& v, IN size_type offset = 0) CONST { return crfind(v, offset); }
template<typename compare_type>
BOOL contains(IN CONST compare_type& v) CONST;
public:
size_type size() CONST { return m_count; }
pointer_type first() { return m_first; }
const_pointer_type first() CONST { return m_first; }
pointer_type last() { return m_last; }
const_pointer_type last() CONST { return m_last; }
allocator_type& allocator() { return m_allocator; }
VOID allocator(IN CONST allocator_type& v) { m_allocator = v; }
protected:
VIRTUAL VOID take_from(IN List&& r);
VIRTUAL VOID copy_from(IN CONST List& r);
private:
pointer_type getNodeByIndex(IN SIZE_T index) CONST;
pointer_type getNodeByReverseIndex(IN SIZE_T index) CONST;
protected:
size_type m_count {};
pointer_type m_first {};
pointer_type m_last {};
protected:
allocator_type m_allocator {};
};
}

View File

@ -0,0 +1,212 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "entry.inl"
#include "interface/list.interface.inl"
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, ListEntry<_value_type>>
#define __ia_identifier List<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(VOID, copy_from, IN CONST __ia_identifier& r)
{
m_allocator = r.m_allocator.selectOnContainerCopy();
m_count = r.m_count;
m_first = r.m_first;
m_last = r.m_last;
}
define_member_function(VOID, take_from, IN __ia_identifier&& r)
{
ia_swap(m_count, r.m_count);
ia_swap(m_first, r.m_first);
ia_swap(m_last, r.m_last);
ia_swap(m_allocator, r.m_allocator);
}
define_member_function(, List, )
{
m_count = 0;
}
define_member_function(, List, IN List&& o)
{
take_from(IA_MOVE(o));
}
define_member_function(, List, IN CONST List& o)
{
copy_from(o);
}
define_member_function(, ~List, )
{
auto current = m_first;
while(current)
{
const auto t = current->m_next;
dealloc<_alignment>(m_allocator, current);
current = t;
IA_ASSERT((current != m_last) || (!current || !current->m_next));
}
}
define_member_function(VOID, operator=, IN List&& o)
{
take_from(IA_MOVE(o));
}
define_member_function(VOID, operator=, IN CONST List& o)
{
copy_from(o);
}
}
namespace ia
{
define_member_function(BOOL, erase, IN SIZE_T index)
{
const auto t = getNodeByIndex(index);
if(!t) return false;
t->m_prev->m_next = t->m_next;
t->m_next->m_prev = t->m_prev;
dealloc<_alignment>(m_allocator, t);
m_count--;
return true;
}
define_member_function(__ia_identifier::pointer_type, append, IN _value_type&& v)
{
// [IATODO: IMP] (URGENT) MOCK
if(m_last)
{
const auto n = new (alloc<_alignment>(m_allocator, 1)) ListEntry<_value_type>(IA_MOVE(v));
m_last->m_next = n;
const auto t = m_last;
m_last = m_last->m_next;
m_last->m_prev = t;
return n;
}
else if(m_first)
{
m_last = new (alloc<_alignment>(m_allocator, 1)) ListEntry<_value_type>(IA_MOVE(v));
m_last->m_prev = m_first;
m_first->m_next = m_last;
return m_last;
}
else
{
m_first = new (alloc<_alignment>(m_allocator, 1)) ListEntry<_value_type>(IA_MOVE(v));
return m_first;
}
m_count++;
}
define_member_function(__ia_identifier::pointer_type, append, IN const_reference_type v)
{
return append(IA_MOVE(_value_type(v)));
}
define_member_function(__ia_identifier::pointer_type, insert, IN SIZE_T index, IN _value_type&& v)
{
const auto t = getNodeByIndex(index);
if(!t)
return append(IA_MOVE(v));
const auto n = new (alloc<_alignment>(m_allocator, 1)) ListEntry<_value_type>(IA_MOVE(v));
n->m_prev = t->m_prev;
n->m_next = t;
t->m_prev->m_next = n;
t->m_prev = n;
m_count++;
return n;
}
define_member_function(__ia_identifier::pointer_type, insert, IN SIZE_T index, IN const_reference_type v)
{
return insert(index, IA_MOVE(_value_type(v)));
}
}
namespace ia
{
define_member_function(template<typename compare_type> __ia_identifier::pointer_type, find, IN CONST compare_type& v, IN size_type offset)
{
for(auto it = getNodeByIndex(offset); it; it = it->m_next)
if(static_cast<_value_type>(*it) == v) return it;
return nullptr;
}
define_member_function(template<typename compare_type> __ia_identifier::pointer_type, rfind, IN CONST compare_type& v, IN size_type offset)
{
for(auto it = getNodeByReverseIndex(offset); it; it = it->m_prev)
if(static_cast<_value_type>(*it) == v) return it;
return nullptr;
}
define_const_member_function(template<typename compare_type> __ia_identifier::const_pointer_type, cfind, IN CONST compare_type& v, IN size_type offset)
{
for(auto it = getNodeByIndex(offset); it; it = it->m_next)
if(static_cast<_value_type>(*it) == v) return it;
return nullptr;
}
define_const_member_function(template<typename compare_type> __ia_identifier::const_pointer_type, crfind, IN CONST compare_type& v, IN size_type offset)
{
for(auto it = getNodeByReverseIndex(offset); it; it = it->m_prev)
if(static_cast<_value_type>(*it) == v) return it;
return nullptr;
}
define_const_member_function(template<typename compare_type> BOOL, contains, IN CONST compare_type& v)
{
for(auto it = m_first; it; it = it->m_next)
if(static_cast<_value_type>(*it) == v) return true;
return false;
}
}
namespace ia
{
define_const_member_function(__ia_identifier::pointer_type, getNodeByIndex, IN SIZE_T index)
{
SIZE_T i { 0 };
for(auto it = m_first; it; it = it->m_next, i++)
{
if(i == index) return it;
}
return nullptr;
}
define_const_member_function(__ia_identifier::pointer_type, getNodeByReverseIndex, IN SIZE_T index)
{
SIZE_T i { 0 };
for(auto it = m_last; it; it = it->m_prev, i++)
{
if(i == index) return it;
}
return nullptr;
}
}
#undef __template
#undef __ia_identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,86 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/list.hpp>
#include <iacore/vector.hpp>
#include <iacore/hashable.hpp>
namespace ia
{
template<typename _key_type, typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires hashable_type<_key_type> && valid_allocator_type<_allocator_type, _value_type>
class Map
{
STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000;
struct KeyValuePair { KeyValuePair() {} KeyValuePair(IN CONST _key_type& key, IN _value_type&& value): Key(key), Value(IA_MOVE(value)) {} _key_type Key; _value_type Value; };
public:
using size_type = SIZE_T;
using ssize_type = SSIZE_T;
using key_type = _key_type;
using value_type = _value_type;
using allocator_type = _allocator_type;
using iterator = Vector<ListEntry<KeyValuePair>*>::iterator;
using const_iterator = Vector<ListEntry<KeyValuePair>*>::const_iterator;
using reverse_iterator = Vector<ListEntry<KeyValuePair>*>::reverse_iterator;
using reverse_const_iterator = Vector<ListEntry<KeyValuePair>*>::reverse_const_iterator;
STATIC CONSTEXPR size_type alignment = _alignment;
public:
Map();
~Map();
public:
VOID set(IN CONST key_type& key, IN value_type&& value);
VOID set(IN CONST key_type& key, IN CONST value_type& value) { set(key, IA_MOVE(value_type(value))); }
CONST value_type* get(IN CONST key_type& key) CONST;
value_type* get(IN CONST key_type& key) { return const_cast<value_type*>(((CONST Map*)(this))->get(key)); }
BOOL contains(IN CONST key_type& key) CONST;
public:
_value_type& operator[](IN CONST _key_type& key) { const auto t = get(key); if(t) return *t; set(key, value_type()); return (*m_insertedOrder.back())->Value; }
CONST _value_type& operator[](IN CONST _key_type& key) CONST { const auto t = get(key); if(!t) throw "no such key"; return *t; }
public:
iterator begin() { return m_insertedOrder.begin(); }
iterator end() { return m_insertedOrder.end(); }
const_iterator begin() CONST { return m_insertedOrder.begin(); }
const_iterator end() CONST { return m_insertedOrder.end(); }
const_iterator cbegin() CONST { return m_insertedOrder.cbegin(); }
const_iterator cend() CONST { return m_insertedOrder.cend(); }
reverse_iterator rbegin() { return m_insertedOrder.rbegin(); }
reverse_iterator rend() { return m_insertedOrder.rend(); }
reverse_const_iterator rbegin() CONST { return m_insertedOrder.rbegin(); }
reverse_const_iterator rend() CONST { return m_insertedOrder.rend(); }
reverse_const_iterator crbegin() CONST { return m_insertedOrder.crbegin(); }
reverse_const_iterator crend() CONST { return m_insertedOrder.crend(); }
private:
ALWAYS_INLINE List<KeyValuePair>& getBucket(IN CONST key_type& key); // [IATODO: IMPL] Add a helper macro for const version function definition
ALWAYS_INLINE CONST List<KeyValuePair>& getBucket(IN CONST key_type& key) CONST;
private:
Vector<List<KeyValuePair>> m_buckets;
Vector<ListEntry<KeyValuePair>*> m_insertedOrder;
};
}

View File

@ -0,0 +1,84 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/map.interface.inl"
#define __template template<typename _key_type, typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires hashable_type<_key_type> && valid_allocator_type<_allocator_type, _value_type>
#define __ia_identifier Map<_key_type, _value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(, Map, )
{
m_buckets.resize(BUCKET_COUNT);
}
define_member_function(, ~Map, )
{
}
}
namespace ia
{
define_member_function(VOID, set, IN CONST key_type& key, IN value_type&& value)
{
m_insertedOrder.pushBack(getBucket(key).append({ key, IA_MOVE(value) }));
}
define_const_member_function(CONST _value_type*, get, IN CONST key_type& key)
{
auto& bucket = getBucket(key);
for(auto it = bucket.first(); it; it = bucket.next(it))
{
if(static_cast<KeyValuePair>(*it).Key == key)
return &(*it)->Value;
}
return nullptr;
}
define_const_member_function(BOOL, contains, IN CONST key_type& key)
{
auto& bucket = getBucket(key);
for(auto it = bucket.first(); it; it = bucket.next(it))
{
if(static_cast<KeyValuePair>(*it).Key == key)
return true;
}
return false;
}
}
namespace ia
{
define_member_function(List<typename __ia_identifier::KeyValuePair>&, getBucket, IN CONST key_type& key)
{
return m_buckets[key.hash() % BUCKET_COUNT];
}
define_const_member_function(CONST List<typename __ia_identifier::KeyValuePair>&, getBucket, IN CONST key_type& key)
{
return m_buckets[key.hash() % BUCKET_COUNT];
}
}
#undef __template
#undef __ia_identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,106 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iiallocator.inl"
#include "interface/general.interface.inl"
namespace ia
{
template<typename _value_type>
GeneralAllocator<_value_type>::pointer_type GeneralAllocator<_value_type>::allocate(IN SIZE_T count, IN PCVOID hint)
{
UNUSED(hint);
return reinterpret_cast<pointer_type>(_ia_malloc(sizeof(value_type) * count));
}
template<typename _value_type>
GeneralAllocator<_value_type>::result_type GeneralAllocator<_value_type>::allocateAtLeast(IN SIZE_T count, IN PCVOID hint)
{
UNUSED(hint);
return { count, allocate(count, hint) };
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::deallocate(IN pointer_type ptr)
{
_ia_free(ptr);
}
template<typename _value_type>
GeneralAllocator<_value_type>::pointer_type GeneralAllocator<_value_type>::allocateAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint)
{
UNUSED(hint);
const size_type size = (sizeof(value_type) * count);
const auto ptr = reinterpret_cast<size_type>(_ia_malloc(size + alignment + sizeof(PVOID)));
const auto aligned_ptr = reinterpret_cast<size_type>(ptr + sizeof(PVOID) + alignment - (ptr % alignment));
*(reinterpret_cast<size_type*>(aligned_ptr-sizeof(PVOID))) = ptr;
return reinterpret_cast<pointer_type>(aligned_ptr);
}
template<typename _value_type>
GeneralAllocator<_value_type>::result_type GeneralAllocator<_value_type>::allocateAtLeastAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint)
{
UNUSED(hint);
return { count, allocateAligned(count, alignment, hint) };
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::deallocateAligned(IN pointer_type ptr, IN SIZE_T alignment)
{
const auto allocated_ptr = *(reinterpret_cast<size_type*>(reinterpret_cast<size_type>(ptr) - sizeof(PVOID)));
_ia_free(reinterpret_cast<PVOID>(allocated_ptr));
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::construct(IN pointer_type ptr) CONST
{
new (ptr) value_type();
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::destruct(IN pointer_type ptr) CONST
{
ptr->~value_type();
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::construct(IN pointer_type ptr, IN size_type count) CONST
{
for(size_type i = 0; i < count; i++)
new (&ptr[i]) value_type();
}
template<typename _value_type>
VOID GeneralAllocator<_value_type>::destruct(IN pointer_type ptr, IN size_type count) CONST
{
for(size_type i = 0; i < count; i++)
ptr[i].~value_type();
}
template<typename _value_type>
GeneralAllocator<_value_type>::size_type GeneralAllocator<_value_type>::maxSize() noexcept
{
return SIZE_MAX;
}
template<typename _value_type>
GeneralAllocator<_value_type>::allocator_type GeneralAllocator<_value_type>::selectOnContainerCopy() CONST
{
return allocator_type();
}
}

View File

@ -0,0 +1,62 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/iiallocator.interface.inl"
namespace ia
{
template<typename allocator_type, typename value_type>
concept valid_allocator_type = std::derived_from<allocator_type, IIAllocator<allocator_type, value_type>>;
template<CONST SIZE_T alignment = 1, typename allocator_type>
requires valid_allocator_type<allocator_type, typename allocator_type::value_type>
allocator_type::pointer_type alloc(IN allocator_type& allocator,
IN typename allocator_type::size_type count, IN PCVOID hint = nullptr)
{
if constexpr(alignment > 1) return allocator.allocateAligned(count, alignment, hint);
else return allocator.allocate(count, hint);
}
template<CONST SIZE_T alignment = 1, typename allocator_type>
requires valid_allocator_type<allocator_type, typename allocator_type::value_type>
allocator_type::result_type allocAtLeast(IN allocator_type& allocator,
IN typename allocator_type::size_type count, IN PCVOID hint = nullptr)
{
if constexpr(alignment > 1) return allocator.allocateAtLeastAligned(count, alignment, hint);
else return allocator.allocateAtLeast(count, hint);
}
template<CONST SIZE_T alignment = 1, typename allocator_type>
requires valid_allocator_type<allocator_type, typename allocator_type::value_type>
VOID dealloc(IN allocator_type& allocator, IN typename allocator_type::pointer_type ptr)
{
if constexpr(alignment > 1) allocator.deallocateAligned(ptr, alignment);
else allocator.deallocate(ptr);
}
}
#undef malloc
#undef free
namespace ia
{
ALWAYS_INLINE PVOID _ia_malloc(IN SIZE_T size) { return std::malloc(size); }
ALWAYS_INLINE VOID _ia_free(IN PVOID ptr) { std::free(ptr); }
ALWAYS_INLINE PVOID malloc(IN SIZE_T size) { return _ia_malloc(size); }
ALWAYS_INLINE VOID free(IN PVOID ptr) { _ia_free(ptr); }
}

View File

@ -0,0 +1,55 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iiallocator.interface.inl"
namespace ia
{
template<typename _value_type>
class GeneralAllocator: public IIAllocator<GeneralAllocator<_value_type>, _value_type>
{
using Base = IIAllocator<GeneralAllocator<_value_type>, _value_type>;
public:
using size_type = Base::size_type;
using value_type = Base::value_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using result_type = Base::result_type;
public:
INLINE pointer_type allocate(IN SIZE_T count, IN PCVOID hint = nullptr);
INLINE pointer_type allocateAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint = nullptr);
INLINE result_type allocateAtLeast(IN SIZE_T count, IN PCVOID hint = nullptr);
INLINE result_type allocateAtLeastAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint = nullptr);
INLINE VOID deallocate(IN pointer_type ptr);
INLINE VOID deallocateAligned(IN pointer_type ptr, IN SIZE_T alignment);
INLINE VOID construct(IN pointer_type ptr) CONST;
INLINE VOID destruct(IN pointer_type ptr) CONST;
INLINE VOID construct(IN pointer_type ptr, IN size_type count) CONST;
INLINE VOID destruct(IN pointer_type ptr, IN size_type count) CONST;
INLINE size_type maxSize() noexcept;
INLINE allocator_type selectOnContainerCopy() CONST;
};
}

View File

@ -0,0 +1,66 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <memory.h>
#include <iacore/base.hpp>
namespace ia
{
template<typename _value_type>
struct AllocationResult
{
using size_type = SIZE_T;
using value_type = _value_type;
using pointer_type = _value_type*;
public:
size_type Count { 0 };
pointer_type Memory { nullptr };
};
template<typename _allocator_type, typename _value_type>
class IIAllocator
{
public:
using size_type = SIZE_T;
using value_type = _value_type;
using pointer_type = _value_type*;
using reference_type = _value_type&;
using allocator_type = _allocator_type;
using result_type = AllocationResult<_value_type>;
public:
VIRTUAL pointer_type allocate(IN SIZE_T count, IN PCVOID hint = nullptr) = 0;
VIRTUAL pointer_type allocateAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint = nullptr) = 0;
VIRTUAL result_type allocateAtLeast(IN SIZE_T count, IN PCVOID hint = nullptr) = 0;
VIRTUAL result_type allocateAtLeastAligned(IN SIZE_T count, IN SIZE_T alignment, IN PCVOID hint = nullptr) = 0;
VIRTUAL VOID deallocate(IN pointer_type ptr) = 0;
VIRTUAL VOID deallocateAligned(IN pointer_type ptr, IN SIZE_T alignment) = 0;
VIRTUAL VOID construct(IN pointer_type ptr) CONST = 0;
VIRTUAL VOID destruct(IN pointer_type ptr) CONST = 0;
VIRTUAL VOID construct(IN pointer_type ptr, IN size_type count) CONST = 0;
VIRTUAL VOID destruct(IN pointer_type ptr, IN size_type count) CONST = 0;
VIRTUAL size_type maxSize() noexcept = 0;
VIRTUAL allocator_type selectOnContainerCopy() CONST = 0;
};
}

View File

@ -0,0 +1,24 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
namespace ia
{
}

View File

@ -0,0 +1,24 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/orchestrator.interface.inl"
namespace ia
{
}

View File

@ -0,0 +1,29 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
#include <memory>
namespace ia
{
template<typename _value_type>
using RefPtr = std::shared_ptr<_value_type>;
template<typename _value_type, typename... Args>
INLINE RefPtr<_value_type> MakeRefPtr(Args... args) { return std::make_shared<_value_type>(args...); }
}

View File

@ -0,0 +1,55 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
namespace ia
{
class Platform
{
public:
enum class CPUFeature
{
SSE,
SSE2,
SSE3,
SSE4_1,
SSE4_2,
AVX,
AVX2
};
public:
INLINE STATIC CONSTEXPR PCCHAR name();
INLINE STATIC INT32 processorThreadCount();
INLINE STATIC SIZE_T totalAvailableMemory();
INLINE STATIC BOOL isSupported(IN CPUFeature feature);
public:
INLINE STATIC UINT32 random();
INLINE STATIC UINT64 timestamp();
INLINE STATIC VOID sleep(UINT64 milliseconds);
private:
Platform() {}
};
}

View File

@ -0,0 +1,135 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/platform.interface.inl"
#include <chrono>
#include <thread>
// Following platform identification code is based on the template found at https://stackoverflow.com/a/5920028
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#ifdef _WIN64
#define IA_PLATFORM_WIN64 1
#define IA_PLATFORM_WINDOWS 1
#else
#define IA_PLATFORM_WIN32 1
#define IA_PLATFORM_WINDOWS 1
#endif
#elif __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_MACCATALYST
#define IA_PLATFORM_IOS 1
#elif TARGET_OS_MAC
#define IA_PLATFORM_MAC 1
#endif
#define IA_PLATFORM_UNIX 1
#elif __ANDROID__
#define IA_PLATFORM_ANDROID 1
#define IA_PLATFORM_LINUX 1
#define IA_PLATFORM_UNIX 1
#elif __linux__
#define IA_PLATFORM_LINUX 1
#define IA_PLATFORM_UNIX 1
#elif __unix__
#define IA_PLATFORM_UNIX 1
#endif
#if IA_PLATFORM_WIN32 || IA_PLATFORM_WIN64
#include <windows.h>
#elif IA_PLATFORM_UNIX
#include <unistd.h>
#endif
namespace ia
{
CONSTEXPR PCCHAR Platform::name()
{
#if IA_PLATFORM_WIN64
return "win64";
#elif IA_PLATFORM_WIN32
return "win32";
#elif IA_PLATFORM_MAC
return "mac";
#elif IA_PLATFORM_IOS
return "ios";
#elif IA_PLATFORM_ANDROID
return "android";
#elif IA_PLATFORM_LINUX
return "linux";
#else
return "unknown";
#endif
}
INT32 Platform::processorThreadCount()
{
return static_cast<INT32>(std::thread::hardware_concurrency());
}
SIZE_T Platform::totalAvailableMemory()
{
// Based on the code found at https://stackoverflow.com/a/2513561
#if IA_PLATFORM_WIN32 || IA_PLATFORM_WIN64
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
return status.ullTotalPhys;
#elif IA_PLATFORM_UNIX
return sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
#else
return 0;
#endif
}
BOOL Platform::isSupported(IN CPUFeature feature)
{
// This implementation is based on the code found at https://gist.github.com/9prady9/a5e1e8bdbc9dc58b3349
UINT32 eax, ebx, ecx, edx;
if(feature == CPUFeature::AVX2)
{
ASM("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (7), "c" (0));
return ebx & 0x00000020;
}
ASM("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (1), "c" (0));
switch(feature)
{
case CPUFeature::SSE: return edx & 0x02000000;
case CPUFeature::SSE2: return edx & 0x04000000;
case CPUFeature::SSE3: return ecx & 0x00000001;
case CPUFeature::SSE4_1: return ecx & 0x00080000;
case CPUFeature::SSE4_2: return ecx & 0x00100000;
case CPUFeature::AVX: return ecx & 0x10000000;
default: return false;
}
}
UINT32 Platform::random()
{
return rand();
}
UINT64 Platform::timestamp()
{
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
VOID Platform::sleep(UINT64 milliseconds)
{
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
}

View File

@ -0,0 +1,73 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/vector.hpp>
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class Set: public OrderedVector<_value_type, _allocator_type, _alignment>
{
using Base = OrderedVector<_value_type, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
Set(): Base() {}
Set(IN Set&& r): Base(r) {}
Set(IN CONST Set& r): Base(r) {}
Set(IN initializer_list<value_type> v);
~Set() {}
VOID operator=(IN CONST Set& r) { Base::copy_from(r); }
VOID operator=(IN Set&& r) { Base::take_from(IA_MOVE(r)); }
public:
VOID append(IN value_type&& v);
VOID append(IN const_reference_type v);
VOID append(IN size_type n, IN const_pointer_type v);
VOID append(IN initializer_list<value_type> v);
template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
VOID append(IN iterator_type first, IN iterator_type last);
public:
VOID pushBack(IN value_type&& v) { append(v); }
VOID pushBack(IN const_reference_type v) { append(v); }
public:
VOID resort() = delete;
VOID append(IN size_type n, IN const_reference_type v) = delete;
Base slice(IN size_type start, IN size_type count, IN size_type stride = 1) CONST = delete;
Base slice(IN const_iterator first, IN const_iterator last, IN size_type stride = 1) CONST = delete;
};
}

View File

@ -0,0 +1,66 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/set.interface.inl"
#define __template_iterator template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, _value_type>
#define __identifier Set<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(, Set, IN initializer_list<value_type> v)
{
for(auto it = v.begin(); it != v.end(); it++) append(*it); // [IATODO]: [OPTIMIZE-P3]
}
define_member_function(VOID, append, IN value_type&& v)
{
if(Base::contains(v)) return;
Base::append(IA_MOVE(v));
}
define_member_function(VOID, append, IN const_reference_type v)
{
if(Base::contains(v)) return;
Base::append(v);
}
define_member_function(VOID, append, IN size_type n, IN const_pointer_type v)
{
for(size_type i = 0; i < n; i++) append(v[i]); // [IATODO]: [OPTIMIZE-P3]
}
define_member_function(VOID, append, IN initializer_list<value_type> v)
{
for(auto it = v.begin(); it != v.end(); it++) append(*it); // [IATODO]: [OPTIMIZE-P3]
}
define_member_function(__template_iterator VOID, append, IN iterator_type first, IN iterator_type last)
{
for(auto it = first; it != last; it++) append(*it); // [IATODO]: [OPTIMIZE-P3]
}
}
#undef __template_iterator
#undef __template
#undef __identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,24 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/filestream.interface.inl"
namespace ia
{
}

View File

@ -0,0 +1,55 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iistream.interface.inl"
#include <fstream>
namespace ia
{
// NOTE: THIS IS A MOCK IMPLEMENTATION
// [IATODO: IMPL] [URGENT] (Mock)
// [IATODO: IMPL] FileReadStream
class FileWriteStream: public IIStream
{
public:
FileWriteStream() {}
FileWriteStream(IN CONST String& filePath) { open(filePath); }
~FileWriteStream() { if(isOpen()) close(); }
public:
VOID open(IN CONST String& filePath) { m_impl.open(filePath.c_str(), std::ios::out | std::ios::binary); }
VOID close() { m_impl.close(); }
BOOL isOpen() CONST { return m_impl.is_open(); }
public:
template<typename _value_type>
FileWriteStream& operator<<(IN CONST _value_type& v) { m_impl << v; return *this; }
FileWriteStream& operator<<(IN CONST String& v) { m_impl << v.c_str(); return *this; }
public:
operator BOOL() CONST { return m_impl.is_open(); }
private:
std::ofstream m_impl;
};
}

View File

@ -0,0 +1,28 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "../../string/string.inl"
namespace ia
{
class IIStream
{
public:
};
}

View File

@ -0,0 +1,44 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iistream.interface.inl"
#include <sstream>
namespace ia
{
// NOTE: THIS IS A MOCK IMPLEMENTATION
// [IATODO: IMPL] [URGENT] (Mock)
class StringStream: public IIStream
{
public:
StringStream() {}
public:
INLINE String str() CONST;
public:
template<typename _value_type>
StringStream& operator<<(IN CONST _value_type& v) { m_impl << v; return *this; }
StringStream& operator<<(IN CONST String& v) { m_impl << v.c_str(); return *this; }
private:
std::stringstream m_impl;
};
}

View File

@ -0,0 +1,27 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/stringstream.interface.inl"
namespace ia
{
String StringStream::str() CONST
{
return m_impl.str().c_str();
}
}

View File

@ -0,0 +1,184 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/container.hpp>
namespace ia
{
template<typename _allocator_type = GeneralAllocator<CHAR>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, CHAR>
class StringT : public FixedContainer<CHAR, _allocator_type, _alignment>
{
using Base = FixedContainer<CHAR, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using char_type = Base::value_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
INLINE StringT();
INLINE StringT(IN size_type count);
INLINE StringT(IN const_pointer_type str);
INLINE StringT(IN size_type n, IN char_type v);
StringT(IN StringT &&r)
{
take_from(IA_MOVE(r));
}
StringT(IN CONST StringT &r)
{
copy_from(r);
}
~StringT()
{
}
VOID operator=(IN StringT &&r)
{
take_from(IA_MOVE(r));
}
VOID operator=(IN CONST StringT &r)
{
copy_from(r);
}
public:
INLINE VOID append(IN char_type v);
INLINE VOID append(IN const_pointer_type v);
INLINE VOID append(IN CONST StringT &v);
INLINE VOID append(IN size_type n, IN char_type v);
template<typename iterator_type>
requires valid_forward_iterator_type<iterator_type>
VOID append(IN iterator_type first, IN iterator_type last);
INLINE iterator insert(IN const_iterator p, IN char_type v);
INLINE iterator insert(IN const_iterator p, IN const_pointer_type v);
INLINE iterator insert(IN const_iterator p, IN CONST StringT &v);
INLINE iterator insert(IN const_iterator p, IN size_type n, IN char_type v);
template<typename iterator_type>
requires valid_forward_iterator_type<iterator_type>
iterator insert(IN const_iterator p, IN iterator_type first, IN iterator_type last);
INLINE iterator erase(IN const_iterator p, IN size_type n = 1);
INLINE iterator erase(IN const_iterator first, IN const_iterator last);
INLINE StringT slice(IN size_type start, IN size_type end, IN size_type stride = 1) CONST;
INLINE StringT slice(IN const_iterator first, IN const_iterator last, IN size_type stride = 1) CONST;
public:
VOID operator+=(IN char_type v)
{
append(v);
}
VOID operator+=(IN const_pointer_type v)
{
append(v);
}
VOID operator+=(IN CONST StringT &o)
{
append(o);
}
VOID pushBack(IN char_type v)
{
append(v);
}
char_type popBack()
{
if (Base::m_count <= 1)
{
Base::m_data[0] = '\0';
return '\0';
}
const auto t = Base::m_data[--Base::m_count - 1];
Base::m_data[Base::m_count - 1] = '\0';
return t;
}
INLINE BOOL operator==(IN CONST StringT &o) CONST;
public:
INLINE VOID clear();
INLINE VOID reset();
INLINE BOOL resize(IN size_type newCount);
INLINE BOOL reserve(IN size_type newCapacity);
public:
BOOL empty() CONST
{
return Base::m_count <= 1;
}
size_type length() CONST
{
return Base::m_count - 1;
}
size_type capacity() CONST
{
return m_capacity;
}
size_type size() CONST
{
return length();
}
const_pointer_type c_str() CONST
{
return Base::m_data;
}
protected:
INLINE VOID shrink();
INLINE BOOL grow(IN size_type size);
INLINE BOOL grow(IN size_type size, OUT pointer_type *oldData);
INLINE BOOL resize(IN size_type newCount, OUT pointer_type *oldData);
INLINE BOOL reserve(IN size_type newCapacity, OUT pointer_type *oldData);
protected:
INLINE VOID take_from(IN StringT &&r);
INLINE VOID copy_from(IN CONST StringT &r);
protected:
size_type m_capacity{0};
};
using String = StringT<>;
} // namespace ia

View File

@ -0,0 +1,362 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/string.interface.inl"
#define __template_iterator template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
#define __template template<typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, CHAR>
#define __ia__identifier StringT<_allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia__identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(, StringT,):
Base(1)
{
Base::back() = '\0';
m_capacity = Base::m_count;
}
define_member_function(, StringT, IN size_type count):
Base(count + 1)
{
Base::back() = '\0';
m_capacity = Base::m_count;
}
define_member_function(, StringT, IN const_pointer_type str):
Base(ia_strlen(str) + 1)
{
ia_memcpy(Base::data(), str, Base::m_count * sizeof(value_type));
m_capacity = Base::m_count;
}
define_member_function(, StringT, IN size_type n, IN char_type v):
Base(n + 1)
{
ia_memset(Base::data(), v, n);
Base::back() = '\0';
m_capacity = Base::m_count;
}
define_member_function(VOID, take_from, IN StringT&& r)
{
ia_swap(Base::m_data, r.m_data);
ia_swap(Base::m_count, r.m_count);
ia_swap(Base::m_allocator, r.m_allocator);
ia_swap(m_capacity, r.m_capacity);
}
define_member_function(VOID, copy_from, IN CONST StringT& r)
{
Base::m_allocator = r.m_allocator.selectOnContainerCopy();
reserve(r.capacity());
for(Base::m_count = 0; Base::m_count < r.m_count; Base::m_count++)
new (&Base::m_data[Base::m_count]) value_type(r.m_data[Base::m_count]);
}
define_const_member_function(BOOL, operator==, IN CONST StringT& o)
{
// [IATODO: OPT]: (Optimize)
if(length() != o.length()) return false;
auto d1 = Base::m_data;
auto d2 = o.m_data;
while(true)
{
const auto c1 = *d1++; if(!c1) break;
const auto c2 = *d2++; if(!c2) break;
if(c1 != c2) return false;
}
return true;
}
}
namespace ia
{
define_member_function(VOID, append, IN char_type v)
{
grow(1);
Base::m_data[Base::m_count - 1] = v;
Base::m_data[Base::m_count++] = '\0';
}
define_member_function(VOID, append, IN const_pointer_type v)
{
const auto s = ia_strlen(v);
grow(s);
ia_memcpy(&Base::m_data[Base::m_count - 1], v, s + 1);
Base::m_count += s;
}
define_member_function(VOID, append, IN CONST StringT& v)
{
// [IATODO: OPT]: (Optimize)
append(v.m_data);
}
define_member_function(VOID, append, IN size_type n, IN char_type v)
{
grow(n);
ia_memset(&Base::m_data[Base::m_count - 1], v, n);
Base::m_count += n;
Base::back() = '\0';
}
define_member_function(__template_iterator VOID, append, IN iterator_type first, IN iterator_type last)
{
grow(last - first);
Base::m_count--;
for(auto it = first; it != last; it++) Base::m_data[Base::m_count++] = *it;
Base::back() = '\0';
}
}
namespace ia
{
#define put_element(start, element) new (&Base::m_data[start]) value_type(element);
#define move_element(start, element) new (&Base::m_data[start]) value_type(IA_MOVE(element));
#define move_elements(start, data, count) for(size_type i = 0; i < count; i++) new (&Base::m_data[start + i]) value_type(IA_MOVE((data)[i]));
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN char_type v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= (Base::m_count - 1));
pointer_type oldData {};
if(grow(1, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + 1, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + 1, Base::m_data[i]);
}
move_element(insert_at, v);
Base::m_data[Base::m_count++] = '\0';
return { Base::m_data + insert_at + 1 };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN const_pointer_type v)
{
const auto n = ia_strlen(v);
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= (Base::m_count - 1));
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
for(size_type i = 0; i < n; i++) put_element(insert_at + i, v[i]);
Base::m_count += n;
Base::back() = '\0';
return { Base::m_data + insert_at + n };
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN CONST StringT& v)
{
insert(p, v.m_data);
}
define_member_function(__ia__identifier::iterator, insert, IN const_iterator p, IN size_type n, IN char_type v)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= (Base::m_count - 1));
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
for(size_type i = 0; i < n; i++) put_element(insert_at + i, v);
Base::m_count += n;
Base::back() = '\0';
return { Base::m_data + insert_at + n };
}
define_member_function(__template_iterator __ia__identifier::iterator, insert, IN const_iterator p, IN iterator_type first, IN iterator_type last)
{
const auto insert_at = p - Base::cbegin();
IA_ASSERT(insert_at <= (Base::m_count - 1));
const auto n = last - first;
pointer_type oldData {};
if(grow(n, &oldData))
{
move_elements(0, oldData, insert_at);
move_elements(insert_at + n, &oldData[insert_at], Base::m_count - insert_at);
dealloc<_alignment>(Base::m_allocator, oldData);
}
else
{
for(ssize_type i = Base::m_count - 1; i >= insert_at; i--)
move_element(i + n, Base::m_data[i]);
}
ssize_type i { insert_at };
for(auto it = first; it != last; it++, i++) put_element(i, *it);
Base::m_count += n;
Base::back() = '\0';
return { Base::m_data + insert_at + n };
}
#undef put_element
#undef move_element
#undef move_elements
}
namespace ia
{
define_member_function(__ia__identifier::iterator, erase, IN const_iterator p, IN size_type n)
{
const auto erase_at = p - Base::cbegin();
IA_ASSERT((erase_at + n) <= (Base::m_count - 1));
for(size_type i = 0; i < n; i++) Base::m_data[erase_at + i].~value_type();
for(size_type i = erase_at + n; i < Base::m_count; i++) move_element(i - n, Base::m_data[i]);
Base::m_count -= n;
shrink();
return { Base::m_data + erase_at + n };
}
define_member_function(__ia__identifier::iterator, erase, IN const_iterator first, IN const_iterator last)
{
const auto n = last - first;
const auto erase_at = first - Base::cbegin();
IA_ASSERT((erase_at + n) <= (Base::m_count - 1));
for(size_type i = 0; i < n; i++) Base::m_data[erase_at + i].~value_type();
for(size_type i = erase_at + n; i < Base::m_count; i++) move_element(i - n, Base::m_data[i]);
Base::m_count -= n;
shrink();
return { Base::m_data + erase_at + n };
}
define_const_member_function(__ia__identifier, slice, IN size_type start, IN size_type end, IN size_type stride)
{
__ia__identifier res;
res.m_count = 0;
res.reserve(((end - start)/stride) + 2);
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
res.back() = '\0';
return IA_MOVE(res);
}
define_const_member_function(__ia__identifier, slice, IN const_iterator first, IN const_iterator last, IN size_type stride)
{
__ia__identifier res;
res.m_count = 0;
const auto start = first - Base::cbegin();
const auto count = last - first;
res.reserve((count/stride) + 2);
const auto end = start + count + 1;
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
res.back() = '\0';
return IA_MOVE(res);
}
}
namespace ia
{
define_member_function(VOID, clear,)
{
if(Base::m_data) Base::m_allocator.destruct(Base::m_data, Base::m_count);
Base::m_count = 0;
}
define_member_function(VOID, reset,)
{
Base::reset();
m_capacity = 0;
resize(1);
Base::m_data[0] = '\0';
}
define_member_function(BOOL, resize, IN size_type newCount)
{
const auto did_reallocate = reserve(newCount);
for(; Base::m_count < newCount; Base::m_count++) Base::m_data[Base::m_count] = 0;
return did_reallocate;
}
define_member_function(BOOL, reserve, IN size_type newCapacity)
{
const auto oldData = Base::m_data;
if(newCapacity <= m_capacity) return false;
Base::m_data = alloc<_alignment>(Base::m_allocator, newCapacity);
m_capacity = newCapacity;
if(!oldData) return true;
ia_memcpy(Base::m_data, oldData, Base::m_count * sizeof(value_type));
dealloc<_alignment>(Base::m_allocator, oldData);
return true;
}
}
namespace ia
{
define_member_function(VOID, shrink,)
{
// [IATODO: IMPL]: [URGENT]
throw "NOT IMPLEMENTED";
}
define_member_function(BOOL, grow, IN size_type size)
{
// [IATODO: OPT]: [URGENT] Proper grow using reallocation counts
return reserve(Base::m_count + size);
}
define_member_function(BOOL, grow, IN size_type size, OUT pointer_type* oldData)
{
// [IATODO: OPT]: [URGENT] Proper grow using reallocation counts
return reserve(Base::m_count + size, oldData);
}
define_member_function(BOOL, resize, IN size_type newCount, OUT pointer_type* oldData)
{
const auto did_reallocate = reserve(newCount, oldData);
Base::m_count = newCount;
return did_reallocate;
}
define_member_function(BOOL, reserve, IN size_type newCapacity, OUT pointer_type* oldData)
{
*oldData = Base::m_data;
if(newCapacity <= m_capacity) return false;
Base::m_data = alloc<_alignment>(Base::m_allocator, newCapacity);
m_capacity = newCapacity;
return true;
}
}
#undef __template_iterator
#undef __template
#undef __ia__identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,111 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "unordered.interface.inl"
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class OrderedVector: public DynamicContainer<_value_type, _allocator_type, _alignment>
{
using Base = DynamicContainer<_value_type, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
OrderedVector(): Base() {}
OrderedVector(IN size_type count): Base(count) {}
OrderedVector(IN initializer_list<value_type> v): Base(v) { resort(); }
OrderedVector(IN OrderedVector&& r): Base(r) {}
OrderedVector(IN CONST OrderedVector& r): Base(r) {}
OrderedVector(IN CONST UnorderedVector<_value_type, _allocator_type, _alignment>& r): Base(r) { resort(); }
~OrderedVector() {}
VOID operator=(IN CONST OrderedVector& r) { Base::copy_from(r); }
VOID operator=(IN OrderedVector&& r) { Base::take_from(IA_MOVE(r)); }
public:
VOID append(IN value_type&& v);
VOID append(IN const_reference_type v);
VOID append(IN size_type n, IN const_reference_type v);
VOID append(IN size_type n, IN const_pointer_type v);
VOID append(IN initializer_list<value_type> v);
template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
VOID append(IN iterator_type first, IN iterator_type last);
OrderedVector slice(IN size_type start, IN size_type end, IN size_type stride = 1) CONST;
OrderedVector slice(IN const_iterator first, IN const_iterator last, IN size_type stride = 1) CONST;
VOID resort();
public:
template<typename compare_type>
const_iterator cfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
const_iterator cfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type>
const_iterator crfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
const_iterator crfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type>
BOOL contains(IN CONST compare_type& v) CONST;
BOOL contains(IN CONST comparator_type c) CONST;
template<typename compare_type>
iterator find(IN CONST compare_type& v, IN size_type offset = 0) { return cfind(v, offset); }
iterator find(IN comparator_type c, IN size_type offset = 0) { return cfind(c, offset); }
template<typename compare_type>
iterator rfind(IN CONST compare_type& v, IN size_type offset = 0) { return crfind(v, offset); }
iterator rfind(IN comparator_type c, IN size_type offset = 0) { return crfind(c, offset); }
template<typename compare_type>
const_iterator find(IN CONST compare_type& v, IN size_type offset = 0) CONST { return cfind(v, offset); }
const_iterator find(IN comparator_type c, IN size_type offset = 0) CONST { return cfind(c, offset); }
template<typename compare_type>
const_iterator rfind(IN CONST compare_type& v, IN size_type offset = 0) CONST { return crfind(v, offset); }
const_iterator rfind(IN comparator_type c, IN size_type offset = 0) CONST { return crfind(c, offset); }
public:
VOID pushBack(IN value_type&& v) { append(v); }
VOID pushBack(IN const_reference_type v) { append(v); }
value_type popBack() { IA_ASSERT(Base::m_count > 0); return IA_MOVE(Base::m_data[--Base::m_count]); }
public:
iterator insert(IN const_iterator p, IN value_type&& v) = delete;
iterator insert(IN const_iterator p, IN const_reference_type v) = delete;
iterator insert(IN const_iterator p, IN size_type n, IN const_reference_type v) = delete;
iterator insert(IN const_iterator p, IN size_type n, IN const_pointer_type v) = delete;
iterator insert(IN const_iterator p, IN initializer_list<value_type> v) = delete;
template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
iterator insert(IN const_iterator p, IN iterator_type first, IN iterator_type last) = delete;
};
}

View File

@ -0,0 +1,65 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/container.hpp>
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
class UnorderedVector: public DynamicContainer<_value_type, _allocator_type, _alignment>
{
using Base = DynamicContainer<_value_type, _allocator_type, _alignment>;
public:
using size_type = Base::size_type;
using ssize_type = Base::ssize_type;
using value_type = Base::value_type;
using buffer_type = Base::buffer_type;
using pointer_type = Base::pointer_type;
using reference_type = Base::reference_type;
using allocator_type = Base::allocator_type;
using const_pointer_type = Base::const_pointer_type;
using const_reference_type = Base::const_reference_type;
using iterator = Base::iterator;
using const_iterator = Base::const_iterator;
using reverse_iterator = Base::reverse_iterator;
using reverse_const_iterator = Base::reverse_const_iterator;
using comparator_type = Base::comparator_type;
public:
UnorderedVector(): Base() {}
UnorderedVector(IN size_type count): Base(count) {}
UnorderedVector(IN initializer_list<value_type> v): Base(v) {}
UnorderedVector(IN UnorderedVector&& r): Base(r) {}
UnorderedVector(IN CONST UnorderedVector& r): Base(r) {}
~UnorderedVector() {}
VOID operator=(IN CONST UnorderedVector& r) { Base::copy_from(r); }
VOID operator=(IN UnorderedVector&& r) { Base::take_from(IA_MOVE(r)); }
public:
UnorderedVector slice(IN size_type start, IN size_type end, IN size_type stride = 1) CONST;
UnorderedVector slice(IN const_iterator first, IN const_iterator last, IN size_type stride = 1) CONST;
public:
VOID pushBack(IN value_type&& v) { Base::append(v); }
VOID pushBack(IN const_reference_type v) { Base::append(v); }
value_type popBack() { IA_ASSERT(Base::m_count > 0); return IA_MOVE(Base::m_data[--Base::m_count]); }
};
}

View File

@ -0,0 +1,136 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/algorithm.hpp>
#include "interface/ordered.interface.inl"
#define __template_iterator template<typename iterator_type> requires valid_forward_iterator_type<iterator_type>
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, _value_type>
#define __ia_identifier OrderedVector<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_member_function(VOID, append, IN value_type&& v)
{
Base::insert(BinarySearchLeft(Base::cbegin(), Base::cend(), v), IA_MOVE(v));
}
define_member_function(VOID, append, IN const_reference_type v)
{
Base::insert(BinarySearchLeft(Base::cbegin(), Base::cend(), v), v);
}
define_member_function(VOID, append, IN size_type n, IN const_reference_type v)
{
const auto t = BinarySearchLeft(Base::cbegin(), Base::cend(), v);
Base::insert(t, n, v);
}
define_member_function(VOID, append, IN size_type n, IN const_pointer_type v)
{
for(size_type i = 0; i < n; i++)
{
const auto val = v[i];
Base::insert(BinarySearchLeft(Base::cbegin(), Base::cend(), val), val);
}
}
define_member_function(VOID, append, IN initializer_list<value_type> v)
{
for(auto it = v.begin(); it != v.end(); it++)
Base::insert(BinarySearchLeft(Base::cbegin(), Base::cend(), *it), *it);
}
define_member_function(__template_iterator VOID, append, IN iterator_type first, IN iterator_type last)
{
for(auto it = first; it != last; it++)
Base::insert(BinarySearchLeft(Base::cbegin(), Base::cend(), *it), *it);
}
define_member_function(VOID, resort,)
{
QuickSort(Base::begin(), Base::end());
}
define_const_member_function(__ia_identifier, slice, IN size_type start, IN size_type end, IN size_type stride)
{
__ia_identifier res;
res.reserve(((end - start)/stride) + 1);
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
return IA_MOVE(res);
}
define_const_member_function(__ia_identifier, slice, IN const_iterator first, IN const_iterator last, IN size_type stride)
{
__ia_identifier res;
const auto start = first - Base::cbegin();
const auto count = last - first;
res.reserve((count/stride) + 1);
const auto end = start + count;
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
return IA_MOVE(res);
}
define_const_member_function(__ia_identifier::const_iterator, cfind, IN comparator_type c, IN size_type offset)
{
// [IATODO: IMPL]
throw "NOT IMPLEMENTED";
return Base::cend();
}
define_const_member_function(template<typename compare_type> __ia_identifier::const_iterator, cfind, IN CONST compare_type& v, IN size_type offset)
{
const auto t = BinarySearchLeft(Base::cbegin() + offset, Base::cend(), v);
return ((t != Base::cend()) && (*t == v)) ? t : Base::cend();
}
define_const_member_function(__ia_identifier::const_iterator, crfind, IN comparator_type c, IN size_type offset)
{
// [IATODO: IMPL]
throw "NOT IMPLEMENTED";
return Base::cend();
}
define_const_member_function(template<typename compare_type> __ia_identifier::const_iterator, crfind, IN CONST compare_type& v, IN size_type offset)
{
const auto t = BinarySearchRight(Base::cbegin(), Base::cend() - offset, v);
return ((t != Base::cend()) && (*t == v)) ? t : Base::cend();
}
define_const_member_function(BOOL, contains, IN comparator_type c)
{
// [IATODO: IMPL]
throw "NOT IMPLEMENTED";
return Base::cend();
}
define_const_member_function(template<typename compare_type> BOOL, contains, IN CONST compare_type& v)
{
const auto t = BinarySearchLeft(Base::cbegin(), Base::cend(), v);
return (t != Base::cend()) && (*t == v);
}
}
#undef __template_iterator
#undef __template
#undef __ia_identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,51 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/unordered.interface.inl"
#define __template template<typename _value_type, typename _allocator_type, CONST SIZE_T _alignment> requires valid_allocator_type<_allocator_type, _value_type>
#define __ia_identifier UnorderedVector<_value_type, _allocator_type, _alignment>
#define define_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__)
#define define_const_member_function(return_type, name, ...) __template return_type __ia_identifier::name(__VA_ARGS__) CONST
namespace ia
{
define_const_member_function(__ia_identifier, slice, IN size_type start, IN size_type end, IN size_type stride)
{
__ia_identifier res;
res.reserve(((end - start)/stride) + 1);
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
return IA_MOVE(res);
}
define_const_member_function(__ia_identifier, slice, IN const_iterator first, IN const_iterator last, IN size_type stride)
{
__ia_identifier res;
const auto start = first - Base::cbegin();
const auto count = last - first;
res.reserve((count/stride) + 1);
const auto end = start + count;
for(size_type i = start; i < end; i += stride) new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
return IA_MOVE(res);
}
}
#undef __template
#undef __ia_identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -0,0 +1,24 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/base.hpp>
namespace ia
{
// [IATODO: IMP]
}

View File

@ -0,0 +1,24 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "interface/xop.interface.inl"
namespace ia
{
// [IATODO: IMP]
}

View File

@ -0,0 +1,22 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/algorithm/binary-search.inl"
#include "iacore/algorithm/quick-sort.inl"
namespace ia {}

View File

@ -0,0 +1,22 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/memory/allocator/general.inl"
#include "iacore/memory/allocator/orchestrator.inl"
namespace ia {}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/array/array.inl"
namespace ia {}

View File

@ -0,0 +1,59 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#if __STDC_HOSTED__ and !IACORE_FREESTANDING
#include <iacore/types.hpp>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#define _lib_impl_ std
#else
#include "iacore/lib.hpp"
#define _lib_impl_ ia
#endif
#undef min
#undef max
#define ia_min(...) _lib_impl_::min(__VA_ARGS__)
#define ia_max(...) _lib_impl_::max(__VA_ARGS__)
#define ia_free(...) _lib_impl_::free(__VA_ARGS__)
#define ia_swap(...) _lib_impl_::swap(__VA_ARGS__)
#define ia_malloc(...) _lib_impl_::malloc(__VA_ARGS__)
#define ia_ceil(...) _lib_impl_::ceil(__VA_ARGS__)
#define ia_round(...) _lib_impl_::round(__VA_ARGS__)
#define ia_floor(...) _lib_impl_::floor(__VA_ARGS__)
#define ia_memset(...) _lib_impl_::memset(__VA_ARGS__)
#define ia_memcpy(...) _lib_impl_::memcpy(__VA_ARGS__)
#define ia_memmov(...) _lib_impl_::memmove(__VA_ARGS__)
#define ia_memcmp(...) _lib_impl_::memcmp(__VA_ARGS__)
#define ia_memmem(...) _lib_impl_::memmem(__VA_ARGS__)
#define ia_memchr(...) _lib_impl_::memchr(__VA_ARGS__)
#define ia_memcchr(...) _lib_impl_::memcchr(__VA_ARGS__)
#define ia_strlen(...) _lib_impl_::strlen(__VA_ARGS__)
#define ia_strcmp(...) _lib_impl_::strcmp(__VA_ARGS__)
#define ia_strncmp(...) _lib_impl_::strncmp(__VA_ARGS__)
#define ia_stpcpy(...) _lib_impl_::stpcpy(__VA_ARGS__)
#define ia_strcpy(...) _lib_impl_::strcpy(__VA_ARGS__)
#define ia_strcat(...) _lib_impl_::strcat(__VA_ARGS__)
namespace ia {}

View File

@ -0,0 +1,119 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/file.hpp"
namespace ia
{
class ByteStream
{
public:
ByteStream(IN CONST String& filePath)
{
File f(filePath, File::OPEN_FLAG_READ | File::OPEN_FLAG_BINARY);
const auto buffer = new UINT8[f.Size()];
f.Read(buffer, f.Size(), f.Size());
m_buffer = buffer;
m_bufferSize = f.Size();
m_cursor = 0;
m_isBufferOwner = true;
}
ByteStream(IN PCUINT8 buffer, IN SIZE_T bufferSize)
{
m_buffer = buffer;
m_bufferSize = bufferSize;
m_cursor = 0;
m_isBufferOwner = false;
}
~ByteStream()
{
if(m_isBufferOwner && m_buffer)
delete[] m_buffer;
}
public:
VOID Read(OUT PUINT8 buffer)
{
ia_memcpy(buffer, &m_buffer[m_cursor], Remaining());
m_cursor = m_bufferSize;
}
VOID Read(IN SIZE_T count, OUT PUINT8 buffer)
{
EnsureAvailable(count);
ia_memcpy(buffer, &m_buffer[m_cursor], count);
m_cursor += count;
}
UINT8 ReadUInt8()
{
EnsureAvailable(1);
return m_buffer[m_cursor++];
}
UINT16 ReadUInt16()
{
EnsureAvailable(2);
const auto t = m_buffer[m_cursor++];
return (static_cast<UINT64>(m_buffer[m_cursor++]) << 8) | t;
}
UINT32 ReadUInt32()
{
EnsureAvailable(4);
const auto t0 = m_buffer[m_cursor++];
const auto t1 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t2 = static_cast<UINT64>(m_buffer[m_cursor++]);
return (static_cast<UINT64>(m_buffer[m_cursor++]) << 24) | (t2 << 16) | (t1 << 8) | t0;
}
UINT64 ReadUInt64()
{
EnsureAvailable(8);
const auto t0 = m_buffer[m_cursor++];
const auto t1 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t2 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t3 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t4 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t5 = static_cast<UINT64>(m_buffer[m_cursor++]);
const auto t6 = static_cast<UINT64>(m_buffer[m_cursor++]);
return (static_cast<UINT64>(m_buffer[m_cursor++]) << 56) | (t6 << 48) | (t5 << 40) | (t4 << 32) | (t3 << 24) | (t2 << 16) | (t1 << 8) | t0;
}
public:
VOID Seek(IN SIZE_T position) { m_cursor = position; }
SIZE_T Cursor() CONST { return m_cursor; }
SIZE_T Remaining() CONST { return m_bufferSize - m_cursor; }
private:
ALWAYS_INLINE VOID EnsureAvailable(IN SIZE_T count)
{
if((m_cursor + count) > m_bufferSize)
THROW_UNEXPECTED_EOF();
}
private:
SIZE_T m_cursor {};
PCUINT8 m_buffer {};
SIZE_T m_bufferSize {};
BOOL m_isBufferOwner {};
};
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/bytestring/bytestring.inl"
namespace ia {}

View File

@ -0,0 +1,42 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/definitions.hpp"
#if __IA_DEBUG || IAC_SEC_LEVEL(1)
#define __IAC_OVERFLOW_CHECKS 1
#else
#define __IAC_OVERFLOW_CHECKS 0
#endif
#if __IA_DEBUG || IAC_SEC_LEVEL(2)
#define __IAC_SANITY_CHECKS 1
#else
#define __IAC_SANITY_CHECKS 0
#endif
#if __IAC_OVERFLOW_CHECKS
#define IAC_CHECK_OVERFLOW(v, l) if((v) > (l)) THROW_MEMORY_OVERFLOW("oveflow check failed");
#else
#define IAC_CHECK_OVERFLOW(v, l)
#endif
#if __IAC_SANITY_CHECKS
#define IAC_CHECK_SANITY(c) if(!(c)) THROW_INVALID_DATA("sanity check failed");
#else
#define IAC_CHECK_SANITY(c)
#endif

View File

@ -0,0 +1,22 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/container/fixed.inl"
#include "iacore/container/dynamic.inl"
namespace ia {}

View File

@ -0,0 +1,164 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <new>
#include <cstddef>
#include <concepts>
#include <functional>
#include <assert.h>
#include <type_traits>
#include <initializer_list>
#if defined (_MSC_VER ) && !defined(__clang__)
#error "IA software does not support compilation with MSVC. Please use Clang on Windows platforms."
#endif
#define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v)
#define IA_DEFINED_TRUE(o) (defined(o) && (o > 0))
#if defined(__IA_DEBUG) && __IA_DEBUG
#define __DEBUG_MODE__
#define __BUILD_MODE_NAME "debug"
#define DEBUG_ONLY(v) v
#else
#define __RELEASE_MODE__
#define __BUILD_MODE_NAME "release"
#ifndef NDEBUG
#define NDEBUG
#endif
#ifndef __OPTIMIZE__
#define __OPTIMIZE__
#endif
#define DEBUG_ONLY(f)
#endif
#define AUTO auto
#define CONST const
#define STATIC static
#define EXTERN extern
#define VIRTUAL virtual
#define OVERRIDE override
#define CONSTEXPR constexpr
#define NOEXCEPT noexcept
#define NORETURN [[noreturn]]
#define IA_MOVE(...) std::move(__VA_ARGS__)
#define DEFINE_TYPE(t, v) typedef v t
#define FORWARD_DECLARE(t, i) t i
#define PURE_VIRTUAL(f) VIRTUAL f = 0
#define INLINE inline
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
#define ALWAYS_INLINE __forceinline
#endif
#define UNUSED(v) ((void)v);
#define NO_DISCARD(s) [[nodiscard(s)]]
#define B_LIKELY(cond) (cond) [[likely]]
#define B_UNLIKELY(cond) (cond) [[unlikely]]
#define __INTERNAL_IA_STRINGIFY(value) #value
#define IA_STRINGIFY(value) __INTERNAL_IA_STRINGIFY(value)
#define DECONST(t, v) const_cast<t>(v)
#define ALIGN(a) __attribute__((aligned(a)))
// Mark every explicit assembly instruction as volatile
#define ASM(...) __asm__ volatile(__VA_ARGS__)
#ifndef NULL
#define NULL 0
#endif
#ifndef NULLPTR
#define NULLPTR nullptr
#endif
#undef TRUE
#undef FALSE
#define FALSE false
#define TRUE true
#define IN
#define OUT
#define INOUT
#undef VOID
#undef C_DECL
#define C_DECL(f) EXTERN "C" f
#define CAST(v, t) ((t)v)
#define ALIAS_FUNCTION(alias, function) template <typename... Args> \
auto alias(Args&&... args) -> decltype(f(std::forward<Args>(args)...)) \
{ \
return function(std::forward<Args>(args)...); \
}
#define ALIAS_TEMPLATE_FUNCTION(t, alias, function) template <typename t, typename... Args> \
auto alias(Args&&... args) -> decltype(function<t>(std::forward<Args>(args)...)) \
{ \
return function<t>(std::forward<Args>(args)...); \
}
#define IA_RELEASE_ASSERT(v) assert((v))
#define IA_RELEASE_ASSERT_MSG(v, m) assert((v) && m)
#if defined(__DEBUG_MODE__)
#define IA_ASSERT(v) IA_RELEASE_ASSERT(v)
#define IA_ASSERT_MSG(v, m) IA_RELEASE_ASSERT_MSG(v, m)
#else
#define IA_ASSERT(v)
#define IA_ASSERT_MSG(v, m)
#endif
#define IA_ASSERT_EQ(a, b) IA_ASSERT((a) == (b))
#define IA_ASSERT_GE(a, b) IA_ASSERT((a) >= (b))
#define IA_ASSERT_LE(a, b) IA_ASSERT(a <= b)
#define IA_ASSERT_LT(a, b) IA_ASSERT(a < b)
#define IA_ASSERT_GT(a, b) IA_ASSERT(a > b)
#define IA_ASSERT_IMPLIES(a, b) IA_ASSERT(!(a) || (b))
#define IA_ASSERT_NOT_NULL(v) IA_ASSERT(((v) != nullptr))
#define IA_UNREACHABLE(msg) IA_RELEASE_ASSERT_MSG(false, "an unreachable portion of code was executed: " msg)
#define IA_MAX_PATH_LENGTH PATH_MAX
#define IA_MAX_POSSIBLE_SIZE (static_cast<SIZE_T>(0x7FFFFFFFFFFFF))
#define IA_MAX_STRING_LENGTH (IA_MAX_POSSIBLE_SIZE >> 8)
#define __CC_BLACK "\033[30m"
#define __CC_RED "\033[31m"
#define __CC_GREEN "\033[32m"
#define __CC_YELLOW "\033[33m"
#define __CC_BLUE "\033[34m"
#define __CC_MAGENTA "\033[35m"
#define __CC_CYAN "\033[36m"
#define __CC_WHITE "\033[37m"
#define __CC_DEFAULT "\033[39m"

View File

@ -0,0 +1,139 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <iacore/string.hpp>
namespace ia {
enum class ExceptionKind {
UNKNOWN = 0,
CUSTOM,
NOT_IMPLEMENTED,
FILE_OPEN_READ,
FILE_OPEN_WRITE,
MEMORY_ALLOC,
MEMORY_DEALLOC,
MEMORY_OVERFLOW,
INTEGER_OVERFLOW,
UNEXPECTED_EOF,
INVALID_DATA,
INVALID_USAGE,
NO_SUCH_KEY,
SECURITY_VIOLATION,
SECURITY_BYPASS,
};
class RuntimeException : public std::exception {
public:
RuntimeException(IN ExceptionKind kind, IN CONST String &message)
: m_kind(kind) {
initialize(kind, message);
}
PCCHAR what() CONST NOEXCEPT OVERRIDE { return m_message.data(); }
ExceptionKind kind() CONST NOEXCEPT { return m_kind; }
CONST String &message() CONST NOEXCEPT { return m_message; }
private:
VOID initialize(IN ExceptionKind kind, IN CONST String &message) NOEXCEPT
{
switch (kind) {
case ExceptionKind::FILE_OPEN_READ:
m_message = BuildString("[open_file:read] ", message);
break;
case ExceptionKind::FILE_OPEN_WRITE:
m_message = BuildString("[open_file:write] ", message);
break;
case ExceptionKind::MEMORY_ALLOC:
m_message = BuildString("[mem_alloc] ", message);
break;
case ExceptionKind::MEMORY_DEALLOC:
m_message = BuildString("[mem_dealloc] ", message);
break;
case ExceptionKind::MEMORY_OVERFLOW:
m_message = BuildString("[mem_overflow] ", message);
break;
case ExceptionKind::INTEGER_OVERFLOW:
m_message = BuildString("[int_overflow] ", message);
break;
case ExceptionKind::UNEXPECTED_EOF:
m_message = BuildString("[unexpected_eof] ", message);
break;
case ExceptionKind::INVALID_DATA:
m_message = BuildString("[invalid_data] ", message);
break;
case ExceptionKind::INVALID_USAGE:
m_message = BuildString("[invalid_usage] ", message);
break;
case ExceptionKind::NO_SUCH_KEY:
m_message = BuildString("[no_such_key] ", message);
break;
case ExceptionKind::SECURITY_VIOLATION:
case ExceptionKind::SECURITY_BYPASS: {
printf(__CC_RED "\n\n------------------------\n [INTRUSION "
"DETECTED]\n------------------------\n\n Entering "
"lockdown...\n\n------------------------\n" __CC_DEFAULT
"\n");
while (true) {
}
} break;
case ExceptionKind::NOT_IMPLEMENTED:
m_message = BuildString("[NOT IMPLEMENTED]: We're sorry for the "
"inconvenience 😦 Please report this on our Git "
"page so we can move it up the priority queue.");
break;
case ExceptionKind::CUSTOM:
m_message = message;
break;
default:
case ExceptionKind::UNKNOWN:
m_message = BuildString("[Unknown] ", message);
break;
}
}
private:
String m_message;
CONST ExceptionKind m_kind{ExceptionKind::UNKNOWN};
};
#define FOR_EACH_RUNTIME_EXCEPT_TYPE(DO) \
DO(UNKNOWN) \
DO(CUSTOM) \
DO(NOT_IMPLEMENTED) \
DO(FILE_OPEN_READ) \
DO(FILE_OPEN_WRITE) \
DO(MEMORY_ALLOC) \
DO(MEMORY_DEALLOC) \
DO(MEMORY_OVERFLOW) \
DO(INTEGER_OVERFLOW) \
DO(UNEXPECTED_EOF) \
DO(INVALID_DATA) \
DO(INVALID_USAGE) \
DO(NO_SUCH_KEY) \
DO(SECURITY_VIOLATION) \
DO(SECURITY_BYPASS)
#define DEFINE_THROWER(name) \
template <typename... Args> NORETURN VOID THROW_##name(Args... args) { \
throw RuntimeException(ExceptionKind::name, BuildString(args...)); \
}
FOR_EACH_RUNTIME_EXCEPT_TYPE(DEFINE_THROWER);
#undef DEFINE_THROWER
#undef FOR_EACH_RUNTIME_EXCEPT_TYPE
} // namespace ia

View File

@ -0,0 +1,108 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/types.hpp"
#include <cstdio>
#include <filesystem>
#include <iacore/exception.hpp>
#include <iacore/string.hpp>
namespace ia
{
class File
{
public:
enum OpenFlags : UINT32
{
OPEN_FLAG_READ = 1,
OPEN_FLAG_WRITE = 2,
OPEN_FLAG_BINARY = 4,
};
public:
File(IN CONST String &path, IN UINT32 flags)
{
String mode = "";
if (flags & OPEN_FLAG_READ)
mode += 'r';
if (flags & OPEN_FLAG_WRITE)
mode += 'w';
if (flags & OPEN_FLAG_BINARY)
mode += 'b';
m_filePtr = fopen(path.c_str(), mode.c_str());
if (!m_filePtr)
THROW_FILE_OPEN_READ(path);
m_openFlags = flags;
}
~File()
{
fclose(m_filePtr);
}
BOOL isOpen() CONST
{
return !m_filePtr;
}
SIZE_T Size() CONST
{
const auto c = ftell(m_filePtr);
fseek(m_filePtr, 0, SEEK_END);
const auto size = ftell(m_filePtr);
fseek(m_filePtr, c, SEEK_SET);
return size;
}
SIZE_T Read(OUT PVOID buffer, IN SIZE_T bufferSize, IN SIZE_T readSize)
{
if (readSize > bufferSize)
return 0;
fread(buffer, 1, readSize, m_filePtr);
return readSize;
}
public:
template<BOOL includeExtension> STATIC INLINE String ExtractFilenameFromPath(IN CONST String &path)
{
#if IA_DEFINED_TRUE(IA_PLATFORM_WINDOWS)
constexpr char pathDelimiter = '\\';
#else
constexpr char pathDelimiter = '/';
#endif
auto t = path.rfind(pathDelimiter, 0);
if (t == path.end())
{
if constexpr (includeExtension)
return path.slice(path.begin(), path.cend());
return path.slice(path.begin(), path.rfind('.', 0));
}
if constexpr (includeExtension)
return path.slice(t + 1, path.cend());
return path.slice(t + 1, path.rfind('.', 0));
}
private:
FILE *m_filePtr{};
SIZE_T m_cursor{};
UINT32 m_openFlags{};
};
} // namespace ia

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/hashable/iihashable.inl"
namespace ia {}

View File

@ -0,0 +1,17 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once

View File

@ -0,0 +1,53 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "file.hpp"
namespace ia
{
class IAML
{
public:
public:
IAML(IN CONST String& path) { ParseFromFile(path); }
~IAML() {}
private:
VOID ParseFromFile(IN CONST String& path);
VOID ParseFromMemory(IN CONST String& iaml);
};
}
namespace ia
{
VOID IAML::ParseFromFile(IN CONST String& path)
{
File f(path, File::OPEN_FLAG_READ);
String data;
data.resize(f.Size() + 1);
f.Read(data.data(), f.Size(), f.Size());
ParseFromMemory(data);
}
VOID IAML::ParseFromMemory(IN CONST String& iaml)
{
}
}

View File

@ -0,0 +1,183 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// Minimal IATest that does not depend on anything from IACore
// except for the types and definitions.
#pragma once
#include <stdio.h>
#include <string>
#include <vector>
#include <iacore/types.hpp>
#define valid_iatest_runner(type) iatest::_valid_iatest_runner<type>::value_type
#define template_iatest_runner template<typename _runner_type> requires valid_iatest_runner(_runner_type)
#define __iat_micro_test(t) if(!t) return false
#define IAT_CHECK(v) __iat_micro_test(_test((v), #v))
#define IAT_CHECK_NOT(v) __iat_micro_test(_test_not((v), "NOT " #v))
#define IAT_CHECK_EQ(lhs, rhs) __iat_micro_test(_test_eq((lhs), (rhs), #lhs " == " #rhs))
#define IAT_CHECK_NEQ(lhs, rhs) __iat_micro_test(_test_neq((lhs), (rhs), #lhs " != " #rhs))
#define IAT_NAMED_CHECK(n, v) __iat_micro_test(_test((v), n))
#define IAT_NAMED_CHECK_NOT(n, v) __iat_micro_test(_test_not((v), n))
#define IAT_NAMED_CHECK_EQ(n, lhs, rhs) __iat_micro_test(_test_eq((lhs), (rhs), n))
#define IAT_NAMED_CHECK_NEQ(n, lhs, rhs) __iat_micro_test(_test_neq((lhs), (rhs), n))
#define IAT_UNIT(func) _test_unit([this](){ return this->func(); }, # func)
#define IAT_NAMED_UNIT(n, func) _test_unit([this](){ return this->func(); }, n)
#define IAT_BLOCK(name) class name: public ia::iatest::block
#define IAT_BEGIN_BLOCK(_group, _name) class _group##_##_name : public ia::iatest::block { \
public: PCCHAR name() CONST { return "" #_group ":" #_name; } private:
#define IAT_END_BLOCK() };
#define IAT_BEGIN_TEST_LIST() public: VOID declareTests() {
#define IAT_ADD_TEST(name) IAT_UNIT(name)
#define IAT_END_TEST_LIST() } private:
namespace ia::iatest
{
DEFINE_TYPE(functor_t, std::function<BOOL()>);
typedef struct _unit
{
std::string Name;
functor_t Functor;
} unit_t;
class block
{
public:
PURE_VIRTUAL(PCCHAR name() CONST);
PURE_VIRTUAL(VOID declareTests());
protected:
template<typename _lhs_type, typename _rhs_type>
BOOL _test_eq(IN _lhs_type lhs, IN _rhs_type rhs, IN PCCHAR description)
{
if(lhs != rhs)
{
printf(__CC_BLUE " %s... " __CC_RED "FAILED" __CC_DEFAULT "\n", description);
return false;
}
return true;
}
template<typename _lhs_type, typename _rhs_type>
BOOL _test_neq(IN _lhs_type lhs, IN _rhs_type rhs, IN PCCHAR description)
{
if(lhs == rhs)
{
printf(__CC_BLUE " %s... " __CC_RED "FAILED" __CC_DEFAULT "\n", description);
return false;
}
return true;
}
BOOL _test(IN BOOL value, IN PCCHAR description)
{
if(!value)
{
printf(__CC_BLUE " %s... " __CC_RED "FAILED" __CC_DEFAULT "\n", description);
return false;
}
return true;
}
BOOL _test_not(IN BOOL value, IN PCCHAR description)
{
if(value)
{
printf(__CC_BLUE " %s... " __CC_RED "FAILED" __CC_DEFAULT "\n", description);
return false;
}
return true;
}
VOID _test_unit(IN functor_t functor, IN PCCHAR name)
{
m_units.push_back({name, functor});
}
public:
std::vector<unit_t>& units() { return m_units; }
private:
std::vector<unit_t> m_units;
};
template<typename block_class>
concept valid_block_class = std::derived_from<block_class, block>;
template<BOOL stopOnFail = false, BOOL isVerbose = false>
class runner
{
public:
runner(){}
~runner() { summarize(); }
template<typename block_class>
requires valid_block_class<block_class>
VOID testBlock();
private:
VOID summarize();
private:
SIZE_T m_testCount { 0 };
SIZE_T m_failCount { 0 };
SIZE_T m_blockCount { 0 };
};
template<BOOL stopOnFail, BOOL isVerbose>
template<typename block_class>
requires valid_block_class<block_class>
VOID runner<stopOnFail, isVerbose>::testBlock()
{
m_blockCount++;
block_class b;
b.declareTests();
printf(__CC_MAGENTA "Testing [%s]..." __CC_DEFAULT "\n", b.name());
for(auto& v: b.units())
{
m_testCount++;
printf(__CC_YELLOW " Testing %s...\n", v.Name.c_str());
if(!v.Functor())
{
m_failCount++;
if constexpr(stopOnFail) { summarize(); exit(-1); }
}
}
fputs(__CC_DEFAULT "\n", stdout);
}
template<BOOL stopOnFail, BOOL isVerbose>
VOID runner<stopOnFail, isVerbose>::summarize()
{
printf(__CC_GREEN "\n-----------------------------------\n\t SUMMARY\n-----------------------------------\n");
if(!m_failCount) fputs("\n\tALL TESTS PASSED!\n\n", stdout);
else printf(__CC_RED "%zu OUT OF %zu TESTS FAILED\n" __CC_YELLOW "Success Rate: %.2f%%\n", m_failCount, m_testCount, (100.0 * static_cast<FLOAT64>(m_testCount - m_failCount)/static_cast<FLOAT64>(m_testCount)));
printf(__CC_MAGENTA "Ran %zu test(s) across %zu block(s)\n" __CC_GREEN "-----------------------------------" __CC_DEFAULT "\n", m_testCount, m_blockCount);
}
template<typename>
struct _valid_iatest_runner : std::false_type {};
template<BOOL stopOnFail, BOOL isVerbose>
struct _valid_iatest_runner<runner<stopOnFail,isVerbose>> : std::true_type {};
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/iterator/iterator.inl"
namespace ia {}

View File

@ -0,0 +1,23 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/lib/math.inl"
#include "iacore/lib/mem.inl"
#include "iacore/lib/str.inl"
namespace ia {}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/list/list.inl"
namespace ia {}

View File

@ -0,0 +1,23 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/map/map.inl"
namespace ia
{
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/memory/ptr/interface/refptr.interface.inl"
namespace ia {}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/platform/platform.inl"
namespace ia {}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/set/set.inl"
namespace ia {}

View File

@ -0,0 +1,22 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/stream/stringstream.inl"
#include "iacore/stream/filestream.inl"
namespace ia {}

View File

@ -0,0 +1,30 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/stream/stringstream.inl"
namespace ia
{
template<typename... Args>
String BuildString(Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
return ss.str();
}
}

View File

@ -0,0 +1,135 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/checks.hpp"
namespace ia
{
template<typename _value_type>
using initializer_list = std::initializer_list<_value_type>;
#undef VOID
typedef void VOID;
typedef bool BOOL;
typedef char CHAR;
typedef uint16_t CHAR16;
typedef int8_t INT8;
typedef int16_t INT16;
typedef int32_t INT32;
typedef int64_t INT64;
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
typedef float FLOAT32;
typedef double FLOAT64;
typedef INT32 INT;
typedef UINT32 UINT;
typedef size_t SIZE_T;
typedef std::make_signed_t<size_t> SSIZE_T;
typedef std::align_val_t ALIGN_T;
// pointer types
typedef VOID* PVOID;
typedef BOOL* PBOOL;
typedef CHAR* PCHAR;
typedef CHAR16* PCHAR16;
typedef INT8* PINT8;
typedef INT16* PINT16;
typedef INT32* PINT32;
typedef INT64* PINT64;
typedef UINT8* PUINT8;
typedef UINT16* PUINT16;
typedef UINT32* PUINT32;
typedef UINT64* PUINT64;
typedef INT* PINT;
typedef UINT* PUINT;
typedef SIZE_T* PSIZE;
typedef SSIZE_T* PSSIZE;
typedef FLOAT32 PFLOAT32;
typedef FLOAT64 PFLOAT64;
// const pointer types
typedef CONST VOID* PCVOID;
typedef CONST BOOL* PCBOOL;
typedef CONST CHAR* PCCHAR;
typedef CONST CHAR16* PCCHAR16;
typedef CONST INT8* PCINT8;
typedef CONST INT16* PCINT16;
typedef CONST INT32* PCINT32;
typedef CONST INT64* PCINT64;
typedef CONST UINT8* PCUINT8;
typedef CONST UINT16* PCUINT16;
typedef CONST UINT32* PCUINT32;
typedef CONST UINT64* PCUINT64;
typedef CONST INT* PCINT;
typedef CONST UINT* PCUINT;
typedef CONST SIZE_T* PCSIZE;
typedef CONST SSIZE_T* PCSSIZE;
typedef CONST FLOAT32 PCFLOAT32;
typedef CONST FLOAT64 PCFLOAT64;
/* Uses the UEFI standard GUID structure definition */
typedef struct _IA_GUID
{
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8 Data4[8];
bool operator==(const _IA_GUID& other)
{
UINT64* myData = (UINT64*)(&Data1);
UINT64* otherData = (UINT64*)(&(other.Data1));
return ((myData[0] == otherData[0]) && (myData[1] == otherData[1]));
}
} GUID;
namespace types
{
static BOOL __internal_validate_types()
{
if(sizeof(CHAR) != static_cast<size_t>(1)) return false;
if(sizeof(INT8) != static_cast<size_t>(1)) return false;
if(sizeof(INT16) != static_cast<size_t>(2)) return false;
if(sizeof(INT32) != static_cast<size_t>(4)) return false;
if(sizeof(INT64) != static_cast<size_t>(8)) return false;
if(sizeof(UINT8) != static_cast<size_t>(1)) return false;
if(sizeof(UINT16) != static_cast<size_t>(2)) return false;
if(sizeof(UINT32) != static_cast<size_t>(4)) return false;
if(sizeof(UINT64) != static_cast<size_t>(8)) return false;
if(sizeof(FLOAT32) != static_cast<size_t>(4)) return false;
if(sizeof(FLOAT64) != static_cast<size_t>(8)) return false;
if(sizeof(PVOID) < static_cast<size_t>(4)) return false;
return true;
}
}
}

View File

@ -0,0 +1,27 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/vector/ordered.inl"
#include "iacore/vector/unordered.inl"
namespace ia
{
template<typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1>
requires valid_allocator_type<_allocator_type, _value_type>
using Vector = UnorderedVector<_value_type, _allocator_type, _alignment>;
}

View File

@ -0,0 +1,21 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// Copyright (C) 2024 IAS (ias@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "iacore/xop/xop.inl"
namespace ia {}

View File

@ -0,0 +1,9 @@
add_executable(IACoreTest imp/cpp/Main.cpp)
target_compile_options(IACoreTest PRIVATE
"-g"
"-O0"
"-D__IA_DEBUG=1"
)
target_link_libraries(IACoreTest PRIVATE IACore)

View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main(int argc, char* argv[])
{
return 0;
}