Compare commits

..

39 Commits

Author SHA1 Message Date
38b6137c38 Fixes 2025-11-22 12:48:18 +05:30
1118ec3205 Fixes 2025-11-08 23:46:27 +05:30
a7abdbae57 Fixes 2025-11-07 00:16:34 +05:30
c1cad88224 Add DynamicLib 2025-11-05 23:55:15 +05:30
cdc44137e8 Fixes 2025-11-03 01:46:13 +05:30
2498e7d6e3 Fixes 2025-10-31 17:18:42 +05:30
3add03dcc0 Fixes 2025-10-31 11:16:30 +05:30
f7d4b28744 merge 2025-10-30 23:45:43 +05:30
9f9991494e merge 2025-10-30 23:44:39 +05:30
6c3090f3c6 Add Process, Thread and Environment 2025-10-24 21:11:23 +05:30
5a38f9f36d Merge branch 'main' of https://git.iasoft.dev/dev0/IACore 2025-10-22 09:34:10 +05:30
9bf876f823 Fixes 2025-10-22 09:33:54 +05:30
ee37b0a02b Logger 2025-10-16 13:13:42 +05:30
07638ea7b3 Numeric Limits 2025-10-12 12:52:02 +05:30
6ce5667ada Numeric Limits 2025-10-12 12:51:47 +05:30
5c02010ae1 CLI 2025-10-10 13:30:08 +05:30
af084e0b94 Fix a bug with Map 2025-10-06 00:28:06 +05:30
1815ceb21d Merge branch 'main' of https://git.iasoft.dev/dev0/IACore 2025-10-06 00:11:14 +05:30
71f7ff8a85 Add build flag IA_BUILD_SAMPLES 2025-10-06 00:11:06 +05:30
a73cc7e69c Android Logger Support 2025-10-05 16:17:06 +05:30
66299a7caf Fixes 2025-10-05 01:50:51 +05:30
b38dc220be Fixes 2025-10-03 19:39:54 +05:30
bb2a0501d5 Fixes 2025-10-03 19:25:58 +05:30
0fd33d958e Logger Tag 2025-09-11 13:09:06 +05:30
26debb5534 Logger Tag 2025-09-11 13:07:20 +05:30
8e2e118dd5 HF 2025-09-08 19:54:50 +05:30
ada777c758 HF 2025-09-07 22:25:46 +05:30
e4940eae3b HF 2025-09-07 21:37:18 +05:30
b2f276a491 Restructure 2025-09-07 18:05:06 +05:30
c60810ba7b HF 2025-09-07 18:03:31 +05:30
fd54e8db39 Restructure 2025-09-07 17:53:55 +05:30
503bd51043 StreamReader 2025-09-07 17:43:28 +05:30
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
118 changed files with 2282 additions and 981 deletions

1
.gitignore vendored
View File

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

View File

@ -1,5 +1,6 @@
{
"files.associations": {
"*.rml": "html",
"stdexcept": "cpp",
"chrono": "cpp",
"forward_list": "cpp",
@ -67,6 +68,11 @@
"iostream": "cpp",
"map": "cpp",
"ostream": "cpp",
"xtree": "cpp"
"xtree": "cpp",
"condition_variable": "cpp",
"coroutine": "cpp",
"resumable": "cpp",
"future": "cpp",
"mutex": "cpp"
}
}

2
.vscode/tasks.json vendored
View File

