Compare commits
7 Commits
491342ad50
...
89d9217b29
| Author | SHA1 | Date | |
|---|---|---|---|
| 89d9217b29 | |||
| ed70c2b310 | |||
| 83bb826f24 | |||
| a324de4111 | |||
| f2e6cee915 | |||
| 599e94594a | |||
| 0bb22cf2f4 |
Binary file not shown.
1
.gitignore
vendored
1
.gitignore
vendored
@ -46,4 +46,5 @@
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
.cache/
|
||||
build/
|
||||
|
||||
@ -2,3 +2,4 @@
|
||||
add_library(IACore STATIC imp/cpp/dummy.cpp)
|
||||
|
||||
target_include_directories(IACore PUBLIC inc/hpp imp/inl)
|
||||
target_compile_definitions(IACore PUBLIC _CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
@ -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] };
|
||||
return end();
|
||||
for(size_type i = offset; i < Base::m_count; i++)
|
||||
if(!c(Base::m_data[i])) return { &Base::m_data[i] };
|
||||
return Base::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();
|
||||
for(ssize_type i = (ssize_type)Base::m_count - offset - 1; i >= 0; i--)
|
||||
if(!c(Base::m_data[i])) return { &Base::m_data[i] };
|
||||
return Base::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();
|
||||
for(size_type i = offset; i < Base::m_count; i++)
|
||||
if(v == Base::m_data[i]) return { &Base::m_data[i] };
|
||||
return Base::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();
|
||||
for(ssize_type i = (ssize_type)Base::m_count - offset - 1; i >= 0; i--)
|
||||
if(v == Base::m_data[i]) return { &Base::m_data[i] };
|
||||
return Base::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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,124 +16,160 @@
|
||||
|
||||
#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>
|
||||
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
|
||||
class FixedContainer : public IIHashable, public Span<_value_type>
|
||||
{
|
||||
using Base = Span<_value_type>;
|
||||
|
||||
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 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;
|
||||
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(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); }
|
||||
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;
|
||||
value_type &front()
|
||||
{
|
||||
IA_ASSERT(Base::m_count > 0);
|
||||
return Base::m_data[0];
|
||||
}
|
||||
|
||||
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;
|
||||
CONST value_type &front() CONST
|
||||
{
|
||||
IA_ASSERT(Base::m_count > 0);
|
||||
return Base::m_data[0];
|
||||
}
|
||||
|
||||
value_type &back()
|
||||
{
|
||||
IA_ASSERT(Base::m_count > 0);
|
||||
return Base::m_data[Base::m_count - 1];
|
||||
}
|
||||
|
||||
CONST value_type &back() CONST
|
||||
{
|
||||
IA_ASSERT(Base::m_count > 0);
|
||||
return Base::m_data[Base::m_count - 1];
|
||||
}
|
||||
|
||||
value_type &operator[](IN size_type index)
|
||||
{
|
||||
IA_ASSERT(index < Base::m_count);
|
||||
return Base::m_data[index];
|
||||
}
|
||||
|
||||
CONST value_type &operator[](IN size_type index) CONST
|
||||
{
|
||||
IA_ASSERT(index < Base::m_count);
|
||||
return Base::m_data[index];
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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 find(IN CONST compare_type &v, IN size_type offset = 0) CONST
|
||||
{
|
||||
return cfind(v, offset);
|
||||
}
|
||||
|
||||
template<typename compare_type>
|
||||
const_iterator cfind(IN CONST compare_type& v, IN size_type offset = 0) CONST;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
allocator_type& allocator() { return m_allocator; }
|
||||
VOID allocator(IN CONST allocator_type& v) { m_allocator = v; }
|
||||
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);
|
||||
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 {};
|
||||
allocator_type m_allocator{};
|
||||
};
|
||||
}
|
||||
} // namespace ia
|
||||
|
||||
@ -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
|
||||
92
Src/IACore/imp/inl/iacore/container/span.inl
Normal file
92
Src/IACore/imp/inl/iacore/container/span.inl
Normal 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
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
namespace ia
|
||||
{
|
||||
// [IATODO: IMPL] (Allocator must be fore _value_type, not ListEntry<_value_type>)
|
||||
// [IATODO: IMPL] (Allocator must be for _value_type, not ListEntry<_value_type>)
|
||||
template<typename _value_type>
|
||||
class ListEntry;
|
||||
|
||||
|
||||
@ -36,10 +36,10 @@ namespace ia
|
||||
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;
|
||||
using iterator = Vector<KeyValuePair*>::iterator;
|
||||
using const_iterator = Vector<KeyValuePair*>::const_iterator;
|
||||
using reverse_iterator = Vector<KeyValuePair*>::reverse_iterator;
|
||||
using reverse_const_iterator = Vector<KeyValuePair*>::reverse_const_iterator;
|
||||
|
||||
STATIC CONSTEXPR size_type alignment = _alignment;
|
||||
|
||||
@ -57,7 +57,7 @@ namespace ia
|
||||
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; }
|
||||
_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:
|
||||
@ -81,6 +81,6 @@ namespace ia
|
||||
|
||||
private:
|
||||
Vector<List<KeyValuePair>> m_buckets;
|
||||
Vector<ListEntry<KeyValuePair>*> m_insertedOrder;
|
||||
Vector<KeyValuePair*> m_insertedOrder;
|
||||
};
|
||||
}
|
||||
|
||||
@ -39,7 +39,8 @@ 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) }));
|
||||
const auto listEntry = getBucket(key).append({ key, IA_MOVE(value) });
|
||||
m_insertedOrder.pushBack(*listEntry);
|
||||
}
|
||||
|
||||
define_const_member_function(CONST _value_type*, get, IN CONST key_type& key)
|
||||
|
||||
@ -300,6 +300,7 @@ namespace ia
|
||||
|
||||
define_member_function(BOOL, resize, IN size_type newCount)
|
||||
{
|
||||
newCount += 1;
|
||||
const auto did_reallocate = reserve(newCount);
|
||||
for(; Base::m_count < newCount; Base::m_count++) Base::m_data[Base::m_count] = 0;
|
||||
return did_reallocate;
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "iacore/container/span.inl"
|
||||
#include "iacore/container/fixed.inl"
|
||||
#include "iacore/container/dynamic.inl"
|
||||
|
||||
|
||||
@ -27,9 +27,11 @@
|
||||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
|
||||
#if defined (_MSC_VER ) && !defined(__clang__)
|
||||
#if defined (_MSC_VER )
|
||||
#if !defined(__clang__)
|
||||
#error "IA software does not support compilation with MSVC. Please use Clang on Windows platforms."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v)
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
#include <filesystem>
|
||||
#include <iacore/exception.hpp>
|
||||
#include <iacore/string.hpp>
|
||||
|
||||
#include <iacore/vector.hpp>
|
||||
|
||||
namespace ia
|
||||
{
|
||||
@ -35,6 +35,19 @@ namespace ia
|
||||
OPEN_FLAG_BINARY = 4,
|
||||
};
|
||||
|
||||
public:
|
||||
STATIC Vector<UINT8> ReadToVector(IN CONST String &path)
|
||||
{
|
||||
File f(path, OPEN_FLAG_READ | OPEN_FLAG_BINARY);
|
||||
return f.ReadToVector();
|
||||
}
|
||||
|
||||
STATIC String ReadToString(IN CONST String &path)
|
||||
{
|
||||
File f(path, OPEN_FLAG_READ);
|
||||
return f.ReadToString();
|
||||
}
|
||||
|
||||
public:
|
||||
File(IN CONST String &path, IN UINT32 flags)
|
||||
{
|
||||
@ -78,6 +91,23 @@ namespace ia
|
||||
return readSize;
|
||||
}
|
||||
|
||||
Vector<UINT8> ReadToVector()
|
||||
{
|
||||
Vector<UINT8> result;
|
||||
result.resize(Size());
|
||||
Read(result.data(), result.size(), result.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
String ReadToString()
|
||||
{
|
||||
String result;
|
||||
result.resize(Size());
|
||||
Read(result.data(), result.size(), result.size());
|
||||
result.back() = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
public:
|
||||
template<BOOL includeExtension> STATIC INLINE String ExtractFilenameFromPath(IN CONST String &path)
|
||||
{
|
||||
|
||||
56
Src/IACore/inc/hpp/iacore/log.hpp
Normal file
56
Src/IACore/inc/hpp/iacore/log.hpp
Normal 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
|
||||
@ -16,38 +16,8 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <iacore/log.hpp>
|
||||
#include <iacore/file.hpp>
|
||||
|
||||
#include <iacore/vector.hpp>
|
||||
#include <iacore/map.hpp>
|
||||
|
||||
using namespace ia;
|
||||
|
||||
template<typename _value_type>
|
||||
VOID print(IN CONST Span<_value_type>& s)
|
||||
{
|
||||
for(const auto& v: s)
|
||||
Logger::Info(v);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Vector<int> v1{10, 20, 32};
|
||||
|
||||
print(v1);
|
||||
|
||||
List<int> l1;
|
||||
|
||||
Map<String, int> m1;
|
||||
m1["sdd"] = 2;
|
||||
m1["bx"] = 5;
|
||||
|
||||
for(const auto& v: m1)
|
||||
{
|
||||
printf("%s, %i\n", v->Key.c_str(), v->Value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
4
Src/IACoreTest/res/sample.txt
Normal file
4
Src/IACoreTest/res/sample.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Hello
|
||||
W
|
||||
o
|
||||
rld
|
||||
Reference in New Issue
Block a user