Compare commits

...

7 Commits

Author SHA1 Message Date
89d9217b29 fix rfind 2025-08-05 03:19:58 +05:30
ed70c2b310 Fixed map iterator 2025-07-19 12:10:06 +05:30
83bb826f24 Read file to string/buffer 2025-07-18 22:46:35 +05:30
a324de4111 Span 2025-07-18 22:37:47 +05:30
f2e6cee915 fix msvc crt deprication warnings 2025-07-08 13:42:28 +05:30
599e94594a fix msvc crt deprication warnings 2025-07-08 13:40:14 +05:30
0bb22cf2f4 fix msvc crt deprication warnings 2025-07-08 03:44:04 +05:30
18 changed files with 491 additions and 248 deletions

1
.gitignore vendored
View File

@ -46,4 +46,5 @@
# Built Visual Studio Code Extensions # Built Visual Studio Code Extensions
*.vsix *.vsix
.cache/
build/ build/

View File

@ -2,3 +2,4 @@
add_library(IACore STATIC imp/cpp/dummy.cpp) add_library(IACore STATIC imp/cpp/dummy.cpp)
target_include_directories(IACore PUBLIC inc/hpp imp/inl) target_include_directories(IACore PUBLIC inc/hpp imp/inl)
target_compile_definitions(IACore PUBLIC _CRT_SECURE_NO_WARNINGS)

View File

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

View File

@ -16,95 +16,133 @@
#pragma once #pragma once
#include <iacore/hashable.hpp>
#include <iacore/allocator.hpp> #include <iacore/allocator.hpp>
#include <iacore/memory.hpp> #include <iacore/memory.hpp>
#include "iterator.interface.inl" #include "span.interface.inl"
namespace ia 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> 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: public:
using size_type = SIZE_T; using typename Base::size_type;
using ssize_type = SSIZE_T; using typename Base::ssize_type;
using value_type = _value_type; using typename Base::value_type;
using buffer_type = value_type*; using typename Base::pointer_type;
using pointer_type = value_type*; using typename Base::const_pointer_type;
using reference_type = value_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 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; STATIC CONSTEXPR size_type alignment = _alignment;
public: public:
FixedContainer(); FixedContainer();
FixedContainer(IN size_type count); FixedContainer(IN size_type count);
FixedContainer(IN initializer_list<value_type> v); 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(); ~FixedContainer();
VOID operator=(IN FixedContainer&& r) { take_from(IA_MOVE(r)); } VOID operator=(IN FixedContainer &&r)
VOID operator=(IN CONST FixedContainer& r) { copy_from(r); } {
take_from(IA_MOVE(r));
}
VOID operator=(IN CONST FixedContainer &r)
{
copy_from(r);
}
public: public:
iterator begin(); value_type &front()
iterator end(); {
const_iterator begin() CONST; IA_ASSERT(Base::m_count > 0);
const_iterator end() CONST; return Base::m_data[0];
const_iterator cbegin() CONST; }
const_iterator cend() CONST;
reverse_iterator rbegin(); CONST value_type &front() CONST
reverse_iterator rend(); {
reverse_const_iterator rbegin() CONST; IA_ASSERT(Base::m_count > 0);
reverse_const_iterator rend() CONST; return Base::m_data[0];
reverse_const_iterator crbegin() CONST; }
reverse_const_iterator crend() CONST;
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: public:
value_type& front() { IA_ASSERT(m_count > 0); return m_data[0]; } template<typename compare_type> iterator find(IN CONST compare_type &v, IN size_type offset = 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); iterator find(IN comparator_type c, IN size_type offset = 0);
template<typename compare_type> template<typename compare_type> iterator rfind(IN CONST compare_type &v, IN size_type offset = 0);
iterator rfind(IN CONST compare_type& v, IN size_type offset = 0);
iterator rfind(IN comparator_type c, IN size_type offset = 0); iterator rfind(IN comparator_type c, IN size_type offset = 0);
template<typename compare_type> template<typename compare_type> const_iterator find(IN CONST compare_type &v, IN size_type offset = 0) CONST
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); } return cfind(v, 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 comparator_type c, IN size_type offset = 0) CONST
const_iterator cfind(IN CONST compare_type& v, 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; const_iterator cfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type> template<typename compare_type> const_iterator crfind(IN CONST compare_type &v, IN size_type offset = 0) CONST;
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; const_iterator crfind(IN comparator_type c, IN size_type offset = 0) CONST;
template<typename compare_type> template<typename compare_type> BOOL contains(IN CONST compare_type &v) CONST;
BOOL contains(IN CONST compare_type& v) CONST;
BOOL contains(IN CONST comparator_type c) CONST; BOOL contains(IN CONST comparator_type c) CONST;
public: public:
@ -114,13 +152,15 @@ namespace ia
BOOL operator==(IN CONST FixedContainer &o) CONST; BOOL operator==(IN CONST FixedContainer &o) CONST;
public: public:
pointer_type data() { return m_data; } allocator_type &allocator()
const_pointer_type CONST data() CONST { return m_data; } {
VIRTUAL size_type size() CONST { return m_count; } return m_allocator;
VIRTUAL BOOL empty() CONST { return !m_count; } }
allocator_type& allocator() { return m_allocator; } VOID allocator(IN CONST allocator_type &v)
VOID allocator(IN CONST allocator_type& v) { m_allocator = v; } {
m_allocator = v;
}
public: public:
VIRTUAL VOID reset(); VIRTUAL VOID reset();
@ -129,11 +169,7 @@ namespace ia
VIRTUAL VOID take_from(IN FixedContainer &&r); VIRTUAL VOID take_from(IN FixedContainer &&r);
VIRTUAL VOID copy_from(IN CONST FixedContainer &r); VIRTUAL VOID copy_from(IN CONST FixedContainer &r);
protected:
size_type m_count { 0 };
buffer_type m_data { nullptr };
protected: protected:
allocator_type m_allocator{}; 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

@ -20,7 +20,7 @@
namespace ia 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> template<typename _value_type>
class ListEntry; class ListEntry;

View File

@ -36,10 +36,10 @@ namespace ia
using key_type = _key_type; using key_type = _key_type;
using value_type = _value_type; using value_type = _value_type;
using allocator_type = _allocator_type; using allocator_type = _allocator_type;
using iterator = Vector<ListEntry<KeyValuePair>*>::iterator; using iterator = Vector<KeyValuePair*>::iterator;
using const_iterator = Vector<ListEntry<KeyValuePair>*>::const_iterator; using const_iterator = Vector<KeyValuePair*>::const_iterator;
using reverse_iterator = Vector<ListEntry<KeyValuePair>*>::reverse_iterator; using reverse_iterator = Vector<KeyValuePair*>::reverse_iterator;
using reverse_const_iterator = Vector<ListEntry<KeyValuePair>*>::reverse_const_iterator; using reverse_const_iterator = Vector<KeyValuePair*>::reverse_const_iterator;
STATIC CONSTEXPR size_type alignment = _alignment; STATIC CONSTEXPR size_type alignment = _alignment;
@ -57,7 +57,7 @@ namespace ia
BOOL contains(IN CONST key_type& key) CONST; BOOL contains(IN CONST key_type& key) CONST;
public: 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; } CONST _value_type& operator[](IN CONST _key_type& key) CONST { const auto t = get(key); if(!t) throw "no such key"; return *t; }
public: public:
@ -81,6 +81,6 @@ namespace ia
private: private:
Vector<List<KeyValuePair>> m_buckets; Vector<List<KeyValuePair>> m_buckets;
Vector<ListEntry<KeyValuePair>*> m_insertedOrder; Vector<KeyValuePair*> m_insertedOrder;
}; };
} }