@ -3,7 +3,7 @@
{
"label": "build",
"type": "shell",
"command": "cmake -S. -B./build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ && cmake --build build",
"command": "cmake -S. -B./build -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DIA_BUILD_SAMPLES=ON && cmake --build build",
"group": {
"kind": "build",
"isDefault": true

View File

@ -9,4 +9,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
project(IACore)
add_subdirectory(Src/IACore)
add_subdirectory(Src/IACoreTest)
if(IA_BUILD_SAMPLES)
add_subdirectory(Src/IACoreTest)
endif()

View File

@ -2,3 +2,8 @@
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)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
target_link_libraries(IACore PUBLIC dl)
endif()

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/Vector.hpp>
#include <IACore/Exception.hpp>
namespace ia
{
class IStreamReader
{
public:
STATIC RefPtr<IStreamReader> Create(IN PCCHAR filePath);
STATIC RefPtr<IStreamReader> Create(IN Vector<UINT8> &&data);
public:
PURE_VIRTUAL(BOOL CompareBytes(IN PCUINT8 data, IN INT64 length) CONST);
PURE_VIRTUAL(Vector<UINT8> Read());
PURE_VIRTUAL(Vector<UINT8> Read(IN INT64 size));
PURE_VIRTUAL(VOID Read(IN INT64 size, IN PUINT8 buffer));
PURE_VIRTUAL(UINT8 Read8());
PURE_VIRTUAL(UINT16 Read16());
PURE_VIRTUAL(UINT32 Read32());
PURE_VIRTUAL(UINT64 Read64());
PURE_VIRTUAL(VOID Skip(IN INT64 size));
PURE_VIRTUAL(INT64 Cursor() CONST);
PURE_VIRTUAL(VOID Seek(IN INT64 newCursor));
};
class MemoryStreamReader : public IStreamReader
{
public:
STATIC INLINE RefPtr<IStreamReader> Create(IN Vector<UINT8> &&data);
public:
INLINE BOOL CompareBytes(IN PCUINT8 data, IN INT64 length) CONST;
INLINE Vector<UINT8> Read();
INLINE Vector<UINT8> Read(IN INT64 size);
INLINE VOID Read(IN INT64 size, IN PUINT8 buffer);
INLINE Vector<UINT8> ReadAndInflate(IN INT64 size);
INLINE UINT8 Read8();
INLINE UINT16 Read16();
INLINE UINT32 Read32();
INLINE UINT64 Read64();
VOID Skip(IN INT64 size)
{
m_cursor += size;
}
INT64 Cursor() CONST
{
return m_cursor;
}
VOID Seek(IN INT64 newCursor)
{
m_cursor = newCursor;
}
private:
INT64 m_cursor{};
Vector<UINT8> m_buffer;
private:
INLINE MemoryStreamReader(IN Vector<UINT8> &&data);
};
class FileStreamReader : public IStreamReader
{
public:
STATIC INLINE RefPtr<IStreamReader> Create(IN PCCHAR filePath);
INLINE ~FileStreamReader();
public:
INLINE BOOL CompareBytes(IN PCUINT8 data, IN INT64 length) CONST;
INLINE Vector<UINT8> Read();
INLINE Vector<UINT8> Read(IN INT64 size);
INLINE VOID Read(IN INT64 size, IN PUINT8 buffer);
INLINE Vector<UINT8> ReadAndInflate(IN INT64 size);
INLINE UINT8 Read8();
INLINE UINT16 Read16();
INLINE UINT32 Read32();
INLINE UINT64 Read64();
VOID Skip(IN INT64 size)
{
fseek(m_filePtr, ftell(m_filePtr) + size, SEEK_SET);
}
INT64 Cursor() CONST
{
return ftell(m_filePtr);
}
VOID Seek(IN INT64 newCursor)
{
fseek(m_filePtr, newCursor, SEEK_SET);
}
private:
FILE *m_filePtr{};
private:
INLINE FileStreamReader(IN PCCHAR filePath);
};
INLINE RefPtr<IStreamReader> IStreamReader::Create(IN PCCHAR filePath)
{
return FileStreamReader::Create(filePath);
}
INLINE RefPtr<IStreamReader> IStreamReader::Create(IN Vector<UINT8> &&data)
{
return MemoryStreamReader::Create(std::move(data));
}
} // namespace ia

View File

@ -0,0 +1,196 @@
// 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/StreamReader.interface.inl"
namespace ia
{
RefPtr<IStreamReader> MemoryStreamReader::Create(IN Vector<UINT8> &&data)
{
struct make_shared_enabler : public MemoryStreamReader
{
make_shared_enabler(IN Vector<UINT8> &&data) : MemoryStreamReader(std::move(data))
{
}
};
return std::make_shared<make_shared_enabler>(std::move(data));
}
MemoryStreamReader::MemoryStreamReader(IN Vector<UINT8> &&data) : m_buffer(std::move(data))
{
m_cursor = 0;
}
BOOL MemoryStreamReader::CompareBytes(IN PCUINT8 data, IN INT64 length) const
{
IA_RELEASE_ASSERT((m_cursor + length) <= m_buffer.size());
return !memcmp(&m_buffer[m_cursor], data, length);
}
Vector<UINT8> MemoryStreamReader::Read()
{
Vector<UINT8> res;
res.resize(m_buffer.size() - m_cursor);
Read(res.size(), res.data());
return res;
}
Vector<UINT8> MemoryStreamReader::Read(IN INT64 size)
{
Vector<UINT8> res;
res.resize(size);
Read(size, res.data());
return res;
}
VOID MemoryStreamReader::Read(IN INT64 size, IN PUINT8 buffer)
{
IA_RELEASE_ASSERT((m_cursor + size) <= m_buffer.size());
memcpy(buffer, &m_buffer[m_cursor], size);
m_cursor += size;
}
UINT8 MemoryStreamReader::Read8()
{
IA_RELEASE_ASSERT((m_cursor + 1) <= m_buffer.size());
return m_buffer[m_cursor++];
}
UINT16 MemoryStreamReader::Read16()
{
IA_RELEASE_ASSERT((m_cursor + 2) <= m_buffer.size());
const auto r = *reinterpret_cast<UINT16 *>(&m_buffer[m_cursor]);
m_cursor += 2;
return r;
}
UINT32 MemoryStreamReader::Read32()
{
IA_RELEASE_ASSERT((m_cursor + 4) <= m_buffer.size());
const auto r = *reinterpret_cast<UINT32 *>(&m_buffer[m_cursor]);
m_cursor += 4;
return r;
}
UINT64 MemoryStreamReader::Read64()
{
IA_RELEASE_ASSERT((m_cursor + 8) <= m_buffer.size());
const auto r = *reinterpret_cast<UINT64 *>(&m_buffer[m_cursor]);
m_cursor += 8;
return r;
}
} // namespace ia
namespace ia
{
RefPtr<IStreamReader> FileStreamReader::Create(IN PCCHAR filePath)
{
struct make_shared_enabler : public FileStreamReader
{
make_shared_enabler(IN PCCHAR filePath) : FileStreamReader(filePath)
{
}
};
return std::make_shared<make_shared_enabler>(filePath);
}
FileStreamReader::FileStreamReader(IN PCCHAR filePath)
{
m_filePtr = fopen(filePath, "rb");
if (!m_filePtr)
THROW_FILE_OPEN_READ(filePath);
}
FileStreamReader ::~FileStreamReader()
{
if (m_filePtr)
fclose(m_filePtr);
}
BOOL FileStreamReader::CompareBytes(IN PCUINT8 data, IN INT64 length) CONST
{
IA_RELEASE_ASSERT(m_filePtr);
STATIC Vector<UINT8> TmpBuffer;
if (TmpBuffer.size() < length)
TmpBuffer.resize(length);
IA_RELEASE_ASSERT(fread(TmpBuffer.data(), 1, length, m_filePtr) == length);
return !memcmp(TmpBuffer.data(), data, length);
}
Vector<UINT8> FileStreamReader::Read()
{
IA_RELEASE_ASSERT(m_filePtr);
Vector<UINT8> result;
const auto s = ftell(m_filePtr);
fseek(m_filePtr, 0, SEEK_END);
const auto e = ftell(m_filePtr);
fseek(m_filePtr, s, SEEK_SET);
result.resize(e - s);
IA_RELEASE_ASSERT(fread(result.data(), 1, result.size(), m_filePtr) == result.size());
return result;
}
Vector<UINT8> FileStreamReader::Read(IN INT64 size)
{
IA_RELEASE_ASSERT(m_filePtr);
Vector<UINT8> result;
result.resize(size);
IA_RELEASE_ASSERT(fread(result.data(), 1, size, m_filePtr) == size);
return result;
}
VOID FileStreamReader::Read(IN INT64 size, IN PUINT8 buffer)
{
IA_RELEASE_ASSERT(m_filePtr);
IA_RELEASE_ASSERT(fread(buffer, 1, size, m_filePtr) == size);
}
UINT8 FileStreamReader::Read8()
{
IA_RELEASE_ASSERT(m_filePtr);
UINT8 result;
IA_RELEASE_ASSERT(fread(&result, 1, 1, m_filePtr) == 1);
return result;
}
UINT16 FileStreamReader::Read16()
{
IA_RELEASE_ASSERT(m_filePtr);
UINT16 result;
IA_RELEASE_ASSERT(fread(&result, 2, 1, m_filePtr) == 1);
return result;
}
UINT32 FileStreamReader::Read32()
{
IA_RELEASE_ASSERT(m_filePtr);
UINT32 result;
IA_RELEASE_ASSERT(fread(&result, 4, 1, m_filePtr) == 1);
return result;
}
UINT64 FileStreamReader::Read64()
{
IA_RELEASE_ASSERT(m_filePtr);
UINT64 result;
IA_RELEASE_ASSERT(fread(&result, 8, 1, m_filePtr) == 1);
return result;
}
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/iterator.hpp>
#include <IACore/Iterator.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/iterator.hpp>
#include <IACore/Iterator.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/container.hpp>
#include <IACore/container.hpp>
namespace ia
{

View File

@ -16,8 +16,8 @@
#pragma once
#include <iacore/exception.hpp>
#include <iacore/vector.hpp>
#include <IACore/exception.hpp>
#include <IACore/vector.hpp>
namespace ia
{

View File

@ -300,6 +300,7 @@ namespace ia
{
const auto did_reallocate = reserve(newCount);
for(; Base::m_count < newCount; Base::m_count++) Base::m_allocator.construct(&Base::m_data[Base::m_count]);
Base::m_count = newCount;
return did_reallocate;
}

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] };
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));
}
}

