From fd5ed562a19e4f36b192765961268ff7dc59a75f Mon Sep 17 00:00:00 2001 From: Rafal Zabdyr Date: Mon, 15 Sep 2025 20:13:32 +0200 Subject: [PATCH 1/2] Checkpoint from VS Code for coding agent session --- .vscode/settings.json | 53 +++ AmigaOS.cpp.wrapper.code-workspace | 54 ++- wrappers/src/AOS/Cybergraphics/Library.cpp | 2 + wrappers/src/AOS/Dos/Library.hpp | 2 +- wrappers/src/AOS/Icon/DiskObjectScope.cpp | 4 +- wrappers/src/AOS/Icon/DiskObjectScope.hpp | 4 +- wrappers/src/AOS/TagUtil.cpp | 61 +++ wrappers/src/Core/ToString.hpp | 6 + wrappers/src/Core/ToString.tmp | 27 ++ wrappers/src/amiga_std_light/vector.hpp | 0 wrappers/src/std/optional.hpp | 432 +++++++++++++++++++ wrappers/src/temp/string.cpp | 473 +++++++++++++++++++++ wrappers/src/temp/string.hpp | 131 ++++++ wrappers/src/temp/vector.hpp | 374 ++++++++++++++++ 14 files changed, 1617 insertions(+), 6 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 wrappers/src/Core/ToString.tmp create mode 100644 wrappers/src/amiga_std_light/vector.hpp create mode 100644 wrappers/src/std/optional.hpp create mode 100644 wrappers/src/temp/string.cpp create mode 100644 wrappers/src/temp/string.hpp create mode 100644 wrappers/src/temp/vector.hpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6d2038d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,53 @@ +{ + "files.associations": { + "*.inc": "php", + "string": "cpp", + "vector": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "ratio": "cpp", + "set": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/AmigaOS.cpp.wrapper.code-workspace b/AmigaOS.cpp.wrapper.code-workspace index 517e0b2..1f35a6c 100644 --- a/AmigaOS.cpp.wrapper.code-workspace +++ b/AmigaOS.cpp.wrapper.code-workspace @@ -4,5 +4,57 @@ "path": "." } ], - "settings": {} + "settings": { + "files.associations": { + "*.inc": "php", + "stdexcept": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "set": "cpp", + "string": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp", + "chrono": "cpp", + "ratio": "cpp" + } + } } \ No newline at end of file diff --git a/wrappers/src/AOS/Cybergraphics/Library.cpp b/wrappers/src/AOS/Cybergraphics/Library.cpp index 0c0aea2..8db0ecb 100644 --- a/wrappers/src/AOS/Cybergraphics/Library.cpp +++ b/wrappers/src/AOS/Cybergraphics/Library.cpp @@ -56,6 +56,8 @@ namespace AOS::Cybergraphics std::vector Library::GetBoards() noexcept { + // return { BoardID::Pixel64, BoardID::BlizzardVisionPPC, BoardID::RainbowIII }; + std::vector boards; for (const auto &board : allBoards) if (libBestCModeID(board.second) != (unsigned long)INVALID_ID) diff --git a/wrappers/src/AOS/Dos/Library.hpp b/wrappers/src/AOS/Dos/Library.hpp index 9bec4b2..4bd324f 100644 --- a/wrappers/src/AOS/Dos/Library.hpp +++ b/wrappers/src/AOS/Dos/Library.hpp @@ -8,9 +8,9 @@ #include "ValueTypes/GVF.hpp" +#include "std/optional.hpp" #include #include -#include #include #include diff --git a/wrappers/src/AOS/Icon/DiskObjectScope.cpp b/wrappers/src/AOS/Icon/DiskObjectScope.cpp index e6622e4..7efef8a 100644 --- a/wrappers/src/AOS/Icon/DiskObjectScope.cpp +++ b/wrappers/src/AOS/Icon/DiskObjectScope.cpp @@ -12,10 +12,10 @@ namespace AOS::Icon { - DiskObjectScope::DiskObjectScope(const std::string &diskObjectName) + DiskObjectScope::DiskObjectScope(const std::string &diskObjectName, bool exceptionOnError) { mpDiskObject = (struct DiskObject *)GetDiskObject((STRPTR)diskObjectName.c_str()); - if (!mpDiskObject) + if (!mpDiskObject && exceptionOnError) { auto error = std::string { __PRETTY_FUNCTION__ } + " GetDiskObject(" + diskObjectName + ") failed!"; throw std::runtime_error(error); diff --git a/wrappers/src/AOS/Icon/DiskObjectScope.hpp b/wrappers/src/AOS/Icon/DiskObjectScope.hpp index 7b94d3e..26f2567 100644 --- a/wrappers/src/AOS/Icon/DiskObjectScope.hpp +++ b/wrappers/src/AOS/Icon/DiskObjectScope.hpp @@ -17,13 +17,13 @@ namespace AOS::Icon struct DiskObject *mpDiskObject; public: - DiskObjectScope(const std::string &diskObjectName); + DiskObjectScope(const std::string &diskObjectName, bool exceptionOnError = true); ~DiskObjectScope(); std::string FindToolTypeAsString(const std::string &toolTypeName); bool FindToolTypeAsBool(const std::string &toolTypeName); - protected: + // may be nullptr if exceptionOnError = false and GetDiskObject() failed struct DiskObject *diskObject() const { return mpDiskObject; diff --git a/wrappers/src/AOS/TagUtil.cpp b/wrappers/src/AOS/TagUtil.cpp index e6c762b..1baf265 100644 --- a/wrappers/src/AOS/TagUtil.cpp +++ b/wrappers/src/AOS/TagUtil.cpp @@ -478,6 +478,67 @@ namespace AOS MAP_PAIR(MUIA_Text_Shortened, ValueType::Bool), #endif + + /* + // TextEditor + MAP_PAIR(MUIA_TextEditor_Contents, ValueType::), + MAP_PAIR(MUIA_TextEditor_CursorX, ValueType::), + MAP_PAIR(MUIA_TextEditor_CursorY, ValueType::), + MAP_PAIR(MUIA_TextEditor_DoubleClickHook, ValueType::), + MAP_PAIR(MUIA_TextEditor_TypeAndSpell, ValueType::), + MAP_PAIR(MUIA_TextEditor_ExportHook, ValueType::), + MAP_PAIR(MUIA_TextEditor_ExportWrap, ValueType::), + MAP_PAIR(MUIA_TextEditor_FixedFont, ValueType::), + MAP_PAIR(MUIA_TextEditor_Flow, ValueType::), + MAP_PAIR(MUIA_TextEditor_HasChanged, ValueType::), + MAP_PAIR(MUIA_TextEditor_Prop_DeltaFactor, ValueType::), + MAP_PAIR(MUIA_TextEditor_ImportHook, ValueType::), + MAP_PAIR(MUIA_TextEditor_InsertMode, ValueType::), + MAP_PAIR(MUIA_TextEditor_ImportWrap, ValueType::), + MAP_PAIR(MUIA_TextEditor_KeyBindings, ValueType::), + MAP_PAIR(MUIA_TextEditor_UndoAvailable, ValueType::), + MAP_PAIR(MUIA_TextEditor_RedoAvailable, ValueType::), + MAP_PAIR(MUIA_TextEditor_AreaMarked, ValueType::), + MAP_PAIR(MUIA_TextEditor_Prop_Entries, ValueType::), + MAP_PAIR(MUIA_TextEditor_Prop_Visible, ValueType::), + MAP_PAIR(MUIA_TextEditor_Quiet, ValueType::), + MAP_PAIR(MUIA_TextEditor_NumLock, ValueType::), + MAP_PAIR(MUIA_TextEditor_ReadOnly, ValueType::), + MAP_PAIR(MUIA_TextEditor_Slider, ValueType::), + MAP_PAIR(MUIA_TextEditor_InVirtualGroup, ValueType::), + MAP_PAIR(MUIA_TextEditor_StyleBold, ValueType::), + MAP_PAIR(MUIA_TextEditor_StyleItalic, ValueType::), + MAP_PAIR(MUIA_TextEditor_StyleUnderline, ValueType::), + MAP_PAIR(MUIA_TextEditor_Prop_First, ValueType::), + MAP_PAIR(MUIA_TextEditor_WrapBorder, ValueType::), + MAP_PAIR(MUIA_TextEditor_Separator, ValueType::), + MAP_PAIR(MUIA_TextEditor_Pen, ValueType::), + MAP_PAIR(MUIA_TextEditor_ColorMap, ValueType::), + MAP_PAIR(MUIA_TextEditor_MultiColorQuoting, ValueType::), + MAP_PAIR(MUIA_TextEditor_Rows, ValueType::), + MAP_PAIR(MUIA_TextEditor_Columns, ValueType::), + MAP_PAIR(MUIA_TextEditor_AutoClip, ValueType::), + MAP_PAIR(MUIA_TextEditor_CursorPosition, ValueType::), + MAP_PAIR(MUIA_TextEditor_KeyUpFocus, ValueType::), + MAP_PAIR(MUIA_TextEditor_UndoLevels, ValueType::), + MAP_PAIR(MUIA_TextEditor_WrapMode, ValueType::), + MAP_PAIR(MUIA_TextEditor_ActiveObjectOnClick, ValueType::), + MAP_PAIR(MUIA_TextEditor_PasteStyles, ValueType::), + MAP_PAIR(MUIA_TextEditor_PasteColors, ValueType::), + MAP_PAIR(MUIA_TextEditor_ConvertTabs, ValueType::), + MAP_PAIR(MUIA_TextEditor_WrapWords, ValueType::), + MAP_PAIR(MUIA_TextEditor_TabSize, ValueType::), + MAP_PAIR(MUIA_TextEditor_Keywords, ValueType::), + MAP_PAIR(MUIA_TextEditor_MatchedKeyword, ValueType::), + MAP_PAIR(MUIA_TextEditor_CursorIndex, ValueType::), + MAP_PAIR(MUIA_TextEditor_RGBMode, ValueType::), + MAP_PAIR(MUIA_TextEditor_HorizontalSlider, ValueType::), + MAP_PAIR(MUIA_TextEditor_GlobalFlow, ValueType::), + MAP_PAIR(MUIA_TextEditor_ContentsChanged, ValueType::), + MAP_PAIR(MUIA_TextEditor_MetaDataChanged, ValueType::), + MAP_PAIR(MUIA_TextEditor_InactiveContents, ValueType::), + */ + // ASL MAP_PAIR(ASLFR_TextAttr, ValueType::Pointer), MAP_PAIR(ASLFR_Locale, ValueType::Pointer), diff --git a/wrappers/src/Core/ToString.hpp b/wrappers/src/Core/ToString.hpp index cb5e8b2..349338b 100644 --- a/wrappers/src/Core/ToString.hpp +++ b/wrappers/src/Core/ToString.hpp @@ -9,6 +9,12 @@ #include #include +#ifdef STD_LIGHT +#ifdef Format +#undef Format +#endif +#endif // STD_LIGHT + class ToString { public: diff --git a/wrappers/src/Core/ToString.tmp b/wrappers/src/Core/ToString.tmp new file mode 100644 index 0000000..1e4a37b --- /dev/null +++ b/wrappers/src/Core/ToString.tmp @@ -0,0 +1,27 @@ +// template inline std::string ToString::Format(std::string format, const T0 &arg0) +// { +// try +// { +// if (std::is_same::value) +// { +// return format.replace(format.find("{}"), 2, arg0); +// } +// else if (std::is_same>::value) +// { +// return format.replace(format.find("{}"), 2, Concatenate(arg0)); +// } +// else +// { +// auto error = std::string { __PRETTY_FUNCTION__ } + ", unsupported arg0 type!"; +// throw std::runtime_error(error); +// } +// } +// catch (...) +// { +// std::cerr << "exception on std::format(arg0)=" << format << std::endl; +// return format; +// } +// } + +// template +// static std::string Format(std::string format, const T0 &arg0); diff --git a/wrappers/src/amiga_std_light/vector.hpp b/wrappers/src/amiga_std_light/vector.hpp new file mode 100644 index 0000000..e69de29 diff --git a/wrappers/src/std/optional.hpp b/wrappers/src/std/optional.hpp new file mode 100644 index 0000000..60e5bcd --- /dev/null +++ b/wrappers/src/std/optional.hpp @@ -0,0 +1,432 @@ +#pragma once + +#ifdef __MORPHOS__ +#include +#else + +#include +#include +#include + +namespace std +{ + // Exception thrown when accessing empty optional + class bad_optional_access : public std::exception + { + public: + const char* what() const noexcept override + { + return "bad optional access"; + } + }; + + // Tag type for creating empty optional + struct nullopt_t + { + explicit constexpr nullopt_t(int) {} + }; + + constexpr nullopt_t nullopt{0}; + + // Tag type for in-place construction + struct in_place_t + { + explicit constexpr in_place_t() = default; + }; + + constexpr in_place_t in_place{}; + + template + class optional + { + private: + alignas(T) char storage_[sizeof(T)]; + bool has_value_; + + T* ptr() noexcept + { + return reinterpret_cast(storage_); + } + + const T* ptr() const noexcept + { + return reinterpret_cast(storage_); + } + + void destroy() + { + if (has_value_) + { + ptr()->~T(); + has_value_ = false; + } + } + + public: + using value_type = T; + + // Default constructor - creates empty optional + constexpr optional() noexcept : has_value_(false) {} + + // Nullopt constructor - creates empty optional + constexpr optional(nullopt_t) noexcept : has_value_(false) {} + + // Copy constructor + optional(const optional& other) + : has_value_(other.has_value_) + { + if (other.has_value_) + { + new (storage_) T(*other.ptr()); + } + } + + // Move constructor + optional(optional&& other) noexcept(std::is_nothrow_move_constructible::value) + : has_value_(other.has_value_) + { + if (other.has_value_) + { + new (storage_) T(std::move(*other.ptr())); + other.destroy(); + } + } + + // Value constructor + template + constexpr optional(U&& value) + : has_value_(true) + { + new (storage_) T(std::forward(value)); + } + + // In-place constructor + template + constexpr explicit optional(in_place_t, Args&&... args) + : has_value_(true) + { + new (storage_) T(std::forward(args)...); + } + + // Destructor + ~optional() + { + destroy(); + } + + // Copy assignment + optional& operator=(const optional& other) + { + if (this != &other) + { + if (other.has_value_) + { + if (has_value_) + { + *ptr() = *other.ptr(); + } + else + { + new (storage_) T(*other.ptr()); + has_value_ = true; + } + } + else + { + destroy(); + } + } + return *this; + } + + // Move assignment + optional& operator=(optional&& other) noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) + { + if (this != &other) + { + if (other.has_value_) + { + if (has_value_) + { + *ptr() = std::move(*other.ptr()); + } + else + { + new (storage_) T(std::move(*other.ptr())); + has_value_ = true; + } + other.destroy(); + } + else + { + destroy(); + } + } + return *this; + } + + // Nullopt assignment + optional& operator=(nullopt_t) noexcept + { + destroy(); + return *this; + } + + // Value assignment + template + optional& operator=(U&& value) + { + if (has_value_) + { + *ptr() = std::forward(value); + } + else + { + new (storage_) T(std::forward(value)); + has_value_ = true; + } + return *this; + } + + // Check if optional has value + constexpr bool has_value() const noexcept + { + return has_value_; + } + + // Conversion to bool + constexpr explicit operator bool() const noexcept + { + return has_value_; + } + + // Access value (throws if empty) + constexpr T& value() & + { + if (!has_value_) + throw bad_optional_access(); + return *ptr(); + } + + constexpr const T& value() const & + { + if (!has_value_) + throw bad_optional_access(); + return *ptr(); + } + + constexpr T&& value() && + { + if (!has_value_) + throw bad_optional_access(); + return std::move(*ptr()); + } + + constexpr const T&& value() const && + { + if (!has_value_) + throw bad_optional_access(); + return std::move(*ptr()); + } + + // Access value (undefined behavior if empty) + constexpr T& operator*() & noexcept + { + return *ptr(); + } + + constexpr const T& operator*() const & noexcept + { + return *ptr(); + } + + constexpr T&& operator*() && noexcept + { + return std::move(*ptr()); + } + + constexpr const T&& operator*() const && noexcept + { + return std::move(*ptr()); + } + + // Access value pointer (undefined behavior if empty) + constexpr T* operator->() noexcept + { + return ptr(); + } + + constexpr const T* operator->() const noexcept + { + return ptr(); + } + + // Access value with default + template + constexpr T value_or(U&& default_value) const & + { + return has_value_ ? *ptr() : static_cast(std::forward(default_value)); + } + + template + constexpr T value_or(U&& default_value) && + { + return has_value_ ? std::move(*ptr()) : static_cast(std::forward(default_value)); + } + + // Swap + void swap(optional& other) noexcept(std::is_nothrow_move_constructible::value && std::is_nothrow_swappable::value) + { + if (has_value_ && other.has_value_) + { + using std::swap; + swap(*ptr(), *other.ptr()); + } + else if (has_value_) + { + new (other.storage_) T(std::move(*ptr())); + other.has_value_ = true; + destroy(); + } + else if (other.has_value_) + { + new (storage_) T(std::move(*other.ptr())); + has_value_ = true; + other.destroy(); + } + } + + // Reset - make optional empty + void reset() noexcept + { + destroy(); + } + + // Emplace - construct value in place + template + T& emplace(Args&&... args) + { + destroy(); + new (storage_) T(std::forward(args)...); + has_value_ = true; + return *ptr(); + } + }; + + // Comparison operators + template + constexpr bool operator==(const optional& lhs, const optional& rhs) + { + if (lhs.has_value() != rhs.has_value()) + return false; + if (!lhs.has_value()) + return true; + return *lhs == *rhs; + } + + template + constexpr bool operator!=(const optional& lhs, const optional& rhs) + { + return !(lhs == rhs); + } + + template + constexpr bool operator<(const optional& lhs, const optional& rhs) + { + if (!rhs.has_value()) + return false; + if (!lhs.has_value()) + return true; + return *lhs < *rhs; + } + + template + constexpr bool operator<=(const optional& lhs, const optional& rhs) + { + return !(rhs < lhs); + } + + template + constexpr bool operator>(const optional& lhs, const optional& rhs) + { + return rhs < lhs; + } + + template + constexpr bool operator>=(const optional& lhs, const optional& rhs) + { + return !(lhs < rhs); + } + + // Comparison with nullopt + template + constexpr bool operator==(const optional& opt, nullopt_t) noexcept + { + return !opt.has_value(); + } + + template + constexpr bool operator==(nullopt_t, const optional& opt) noexcept + { + return !opt.has_value(); + } + + template + constexpr bool operator!=(const optional& opt, nullopt_t) noexcept + { + return opt.has_value(); + } + + template + constexpr bool operator!=(nullopt_t, const optional& opt) noexcept + { + return opt.has_value(); + } + + // Comparison with values + template + constexpr bool operator==(const optional& opt, const U& value) + { + return opt.has_value() && *opt == value; + } + + template + constexpr bool operator==(const T& value, const optional& opt) + { + return opt.has_value() && value == *opt; + } + + template + constexpr bool operator!=(const optional& opt, const U& value) + { + return !opt.has_value() || *opt != value; + } + + template + constexpr bool operator!=(const T& value, const optional& opt) + { + return !opt.has_value() || value != *opt; + } + + // Utility functions + template + void swap(optional& lhs, optional& rhs) noexcept(noexcept(lhs.swap(rhs))) + { + lhs.swap(rhs); + } + + template + constexpr optional::type> make_optional(T&& value) + { + return optional::type>(std::forward(value)); + } + + template + constexpr optional make_optional(Args&&... args) + { + return optional(in_place, std::forward(args)...); + } + +} // namespace std + +#endif \ No newline at end of file diff --git a/wrappers/src/temp/string.cpp b/wrappers/src/temp/string.cpp new file mode 100644 index 0000000..70d6f7f --- /dev/null +++ b/wrappers/src/temp/string.cpp @@ -0,0 +1,473 @@ +// +// AmigaOS C++ wrapper +// +// (c) 2024-2025 TDolphin +// + +#pragma once + +#include + +/* +#include "string.hpp" + +#ifdef STD_LIGHT + +#include +#include + +#include + +namespace amiga_std_light +{ + // Private helper methods + void basic_string::reallocate(size_t new_capacity) + { + if (new_capacity <= capacity_) + return; + + char *new_data = static_cast(AllocMem(new_capacity + 1, MEMF_PUBLIC)); + if (!new_data) + return; // Handle allocation failure gracefully + + if (data_) + { + std::memcpy(new_data, data_, size_); + FreeMem(data_, capacity_ + 1); + } + + data_ = new_data; + capacity_ = new_capacity; + data_[size_] = '\0'; + } + + void basic_string::ensure_capacity(size_t needed_size) + { + if (needed_size > capacity_) + { + size_t new_capacity = capacity_ == 0 ? 16 : capacity_; + while (new_capacity < needed_size) + new_capacity *= 2; + reallocate(new_capacity); + } + } + + // Constructors + basic_string::basic_string() + : data_(nullptr), size_(0), capacity_(0) + { + } + + basic_string::basic_string(const char *str) + : data_(nullptr), size_(0), capacity_(0) + { + if (str) + { + size_ = std::strlen(str); + ensure_capacity(size_); + std::memcpy(data_, str, size_); + data_[size_] = '\0'; + } + } + + basic_string::basic_string(const char *str, size_t len) + : data_(nullptr), size_(0), capacity_(0) + { + if (str && len > 0) + { + size_ = len; + ensure_capacity(size_); + std::memcpy(data_, str, size_); + data_[size_] = '\0'; + } + } + + basic_string::basic_string(const basic_string &other) + : data_(nullptr), size_(0), capacity_(0) + { + if (other.size_ > 0) + { + size_ = other.size_; + ensure_capacity(size_); + std::memcpy(data_, other.data_, size_); + data_[size_] = '\0'; + } + } + + basic_string::basic_string(size_t count, char ch) + : data_(nullptr), size_(0), capacity_(0) + { + if (count > 0) + { + size_ = count; + ensure_capacity(size_); + std::memset(data_, ch, size_); + data_[size_] = '\0'; + } + } + + // Destructor + basic_string::~basic_string() + { + if (data_) + { + FreeMem(data_, capacity_ + 1); + } + } + + // Assignment operators + basic_string &basic_string::operator=(const basic_string &other) + { + if (this != &other) + { + clear(); + if (other.size_ > 0) + { + ensure_capacity(other.size_); + size_ = other.size_; + std::memcpy(data_, other.data_, size_); + data_[size_] = '\0'; + } + } + return *this; + } + + basic_string &basic_string::operator=(const char *str) + { + clear(); + if (str) + { + size_t len = std::strlen(str); + if (len > 0) + { + ensure_capacity(len); + size_ = len; + std::memcpy(data_, str, size_); + data_[size_] = '\0'; + } + } + return *this; + } + + basic_string &basic_string::operator=(char ch) + { + clear(); + ensure_capacity(1); + size_ = 1; + data_[0] = ch; + data_[1] = '\0'; + return *this; + } + + // Element access + char &basic_string::operator[](size_t index) + { + return data_[index]; + } + + const char &basic_string::operator[](size_t index) const + { + return data_[index]; + } + + char &basic_string::at(size_t index) + { + return data_[index]; // Should add bounds checking in production + } + + const char &basic_string::at(size_t index) const + { + return data_[index]; // Should add bounds checking in production + } + + char &basic_string::front() + { + return data_[0]; + } + + const char &basic_string::front() const + { + return data_[0]; + } + + char &basic_string::back() + { + return data_[size_ - 1]; + } + + const char &basic_string::back() const + { + return data_[size_ - 1]; + } + + const char *basic_string::data() const + { + return data_ ? data_ : ""; + } + + const char *basic_string::c_str() const + { + return data(); + } + + // Iterators + char *basic_string::begin() + { + return data_; + } + + const char *basic_string::begin() const + { + return data_; + } + + char *basic_string::end() + { + return data_ + size_; + } + + const char *basic_string::end() const + { + return data_ + size_; + } + + // Capacity + bool basic_string::empty() const + { + return size_ == 0; + } + + size_t basic_string::size() const + { + return size_; + } + + size_t basic_string::length() const + { + return size_; + } + + size_t basic_string::capacity() const + { + return capacity_; + } + + void basic_string::reserve(size_t new_capacity) + { + if (new_capacity > capacity_) + { + reallocate(new_capacity); + } + } + + void basic_string::shrink_to_fit() + { + if (capacity_ > size_) + { + reallocate(size_); + } + } + + // Modifiers + void basic_string::clear() + { + size_ = 0; + if (data_) + { + data_[0] = '\0'; + } + } + + basic_string &basic_string::append(const char *str) + { + if (str) + { + size_t len = std::strlen(str); + if (len > 0) + { + ensure_capacity(size_ + len); + std::memcpy(data_ + size_, str, len); + size_ += len; + data_[size_] = '\0'; + } + } + return *this; + } + + basic_string &basic_string::append(const basic_string &str) + { + if (str.size_ > 0) + { + ensure_capacity(size_ + str.size_); + std::memcpy(data_ + size_, str.data_, str.size_); + size_ += str.size_; + data_[size_] = '\0'; + } + return *this; + } + + basic_string &basic_string::append(size_t count, char ch) + { + if (count > 0) + { + ensure_capacity(size_ + count); + std::memset(data_ + size_, ch, count); + size_ += count; + data_[size_] = '\0'; + } + return *this; + } + + void basic_string::push_back(char ch) + { + ensure_capacity(size_ + 1); + data_[size_] = ch; + size_++; + data_[size_] = '\0'; + } + + void basic_string::pop_back() + { + if (size_ > 0) + { + size_--; + data_[size_] = '\0'; + } + } + + // Operators + basic_string &basic_string::operator+=(const char *str) + { + return append(str); + } + + basic_string &basic_string::operator+=(const basic_string &str) + { + return append(str); + } + + basic_string &basic_string::operator+=(char ch) + { + push_back(ch); + return *this; + } + + basic_string basic_string::operator+(const char *str) const + { + basic_string result(*this); + result.append(str); + return result; + } + + basic_string basic_string::operator+(const basic_string &str) const + { + basic_string result(*this); + result.append(str); + return result; + } + + basic_string basic_string::operator+(char ch) const + { + basic_string result(*this); + result.push_back(ch); + return result; + } + + // Comparison operators + bool basic_string::operator==(const char *str) const + { + if (!str) + return size_ == 0; + return std::strcmp(data(), str) == 0; + } + + bool basic_string::operator==(const basic_string &str) const + { + if (size_ != str.size_) + return false; + if (size_ == 0) + return true; + return std::memcmp(data_, str.data_, size_) == 0; + } + + bool basic_string::operator!=(const char *str) const + { + return !(*this == str); + } + + bool basic_string::operator!=(const basic_string &str) const + { + return !(*this == str); + } + + bool basic_string::operator<(const char *str) const + { + return std::strcmp(data(), str ? str : "") < 0; + } + + bool basic_string::operator<(const basic_string &str) const + { + return std::strcmp(data(), str.data()) < 0; + } + + // String operations + size_t basic_string::find(const char *str, size_t pos) const + { + if (!str || pos >= size_) + return npos; + + const char *found = std::strstr(data_ + pos, str); + if (found) + return found - data_; + return npos; + } + + size_t basic_string::find(char ch, size_t pos) const + { + if (pos >= size_) + return npos; + + const char *found = std::strchr(data_ + pos, ch); + if (found) + return found - data_; + return npos; + } + + basic_string basic_string::substr(size_t pos, size_t len) const + { + if (pos >= size_) + return basic_string(); + + if (len == npos || pos + len > size_) + len = size_ - pos; + + return basic_string(data_ + pos, len); + } + + int basic_string::compare(const char *str) const + { + return std::strcmp(data(), str ? str : ""); + } + + int basic_string::compare(const basic_string &str) const + { + return std::strcmp(data(), str.data()); + } + + // Non-member operators + basic_string operator+(const char *lhs, const basic_string &rhs) + { + basic_string result(lhs); + result.append(rhs); + return result; + } + + basic_string operator+(char lhs, const basic_string &rhs) + { + basic_string result(1, lhs); + result.append(rhs); + return result; + } +} + +#endif*/ \ No newline at end of file diff --git a/wrappers/src/temp/string.hpp b/wrappers/src/temp/string.hpp new file mode 100644 index 0000000..9be27e9 --- /dev/null +++ b/wrappers/src/temp/string.hpp @@ -0,0 +1,131 @@ +// +// AmigaOS C++ wrapper +// +// (c) 2024-2025 TDolphin +// + +#pragma once + +#ifdef STD_LIGHT + +#include +#include + +namespace amiga_std_light +{ + class basic_string + { + private: + char *data_; + size_t size_; + size_t capacity_; + + void reallocate(size_t new_capacity); + void ensure_capacity(size_t needed_size); + + public: + // Constructors + basic_string(); + basic_string(const char *str); + basic_string(const char *str, size_t len); + basic_string(const basic_string &other); + basic_string(size_t count, char ch); + + // Destructor + ~basic_string(); + + // Assignment operators + basic_string &operator=(const basic_string &other); + basic_string &operator=(const char *str); + basic_string &operator=(char ch); + + // Element access + char &operator[](size_t index); + const char &operator[](size_t index) const; + char &at(size_t index); + const char &at(size_t index) const; + char &front(); + const char &front() const; + char &back(); + const char &back() const; + const char *data() const; + const char *c_str() const; + + // Iterators (simple pointer-based) + char *begin(); + const char *begin() const; + char *end(); + const char *end() const; + + // Capacity + bool empty() const; + size_t size() const; + size_t length() const; + size_t capacity() const; + void reserve(size_t new_capacity); + void shrink_to_fit(); + + // Modifiers + void clear(); + basic_string &insert(size_t index, const char *str); + basic_string &insert(size_t index, const basic_string &str); + basic_string &erase(size_t index = 0, size_t len = npos); + void push_back(char ch); + void pop_back(); + basic_string &append(const char *str); + basic_string &append(const basic_string &str); + basic_string &append(size_t count, char ch); + basic_string &assign(const char *str); + basic_string &assign(const basic_string &str); + basic_string &assign(size_t count, char ch); + + // String operations + size_t find(const char *str, size_t pos = 0) const; + size_t find(const basic_string &str, size_t pos = 0) const; + size_t find(char ch, size_t pos = 0) const; + size_t rfind(const char *str, size_t pos = npos) const; + size_t rfind(const basic_string &str, size_t pos = npos) const; + size_t rfind(char ch, size_t pos = npos) const; + basic_string substr(size_t pos = 0, size_t len = npos) const; + int compare(const char *str) const; + int compare(const basic_string &str) const; + + // Operators + basic_string operator+(const char *str) const; + basic_string operator+(const basic_string &str) const; + basic_string operator+(char ch) const; + basic_string &operator+=(const char *str); + basic_string &operator+=(const basic_string &str); + basic_string &operator+=(char ch); + + // Comparison operators + bool operator==(const char *str) const; + bool operator==(const basic_string &str) const; + bool operator!=(const char *str) const; + bool operator!=(const basic_string &str) const; + bool operator<(const char *str) const; + bool operator<(const basic_string &str) const; + bool operator<=(const char *str) const; + bool operator<=(const basic_string &str) const; + bool operator>(const char *str) const; + bool operator>(const basic_string &str) const; + bool operator>=(const char *str) const; + bool operator>=(const basic_string &str) const; + + // Constants + static const size_t npos = static_cast(-1); + }; + + // Non-member operators + basic_string operator+(const char *lhs, const basic_string &rhs); + basic_string operator+(char lhs, const basic_string &rhs); +} + +namespace std +{ + using string = amiga_std_light::basic_string; +} + +#else +#include +#endif \ No newline at end of file diff --git a/wrappers/src/temp/vector.hpp b/wrappers/src/temp/vector.hpp new file mode 100644 index 0000000..0468c95 --- /dev/null +++ b/wrappers/src/temp/vector.hpp @@ -0,0 +1,374 @@ +#pragma once + +#include +#include +#include +#include + +#include + +/* +#include + +namespace amiga_std_light +{ + template class vector + { + private: + T *data_; + size_t size_; + size_t capacity_; + + static constexpr size_t DEFAULT_CAPACITY = 4; + static constexpr float GROWTH_FACTOR = 1.5f; + + void grow() + { + size_t new_capacity = capacity_ == 0 ? DEFAULT_CAPACITY : static_cast(capacity_ * GROWTH_FACTOR); + reserve(new_capacity); + } + + void deallocate() + { + if (data_) + { + // Wywołaj destruktory dla wszystkich elementów + for (size_t i = 0; i < size_; ++i) + { + data_[i].~T(); + } + // Zwolnij pamięć przez AmigaOS + FreeMem(data_, capacity_ * sizeof(T)); + data_ = nullptr; + size_ = 0; + capacity_ = 0; + } + } + + public: + // Typy pomocnicze + using value_type = T; + using size_type = size_t; + using reference = T &; + using const_reference = const T &; + using pointer = T *; + using const_pointer = const T *; + using iterator = T *; + using const_iterator = const T *; + + // Konstruktory + vector() + : data_(nullptr) + , size_(0) + , capacity_(0) + { + } + + explicit vector(size_t count) + : data_(nullptr) + , size_(0) + , capacity_(0) + { + resize(count); + } + + vector(size_t count, const T &value) + : data_(nullptr) + , size_(0) + , capacity_(0) + { + resize(count, value); + } + + // Konstruktor z initializer_list + vector(std::initializer_list init) + : data_(nullptr) + , size_(0) + , capacity_(0) + { + reserve(init.size()); + for (const auto &item : init) + { + push_back(item); + } + } + + // Copy constructor + vector(const vector &other) + : data_(nullptr) + , size_(0) + , capacity_(0) + { + reserve(other.size_); + for (size_t i = 0; i < other.size_; ++i) + { + push_back(other.data_[i]); + } + } + + // Destruktor + ~vector() + { + deallocate(); + } + + // Assignment operator + vector &operator=(const vector &other) + { + if (this != &other) + { + clear(); + reserve(other.size_); + for (size_t i = 0; i < other.size_; ++i) + { + push_back(other.data_[i]); + } + } + return *this; + } + + // Assignment operator z initializer_list + vector &operator=(std::initializer_list init) + { + clear(); + reserve(init.size()); + for (const auto &item : init) + { + push_back(item); + } + return *this; + } + + // Iteratory + iterator begin() + { + return data_; + } + const_iterator begin() const + { + return data_; + } + iterator end() + { + return data_ + size_; + } + const_iterator end() const + { + return data_ + size_; + } + + // Dostęp do elementów + reference operator[](size_t index) + { + return data_[index]; + } + + const_reference operator[](size_t index) const + { + return data_[index]; + } + + reference at(size_t index) + { + if (index >= size_) + { + throw std::out_of_range("vector::at: index out of range"); + } + return data_[index]; + } + + const_reference at(size_t index) const + { + if (index >= size_) + { + throw std::out_of_range("vector::at: index out of range"); + } + return data_[index]; + } + + reference front() + { + return data_[0]; + } + const_reference front() const + { + return data_[0]; + } + reference back() + { + return data_[size_ - 1]; + } + const_reference back() const + { + return data_[size_ - 1]; + } + + // Informacje o rozmiarze + size_t size() const + { + return size_; + } + size_t capacity() const + { + return capacity_; + } + bool empty() const + { + return size_ == 0; + } + + // Modyfikacje rozmiaru + void reserve(size_t new_capacity) + { + if (new_capacity <= capacity_) + { + return; + } + + // Alokuj nową pamięć przez AmigaOS + T *new_data = static_cast(AllocMem(new_capacity * sizeof(T), MEMF_ANY)); + if (!new_data) + { + throw std::bad_alloc(); + } + + // Przenieś istniejące elementy + for (size_t i = 0; i < size_; ++i) + { + new (&new_data[i]) T(std::move(data_[i])); + data_[i].~T(); + } + + // Zwolnij starą pamięć + if (data_) + { + FreeMem(data_, capacity_ * sizeof(T)); + } + + data_ = new_data; + capacity_ = new_capacity; + } + + void resize(size_t new_size) + { + if (new_size > capacity_) + { + reserve(new_size); + } + + // Zniszcz nadmiarowe elementy + for (size_t i = new_size; i < size_; ++i) + { + data_[i].~T(); + } + + // Skonstruuj nowe elementy z domyślną wartością + for (size_t i = size_; i < new_size; ++i) + { + new (&data_[i]) T(); + } + + size_ = new_size; + } + + void resize(size_t new_size, const T &value) + { + if (new_size > capacity_) + { + reserve(new_size); + } + + // Zniszcz nadmiarowe elementy + for (size_t i = new_size; i < size_; ++i) + { + data_[i].~T(); + } + + // Skonstruuj nowe elementy z podaną wartością + for (size_t i = size_; i < new_size; ++i) + { + new (&data_[i]) T(value); + } + + size_ = new_size; + } + + void clear() + { + for (size_t i = 0; i < size_; ++i) + { + data_[i].~T(); + } + size_ = 0; + } + + // Dodawanie/usuwanie elementów + void push_back(const T &value) + { + if (size_ >= capacity_) + { + grow(); + } + new (&data_[size_]) T(value); + ++size_; + } + + void push_back(T &&value) + { + if (size_ >= capacity_) + { + grow(); + } + new (&data_[size_]) T(std::move(value)); + ++size_; + } + + void pop_back() + { + if (size_ > 0) + { + --size_; + data_[size_].~T(); + } + } + + // Emplacement + template void emplace_back(Args &&...args) + { + if (size_ >= capacity_) + { + grow(); + } + new (&data_[size_]) T(std::forward(args)...); + ++size_; + } + + // Dostęp do surowych danych + T *data() + { + return data_; + } + const T *data() const + { + return data_; + } + + // Metoda assign z initializer_list + void assign(std::initializer_list init) + { + clear(); + reserve(init.size()); + for (const auto &item : init) + { + push_back(item); + } + } + }; + +} // namespace amiga_std_light + +// Nadpisanie namespace std +namespace std +{ + using amiga_std_light::vector; +}*/ \ No newline at end of file From 44dc2ed65c0b3d61bca21031de89b93b68593362 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Sep 2025 18:13:36 +0000 Subject: [PATCH 2/2] Initial plan