View File

@ -39,7 +39,8 @@ namespace ia
{ {
define_member_function(VOID, set, IN CONST key_type& key, IN value_type&& value) 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) define_const_member_function(CONST _value_type*, get, IN CONST key_type& key)

View File

@ -300,6 +300,7 @@ namespace ia
define_member_function(BOOL, resize, IN size_type newCount) define_member_function(BOOL, resize, IN size_type newCount)
{ {
newCount += 1;
const auto did_reallocate = reserve(newCount); const auto did_reallocate = reserve(newCount);
for(; Base::m_count < newCount; Base::m_count++) Base::m_data[Base::m_count] = 0; for(; Base::m_count < newCount; Base::m_count++) Base::m_data[Base::m_count] = 0;
return did_reallocate; return did_reallocate;

View File

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

View File

@ -27,9 +27,11 @@
#include <type_traits> #include <type_traits>
#include <initializer_list> #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." #error "IA software does not support compilation with MSVC. Please use Clang on Windows platforms."
#endif #endif
#endif
#define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v) #define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v)

View File

@ -21,7 +21,7 @@
#include <filesystem> #include <filesystem>
#include <iacore/exception.hpp> #include <iacore/exception.hpp>
#include <iacore/string.hpp> #include <iacore/string.hpp>
#include <iacore/vector.hpp>
namespace ia namespace ia
{ {
@ -35,6 +35,19 @@ namespace ia
OPEN_FLAG_BINARY = 4, 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: public:
File(IN CONST String &path, IN UINT32 flags) File(IN CONST String &path, IN UINT32 flags)
{ {
@ -78,6 +91,23 @@ namespace ia
return readSize; 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: public:
template<BOOL includeExtension> STATIC INLINE String ExtractFilenameFromPath(IN CONST String &path) template<BOOL includeExtension> STATIC INLINE String ExtractFilenameFromPath(IN CONST String &path)
{ {

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

@ -16,38 +16,8 @@
#pragma once #pragma once
#include "file.hpp" #include "iacore/container/span.inl"
namespace ia 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,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[]) 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; return 0;
} }

View File

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