Compare commits

...

25 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
38 changed files with 1127 additions and 247 deletions

View File

@ -1,5 +1,6 @@
{ {
"files.associations": { "files.associations": {
"*.rml": "html",
"stdexcept": "cpp", "stdexcept": "cpp",
"chrono": "cpp", "chrono": "cpp",
"forward_list": "cpp", "forward_list": "cpp",
@ -67,6 +68,11 @@
"iostream": "cpp", "iostream": "cpp",
"map": "cpp", "map": "cpp",
"ostream": "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", "label": "build",
"type": "shell", "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": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true

View File

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

View File

@ -3,3 +3,7 @@ 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) 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

@ -16,7 +16,7 @@
#pragma once #pragma once
#include "interface/StreamReader.interface.inl" #include "Interface/StreamReader.interface.inl"
namespace ia namespace ia
{ {
@ -62,7 +62,7 @@ namespace ia
VOID MemoryStreamReader::Read(IN INT64 size, IN PUINT8 buffer) VOID MemoryStreamReader::Read(IN INT64 size, IN PUINT8 buffer)
{ {
IA_RELEASE_ASSERT((m_cursor + size) <= m_buffer.size()); IA_RELEASE_ASSERT((m_cursor + size) <= m_buffer.size());
memcpy_s(buffer, size, &m_buffer[m_cursor], size); memcpy(buffer, &m_buffer[m_cursor], size);
m_cursor += size; m_cursor += size;
} }
@ -113,7 +113,7 @@ namespace ia
FileStreamReader::FileStreamReader(IN PCCHAR filePath) FileStreamReader::FileStreamReader(IN PCCHAR filePath)
{ {
fopen_s(&m_filePtr, filePath, "rb"); m_filePtr = fopen(filePath, "rb");
if (!m_filePtr) if (!m_filePtr)
THROW_FILE_OPEN_READ(filePath); THROW_FILE_OPEN_READ(filePath);
} }

View File

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

View File

@ -23,6 +23,11 @@ namespace ia
template<typename _type> template<typename _type>
concept hashable_type = std::derived_from<_type, IIHashable>; concept hashable_type = std::derived_from<_type, IIHashable>;
template<typename T>
concept comparible_type = requires(T a, T b) {
{ a == b } -> std::same_as<bool>;
};
INLINE UINT64 IIHashable::fnv_1a(IN PCUINT8 data, IN SIZE_T dataLength) 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 // Implemented as described at http://isthe.com/chongo/tech/comp/fnv/#google_vignette
@ -34,4 +39,4 @@ namespace ia
} }
return hash; return hash;
} }
} } // namespace ia

View File

@ -23,7 +23,7 @@
namespace ia namespace ia
{ {
template<typename _key_type, typename _value_type, typename _allocator_type = GeneralAllocator<_value_type>, CONST SIZE_T _alignment = 1> 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 class Map
{ {
STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000; STATIC CONSTEXPR SIZE_T BUCKET_COUNT = 1000;

View File

@ -18,10 +18,14 @@
#include "interface/map.interface.inl" #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 __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 __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_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 #define define_const_member_function(return_type, name, ...) \
__template return_type __ia_identifier::name(__VA_ARGS__) CONST
namespace ia namespace ia
{ {
@ -33,7 +37,7 @@ namespace ia
define_member_function(, ~Map, ) define_member_function(, ~Map, )
{ {
} }
} } // namespace ia
namespace ia namespace ia
{ {
@ -64,20 +68,27 @@ namespace ia
} }
return false; return false;
} }
} } // namespace ia
namespace ia namespace ia
{ {
define_member_function(List<typename __ia_identifier::KeyValuePair> &, getBucket, IN CONST key_type &key) 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]; return m_buckets[key.hash() % BUCKET_COUNT];
} }
define_const_member_function(CONST List<typename __ia_identifier::KeyValuePair>&, getBucket, IN CONST key_type& key) 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]; return m_buckets[key.hash() % BUCKET_COUNT];
} }
} } // namespace ia
#undef __template #undef __template
#undef __ia_identifier #undef __ia_identifier

View File