View File

@ -0,0 +1,175 @@
// 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/Memory.hpp>
#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 Span<_value_type>
{
using Base = Span<_value_type>;
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:
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:
value_type &front()
{
IA_ASSERT(Base::m_count > 0);
return Base::m_data[0];
}
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:
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:
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

@ -16,7 +16,7 @@
#pragma once
#include <iacore/iterator.hpp>
#include <IACore/Iterator.hpp>
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

@ -1,53 +1,42 @@
// 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 "interface/iihashable.interface.inl"
namespace ia
{
class IAML
{
public:
template<typename _type>
concept hashable_type = std::derived_from<_type, IIHashable>;
public:
IAML(IN CONST String& path) { ParseFromFile(path); }
~IAML() {}
private:
VOID ParseFromFile(IN CONST String& path);
VOID ParseFromMemory(IN CONST String& iaml);
template<typename T>
concept comparible_type = requires(T a, T b) {
{ a == b } -> std::same_as<bool>;
};
}
namespace ia
{
VOID IAML::ParseFromFile(IN CONST String& path)
INLINE UINT64 IIHashable::fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength)
{
File f(path, File::OPEN_FLAG_READ);
String data;
data.resize(f.Size() + 1);
f.Read(data.data(), f.Size(), f.Size());
ParseFromMemory(data);
// 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;
}
VOID IAML::ParseFromMemory(IN CONST String& iaml)
{
}
}
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/types.hpp>
#include <IACore/types.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/types.hpp>
#include <IACore/types.hpp>
/*
* -----------------------------------

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/types.hpp>
#include <IACore/types.hpp>
/*
* -----------------------------------

View File

@ -16,11 +16,11 @@
#pragma once
#include <iacore/allocator.hpp>
#include <IACore/Allocator.hpp>
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;

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/allocator.hpp>
#include <IACore/Allocator.hpp>
//#include "iterator.interface.inl"
#include "entry.interface.inl"

View File

@ -16,14 +16,14 @@
#pragma once
#include <iacore/list.hpp>
#include <iacore/vector.hpp>
#include <iacore/hashable.hpp>
#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>
requires (hashable_type<_key_type> || std::is_integral_v<_key_type>) && valid_allocator_type<_allocator_type, _value_type>
class Map
{
STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000;
@ -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;
};
}

View File

@ -0,0 +1,96 @@
// 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> || std::is_integral_v<_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
namespace ia
{
define_member_function(VOID, set, IN CONST key_type &key, IN value_type &&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)
{
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
namespace ia
{
define_member_function(List<typename __ia_identifier::KeyValuePair> &, getBucket, IN CONST key_type &key)
{
if constexpr (std::is_integral_v<key_type>)
return m_buckets[key % BUCKET_COUNT];
else
return m_buckets[key.hash() % BUCKET_COUNT];
}
define_const_member_function(CONST List<typename __ia_identifier::KeyValuePair> &, getBucket,
IN CONST key_type &key)
{
if constexpr (std::is_integral_v<key_type>)
return m_buckets[key % BUCKET_COUNT];
else
return m_buckets[key.hash() % BUCKET_COUNT];
}
} // namespace ia
#undef __template
#undef __ia_identifier
#undef define_member_function
#undef define_const_member_function

View File

@ -47,7 +47,7 @@ namespace ia
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));
const auto aligned_ptr = (size_type)(ptr + sizeof(PVOID) + alignment - (ptr % alignment));
*(reinterpret_cast<size_type*>(aligned_ptr-sizeof(PVOID))) = ptr;
return reinterpret_cast<pointer_type>(aligned_ptr);
}

View File

@ -17,7 +17,7 @@
#pragma once
#include <memory.h>
#include <iacore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -0,0 +1,36 @@
// 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>
#define REF_PTR_CLASS \
template<typename _value_type, typename... Args> friend INLINE RefPtr<_value_type> MakeRefPtr(Args &&...args) \
{ \
return std::make_shared<_value_type>(std::forward<Args>(args)...); \
}
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>(std::forward<Args>(args)...);
}
} // namespace ia

View File

@ -0,0 +1,25 @@
// 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 "platform.inl"
#if (defined(IA_CORE_PLATFORM_FEATUES) && (IA_CORE_PLATFORM_FEATUES > 0))
#if (defined(IA_PLATFORM_WIN64) && (IA_PLATFORM_WIN64 > 0))
#include "win/environment.inl"
#endif
#endif

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/String.hpp>
namespace ia
{
class Environment
{
public:
INLINE STATIC String GetVar(IN CONST String& name);
INLINE STATIC BOOL SetVar(IN CONST String& name, IN CONST String& value);
};
}

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/base.hpp>
#include <IACore/Base.hpp>
namespace ia
{

View File

@ -1,29 +1,34 @@
// 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/base.hpp>
#include <memory>
#include <IACore/String.hpp>
namespace ia
{
template<typename _value_type>
using RefPtr = std::shared_ptr<_value_type>;
class SubProcess
{
public:
INLINE SubProcess(IN CONST String &path);
INLINE ~SubProcess();
template<typename _value_type, typename... Args>
INLINE RefPtr<_value_type> MakeRefPtr(Args... args) { return std::make_shared<_value_type>(args...); }
}
INLINE INT32 Launch(IN CONST String &args, IN Function<VOID(CONST String &)> onOutputLineCallback);
private:
CONST String m_path;
};
} // namespace ia

View File

@ -132,4 +132,11 @@ namespace ia
{
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
}
}
}
#if (defined(IA_PLATFORM_WIN64) && (IA_PLATFORM_WIN64 > 0))
#define IA_CORE_PLATFORM_FEATUES 1
#else
#define IA_CORE_PLATFORM_FEATUES 0
#warning "IACore Unsupported Platform: Platform specific features will be disabled"
#endif

View File

@ -0,0 +1,25 @@
// 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 "platform.inl"
#if (defined(IA_CORE_PLATFORM_FEATUES) && (IA_CORE_PLATFORM_FEATUES > 0))
#if (defined(IA_PLATFORM_WIN64) && (IA_PLATFORM_WIN64 > 0))
#include "win/process.inl"
#endif
#endif

View File

@ -1,24 +1,25 @@
// 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 "interface/xop.interface.inl"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace ia
{
// [IATODO: IMP]
}

View File

@ -1,37 +1,40 @@
// 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 "interface/iihashable.interface.inl"
#include "../interface/environment.interface.inl"
#include "common.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++)
String Environment::GetVar(IN CONST String &name)
{
hash = hash ^ data[i];
hash = hash * 1099511628211ul;
const auto l = GetEnvironmentVariableA(name.c_str(), nullptr, 0);
if (!l)
return "";
String result;
result.resize(l);
GetEnvironmentVariableA(name.c_str(), result.data(), l);
result.back() = '\0';
return result;
}
return hash;
}
}
BOOL Environment::SetVar(IN CONST String &name, IN CONST String &value)
{
return SetEnvironmentVariableA(name.c_str(), value.c_str());
}
} // namespace ia

View File

@ -0,0 +1,137 @@
// 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/process.interface.inl"
#include "common.inl"
#include <IACore/Exception.hpp>
namespace ia
{
SubProcess::SubProcess(IN CONST String &path) : m_path(path)
{
}
SubProcess::~SubProcess()
{
}
INT32 SubProcess::Launch(IN CONST String &args, IN Function<VOID(CONST String &)> onOutputLineCallback)
{
String szCmdline = BuildString(m_path, " ", args);
PROCESS_INFORMATION piProcInfo;
STARTUPINFOA siStartInfo;
BOOL bSuccess = FALSE;
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
HANDLE hRdStdIn{};
HANDLE hWrStdIn{};
HANDLE hRdStdOut{};
HANDLE hWrStdOut{};
SECURITY_ATTRIBUTES saAttr;
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
if (!CreatePipe(&hRdStdIn, &hWrStdIn, &saAttr, 0))
THROW_UNKNOWN("Failed to create a win32 pipe");
if (!SetHandleInformation(hWrStdIn, HANDLE_FLAG_INHERIT, 0))
THROW_UNKNOWN("Failed to update a win32 pipe");
if (!CreatePipe(&hRdStdOut, &hWrStdOut, &saAttr, 0))
THROW_UNKNOWN("Failed to create a win32 pipe");
if (!SetHandleInformation(hRdStdOut, HANDLE_FLAG_INHERIT, 0))
THROW_UNKNOWN("Failed to update a win32 pipe");
ZeroMemory(&siStartInfo, sizeof(STARTUPINFOA));
siStartInfo.cb = sizeof(STARTUPINFOA);
siStartInfo.hStdError = hWrStdOut;
siStartInfo.hStdOutput = hWrStdOut;
siStartInfo.hStdInput = hRdStdIn;
siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
bSuccess = CreateProcessA(NULL,
szCmdline.data(), // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
if (!bSuccess)
THROW_UNKNOWN("Couldn't spawn the child process \"", m_path, "\"");
else
{
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
CloseHandle(hWrStdOut);
CloseHandle(hRdStdIn);
}
CloseHandle(hWrStdIn);
DWORD exitCode{};
while (true)
{
GetExitCodeProcess(piProcInfo.hProcess, &exitCode);
if (exitCode != STILL_ACTIVE)
break;
}
Vector<CHAR> currentLine;
CHAR readBuffer[1024];
while (true)
{
DWORD readSize;
const auto success = ReadFile(hRdStdOut, readBuffer, sizeof(readBuffer), &readSize, NULL);
if ((!success) || (!readSize))
break;
for (DWORD i = 0; i < readSize; i++)
{
if (readBuffer[i] == '\n')
{
String result;
result.resize(currentLine.size() + 1);
memcpy(result.data(), currentLine.data(), currentLine.size());
result[currentLine.size()] = '\0';
currentLine.reset();
onOutputLineCallback(result);
}
else
{
currentLine.append(readBuffer[i]);
}
}
}
if (currentLine.size())
{
String result;
result.resize(currentLine.size() + 1);
memcpy(result.data(), currentLine.data(), currentLine.size());
result[currentLine.size()] = '\0';
onOutputLineCallback(result);
}
return exitCode;
}
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/vector.hpp>
#include <IACore/vector.hpp>
namespace ia
{

View File

@ -38,6 +38,11 @@ namespace ia
StringStream& operator<<(IN CONST String& v) { m_impl << v.c_str(); return *this; }
VOID clear()
{
m_impl.clear();
}
private:
std::stringstream m_impl;
};

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/container.hpp>
#include <IACore/Vector.hpp>
namespace ia
{
@ -96,6 +96,10 @@ namespace ia
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;
INLINE Vector<StringT> split(IN CHAR delimiter);
template<typename _value_type>
INLINE STATIC StringT join(IN CONST Vector<_value_type>& values, IN CHAR delimiter);
public:
VOID operator+=(IN char_type v)
{

View File

@ -228,6 +228,32 @@ namespace ia
return { Base::m_data + insert_at + n };
}
define_member_function(Vector<__ia__identifier>, split, IN CHAR delimiter)
{
Vector<__ia__identifier> result;
SIZE_T t = 0;
for(SIZE_T i = 0; i < length(); i++)
{
if(Base::m_data[i] == delimiter)
{
result.pushBack(slice(t, i + 1));
t = i + 1;
}
}
if(t < length())
result.pushBack(slice(t, Base::m_count));
return result;
}
define_member_function(template<typename _value_type> __ia__identifier, join, IN CONST Vector<_value_type>& values, IN CHAR delimiter)
{
__ia__identifier result;
// [IATODO]
return result;
}
#undef put_element
#undef move_element
#undef move_elements
@ -276,7 +302,11 @@ namespace ia
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]);
for(size_type i = start; i < end; i += stride)
{
new (&res.m_data[res.m_count++]) value_type(Base::m_data[i]);
if(!Base::m_data[i]) break;
}
res.back() = '\0';
return IA_MOVE(res);
}
@ -300,6 +330,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;

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/container.hpp>
#include <IACore/Container.hpp>
namespace ia
{

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/algorithm.hpp>
#include <IACore/Algorithm.hpp>
#include "interface/ordered.interface.inl"

View File

@ -1,139 +0,0 @@
// 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

@ -1,84 +0,0 @@
// 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

@ -16,7 +16,7 @@
#pragma once
#include "iacore/algorithm/binary-search.inl"
#include "iacore/algorithm/quick-sort.inl"
#include "IACore/algorithm/binary-search.inl"
#include "IACore/algorithm/quick-sort.inl"
namespace ia {}

View File

@ -16,7 +16,7 @@
#pragma once
#include "iacore/memory/allocator/general.inl"
#include "iacore/memory/allocator/orchestrator.inl"
#include "IACore/memory/allocator/general.inl"
#include "IACore/memory/allocator/orchestrator.inl"
namespace ia {}

View File

@ -16,6 +16,6 @@
#pragma once
#include "iacore/array/array.inl"
#include "IACore/array/array.inl"
namespace ia {}

View File

@ -17,13 +17,13 @@
#pragma once
#if __STDC_HOSTED__ and !IACORE_FREESTANDING
#include <iacore/types.hpp>
#include <IACore/Types.hpp>
#include <stdlib.h>
#include <math.h>
#include <cstring>
#define _lib_impl_ std
#else
#include "iacore/lib.hpp"
#include "IACore/lib.hpp"
#define _lib_impl_ ia
#endif

View File

@ -16,6 +16,6 @@
#pragma once
#include "iacore/bytestring/bytestring.inl"
#include "IACore/bytestring/bytestring.inl"
namespace ia {}

View File

@ -0,0 +1,218 @@
// 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.hpp>
#include <IACore/String.hpp>
#include <IACore/Vector.hpp>
namespace ia
{
class CLI
{
public:
enum class ParameterValueType
{
INT,
STRING,
INT_LIST,
STRING_LIST
};
struct ParameterValue
{
ParameterValueType Type{};
INT32 IntValue{};
String StringValue{};
Vector<INT32> IntListValue{};
Vector<String> StringListValue{};
};
struct ParameterDesc
{
String ID;
String Help;
BOOL IsOptional{};
ParameterValueType Type{};
};
struct SwitchDesc
{
String ID;
String Help;
};
struct CommandDesc
{
String ID;
CHAR Shorthand{};
String Help;
Vector<SwitchDesc> Switches;
Vector<ParameterDesc> Parameters;
std::function<INT32(IN Map<String, ParameterValue> &&parameters, IN Map<String, BOOL> &&switchValues)>
Action;
};
public:
CLI(IN CONST String &appName, IN IA_VERSION_TYPE appVersion, IN CONST String &copyrightNotice)
: m_appName(appName), m_appVersion(IA_STRINGIFY_VERSION(appVersion)), m_copyrightNotice(copyrightNotice)
{
RegisterCommand({
.ID = "help",
.Shorthand = 'h',
.Help = "Displays this help menu",
.Action =
[&](IN Map<String, ParameterValue> &&parameters, IN Map<String, BOOL> &&switchValues) {
DisplayHelp();
return 0;
},
});
}
INLINE INT32 Run(IN INT32 argc, IN PCCHAR argv[]);
protected:
INLINE VOID RegisterCommand(IN CONST CommandDesc &desc);
private:
INLINE VOID DisplayHelp();
private:
CONST String m_appName;
CONST String m_appVersion;
CONST String m_copyrightNotice;
Map<String, CommandDesc> m_commands;
};
} // namespace ia
namespace ia
{
INT32 CLI::Run(IN INT32 argc, IN PCCHAR argv[])
{
printf(__CC_WHITE "%s %s\n%s\n\n" __CC_DEFAULT, m_appName.c_str(), m_appVersion.c_str(),
m_copyrightNotice.c_str());
if (argc < 2)
{
DisplayHelp();
return 0;
}
if (!m_commands.contains(argv[1]))
{
printf(__CC_RED "No such known command \"%s\".\n" __CC_YELLOW
"TIP: Use \"help\" to see available commands!" __CC_DEFAULT "\n",
argv[1]);
return -1;
}
const auto cmd = m_commands[argv[1]];
const auto requiredParamCount = (INT32) cmd.Parameters.size();
if ((requiredParamCount << 1) >= (argc - 1))
{
printf(__CC_RED "Command \"%s\" requires at least %i parameter(s).\n" __CC_YELLOW
"TIP: Use \"help\" to see correct usages!" __CC_DEFAULT "\n",
argv[1], requiredParamCount);
return -1;
}
Map<String, ParameterDesc> params;
for (const auto &t : cmd.Parameters)
params[t.ID] = t;
Map<String, ParameterValue> paramValues;
for (INT32 i = 2; i < argc; i++)
{
if (argv[i][0] == '-')
{
const auto paramName = &(argv[i][1]);
if (!params.contains(paramName))
{
printf(__CC_RED "No such parameter \"%s\".\n" __CC_YELLOW
"TIP: Use \"help\" to see correct usages!" __CC_DEFAULT "\n",
argv[i]);
return -3;
}
const auto& p = params[paramName];
// Read parameter value
const auto value = argv[++i];
switch(p.Type)
{
case ParameterValueType::INT:
paramValues[paramName] = ParameterValue{.Type = p.Type};
break;
case ParameterValueType::STRING:
paramValues[paramName] = ParameterValue{.Type = p.Type, .StringValue = value};
break;
case ParameterValueType::INT_LIST:
paramValues[paramName] = ParameterValue{.Type = p.Type};
break;
case ParameterValueType::STRING_LIST:
paramValues[paramName] = ParameterValue{.Type = p.Type};
break;
}
}
else if (argv[i][0] == '/')
{
}
else
{
printf(__CC_RED "Invalid command syntax, expected a parameter('-') or a switch('/')." __CC_DEFAULT
"\n");
return -2;
}
}
cmd.Action(IA_MOVE(paramValues), {});
return 0;
}
VOID CLI::DisplayHelp()
{
INT32 i{1};
for (const auto &t : m_commands)
{
printf(__CC_WHITE "%i) " __CC_GREEN "%s (%c) " __CC_YELLOW "- %s\n", i, t->Value.ID.c_str(),
t->Value.Shorthand, t->Value.Help.c_str());
for (const auto &v : t->Value.Parameters)
{
printf(__CC_WHITE "\t-%s %s %s\n", v.ID.c_str(), v.IsOptional ? "(optional)" : "", v.Help.c_str());
}
for (const auto &v : t->Value.Switches)
{
printf(__CC_WHITE "//%s %s\n", v.ID.c_str(), v.Help.c_str());
}
printf(__CC_DEFAULT "\n");
i++;
}
}
VOID CLI::RegisterCommand(IN CONST CommandDesc &desc)
{
m_commands[desc.ID] = desc;
}
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include "iacore/definitions.hpp"
#include <IACore/Definitions.hpp>
#if __IA_DEBUG || IAC_SEC_LEVEL(1)
#define __IAC_OVERFLOW_CHECKS 1

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/container/span.inl"
#include "IACore/container/fixed.inl"
#include "IACore/container/dynamic.inl"
namespace ia {}

View File

@ -0,0 +1,188 @@
// 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 <assert.h>
#include <concepts>
#include <cstddef>
#include <functional>
#include <initializer_list>
#include <new>
#include <sstream>
#include <type_traits>
#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 IA_VERSION_TYPE UINT64
#define IA_MAKE_VERSION(major, minor, patch) \
((static_cast<UINT64>(major) & 0xFFFFFF) << 40) | ((static_cast<UINT64>(minor) & 0xFFFFFF) << 16) | \
(static_cast<UINT64>(patch) & 0xFFFF)
#define IA_STRINGIFY_VERSION(version) \
BuildString("v", (version >> 40) & 0xFFFFFF, ".", (version >> 16) & 0xFFFFFF, ".", version & 0xFFFF)
#define IA_PARSE_VERSION_STRING(versionString) \
[](IN std::string str) { \
INT32 minor, major, patch; \
char dot; \
std::stringstream ss(str); \
ss >> major >> dot >> minor >> dot >> patch; \
return IA_MAKE_VERSION(major, minor, patch); \
}(versionString)
#if defined(_MSC_VER)
#define IA_DLL_EXPORT __declspec(dllexport)
#define IA_DLL_IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
#define IA_DLL_EXPORT __attribute__((visibility("default")))
#define IA_DLL_IMPORT
#else
#define IA_DLL_EXPORT
#define IA_DLL_IMPORT
#endif
#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,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/Exception.hpp>
#include <IACore/String.hpp>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#elif defined(__linux__) || defined(__APPLE__)
#include <dlfcn.h>
#endif
namespace ia
{
class DynamicLib
{
public:
STATIC INLINE DynamicLib Load(IN CONST String &searchPath, IN CONST String &name);
INLINE ~DynamicLib();
INLINE VOID Destroy();
public:
INLINE PVOID GetSymbol(IN CONST String &name);
template<typename FunctionType> FunctionType GetFunction(IN CONST String &name)
{
return reinterpret_cast<FunctionType>(GetSymbol(name));
}
private:
INLINE DynamicLib(IN PVOID moduleHandle);
private:
CONST PVOID m_moduleHandle;
};
} // namespace ia
namespace ia
{
DynamicLib::DynamicLib(IN PVOID moduleHandle) : m_moduleHandle(moduleHandle)
{
}
DynamicLib::~DynamicLib()
{
}
#if defined(_WIN32)
DynamicLib DynamicLib::Load(IN CONST String &searchPath, IN CONST String &name)
{
const auto handle = LoadLibraryA(BuildString(searchPath, "/", name, ".dll").c_str());
if (handle == NULL)
THROW_UNKNOWN("DynamicLib: Failed to load the library \"", name, "\" with error: ", GetLastError());
return DynamicLib((PVOID) handle);
}
PVOID DynamicLib::GetSymbol(IN CONST String &name)
{
const auto symbol = GetProcAddress(static_cast<HMODULE>(m_moduleHandle), name.c_str());
if (symbol == NULL)
THROW_UNKNOWN("DynamicLib: Failed to find the symbol \"", name, "\" with error: ", GetLastError());
return (PVOID) symbol;
}
VOID DynamicLib::Destroy()
{
if (m_moduleHandle)
FreeLibrary(static_cast<HMODULE>(m_moduleHandle));
}
#else
DynamicLib DynamicLib::Load(IN CONST String &searchPath, IN CONST String &name)
{
dlerror();
const auto handle = dlopen(BuildString(searchPath, "/", name, ".so").c_str(), RTLD_LAZY);
if (handle == NULL)
THROW_UNKNOWN("DynamicLib: Failed to load the library \"", name, "\" with error: ", dlerror());
return DynamicLib((PVOID) handle);
}
PVOID DynamicLib::GetSymbol(IN CONST String &name)
{
dlerror();
const auto symbol = dlsym(m_moduleHandle, name.c_str());
const char *dlsym_error = dlerror();
if (dlsym_error)
THROW_UNKNOWN("DynamicLib: Failed to find the symbol \"", name, "\" with error: ", dlerror());
return (PVOID) symbol;
}
VOID DynamicLib::Destroy()
{
if (m_moduleHandle)
dlclose(m_moduleHandle);
}
#endif
} // 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/platform/environment.inl>
namespace ia
{
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include <iacore/string.hpp>
#include <IACore/Logger.hpp>
namespace ia {
enum class ExceptionKind {
@ -131,7 +131,9 @@ private:
DO(SECURITY_BYPASS)
#define DEFINE_THROWER(name) \
template <typename... Args> NORETURN VOID THROW_##name(Args... args) { \
throw RuntimeException(ExceptionKind::name, BuildString(args...)); \
const auto msg = BuildString(args...); \
Logger::Error("EXCEPT", "(", #name, "): ", msg); \
throw RuntimeException(ExceptionKind::name, msg); \
}
FOR_EACH_RUNTIME_EXCEPT_TYPE(DEFINE_THROWER);
#undef DEFINE_THROWER

View File

@ -16,12 +16,13 @@
#pragma once
#include "iacore/types.hpp"
#include <cstdio>
#include <filesystem>
#include <iacore/exception.hpp>
#include <iacore/string.hpp>
#include <IACore/Exception.hpp>
#include <IACore/String.hpp>
#include <IACore/Vector.hpp>
#ifdef __ANDROID__
#include <android/asset_manager.h>
#endif
namespace ia
{
@ -35,6 +36,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,26 +92,54 @@ namespace ia
return readSize;
}
public:
template<BOOL includeExtension> STATIC INLINE String ExtractFilenameFromPath(IN CONST String &path)
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 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);
auto t = path.rfind(pathDelimiter);
if (t == path.end())
{
if constexpr (includeExtension)
return path.slice(path.begin(), path.cend());
if CONSTEXPR (includeExtension)
return path;
return path.slice(path.begin(), path.rfind('.', 0));
return path.slice(0, path.rfind('.'));
}
if constexpr (includeExtension)
return path.slice(t + 1, path.cend());
return path.slice(t + 1, path.end());
return path.slice(t + 1, path.rfind('.', 0));
return path.slice(t + 1, path.rfind('.'));
}
template<BOOL includeTrailingSlash> STATIC String ExtractDirectoryFromPath(IN CONST String &path)
{
constexpr char pathDelimiter = '/';
auto t = path.rfind(pathDelimiter);
if (t == path.end())
return "./";
if CONSTEXPR (includeTrailingSlash)
return path.slice(path.begin(), t + 1);
else
return path.slice(path.begin(), t);
}
private:

View File

@ -16,6 +16,6 @@
#pragma once
#include "iacore/hashable/iihashable.inl"
#include "IACore/hashable/iihashable.inl"
namespace ia {}

View File

@ -23,7 +23,7 @@
#include <string>
#include <vector>
#include <iacore/types.hpp>
#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)

View File

@ -16,6 +16,6 @@
#pragma once
#include "iacore/iterator/iterator.inl"
#include "IACore/iterator/iterator.inl"
namespace ia {}

View File

@ -16,7 +16,8 @@
#pragma once
#include "iacore/container/fixed.inl"
#include "iacore/container/dynamic.inl"
#include "IACore/lib/math.inl"
#include "IACore/lib/mem.inl"
#include "IACore/lib/str.inl"
namespace ia {}

View File

@ -16,6 +16,6 @@
#pragma once
#include "iacore/list/list.inl"
#include "IACore/list/list.inl"
namespace ia {}

View File

@ -0,0 +1,83 @@
// 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>
#ifdef __ANDROID__
#include <android/log.h>
#endif
namespace ia
{
class Logger
{
public:
template<typename... Args> STATIC VOID Info(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "IAApp", "%s", ss.str().c_str());
#else
printf("\033[0;37m[INFO]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Success(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "IAApp", "%s", ss.str().c_str());
#else
printf("\033[32m[SUCCESS]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Warn(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_DEBUG, "IAApp", "%s", ss.str().c_str());
#else
printf("\033[33m[WARN]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
template<typename... Args> STATIC VOID Error(PCCHAR tag, Args... args)
{
StringStream ss;
UNUSED((ss << ... << args));
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_ERROR, "IAApp", "%s", ss.str().c_str());
#else
printf("\033[31m[ERROR]: [%s] %s\033[39m\n", tag, ss.str().c_str());
#endif
}
private:
Logger()
{
}
~Logger()
{
}
};
} // namespace ia

View File

@ -16,7 +16,7 @@
#pragma once
#include "iacore/map/map.inl"
#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

@ -16,6 +16,6 @@
#pragma once
#include "iacore/platform/platform.inl"
#include "IACore/platform/platform.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/platform/process.inl>
namespace ia
{
} // namespace ia

Some files were not shown because too many files have changed in this diff Show More