From 7da829d48f9059c83ab9cada2c850621e8bbd3f3 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 22 Sep 2024 12:41:28 -0500 Subject: Basics of library. --- include/array.hpp | 113 -------- include/c_file.hpp | 103 -------- include/fud_array.hpp | 113 ++++++++ include/fud_c_file.hpp | 105 ++++++++ include/fud_fud_type_traits.hpp | 80 ++++++ include/fud_memory.hpp | 150 +++++++++++ include/fud_result.hpp | 83 ++++++ include/fud_status.hpp | 106 ++++++++ include/fud_string.hpp | 201 +++++++++++++++ include/fud_type_traits.hpp | 80 ------ include/fud_unique_array.hpp | 68 +++++ include/fud_utf8.hpp | 552 +++++++++++++++++++++++++++++++++++++++ include/fud_utf8_iterator.hpp | 56 ++++ include/libfud.hpp | 4 +- include/memory.hpp | 140 ---------- include/result.hpp | 83 ------ include/status.hpp | 106 -------- include/string.hpp | 153 ----------- include/unique_array.hpp | 68 ----- include/utf8.hpp | 557 ---------------------------------------- include/utf8_iterator.hpp | 39 --- 21 files changed, 1516 insertions(+), 1444 deletions(-) delete mode 100644 include/array.hpp delete mode 100644 include/c_file.hpp create mode 100644 include/fud_array.hpp create mode 100644 include/fud_c_file.hpp create mode 100644 include/fud_fud_type_traits.hpp create mode 100644 include/fud_memory.hpp create mode 100644 include/fud_result.hpp create mode 100644 include/fud_status.hpp create mode 100644 include/fud_string.hpp delete mode 100644 include/fud_type_traits.hpp create mode 100644 include/fud_unique_array.hpp create mode 100644 include/fud_utf8.hpp create mode 100644 include/fud_utf8_iterator.hpp delete mode 100644 include/memory.hpp delete mode 100644 include/result.hpp delete mode 100644 include/status.hpp delete mode 100644 include/string.hpp delete mode 100644 include/unique_array.hpp delete mode 100644 include/utf8.hpp delete mode 100644 include/utf8_iterator.hpp (limited to 'include') diff --git a/include/array.hpp b/include/array.hpp deleted file mode 100644 index 9de6c0a..0000000 --- a/include/array.hpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * libfud - * Copyright 2024 Dominick Allen - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXT_ARRAY_HPP -#define EXT_ARRAY_HPP - -#include "memory.hpp" - -#include - -namespace fud { - -template -struct Array { - static_assert(Size > 0); - using ValueType = T; - - T m_data[Size]; // NOLINT(cppcoreguidelines-avoid-c-arrays) - - constexpr static Array constFill(T value) - { - Array arr{}; - setMemory(arr, value); - return arr; - } - - [[nodiscard]] constexpr size_t size() const - { - return Size; - } - - constexpr T& front() - { - return m_data[0]; - } - - constexpr const T& front() const - { - return m_data[0]; - } - - constexpr T& back() - { - return m_data[Size - 1]; - } - - constexpr const T& back() const - { - return m_data[Size - 1]; - } - - constexpr T* data() noexcept - { - return m_data; - } - - constexpr const T* data() const noexcept - { - return m_data; - } - - constexpr T* begin() noexcept - { - return m_data; - } - - constexpr const T* begin() const noexcept - { - return m_data; - } - - constexpr T* end() noexcept - { - return m_data + Size; - } - - constexpr const T* end() const noexcept - { - return m_data + Size; - } - - constexpr T& operator[](size_t index) - { - return m_data[index]; - } - - constexpr const T& operator[](size_t index) const - { - return m_data[index]; - } - - constexpr bool operator==(const Array&) const noexcept = default; - - constexpr auto operator<=>(const Array& other) const noexcept = default; -}; - -} // namespace ext_lib - -#endif diff --git a/include/c_file.hpp b/include/c_file.hpp deleted file mode 100644 index 0f43e08..0000000 --- a/include/c_file.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2024 Dominick Allen - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FUD_C_FILE_HPP -#define FUD_C_FILE_HPP - -#include "result.hpp" - -#include -#include - -namespace fud { - -enum class CFileMode : uint8_t -{ - ReadOnly, - ReadWrite, - WriteTruncate, - ReadWriteTruncate, - WriteAppend, - ReadWriteAppend, -}; - -constexpr const char* CBinaryFileModeFromFlags(CFileMode mode) -{ - switch (mode) { - case CFileMode::ReadOnly: - return "rb"; - case CFileMode::ReadWrite: - return "r+b"; - case CFileMode::WriteTruncate: - return "wb"; - case CFileMode::ReadWriteTruncate: - return "w+b"; - case CFileMode::WriteAppend: - return "ab"; - case CFileMode::ReadWriteAppend: - return "a+b"; - default: - return ""; - } -} - -constexpr const char* CTextFileModeFromFlags(CFileMode mode) -{ - switch (mode) { - case CFileMode::ReadOnly: - return "r"; - case CFileMode::ReadWrite: - return "r+"; - case CFileMode::WriteTruncate: - return "w"; - case CFileMode::ReadWriteTruncate: - return "w+"; - case CFileMode::WriteAppend: - return "a"; - case CFileMode::ReadWriteAppend: - return "a+"; - default: - return ""; - } -} - -enum class FileResult -{ - Success, - Error, -}; - -class CBinaryFile { - public: - CBinaryFile(const std::string& filename, CFileMode mode); - CBinaryFile(const std::string& filename, CFileMode mode, const std::string& extraFlags); - ~CBinaryFile(); - FileResult open(); - void close(); - const FILE* file() const; - - private: - std::string m_filename; - std::string m_extraFlags{}; - std::string m_mode; - CFileMode m_modeFlags; - FILE* m_file{nullptr}; -}; - -} // namespace fud - - -#endif diff --git a/include/fud_array.hpp b/include/fud_array.hpp new file mode 100644 index 0000000..4e2c702 --- /dev/null +++ b/include/fud_array.hpp @@ -0,0 +1,113 @@ +/* + * libfud + * Copyright 2024 Dominick Allen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUD_ARRAY_HPP +#define FUD_ARRAY_HPP + +#include "fud_memory.hpp" + +#include + +namespace fud { + +template +struct Array { + static_assert(Size > 0); + using ValueType = T; + + T m_data[Size]; // NOLINT(cppcoreguidelines-avoid-c-arrays) + + constexpr static Array constFill(T value) + { + Array arr{}; + setMemory(arr, value); + return arr; + } + + [[nodiscard]] constexpr size_t size() const + { + return Size; + } + + constexpr T& front() + { + return m_data[0]; + } + + constexpr const T& front() const + { + return m_data[0]; + } + + constexpr T& back() + { + return m_data[Size - 1]; + } + + constexpr const T& back() const + { + return m_data[Size - 1]; + } + + constexpr T* data() noexcept + { + return m_data; + } + + constexpr const T* data() const noexcept + { + return m_data; + } + + constexpr T* begin() noexcept + { + return m_data; + } + + constexpr const T* begin() const noexcept + { + return m_data; + } + + constexpr T* end() noexcept + { + return m_data + Size; + } + + constexpr const T* end() const noexcept + { + return m_data + Size; + } + + constexpr T& operator[](size_t index) + { + return m_data[index]; + } + + constexpr const T& operator[](size_t index) const + { + return m_data[index]; + } + + constexpr bool operator==(const Array&) const noexcept = default; + + constexpr auto operator<=>(const Array& other) const noexcept = default; +}; + +} // namespace fud + +#endif diff --git a/include/fud_c_file.hpp b/include/fud_c_file.hpp new file mode 100644 index 0000000..f89839d --- /dev/null +++ b/include/fud_c_file.hpp @@ -0,0 +1,105 @@ +/* + * libfud + * Copyright 2024 Dominick Allen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUD_C_FILE_HPP +#define FUD_C_FILE_HPP + +#include "fud_string.hpp" +#include "fud_result.hpp" + +#include +#include + +namespace fud { + +enum class CFileMode : uint8_t +{ + ReadOnly, + ReadWrite, + WriteTruncate, + ReadWriteTruncate, + WriteAppend, + ReadWriteAppend, +}; + +constexpr const char* CBinaryFileModeFromFlags(CFileMode mode) +{ + switch (mode) { + case CFileMode::ReadOnly: + return "rb"; + case CFileMode::ReadWrite: + return "r+b"; + case CFileMode::WriteTruncate: + return "wb"; + case CFileMode::ReadWriteTruncate: + return "w+b"; + case CFileMode::WriteAppend: + return "ab"; + case CFileMode::ReadWriteAppend: + return "a+b"; + default: + return ""; + } +} + +constexpr const char* CTextFileModeFromFlags(CFileMode mode) +{ + switch (mode) { + case CFileMode::ReadOnly: + return "r"; + case CFileMode::ReadWrite: + return "r+"; + case CFileMode::WriteTruncate: + return "w"; + case CFileMode::ReadWriteTruncate: + return "w+"; + case CFileMode::WriteAppend: + return "a"; + case CFileMode::ReadWriteAppend: + return "a+"; + default: + return ""; + } +} + +enum class FileResult +{ + Success, + Error, +}; + +class CBinaryFile { + public: + CBinaryFile(const String& filename, CFileMode mode); + CBinaryFile(const String& filename, CFileMode mode, const String& extraFlags); + ~CBinaryFile(); + FileResult open(); + void close(); + const FILE* file() const; + + private: + String m_filename; + String m_extraFlags{}; + String m_mode; + CFileMode m_modeFlags; + FILE* m_file{nullptr}; +}; + +} // namespace fud + + +#endif diff --git a/include/fud_fud_type_traits.hpp b/include/fud_fud_type_traits.hpp new file mode 100644 index 0000000..3fdff79 --- /dev/null +++ b/include/fud_fud_type_traits.hpp @@ -0,0 +1,80 @@ +/* + * libfud + * Copyright 2024 Dominick Allen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUD_TYPE_TRAITS_HPP +#define FUD_TYPE_TRAITS_HPP + +#include +#include + +namespace fud { + +template