@ -19,11 +19,18 @@
#include <IACore/Base.hpp> #include <IACore/Base.hpp>
#include <memory> #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 namespace ia
{ {
template<typename _value_type> template<typename _value_type> using RefPtr = std::shared_ptr<_value_type>;
using RefPtr = std::shared_ptr<_value_type>;
template<typename _value_type, typename... Args> template<typename _value_type, typename... Args> INLINE RefPtr<_value_type> MakeRefPtr(Args &&...args)
INLINE RefPtr<_value_type> MakeRefPtr(Args... args) { return std::make_shared<_value_type>(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 #pragma once
#include <IACore/base.hpp> #include <IACore/Base.hpp>
namespace ia namespace ia
{ {

View File

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

View File

@ -133,3 +133,10 @@ namespace ia
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); 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

@ -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
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
namespace ia
{
}

View File

@ -0,0 +1,40 @@
// 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/environment.interface.inl"
#include "common.inl"
namespace ia
{
String Environment::GetVar(IN CONST String &name)
{
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;
}
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 #pragma once
#include <IACore/Container.hpp> #include <IACore/Vector.hpp>
namespace ia 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 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 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: public:
VOID operator+=(IN char_type v) VOID operator+=(IN char_type v)
{ {

View File

@ -228,6 +228,32 @@ namespace ia
return { Base::m_data + insert_at + n }; 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 put_element
#undef move_element #undef move_element
#undef move_elements #undef move_elements

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

@ -19,13 +19,14 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <new>
#include <cstddef>
#include <concepts>
#include <functional>
#include <assert.h> #include <assert.h>
#include <type_traits> #include <concepts>
#include <cstddef>
#include <functional>
#include <initializer_list> #include <initializer_list>
#include <new>
#include <sstream>
#include <type_traits>
#define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v) #define IAC_SEC_LEVEL(v) (IACORE_SECURITY_LEVEL >= v)
@ -112,13 +113,14 @@
#define CAST(v, t) ((t) v) #define CAST(v, t) ((t) v)
#define ALIAS_FUNCTION(alias, function) template <typename... Args> \ #define ALIAS_FUNCTION(alias, function) \
auto alias(Args&&... args) -> decltype(f(std::forward<Args>(args)...)) \ template<typename... Args> auto alias(Args &&...args) -> decltype(f(std::forward<Args>(args)...)) \
{ \ { \
return function(std::forward<Args>(args)...); \ return function(std::forward<Args>(args)...); \
} }
#define ALIAS_TEMPLATE_FUNCTION(t, alias, function) template <typename t, typename... Args> \ #define ALIAS_TEMPLATE_FUNCTION(t, alias, function) \
template<typename t, typename... Args> \
auto alias(Args &&...args) -> decltype(function<t>(std::forward<Args>(args)...)) \ auto alias(Args &&...args) -> decltype(function<t>(std::forward<Args>(args)...)) \
{ \ { \
return function<t>(std::forward<Args>(args)...); \ return function<t>(std::forward<Args>(args)...); \
@ -149,6 +151,32 @@
#define IA_MAX_POSSIBLE_SIZE (static_cast<SIZE_T>(0x7FFFFFFFFFFFF)) #define IA_MAX_POSSIBLE_SIZE (static_cast<SIZE_T>(0x7FFFFFFFFFFFF))
#define IA_MAX_STRING_LENGTH (IA_MAX_POSSIBLE_SIZE >> 8) #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_BLACK "\033[30m"
#define __CC_RED "\033[31m" #define __CC_RED "\033[31m"
#define __CC_GREEN "\033[32m" #define __CC_GREEN "\033[32m"

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 #pragma once
#include <IACore/String.hpp> #include <IACore/Logger.hpp>
namespace ia { namespace ia {
enum class ExceptionKind { enum class ExceptionKind {
@ -131,7 +131,9 @@ private:
DO(SECURITY_BYPASS) DO(SECURITY_BYPASS)
#define DEFINE_THROWER(name) \ #define DEFINE_THROWER(name) \
template <typename... Args> NORETURN VOID THROW_##name(Args... args) { \ 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); FOR_EACH_RUNTIME_EXCEPT_TYPE(DEFINE_THROWER);
#undef DEFINE_THROWER #undef DEFINE_THROWER

View File

@ -20,6 +20,10 @@
#include <IACore/String.hpp> #include <IACore/String.hpp>
#include <IACore/Vector.hpp> #include <IACore/Vector.hpp>
#ifdef __ANDROID__
#include <android/asset_manager.h>
#endif
namespace ia namespace ia
{ {
class File class File

View File

@ -18,30 +18,57 @@
#include <IACore/String.hpp> #include <IACore/String.hpp>
#ifdef __ANDROID__
#include <android/log.h>
#endif
namespace ia namespace ia
{ {
class Logger class Logger
{ {
public: public:
template<typename... Args> STATIC VOID Info(Args... args) template<typename... Args> STATIC VOID Info(PCCHAR tag, Args... args)
{ {
StringStream ss; StringStream ss;
UNUSED((ss << ... << args)); UNUSED((ss << ... << args));
printf("\033[32m[INFO]: %s\033[39m\n", ss.str().c_str()); #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 Warn(Args... args) template<typename... Args> STATIC VOID Success(PCCHAR tag, Args... args)
{ {
StringStream ss; StringStream ss;
UNUSED((ss << ... << args)); UNUSED((ss << ... << args));
printf("\033[33m[WARN]: %s\033[39m\n", ss.str().c_str()); #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 Error(Args... args) template<typename... Args> STATIC VOID Warn(PCCHAR tag, Args... args)
{ {
StringStream ss; StringStream ss;
UNUSED((ss << ... << args)); UNUSED((ss << ... << args));
printf("\033[31m[ERROR]: %s\033[39m\n", ss.str().c_str()); #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: private:

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

View File

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

View File

@ -18,10 +18,12 @@
#include <IACore/Checks.hpp> #include <IACore/Checks.hpp>
#include <limits>
namespace ia namespace ia
{ {
template<typename _value_type> template<typename _value_type> using InitializerList = std::initializer_list<_value_type>;
using initializer_list = std::initializer_list<_value_type>; template<typename _value_type> using initializer_list = std::initializer_list<_value_type>;
#undef VOID #undef VOID
typedef void VOID; typedef void VOID;
@ -97,6 +99,9 @@ namespace ia
typedef CONST FLOAT32 PCFLOAT32; typedef CONST FLOAT32 PCFLOAT32;
typedef CONST FLOAT64 PCFLOAT64; typedef CONST FLOAT64 PCFLOAT64;
template<typename function_type>
using Function = std::function<function_type>;
/* Uses the UEFI standard GUID structure definition */ /* Uses the UEFI standard GUID structure definition */
typedef struct _IA_GUID typedef struct _IA_GUID
{ {
@ -113,23 +118,38 @@ namespace ia
} }
} GUID; } GUID;
STATIC CONSTEXPR FLOAT32 FLOAT32_EPSILON = std::numeric_limits<FLOAT32>::epsilon();
STATIC CONSTEXPR FLOAT32 FLOAT64_EPSILON = std::numeric_limits<FLOAT64>::epsilon();
namespace types namespace types
{ {
static BOOL __internal_validate_types() static BOOL __internal_validate_types()
{ {
if(sizeof(CHAR) != static_cast<size_t>(1)) return false; if (sizeof(CHAR) != static_cast<size_t>(1))
if(sizeof(INT8) != static_cast<size_t>(1)) return false; return false;
if(sizeof(INT16) != static_cast<size_t>(2)) return false; if (sizeof(INT8) != static_cast<size_t>(1))
if(sizeof(INT32) != static_cast<size_t>(4)) return false; return false;
if(sizeof(INT64) != static_cast<size_t>(8)) return false; if (sizeof(INT16) != static_cast<size_t>(2))
if(sizeof(UINT8) != static_cast<size_t>(1)) return false; return false;
if(sizeof(UINT16) != static_cast<size_t>(2)) return false; if (sizeof(INT32) != static_cast<size_t>(4))
if(sizeof(UINT32) != static_cast<size_t>(4)) return false; return false;
if(sizeof(UINT64) != static_cast<size_t>(8)) return false; if (sizeof(INT64) != static_cast<size_t>(8))
if(sizeof(FLOAT32) != static_cast<size_t>(4)) return false; return false;
if(sizeof(FLOAT64) != static_cast<size_t>(8)) return false; if (sizeof(UINT8) != static_cast<size_t>(1))
if(sizeof(PVOID) < static_cast<size_t>(4)) return false; return false;
if (sizeof(UINT16) != static_cast<size_t>(2))
return false;
if (sizeof(UINT32) != static_cast<size_t>(4))
return false;
if (sizeof(UINT64) != static_cast<size_t>(8))
return false;
if (sizeof(FLOAT32) != static_cast<size_t>(4))
return false;
if (sizeof(FLOAT64) != static_cast<size_t>(8))
return false;
if (sizeof(PVOID) < static_cast<size_t>(4))
return false;
return true; return true;
} }
} } // namespace types
} } // namespace ia

View File

@ -1,34 +1,38 @@
#include <IACore/Logger.hpp>
#include <IACore/File.hpp> #include <IACore/File.hpp>
#include <IACore/Logger.hpp>
#include <IACore/Vector.hpp>
#include <IACore/Map.hpp> #include <IACore/Map.hpp>
#include <IACore/Vector.hpp>
#include <IACore/Process.hpp>
#include <IACore/Environment.hpp>
#include <IACore/DynamicLib.hpp>
using namespace ia; using namespace ia;
template<typename _value_type> template<typename _value_type> VOID print(IN CONST Span<_value_type> &s)
VOID print(IN CONST Span<_value_type>& s)
{ {
for (const auto &v : s) for (const auto &v : s)
Logger::Info(v); Logger::Info("IACore", v);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Vector<int> v1{10, 20, 32}; /*ector<int> v1{10, 20, 32};
print(v1); print(v1);
List<int> l1; List<int> l1;
Map<String, int> m1; Map<String, int> m1;
m1["sdd"] = 2; m1["sdd"] = 2;
m1["bx"] = 5; m1["bx"] = 5;
for (const auto &v : m1) for (const auto &v : m1)
{
printf("%s, %i\n", v->Key.c_str(), v->Value); printf("%s, %i\n", v->Key.c_str(), v->Value);
} SubProcess p("clang++");
p.Launch("a.cpp", [](IN CONST String &line) { printf("[\n%s\n]\n", line.c_str()); });*/
//printf("[%s]\n", Environment::GetVar("IAEDK_ROOT").c_str());
//Environment::SetVar("IAEDK_ROOT", "C:\\IAEDK");
//printf("[%s]\n", Environment::GetVar("IAEDK_ROOT").c_str());
return 0; return 0;
} }