This commit is contained in:
Isuru Samarathunga
2025-07-18 22:37:47 +05:30
parent f2e6cee915
commit a324de4111
10 changed files with 428 additions and 234 deletions

View File

@ -31,15 +31,15 @@ namespace ia
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);
Base::m_count = count;
Base::m_data = alloc<_alignment>(m_allocator, Base::m_count);
m_allocator.construct(Base::m_data, Base::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);
Base::m_data = alloc<_alignment>(m_allocator, v.size());
for(const auto& value: v) new (&Base::m_data[Base::m_count++]) value_type(value);
}
define_member_function(, ~FixedContainer,)
@ -49,19 +49,19 @@ namespace ia
define_member_function(VOID, reset,)
{
if(m_data)
if(Base::m_data)
{
m_allocator.destruct(m_data, m_count);
dealloc<_alignment>(m_allocator, m_data);
m_data = nullptr;
m_allocator.destruct(Base::m_data, Base::m_count);
dealloc<_alignment>(m_allocator, Base::m_data);
Base::m_data = nullptr;
}
m_count = 0;
Base::m_count = 0;
}
define_member_function(__ia__identifier::pointer_type, take,)
{
auto res = m_data;
m_data = nullptr;
auto res = Base::m_data;
Base::m_data = nullptr;
reset();
return res;
}
@ -69,15 +69,15 @@ namespace ia
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]);
Base::m_data = alloc<_alignment>(m_allocator, (Base::m_count = r.Base::m_count));
for(size_type i = 0; i < Base::m_count; i++)
new (&Base::m_data[i]) value_type(r.Base::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(Base::m_data, r.Base::m_data);
ia_swap(Base::m_count, r.Base::m_count);
ia_swap(m_allocator, r.m_allocator);
}
}
@ -106,121 +106,58 @@ namespace ia
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] };
for(size_type i = offset; i < Base::m_count; i++)
if(!c(Base::m_data[i])) return { &Base::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] };
for(ssize_type i = Base::m_count - 1; i >= offset; i--)
if(!c(Base::m_data[i])) return { &Base::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] };
for(size_type i = offset; i < Base::m_count; i++)
if(v == Base::m_data[i]) return { &Base::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] };
for(ssize_type i = Base::m_count - 1; i >= offset; i--)
if(v == Base::m_data[i]) return { &Base::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;
for(size_type i = 0; i < Base::m_count; i++)
if(!c(Base::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;
for(size_type i = 0; i < Base::m_count; i++)
if(v == Base::m_data[i]) return true;
return false;
}
define_const_member_function(BOOL, operator==, IN CONST FixedContainer& o)
{
if(m_count != o.size()) return false;
if(Base::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;
if(Base::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 };
return IIHashable::fnv_1a((PCUINT8)Base::m_data, Base::m_count * sizeof(value_type));
}
}

View File

@ -1,139 +1,175 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// 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"
#include "span.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();
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 Span<_value_type>
{
using Base = Span<_value_type>;
VOID operator=(IN FixedContainer&& r) { take_from(IA_MOVE(r)); }
VOID operator=(IN CONST FixedContainer& r) { copy_from(r); }
public:
using typename Base::size_type;
using typename Base::ssize_type;
using typename Base::value_type;
using typename Base::pointer_type;
using typename Base::const_pointer_type;
using typename Base::buffer_type;
using typename Base::reference_type;
using typename Base::const_reference_type;
using typename Base::iterator;
using typename Base::const_iterator;
using typename Base::reverse_iterator;
using typename Base::reverse_const_iterator;
using typename Base::comparator_type;
using allocator_type = _allocator_type;
STATIC CONSTEXPR size_type alignment = _alignment;
public:
iterator begin();
iterator end();
const_iterator begin() CONST;
const_iterator end() CONST;
const_iterator cbegin() CONST;
const_iterator cend() CONST;
public:
FixedContainer();
FixedContainer(IN size_type count);
FixedContainer(IN initializer_list<value_type> v);
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;
FixedContainer(IN FixedContainer &&r)
{
take_from(IA_MOVE(r));
}
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]; }
FixedContainer(IN CONST FixedContainer &r)
{
copy_from(r);
}
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]; }
~FixedContainer();
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);
VOID operator=(IN FixedContainer &&r)
{
take_from(IA_MOVE(r));
}
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); }
VOID operator=(IN CONST FixedContainer &r)
{
copy_from(r);
}
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;
public:
value_type &front()
{
IA_ASSERT(Base::m_count > 0);
return Base::m_data[0];
}
template<typename compare_type>
BOOL contains(IN CONST compare_type& v) CONST;
BOOL contains(IN CONST comparator_type c) CONST;
CONST value_type &front() CONST
{
IA_ASSERT(Base::m_count > 0);
return Base::m_data[0];
}
public:
UINT64 hash() CONST;
value_type &back()
{
IA_ASSERT(Base::m_count > 0);
return Base::m_data[Base::m_count - 1];
}
public:
BOOL operator==(IN CONST FixedContainer& o) CONST;
CONST value_type &back() CONST
{
IA_ASSERT(Base::m_count > 0);
return Base::m_data[Base::m_count - 1];
}
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; }
value_type &operator[](IN size_type index)
{
IA_ASSERT(index < Base::m_count);
return Base::m_data[index];
}
allocator_type& allocator() { return m_allocator; }
VOID allocator(IN CONST allocator_type& v) { m_allocator = v; }
CONST value_type &operator[](IN size_type index) CONST
{
IA_ASSERT(index < Base::m_count);
return Base::m_data[index];
}
public:
VIRTUAL VOID reset();
VIRTUAL pointer_type take();
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);
VIRTUAL VOID take_from(IN FixedContainer&& r);
VIRTUAL VOID copy_from(IN CONST FixedContainer& r);
template<typename compare_type> const_iterator find(IN CONST compare_type &v, IN size_type offset = 0) CONST
{
return cfind(v, offset);
}
protected:
size_type m_count { 0 };
buffer_type m_data { nullptr };
const_iterator find(IN comparator_type c, IN size_type offset = 0) CONST
{
return cfind(c, offset);
}
protected:
allocator_type m_allocator {};
};
}
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:
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:
allocator_type m_allocator{};
};
} // namespace ia

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 <iacore/allocator.hpp>
#include <iacore/hashable.hpp>
#include <iacore/memory.hpp>
#include "iterator.interface.inl"
namespace ia
{
template<typename _value_type> class Span
{
public:
using size_type = SIZE_T;
using ssize_type = SSIZE_T;
using value_type = _value_type;
using pointer_type = value_type *;
using buffer_type = value_type *;
using reference_type = value_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 &)>;
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:
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;
}
protected:
size_type m_count{0};
pointer_type m_data{nullptr};
};
} // namespace ia

