diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-27 09:43:26 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-27 09:43:26 +0100 |
| commit | 6e4007d383ffd910225941a91bbc929a259c8efb (patch) | |
| tree | fcaaa504d812f85e75afb6ec803ee10fe757d152 /Private/CompilerKit | |
| parent | 7f07441646bba449d8ca60195c032720ce08aa13 (diff) | |
Strings: Fix destructor, add documentation to APIs.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/CompilerKit')
| -rw-r--r-- | Private/CompilerKit/StdKit/AE.hpp | 25 | ||||
| -rw-r--r-- | Private/CompilerKit/StdKit/String.hpp | 25 |
2 files changed, 44 insertions, 6 deletions
diff --git a/Private/CompilerKit/StdKit/AE.hpp b/Private/CompilerKit/StdKit/AE.hpp index 8843404..4567fbc 100644 --- a/Private/CompilerKit/StdKit/AE.hpp +++ b/Private/CompilerKit/StdKit/AE.hpp @@ -91,17 +91,28 @@ std::ifstream &operator>>(std::ifstream& fp, CompilerKit::AERecordHeader& contai namespace CompilerKit::Utils { + /** + * @brief AE Reader protocol + * + */ class AEReadableProtocol final { public: - std::ifstream USED_FP; + std::ifstream FP; public: - AEReadableProtocol() = default; + explicit AEReadableProtocol() = default; ~AEReadableProtocol() = default; CXXKIT_COPY_DELETE(AEReadableProtocol); + /** + * @brief Read AE record + * + * @param raw the containing buffer + * @param sz it's size (without sizeof(AERecordHeader) added to it.) + * @return AERecordHeaderPtr + */ AERecordHeaderPtr Read(char* raw, std::size_t sz) { if (!raw) @@ -111,10 +122,18 @@ namespace CompilerKit::Utils } private: + /** + * @brief Implementation of Read for raw classes. + * + * @tparam TypeClass The class to read. + * @param raw the buffer + * @param sz the size + * @return TypeClass* the returning class. + */ template <typename TypeClass> TypeClass* _Read(char* raw, std::size_t sz) { - USED_FP.read(raw, std::streamsize(sz)); + FP.read(raw, std::streamsize(sz)); return reinterpret_cast<TypeClass*>(raw); } diff --git a/Private/CompilerKit/StdKit/String.hpp b/Private/CompilerKit/StdKit/String.hpp index 0b21b8d..eada24d 100644 --- a/Private/CompilerKit/StdKit/String.hpp +++ b/Private/CompilerKit/StdKit/String.hpp @@ -14,18 +14,33 @@ namespace CompilerKit { + /** + * @brief StringView class, contains a C string and manages it. + * @note No need to manage it it's getting deleted by default. + */ + class StringView final { public: - StringView() = delete; + explicit StringView() = delete; - explicit StringView(SizeType Sz) : m_Sz(Sz) + explicit StringView(SizeType Sz) noexcept + : m_Sz(Sz) { m_Data = new char[Sz]; assert(m_Data); } - ~StringView() = default; + ~StringView() noexcept + { + if (m_Data) + { + memset(m_Data, 0, m_Sz); + delete[] m_Data; + + m_Data = nullptr; + } + } CXXKIT_COPY_DEFAULT(StringView); @@ -61,6 +76,10 @@ namespace CompilerKit }; + /** + * @brief StringBuilder class + * @note These results shall call delete[] after they're used. + */ struct StringBuilder final { static StringView Construct(const CharType *data); |