View File

@ -0,0 +1,92 @@
// 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/span.interface.inl"
#define __template template<typename _value_type>
#define __ia__identifier Span<_value_type>
#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(__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

@ -16,6 +16,7 @@
#pragma once
#include "iacore/container/span.inl"
#include "iacore/container/fixed.inl"
#include "iacore/container/dynamic.inl"

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/string.hpp"
namespace ia
{
class Logger
{
public:
template<typename... Args> STATIC VOID Info(Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
printf("\033[32m[INFO]: %s\033[39m\n", ss.str().c_str());
}
template<typename... Args> STATIC VOID Warn(Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
printf("\033[33m[WARN]: %s\033[39m\n", ss.str().c_str());
}
template<typename... Args> STATIC VOID Error(Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
printf("\033[31m[ERROR]: %s\033[39m\n", ss.str().c_str());
}
private:
Logger()
{
}
~Logger()
{
}
};
} // namespace ia

View File

@ -1,53 +1,23 @@
// IACore-OSS; The Core Library for All IA Open Source Projects
// 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"
#include "iacore/container/span.inl"
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

@ -1,7 +1,21 @@
#include <stdio.h>
#include <iacore/log.hpp>
#include <iacore/file.hpp>
#include <iacore/vector.hpp>
using namespace ia;
VOID print(IN CONST Span<int>& s)
{
for(const auto& v: s)
Logger::Info(v);
}
int main(int argc, char* argv[])
{
Vector<int> v1{10, 20, 32};
print(v1);
return 0;
}

View File

@ -0,0 +1,4 @@
Hello
W
o
rld