From c52dbf5513ae7f106634967162da5cfb01dc5af3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 26 Jul 2025 01:47:32 +0100 Subject: feat: SOCL v1.0.2, changelog soon! Signed-off-by: Amlal El Mahrouss --- compile_flags.txt | 2 +- dev/examples/cgi/CMakeLists.txt | 12 ++ dev/examples/cgi/cgi.cc | 91 +++++++++++ dev/examples/equiv/CMakeLists.txt | 12 ++ dev/examples/equiv/equiv.cc | 19 +++ dev/examples/fix/CMakeLists.txt | 12 ++ dev/examples/fix/fix.cc | 26 ++++ dev/examples/opt/CMakeLists.txt | 12 ++ dev/examples/opt/opt.cc | 44 ++++++ dev/examples/tracked_ptr/CMakeLists.txt | 12 ++ dev/examples/tracked_ptr/tracked_ptr.cc | 52 +++++++ dev/lib/detail/error.hpp | 17 ++ dev/lib/fix/network.hpp | 20 +++ dev/lib/fix/parser.hpp | 198 ++++++++++++++++++++++++ dev/lib/io/print.hpp | 29 ++++ dev/lib/logic/equiv.hpp | 102 ++++++++++++ dev/lib/logic/math.hpp | 35 +++++ dev/lib/logic/opt.hpp | 121 +++++++++++++++ dev/lib/memory/tracked_ptr.hpp | 196 +++++++++++++++++++++++ dev/lib/utility/cgi.hpp | 62 ++++++++ dev/lib/utility/crc32.hpp | 74 +++++++++ dev/lib/utility/embfs.hpp | 79 ++++++++++ dev/tests/.gitkeep | 0 dev/tests/fix_basic/CMakeLists.txt | 23 +++ dev/tests/fix_basic/fix_test.cc | 18 +++ dev/tests/tracked_ptr_basic/CMakeLists.txt | 23 +++ dev/tests/tracked_ptr_basic/tracked_ptr_test.cc | 25 +++ dev/tests/tracked_ptr_leak/CMakeLists.txt | 23 +++ dev/tests/tracked_ptr_leak/tracked_ptr_test.cc | 19 +++ examples/cgi/CMakeLists.txt | 12 -- examples/cgi/cgi.cc | 91 ----------- examples/equiv/CMakeLists.txt | 12 -- examples/equiv/equiv.cc | 19 --- examples/fix/CMakeLists.txt | 12 -- examples/fix/fix.cc | 26 ---- examples/opt/CMakeLists.txt | 12 -- examples/opt/opt.cc | 44 ------ examples/tracked_ptr/CMakeLists.txt | 12 -- examples/tracked_ptr/tracked_ptr.cc | 52 ------- lib/detail/error.hpp | 17 -- lib/fix/network.hpp | 20 --- lib/fix/parser.hpp | 181 ---------------------- lib/io/print.hpp | 29 ---- lib/logic/equiv.hpp | 102 ------------ lib/logic/math.hpp | 35 ----- lib/logic/opt.hpp | 121 --------------- lib/memory/tracked_ptr.hpp | 195 ----------------------- lib/utility/cgi.hpp | 62 -------- lib/utility/crc32.hpp | 74 --------- lib/utility/embfs.hpp | 79 ---------- tests/tracked_ptr/CMakeLists.txt | 23 --- tests/tracked_ptr/tracked_ptr_test.cc | 26 ---- 52 files changed, 1357 insertions(+), 1257 deletions(-) create mode 100644 dev/examples/cgi/CMakeLists.txt create mode 100644 dev/examples/cgi/cgi.cc create mode 100644 dev/examples/equiv/CMakeLists.txt create mode 100644 dev/examples/equiv/equiv.cc create mode 100644 dev/examples/fix/CMakeLists.txt create mode 100644 dev/examples/fix/fix.cc create mode 100644 dev/examples/opt/CMakeLists.txt create mode 100644 dev/examples/opt/opt.cc create mode 100644 dev/examples/tracked_ptr/CMakeLists.txt create mode 100644 dev/examples/tracked_ptr/tracked_ptr.cc create mode 100644 dev/lib/detail/error.hpp create mode 100644 dev/lib/fix/network.hpp create mode 100644 dev/lib/fix/parser.hpp create mode 100644 dev/lib/io/print.hpp create mode 100644 dev/lib/logic/equiv.hpp create mode 100644 dev/lib/logic/math.hpp create mode 100644 dev/lib/logic/opt.hpp create mode 100644 dev/lib/memory/tracked_ptr.hpp create mode 100644 dev/lib/utility/cgi.hpp create mode 100644 dev/lib/utility/crc32.hpp create mode 100644 dev/lib/utility/embfs.hpp create mode 100644 dev/tests/.gitkeep create mode 100644 dev/tests/fix_basic/CMakeLists.txt create mode 100644 dev/tests/fix_basic/fix_test.cc create mode 100644 dev/tests/tracked_ptr_basic/CMakeLists.txt create mode 100644 dev/tests/tracked_ptr_basic/tracked_ptr_test.cc create mode 100644 dev/tests/tracked_ptr_leak/CMakeLists.txt create mode 100644 dev/tests/tracked_ptr_leak/tracked_ptr_test.cc delete mode 100644 examples/cgi/CMakeLists.txt delete mode 100644 examples/cgi/cgi.cc delete mode 100644 examples/equiv/CMakeLists.txt delete mode 100644 examples/equiv/equiv.cc delete mode 100644 examples/fix/CMakeLists.txt delete mode 100644 examples/fix/fix.cc delete mode 100644 examples/opt/CMakeLists.txt delete mode 100644 examples/opt/opt.cc delete mode 100644 examples/tracked_ptr/CMakeLists.txt delete mode 100644 examples/tracked_ptr/tracked_ptr.cc delete mode 100644 lib/detail/error.hpp delete mode 100644 lib/fix/network.hpp delete mode 100644 lib/fix/parser.hpp delete mode 100644 lib/io/print.hpp delete mode 100644 lib/logic/equiv.hpp delete mode 100644 lib/logic/math.hpp delete mode 100644 lib/logic/opt.hpp delete mode 100644 lib/memory/tracked_ptr.hpp delete mode 100644 lib/utility/cgi.hpp delete mode 100644 lib/utility/crc32.hpp delete mode 100644 lib/utility/embfs.hpp delete mode 100644 tests/tracked_ptr/CMakeLists.txt delete mode 100644 tests/tracked_ptr/tracked_ptr_test.cc diff --git a/compile_flags.txt b/compile_flags.txt index b804da6..b820259 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -1,4 +1,4 @@ --I./ +-Idev -std=c++20 -DEMBFS_28BIT_LBA -xc++ \ No newline at end of file diff --git a/dev/examples/cgi/CMakeLists.txt b/dev/examples/cgi/CMakeLists.txt new file mode 100644 index 0000000..391899f --- /dev/null +++ b/dev/examples/cgi/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + CGI + VERSION 1.0 + LANGUAGES CXX) + +add_executable(CGI cgi.cc) + +set_property(TARGET CGI PROPERTY CXX_STANDARD 20) +target_include_directories(CGI PUBLIC ../../) diff --git a/dev/examples/cgi/cgi.cc b/dev/examples/cgi/cgi.cc new file mode 100644 index 0000000..b4c0b34 --- /dev/null +++ b/dev/examples/cgi/cgi.cc @@ -0,0 +1,91 @@ +/* + cgi example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include +#include +#include + +const std::string g_not_found = R"( + + + + + error | snu-lib + + + +

Uh Oh!

+
No index file was found in this directory.
+
+ + + + + + + + + +
Name

Refresh

+
snu's Common Gateway Server.
+ + +)"; + +/* finally test it */ +/* @brief this stub loads a 'index.html' or returns an error message if not found. */ +int main(int argc, char** argv) +{ + // ... let's assume we serve data. + + snu::cgi::cgi_writer writer; + std::stringstream ss_file; + + std::ifstream fp("index.html"); + + if (fp.good()) + ss_file << fp.rdbuf(); + else + ss_file << g_not_found; + + fp.close(); + + writer.eval_html(ss_file); + + return 0; +} diff --git a/dev/examples/equiv/CMakeLists.txt b/dev/examples/equiv/CMakeLists.txt new file mode 100644 index 0000000..8b29e23 --- /dev/null +++ b/dev/examples/equiv/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Equiv + VERSION 1.0 + LANGUAGES CXX) + +add_executable(Equiv equiv.cc) + +set_property(TARGET Equiv PROPERTY CXX_STANDARD 20) +target_include_directories(Equiv PUBLIC ../../) diff --git a/dev/examples/equiv/equiv.cc b/dev/examples/equiv/equiv.cc new file mode 100644 index 0000000..896637d --- /dev/null +++ b/dev/examples/equiv/equiv.cc @@ -0,0 +1,19 @@ +/* + string checksum example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include + +/* finally test it */ +int main(int argc, char** argv) +{ + std::cout << std::boolalpha; + std::cout << snu::equiv::is_same::value << std::endl; + std::cout << snu::equiv::is_same::value << std::endl; + std::cout << snu::equiv::is_same::value << std::endl; + + return 0; +} diff --git a/dev/examples/fix/CMakeLists.txt b/dev/examples/fix/CMakeLists.txt new file mode 100644 index 0000000..db8921b --- /dev/null +++ b/dev/examples/fix/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Fix + VERSION 1.0 + LANGUAGES CXX) + +add_executable(Fix fix.cc) + +set_property(TARGET Fix PROPERTY CXX_STANDARD 20) +target_include_directories(Fix PUBLIC ../../) diff --git a/dev/examples/fix/fix.cc b/dev/examples/fix/fix.cc new file mode 100644 index 0000000..f67d8a0 --- /dev/null +++ b/dev/examples/fix/fix.cc @@ -0,0 +1,26 @@ +/* + fix example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include + +/* finally test it */ +int main(int argc, char** argv) +{ + snu::fix::visitor visitor; + snu::fix::range_data fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + + std::cout << "magic: " << fix.msg_magic_ << std::endl; + std::cout << "is_valid: " << std::boolalpha << fix.is_valid() << std::endl; + + for (auto fields : fix.msg_body_) + { + std::cout << "key: " << fields.first; + std::cout << ", value: " << fields.second << std::endl; + } + + return 0; +} diff --git a/dev/examples/opt/CMakeLists.txt b/dev/examples/opt/CMakeLists.txt new file mode 100644 index 0000000..b63b1de --- /dev/null +++ b/dev/examples/opt/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Opt + VERSION 1.0 + LANGUAGES CXX) + +add_executable(Opt opt.cc) + +set_property(TARGET Opt PROPERTY CXX_STANDARD 20) +target_include_directories(Opt PUBLIC ../../) diff --git a/dev/examples/opt/opt.cc b/dev/examples/opt/opt.cc new file mode 100644 index 0000000..a914d8d --- /dev/null +++ b/dev/examples/opt/opt.cc @@ -0,0 +1,44 @@ +/* + string checksum example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include +#include + +static const char do_hash(const std::string& in) +{ + int hash = 0; + + for (long index = 0; index < in.size(); ++index) + { + hash += in[index]; + } + + return hash; +} + +static auto do_some(const std::string recv_data, const std::string check_data) +{ + const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */ + const int opt_hash = do_hash(recv_data); /* we assume that the hash is correct */ + + auto opt = snu::opt::opt(snu::opt::eval_eq(hash_to_check, opt_hash)); /* do the compute */ + return opt; +} + +/* finally test it */ +int main(int argc, char** argv) +{ + // ... let's assume we fetch data from network... + + snu::println("Testing data..."); + + auto opt = do_some("Ohio", "Ohio"); + opt.expect("Checksum failed, Ohio isn't Ohio!"); + + + return 0; +} diff --git a/dev/examples/tracked_ptr/CMakeLists.txt b/dev/examples/tracked_ptr/CMakeLists.txt new file mode 100644 index 0000000..9396506 --- /dev/null +++ b/dev/examples/tracked_ptr/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + Fix + VERSION 1.0 + LANGUAGES CXX) + +add_executable(TrackedPtr tracked_ptr.cc) + +set_property(TARGET TrackedPtr PROPERTY CXX_STANDARD 20) +target_include_directories(TrackedPtr PUBLIC ../../) diff --git a/dev/examples/tracked_ptr/tracked_ptr.cc b/dev/examples/tracked_ptr/tracked_ptr.cc new file mode 100644 index 0000000..c182494 --- /dev/null +++ b/dev/examples/tracked_ptr/tracked_ptr.cc @@ -0,0 +1,52 @@ +/* + tracked_ptr example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include + +void summon_tracked_ptr() +{ + snu::memory::tracked_ptr ptr = snu::memory::make_tracked(42); + std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; +} + +void summon_leak_tracked_ptr() +{ + snu::memory::tracked_ptr* ptr = new snu::memory::tracked_ptr(42); + std::cout << ptr->data() << "=" << ptr->manager().allocator().allocated_count_ << std::endl; +} + +/* finally test it */ +int main(int argc, char** argv) +{ + summon_tracked_ptr(); + summon_tracked_ptr(); + summon_tracked_ptr(); + summon_tracked_ptr(); + + snu::memory::tracked_ptr ptr; + + std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; + + std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; + + std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; + + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + summon_leak_tracked_ptr(); + + std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; + + std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; + + return 0; +} diff --git a/dev/lib/detail/error.hpp b/dev/lib/detail/error.hpp new file mode 100644 index 0000000..85a5e25 --- /dev/null +++ b/dev/lib/detail/error.hpp @@ -0,0 +1,17 @@ +/* + * File: opt.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_ERR_HPP +#define _SNU_ERR_HPP + +#include + +namespace snu +{ + using runtime_error = std::runtime_error; +} + +#endif // _SNU_ERR_HPP \ No newline at end of file diff --git a/dev/lib/fix/network.hpp b/dev/lib/fix/network.hpp new file mode 100644 index 0000000..0ca0920 --- /dev/null +++ b/dev/lib/fix/network.hpp @@ -0,0 +1,20 @@ +/* +* File: fix/netowrk.hpp + * Purpose: Financial Information Exchange in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_FIX_NETWORK_HPP +#define _SNU_FIX_NETWORK_HPP + +#include +#include + +namespace snu::fix +{ + class network_rx; + class network_tx; +} // namespace snu::fix + +#endif // ifndef _SNU_FIX_NETWORK_HPP \ No newline at end of file diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp new file mode 100644 index 0000000..e432b6c --- /dev/null +++ b/dev/lib/fix/parser.hpp @@ -0,0 +1,198 @@ +/* + * File: fix/parser.hpp + * Purpose: Financial Information Exchange parser in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_FIX_PARSER_HPP +#define _SNU_FIX_PARSER_HPP + +#include +#include +#include +#include +#include + +namespace snu::fix +{ + template + struct visitor; + + template + struct range; + + template + struct range_data; + + /// @brief Buffer+Length structure + template + using range_ptr_t = range; + + namespace detail + { + template + const char_type* begin_fix(); + + template <> + inline const char* begin_fix() + { + return "FIX."; + } + + template <> + inline const char16_t* begin_fix() + { + return u"FIX."; + } + + template <> + inline const char8_t* begin_fix() + { + return u8"FIX."; + } + } // namespace detail + + template + struct range final + { + char_type* bytes_; + size_t length_; + + bool is_valid() + { + return bytes_ && length_ > 0; + } + + operator bool() + { + return this->is_valid(); + } + }; + + /// @brief Convert range to usable string. + /// @note This function assumes that the range is valid and contains ASCII bytes. + template + inline std::basic_string to_string(range& range) noexcept + { + if (range.length_ < 0) + return std::basic_string{}; + + return std::basic_string(range.ascii_bytes_, range.length_); + } + + /// @brief a range object containing the FIX packet values. + template + class range_data final + { + public: + std::basic_string msg_magic_; + std::size_t msg_body_len_; + std::vector, std::basic_string>> msg_body_; + + static inline const char_type* begin = detail::begin_fix(); + + explicit range_data() = default; + ~range_data() = default; + + range_data& operator=(const range_data&) = default; + range_data(const range_data&) = default; + + std::basic_string operator[](const std::basic_string& key) + { + if (key.empty()) + { + return std::basic_string{}; + } + + for (const auto& pair : msg_body_) + { + if (pair.first == key) + { + return pair.second; + } + } + return std::basic_string{}; + } + + bool is_valid() + { + return msg_magic_.starts_with(range_data::begin); + } + + operator bool() + { + return this->is_valid(); + } + }; + + /// @brief visitor object which returns a fix::range_data instance. + template + class visitor final + { + public: + static constexpr const char_type soh = '|'; + static constexpr const char_type eq = '='; + static constexpr uint32_t base = 10U; + + explicit visitor() = default; + ~visitor() = default; + + visitor& operator=(const visitor&) = default; + visitor(const visitor&) = default; + + range operator()(const std::basic_string& in) + { + return this->visit(in); + } + + range_data visit(const std::basic_string& in) + { + thread_local range_data ret{}; + + if (in.empty()) + return ret; + + thread_local std::basic_string in_tmp{}; + + in_tmp.reserve(in.size()); + + try + { + for (auto& ch : in) + { + if (ch != visitor::soh) + { + in_tmp += ch; + continue; + } + + std::basic_string key = in_tmp.substr(0, in_tmp.find(visitor::eq)); + std::basic_string val = in_tmp.substr(in_tmp.find(visitor::eq) + 1); + + if (ret.msg_magic_.empty()) + { + ret.msg_magic_ = val; + } + else + { + ret.msg_body_.emplace_back(std::make_pair(key, val)); + ret.msg_body_len_ += in_tmp.size(); + } + + in_tmp.clear(); + } + } + catch (...) + { + in_tmp.clear(); + return ret; + } + + in_tmp.clear(); + return ret; + } + }; +} // namespace snu::fix + +#endif // ifndef _SNU_FIX_PARSER_HPP diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp new file mode 100644 index 0000000..0a5b5e2 --- /dev/null +++ b/dev/lib/io/print.hpp @@ -0,0 +1,29 @@ +/* + * File: print.hpp + * Purpose: SNU Print library + * Author: Amlal El Mahrouss. (founder@snu.systems) + * Copyright 2025, SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_PRINT_HPP +#define _SNU_PRINT_HPP + +#include + +namespace snu +{ + template + inline void print(T... fmt) + { + std::cout << std::move(fmt...); + } + + template + inline void println(T... fmt) + { + std::cout << std::move(fmt...); + std::cout << std::endl; + } +} // namespace snu + +#endif // ifndef _SNU_PRINT_HPP \ No newline at end of file diff --git a/dev/lib/logic/equiv.hpp b/dev/lib/logic/equiv.hpp new file mode 100644 index 0000000..4bb5904 --- /dev/null +++ b/dev/lib/logic/equiv.hpp @@ -0,0 +1,102 @@ +/* + * File: equiv.hpp + * Purpose: Equivalence runtime c++ header. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#pragma once + +namespace snu::equiv +{ + template + struct basic_hash_trait + { + /// @brief hash from T's result. + static typename T::result hash() + { + static T val; + return val.hash(); + } + }; + + template + struct is_same + { + static constexpr bool value = false; + + /// @brief check if hash matches what we expect. + constexpr bool operator()() noexcept + { + return T::hash() == U::hash(); + } + }; + + template + struct is_same + { + static constexpr bool value = true; + }; + + template + struct is_not_same + { + static constexpr bool value = true; + + constexpr bool operator()() noexcept + { + return T::hash() != U::hash(); + } + }; + + template + struct is_not_same + { + static constexpr bool value = false; + }; + + template + struct equiv_is_int8 + { + private: + T left_ = 255, right_ = 255; + + public: + using result = T; + + constexpr result hash() + { + return (left_ + right_) < 1; + } + }; + + template + struct equiv_not_int8 + { + private: + T left_ = 255, right_ = 255; + + public: + using result = T; + + constexpr result hash() + { + return (left_ + right_) > 0; + } + }; + + template + struct equiv_is_real + { + private: + T left_ = 5, right_ = 3; + + public: + using result = T; + + constexpr result hash() + { + return left_ / right_; + } + }; +} // namespace snu::equiv \ No newline at end of file diff --git a/dev/lib/logic/math.hpp b/dev/lib/logic/math.hpp new file mode 100644 index 0000000..2613799 --- /dev/null +++ b/dev/lib/logic/math.hpp @@ -0,0 +1,35 @@ +/* + * File: math.hpp + * Purpose: Mathematics c++ header. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss all rights reserved. + */ + +#pragma once + +#include + +namespace snu::math +{ + template + struct is_non_boolean_integer final + { + static constexpr const bool value = true; + }; + + template <> + struct is_non_boolean_integer final + { + static constexpr const bool value = false; + }; + + template <> + struct is_non_boolean_integer final + { + static constexpr const bool value = false; + }; + + constexpr inline auto not_a_number = NAN; + constexpr inline auto positive_infinity = INFINITY; + constexpr inline auto negative_infinity = -positive_infinity; +} // namespace snu::math \ No newline at end of file diff --git a/dev/lib/logic/opt.hpp b/dev/lib/logic/opt.hpp new file mode 100644 index 0000000..facbf2c --- /dev/null +++ b/dev/lib/logic/opt.hpp @@ -0,0 +1,121 @@ +/* + * File: opt.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved. + */ + +#ifndef _SNU_OPT_HPP +#define _SNU_OPT_HPP + +#include +#include + +namespace snu::opt +{ + enum class return_type + { + invalid = 0, + okay = 100, + err, + count = err - okay + 1, + }; + + struct opt final + { + explicit opt(const return_type& return_type) + : m_ret(return_type) + { + } + + opt& expect(const char* input) + { + if (m_ret == return_type::err) + { + throw std::runtime_error(input); + } + + return *this; + } + + private: + return_type m_ret; + }; + + template + inline return_type eval(Teller tell, Lst&&... arg) + { + return tell(std::forward(arg)...) ? return_type::okay : return_type::err; + } + + namespace traits + { + struct int_eq_teller + { + explicit int_eq_teller() + { + } + + bool operator()(int a, int b) + { + return (a == b); + } + }; + + struct int_greater_than_teller + { + explicit int_greater_than_teller() + { + } + + bool operator()(int a, int b) + { + return (a > b); + } + }; + + struct int_less_than_teller + { + explicit int_less_than_teller() + { + } + + bool operator()(int a, int b) + { + return (a < b); + } + }; + } // namespace traits + + template + inline return_type eval_less_than(Lst&&... arg) + { + static traits::int_less_than_teller eq; + return eq(std::forward(arg)...) ? return_type::okay : return_type::err; + } + + template + inline return_type eval_eq(Lst&&... arg) + { + static traits::int_eq_teller less_than; + return less_than(std::forward(arg)...) ? return_type::okay : return_type::err; + } + + template + inline return_type eval_greater_than(Lst&&... arg) + { + static traits::int_greater_than_teller greater_than; + return greater_than(std::forward(arg)...) ? return_type::okay : return_type::err; + } + + inline return_type eval_true() + { + return return_type::okay; + } + + inline return_type eval_false() + { + return return_type::err; + } +} // namespace snu::opt + +#endif /* ifndef _SNU_OPT_HPP */ diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp new file mode 100644 index 0000000..238d521 --- /dev/null +++ b/dev/lib/memory/tracked_ptr.hpp @@ -0,0 +1,196 @@ +/* + * File: memory/tracked_ptr.hpp + * Purpose: Custom smart pointer implementation in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#pragma once + +#include +#include +#include +#include + +namespace snu::memory +{ + template + class tracked_allocator; + + template + class tracked_mgr; + + template + class tracked_ptr; + + template + class tracked_allocator + { + public: + std::atomic allocated_count_ = 0; + std::atomic deallocated_count_ = 0; + + public: + template + void retain(T*& ptr, U&&... args) + { + ptr = new T(args...); + + if (ptr) + { + ++allocated_count_; + } + else + { + throw std::bad_alloc(); + } + } + + void dispose(T* ptr) + { + if (ptr) + { + if (allocated_count_) + --allocated_count_; + + ++deallocated_count_; + + delete ptr; + ptr = nullptr; + } + } + }; + + template + class tracked_mgr + { + private: + tracked_allocator allocator_; + + public: + const tracked_allocator& allocator() + { + return allocator_; + } + + template + T* retain(U&&... args) + { + T* ptr = nullptr; + allocator_.retain(ptr, std::forward(args)...); + return ptr; + } + + void dispose(T* ptr) + { + allocator_.dispose(ptr); + } + }; + + template > + class tracked_ptr + { + public: + static Mgr& manager() + { + static Mgr mgr; + return mgr; + } + + public: + template + explicit tracked_ptr(U&&... args) + : ptr_(nullptr) + { + ptr_ = tracked_ptr::manager().retain(std::forward(args)...); + } + + ~tracked_ptr() noexcept + { + this->reset(); + } + + tracked_ptr(const tracked_ptr&) = delete; + tracked_ptr& operator=(const tracked_ptr&) = delete; + + public: + void reset() + { + if (ptr_) + { + tracked_ptr::manager().dispose(ptr_); + ptr_ = nullptr; + } + } + + T* get() const + { + return ptr_; + } + + T* data() + { + return ptr_; + } + + T& operator*() const + { + return *ptr_; + } + + T* operator->() const + { + return ptr_; + } + + explicit operator bool() const + { + return ptr_ != nullptr; + } + + void swap(tracked_ptr& other) + { + std::swap(ptr_, other.ptr_); + } + + public: + tracked_ptr(tracked_ptr&& other) noexcept + : ptr_(other.ptr_) + { + other.ptr_ = nullptr; + } + + tracked_ptr& operator=(tracked_ptr&& other) noexcept + { + if (this != &other) + { + this->reset(); + ptr_ = other.ptr_; + other.ptr_ = nullptr; + } + + return *this; + } + + private: + T* ptr_ = nullptr; + }; + + template + inline auto make_tracked(T arg) -> tracked_ptr + { + return tracked_ptr(std::forward(arg)); + } + + template + inline auto make_tracked(T&&... arg) -> tracked_ptr + { + return tracked_ptr(std::forward(arg)...); + } + + template + inline void swap(tracked_ptr& a, tracked_ptr& b) + { + a.swap(b); + } +} // namespace snu::memory \ No newline at end of file diff --git a/dev/lib/utility/cgi.hpp b/dev/lib/utility/cgi.hpp new file mode 100644 index 0000000..068adf1 --- /dev/null +++ b/dev/lib/utility/cgi.hpp @@ -0,0 +1,62 @@ +/* + * File: cgi.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. + */ + +#ifndef _SNU_CGI_HPP +#define _SNU_CGI_HPP + +#include +#include +#include + +namespace snu +{ + namespace cgi + { + /// @brief CGI Writer class, writes to stdout; as CGI expects. + class writer final + { + writer& eval_(const std::string& mime, const std::stringstream& ss) noexcept + { + std::printf("Content-Type: %s\r\n", mime.c_str()); + std::printf("Server: %s\r\n", "snu-cpp-library"); + std::printf("Content-Length: %ld\r\n\r\n", ss.str().size()); + std::printf("%s", ss.str().c_str()); + + return *this; + } + + public: + explicit writer() = default; + ~writer() = default; + + writer& operator=(const writer&) = default; + writer(const writer&) = default; + + public: + writer& eval_html(const std::stringstream& ss_html) + { + return this->eval_("text/html", ss_html); + } + + writer& eval_xml(const std::stringstream& ss_html) + { + return this->eval_("application/xml", ss_html); + } + + writer& eval_json(const std::stringstream& ss_html) + { + return this->eval_("application/json", ss_html); + } + + writer& eval_js(const std::stringstream& ss_html) + { + return this->eval_("text/javascript", ss_html); + } + }; + } // namespace cgi +} // namespace snu + +#endif // ifndef _SNU_CGI_HPP \ No newline at end of file diff --git a/dev/lib/utility/crc32.hpp b/dev/lib/utility/crc32.hpp new file mode 100644 index 0000000..de78d4e --- /dev/null +++ b/dev/lib/utility/crc32.hpp @@ -0,0 +1,74 @@ +/* + * File: embfs.hpp + * Purpose: Embedded File System. + * Author: Amlal El Mahrouss, + * Copyright 2025, Amlal El Mahrouss all rights reserved. + */ + +#ifndef _SNU_CRC32_HPP +#define _SNU_CRC32_HPP + +#include +#include + +/// @brief Crc32 implementation in C++ +/// @author Amlal EL Mahrouss (founder@snu.systems) + +namespace snu::crc32 +{ + namespace details + { + inline constexpr const std::uint16_t g_crc_sz = 256; + + inline std::uint32_t g_crc_table[g_crc_sz] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + /// + + inline std::uint32_t + calculate_crc32_(const char* in, size_t len) noexcept + { + if (!in || *in == 0) + return ~0; + + std::uint32_t crc = 0xffffffff; + + while ((len--) > 0) + crc = (crc >> 8) ^ g_crc_table[(crc ^ *(in++)) & 0xFF]; + + return ~crc; + } + } // namespace details +} // namespace snu::crc32 + +#endif // !_SNU_CRC32_HPP \ No newline at end of file diff --git a/dev/lib/utility/embfs.hpp b/dev/lib/utility/embfs.hpp new file mode 100644 index 0000000..cb08eb9 --- /dev/null +++ b/dev/lib/utility/embfs.hpp @@ -0,0 +1,79 @@ +/* + * File: embfs.hpp + * Purpose: Embedded File System. + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss all rights reserved. + */ + +#ifndef _SNU_EMBFS_HPP +#define _SNU_EMBFS_HPP + +#include +#include + +/// @brief A filesystem designed for tiny storage medias. +/// @author Amlal EL Mahrouss (founder@snu.systems) + +namespace snu::embfs +{ + namespace traits + { + struct embfs_superblock; + struct embfs_inode; + + inline constexpr const size_t _superblock_name_len = 16; + inline constexpr const size_t _superblock_reserve_len = 462; + inline constexpr const size_t _inode_name_len = 128; + inline constexpr const size_t _inode_arr_len = 12; + inline constexpr const size_t _inode_lookup_len = 8; + +#ifdef EMBFS_28BIT_LBA + typedef std::uint32_t lba_t; +#elif defined(EMBFS_48BIT_LBA) + typedef std::uint64_t lba_t; +#else + typedef std::uint32_t lba_t; +#endif + + typedef std::int16_t sword_t; + typedef std::int32_t sdword_t; + + typedef std::uint8_t utf8_char_t; + + /// @brief Superblock data structure + struct embfs_superblock + { + sword_t s_block_mag; + sdword_t s_num_inodes; + sdword_t s_part_size; + sdword_t s_part_used; + sdword_t s_version; + sword_t s_sector_sz; + lba_t s_inode_start; + lba_t s_inode_end; + utf8_char_t s_name[_superblock_name_len]; + utf8_char_t s_reserved[_superblock_reserve_len]; + }; + + /// @brief Indexed node structure. + /// @brief i_name file name + /// @brief i_size_virt, i_size_phys: virtual and physical (sector count) size. + /// @brief i_offset direct block pointer. + /// @brief i_checksum crc32 checksum. + /// @brief i_flags_perms flags and permissions + /// @brief i_acl_* ACL to keep track of inode allocation status. + struct embfs_inode + { + utf8_char_t i_name[_inode_name_len]; + sword_t i_size_virt, i_size_phys; + lba_t i_offset[_inode_lookup_len]; + sword_t i_checksum, i_flags_perms; + lba_t i_acl_creat, i_acl_edit, i_acl_delet; + }; + + /// @brief Indexed node linear array. + typedef embfs_inode embfs_inode_arr_t[_inode_arr_len]; + } // namespace traits +} // namespace snu::embfs + +#endif // ifndef _SNU_EMBFS_HPP \ No newline at end of file diff --git a/dev/tests/.gitkeep b/dev/tests/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/dev/tests/fix_basic/CMakeLists.txt b/dev/tests/fix_basic/CMakeLists.txt new file mode 100644 index 0000000..3a2542d --- /dev/null +++ b/dev/tests/fix_basic/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(TrackedPtrTests) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(FIXTestBasic fix_test.cc) +target_link_libraries(FIXTestBasic gtest_main) + +set_property(TARGET FIXTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(FIXTestBasic PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(FIXTestBasic) diff --git a/dev/tests/fix_basic/fix_test.cc b/dev/tests/fix_basic/fix_test.cc new file mode 100644 index 0000000..c9ae0b2 --- /dev/null +++ b/dev/tests/fix_basic/fix_test.cc @@ -0,0 +1,18 @@ +/* + * File: tests/tracked_ptr_test.cc + * Purpose: Custom smart pointer unit tests in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#include +#include + +TEST(FIXTest, BasicFIXUsage) +{ + snu::fix::visitor visitor; + snu::fix::range_data fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); + + EXPECT_EQ(fix.msg_magic_, "FIX.4.2"); + EXPECT_TRUE(fix.is_valid()); +} \ No newline at end of file diff --git a/dev/tests/tracked_ptr_basic/CMakeLists.txt b/dev/tests/tracked_ptr_basic/CMakeLists.txt new file mode 100644 index 0000000..97f7204 --- /dev/null +++ b/dev/tests/tracked_ptr_basic/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(TrackedPtrTests) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(TrackedPtrTestBasic tracked_ptr_test.cc) +target_link_libraries(TrackedPtrTestBasic gtest_main) + +set_property(TARGET TrackedPtrTestBasic PROPERTY CXX_STANDARD 20) +target_include_directories(TrackedPtrTestBasic PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(TrackedPtrTestBasic) diff --git a/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc new file mode 100644 index 0000000..462ec5f --- /dev/null +++ b/dev/tests/tracked_ptr_basic/tracked_ptr_test.cc @@ -0,0 +1,25 @@ +/* + * File: tests/tracked_ptr_test.cc + * Purpose: Custom smart pointer unit tests in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#include +#include + +TEST(TrackedPtrTest, BasicTrackedPtrUsage) +{ + snu::memory::tracked_ptr ptr = snu::memory::make_tracked(42); + + ASSERT_TRUE(ptr); + EXPECT_EQ(*ptr, 42); + + snu::memory::tracked_ptr ptr2; + + snu::memory::swap(ptr, ptr2); + + ptr2.reset(); + + EXPECT_EQ(snu::memory::tracked_ptr::manager().allocator().allocated_count_, 1); +} \ No newline at end of file diff --git a/dev/tests/tracked_ptr_leak/CMakeLists.txt b/dev/tests/tracked_ptr_leak/CMakeLists.txt new file mode 100644 index 0000000..17df8f1 --- /dev/null +++ b/dev/tests/tracked_ptr_leak/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.10) +project(TrackedPtrTests) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip +) + +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(TrackedPtrTestLeak tracked_ptr_test.cc) +target_link_libraries(TrackedPtrTestLeak gtest_main) + +set_property(TARGET TrackedPtrTestLeak PROPERTY CXX_STANDARD 20) +target_include_directories(TrackedPtrTestLeak PUBLIC ../../) + +include(GoogleTest) +gtest_discover_tests(TrackedPtrTestLeak) diff --git a/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc new file mode 100644 index 0000000..f583938 --- /dev/null +++ b/dev/tests/tracked_ptr_leak/tracked_ptr_test.cc @@ -0,0 +1,19 @@ +/* + * File: tests/tracked_ptr_test.cc + * Purpose: Custom smart pointer unit tests in C++ + * Author: Amlal El Mahrouss (founder@snu.systems) + * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. + */ + +#include +#include + +TEST(TrackedPtrTest, LeakTrackedPtrUsage) +{ + snu::memory::tracked_ptr* ptr = new snu::memory::tracked_ptr(42); + snu::memory::tracked_ptr* ptr2 = new snu::memory::tracked_ptr(42); + snu::memory::tracked_ptr* ptr3 = new snu::memory::tracked_ptr(42); + + EXPECT_EQ(snu::memory::tracked_ptr::manager().allocator().allocated_count_, 3); + ASSERT_TRUE(snu::memory::tracked_ptr::manager().allocator().deallocated_count_ == 0); +} \ No newline at end of file diff --git a/examples/cgi/CMakeLists.txt b/examples/cgi/CMakeLists.txt deleted file mode 100644 index 391899f..0000000 --- a/examples/cgi/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - CGI - VERSION 1.0 - LANGUAGES CXX) - -add_executable(CGI cgi.cc) - -set_property(TARGET CGI PROPERTY CXX_STANDARD 20) -target_include_directories(CGI PUBLIC ../../) diff --git a/examples/cgi/cgi.cc b/examples/cgi/cgi.cc deleted file mode 100644 index b4c0b34..0000000 --- a/examples/cgi/cgi.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - cgi example - written by Amlal El Mahrouss. - licensed under the MIT license - */ - -#include -#include -#include -#include - -const std::string g_not_found = R"( - - - - - error | snu-lib - - - -

Uh Oh!

-
No index file was found in this directory.
-
- - - - - - - - - -
Name

Refresh

-
snu's Common Gateway Server.
- - -)"; - -/* finally test it */ -/* @brief this stub loads a 'index.html' or returns an error message if not found. */ -int main(int argc, char** argv) -{ - // ... let's assume we serve data. - - snu::cgi::cgi_writer writer; - std::stringstream ss_file; - - std::ifstream fp("index.html"); - - if (fp.good()) - ss_file << fp.rdbuf(); - else - ss_file << g_not_found; - - fp.close(); - - writer.eval_html(ss_file); - - return 0; -} diff --git a/examples/equiv/CMakeLists.txt b/examples/equiv/CMakeLists.txt deleted file mode 100644 index 8b29e23..0000000 --- a/examples/equiv/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Equiv - VERSION 1.0 - LANGUAGES CXX) - -add_executable(Equiv equiv.cc) - -set_property(TARGET Equiv PROPERTY CXX_STANDARD 20) -target_include_directories(Equiv PUBLIC ../../) diff --git a/examples/equiv/equiv.cc b/examples/equiv/equiv.cc deleted file mode 100644 index 896637d..0000000 --- a/examples/equiv/equiv.cc +++ /dev/null @@ -1,19 +0,0 @@ -/* - string checksum example - written by Amlal El Mahrouss. - licensed under the MIT license - */ - -#include -#include - -/* finally test it */ -int main(int argc, char** argv) -{ - std::cout << std::boolalpha; - std::cout << snu::equiv::is_same::value << std::endl; - std::cout << snu::equiv::is_same::value << std::endl; - std::cout << snu::equiv::is_same::value << std::endl; - - return 0; -} diff --git a/examples/fix/CMakeLists.txt b/examples/fix/CMakeLists.txt deleted file mode 100644 index db8921b..0000000 --- a/examples/fix/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Fix - VERSION 1.0 - LANGUAGES CXX) - -add_executable(Fix fix.cc) - -set_property(TARGET Fix PROPERTY CXX_STANDARD 20) -target_include_directories(Fix PUBLIC ../../) diff --git a/examples/fix/fix.cc b/examples/fix/fix.cc deleted file mode 100644 index f67d8a0..0000000 --- a/examples/fix/fix.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - fix example - written by Amlal El Mahrouss. - licensed under the MIT license - */ - -#include -#include - -/* finally test it */ -int main(int argc, char** argv) -{ - snu::fix::visitor visitor; - snu::fix::range_data fix = visitor.visit("8=FIX.4.2|9=65|35=A|49=SERVER|56=CLIENT|34=177|52=20090107-18:15:16|98=0|108=30|10=062|"); - - std::cout << "magic: " << fix.msg_magic_ << std::endl; - std::cout << "is_valid: " << std::boolalpha << fix.is_valid() << std::endl; - - for (auto fields : fix.msg_body_) - { - std::cout << "key: " << fields.first; - std::cout << ", value: " << fields.second << std::endl; - } - - return 0; -} diff --git a/examples/opt/CMakeLists.txt b/examples/opt/CMakeLists.txt deleted file mode 100644 index b63b1de..0000000 --- a/examples/opt/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Opt - VERSION 1.0 - LANGUAGES CXX) - -add_executable(Opt opt.cc) - -set_property(TARGET Opt PROPERTY CXX_STANDARD 20) -target_include_directories(Opt PUBLIC ../../) diff --git a/examples/opt/opt.cc b/examples/opt/opt.cc deleted file mode 100644 index a914d8d..0000000 --- a/examples/opt/opt.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - string checksum example - written by Amlal El Mahrouss. - licensed under the MIT license - */ - -#include -#include -#include - -static const char do_hash(const std::string& in) -{ - int hash = 0; - - for (long index = 0; index < in.size(); ++index) - { - hash += in[index]; - } - - return hash; -} - -static auto do_some(const std::string recv_data, const std::string check_data) -{ - const int hash_to_check = do_hash(check_data); /* here we assume this should match opt_hash */ - const int opt_hash = do_hash(recv_data); /* we assume that the hash is correct */ - - auto opt = snu::opt::opt(snu::opt::eval_eq(hash_to_check, opt_hash)); /* do the compute */ - return opt; -} - -/* finally test it */ -int main(int argc, char** argv) -{ - // ... let's assume we fetch data from network... - - snu::println("Testing data..."); - - auto opt = do_some("Ohio", "Ohio"); - opt.expect("Checksum failed, Ohio isn't Ohio!"); - - - return 0; -} diff --git a/examples/tracked_ptr/CMakeLists.txt b/examples/tracked_ptr/CMakeLists.txt deleted file mode 100644 index 9396506..0000000 --- a/examples/tracked_ptr/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ - -cmake_minimum_required(VERSION 3.15...3.31) - -project( - Fix - VERSION 1.0 - LANGUAGES CXX) - -add_executable(TrackedPtr tracked_ptr.cc) - -set_property(TARGET TrackedPtr PROPERTY CXX_STANDARD 20) -target_include_directories(TrackedPtr PUBLIC ../../) diff --git a/examples/tracked_ptr/tracked_ptr.cc b/examples/tracked_ptr/tracked_ptr.cc deleted file mode 100644 index c182494..0000000 --- a/examples/tracked_ptr/tracked_ptr.cc +++ /dev/null @@ -1,52 +0,0 @@ -/* - tracked_ptr example - written by Amlal El Mahrouss. - licensed under the MIT license - */ - -#include -#include - -void summon_tracked_ptr() -{ - snu::memory::tracked_ptr ptr = snu::memory::make_tracked(42); - std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; -} - -void summon_leak_tracked_ptr() -{ - snu::memory::tracked_ptr* ptr = new snu::memory::tracked_ptr(42); - std::cout << ptr->data() << "=" << ptr->manager().allocator().allocated_count_ << std::endl; -} - -/* finally test it */ -int main(int argc, char** argv) -{ - summon_tracked_ptr(); - summon_tracked_ptr(); - summon_tracked_ptr(); - summon_tracked_ptr(); - - snu::memory::tracked_ptr ptr; - - std::cout << ptr.data() << "=" << ptr.manager().allocator().allocated_count_ << std::endl; - - std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; - - std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; - - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - summon_leak_tracked_ptr(); - - std::cout << "total=" << ptr.manager().allocator().deallocated_count_ << std::endl; - - std::cout << "leak-detected=" << std::boolalpha << (ptr.manager().allocator().allocated_count_ > ptr.manager().allocator().deallocated_count_) << std::endl; - - return 0; -} diff --git a/lib/detail/error.hpp b/lib/detail/error.hpp deleted file mode 100644 index 85a5e25..0000000 --- a/lib/detail/error.hpp +++ /dev/null @@ -1,17 +0,0 @@ -/* - * File: opt.hpp - * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_ERR_HPP -#define _SNU_ERR_HPP - -#include - -namespace snu -{ - using runtime_error = std::runtime_error; -} - -#endif // _SNU_ERR_HPP \ No newline at end of file diff --git a/lib/fix/network.hpp b/lib/fix/network.hpp deleted file mode 100644 index 0ca0920..0000000 --- a/lib/fix/network.hpp +++ /dev/null @@ -1,20 +0,0 @@ -/* -* File: fix/netowrk.hpp - * Purpose: Financial Information Exchange in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_FIX_NETWORK_HPP -#define _SNU_FIX_NETWORK_HPP - -#include -#include - -namespace snu::fix -{ - class network_rx; - class network_tx; -} // namespace snu::fix - -#endif // ifndef _SNU_FIX_NETWORK_HPP \ No newline at end of file diff --git a/lib/fix/parser.hpp b/lib/fix/parser.hpp deleted file mode 100644 index 95d05e6..0000000 --- a/lib/fix/parser.hpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * File: fix/parser.hpp - * Purpose: Financial Information Exchange parser in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_FIX_PARSER_HPP -#define _SNU_FIX_PARSER_HPP - -#include -#include -#include -#include -#include - -namespace snu::fix -{ - template - struct visitor; - - template - struct range; - - template - struct range_data; - - /// @brief Buffer+Length structure - template - using range_ptr_t = range; - - namespace detail - { - template - const char_type* begin_fix(); - - template <> - inline const char* begin_fix() - { - return "FIX."; - } - - template <> - inline const char16_t* begin_fix() - { - return u"FIX."; - } - - template <> - inline const char8_t* begin_fix() - { - return u8"FIX."; - } - } // namespace detail - - template - struct range final - { - char_type* bytes_; - size_t length_; - - bool is_valid() - { - return bytes_ && length_ > 0; - } - - operator bool() - { - return this->is_valid(); - } - }; - - /// @brief Convert range to usable string. - /// @note This function assumes that the range is valid and contains ASCII bytes. - template - inline std::basic_string to_string(range& range) noexcept - { - if (range.length_ < 0) - return std::basic_string{}; - - return std::basic_string(range.ascii_bytes_, range.length_); - } - - /// @brief a range object containing the FIX packet values. - template - class range_data final - { - public: - std::basic_string msg_magic_; - std::size_t msg_body_len_; - std::vector, std::basic_string>> msg_body_; - - static inline const char_type* begin = detail::begin_fix(); - - explicit range_data() = default; - ~range_data() = default; - - range_data& operator=(const range_data&) = default; - range_data(const range_data&) = default; - - bool is_valid() - { - return msg_magic_.starts_with(range_data::begin); - } - - operator bool() - { - return this->is_valid(); - } - }; - - /// @brief visitor object which returns a fix::range_data instance. - template - class visitor final - { - public: - static constexpr const char_type soh = '|'; - static constexpr const char_type eq = '='; - static constexpr uint32_t base = 10U; - - explicit visitor() = default; - ~visitor() = default; - - visitor& operator=(const visitor&) = default; - visitor(const visitor&) = default; - - range operator()(const std::basic_string& in) - { - return this->visit(in); - } - - range_data visit(const std::basic_string& in) - { - thread_local range_data ret{}; - - if (in.empty()) - return ret; - - thread_local std::basic_string in_tmp{}; - - in_tmp.reserve(in.size()); - - try - { - for (auto& ch : in) - { - if (ch != visitor::soh) - { - in_tmp += ch; - continue; - } - - std::basic_string key = in_tmp.substr(0, in_tmp.find(visitor::eq)); - std::basic_string val = in_tmp.substr(in_tmp.find(visitor::eq) + 1); - - if (ret.msg_magic_.empty()) - { - ret.msg_magic_ = val; - } - else - { - ret.msg_body_.emplace_back(std::make_pair(key, val)); - ret.msg_body_len_ += in_tmp.size(); - } - - in_tmp.clear(); - } - } - catch (...) - { - in_tmp.clear(); - return ret; - } - - in_tmp.clear(); - return ret; - } - }; -} // namespace snu::fix - -#endif // ifndef _SNU_FIX_PARSER_HPP diff --git a/lib/io/print.hpp b/lib/io/print.hpp deleted file mode 100644 index 0a5b5e2..0000000 --- a/lib/io/print.hpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * File: print.hpp - * Purpose: SNU Print library - * Author: Amlal El Mahrouss. (founder@snu.systems) - * Copyright 2025, SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_PRINT_HPP -#define _SNU_PRINT_HPP - -#include - -namespace snu -{ - template - inline void print(T... fmt) - { - std::cout << std::move(fmt...); - } - - template - inline void println(T... fmt) - { - std::cout << std::move(fmt...); - std::cout << std::endl; - } -} // namespace snu - -#endif // ifndef _SNU_PRINT_HPP \ No newline at end of file diff --git a/lib/logic/equiv.hpp b/lib/logic/equiv.hpp deleted file mode 100644 index 4bb5904..0000000 --- a/lib/logic/equiv.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * File: equiv.hpp - * Purpose: Equivalence runtime c++ header. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#pragma once - -namespace snu::equiv -{ - template - struct basic_hash_trait - { - /// @brief hash from T's result. - static typename T::result hash() - { - static T val; - return val.hash(); - } - }; - - template - struct is_same - { - static constexpr bool value = false; - - /// @brief check if hash matches what we expect. - constexpr bool operator()() noexcept - { - return T::hash() == U::hash(); - } - }; - - template - struct is_same - { - static constexpr bool value = true; - }; - - template - struct is_not_same - { - static constexpr bool value = true; - - constexpr bool operator()() noexcept - { - return T::hash() != U::hash(); - } - }; - - template - struct is_not_same - { - static constexpr bool value = false; - }; - - template - struct equiv_is_int8 - { - private: - T left_ = 255, right_ = 255; - - public: - using result = T; - - constexpr result hash() - { - return (left_ + right_) < 1; - } - }; - - template - struct equiv_not_int8 - { - private: - T left_ = 255, right_ = 255; - - public: - using result = T; - - constexpr result hash() - { - return (left_ + right_) > 0; - } - }; - - template - struct equiv_is_real - { - private: - T left_ = 5, right_ = 3; - - public: - using result = T; - - constexpr result hash() - { - return left_ / right_; - } - }; -} // namespace snu::equiv \ No newline at end of file diff --git a/lib/logic/math.hpp b/lib/logic/math.hpp deleted file mode 100644 index 2613799..0000000 --- a/lib/logic/math.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * File: math.hpp - * Purpose: Mathematics c++ header. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss all rights reserved. - */ - -#pragma once - -#include - -namespace snu::math -{ - template - struct is_non_boolean_integer final - { - static constexpr const bool value = true; - }; - - template <> - struct is_non_boolean_integer final - { - static constexpr const bool value = false; - }; - - template <> - struct is_non_boolean_integer final - { - static constexpr const bool value = false; - }; - - constexpr inline auto not_a_number = NAN; - constexpr inline auto positive_infinity = INFINITY; - constexpr inline auto negative_infinity = -positive_infinity; -} // namespace snu::math \ No newline at end of file diff --git a/lib/logic/opt.hpp b/lib/logic/opt.hpp deleted file mode 100644 index facbf2c..0000000 --- a/lib/logic/opt.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * File: opt.hpp - * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss/SNU Systems Corp all rights reserved. - */ - -#ifndef _SNU_OPT_HPP -#define _SNU_OPT_HPP - -#include -#include - -namespace snu::opt -{ - enum class return_type - { - invalid = 0, - okay = 100, - err, - count = err - okay + 1, - }; - - struct opt final - { - explicit opt(const return_type& return_type) - : m_ret(return_type) - { - } - - opt& expect(const char* input) - { - if (m_ret == return_type::err) - { - throw std::runtime_error(input); - } - - return *this; - } - - private: - return_type m_ret; - }; - - template - inline return_type eval(Teller tell, Lst&&... arg) - { - return tell(std::forward(arg)...) ? return_type::okay : return_type::err; - } - - namespace traits - { - struct int_eq_teller - { - explicit int_eq_teller() - { - } - - bool operator()(int a, int b) - { - return (a == b); - } - }; - - struct int_greater_than_teller - { - explicit int_greater_than_teller() - { - } - - bool operator()(int a, int b) - { - return (a > b); - } - }; - - struct int_less_than_teller - { - explicit int_less_than_teller() - { - } - - bool operator()(int a, int b) - { - return (a < b); - } - }; - } // namespace traits - - template - inline return_type eval_less_than(Lst&&... arg) - { - static traits::int_less_than_teller eq; - return eq(std::forward(arg)...) ? return_type::okay : return_type::err; - } - - template - inline return_type eval_eq(Lst&&... arg) - { - static traits::int_eq_teller less_than; - return less_than(std::forward(arg)...) ? return_type::okay : return_type::err; - } - - template - inline return_type eval_greater_than(Lst&&... arg) - { - static traits::int_greater_than_teller greater_than; - return greater_than(std::forward(arg)...) ? return_type::okay : return_type::err; - } - - inline return_type eval_true() - { - return return_type::okay; - } - - inline return_type eval_false() - { - return return_type::err; - } -} // namespace snu::opt - -#endif /* ifndef _SNU_OPT_HPP */ diff --git a/lib/memory/tracked_ptr.hpp b/lib/memory/tracked_ptr.hpp deleted file mode 100644 index ec19151..0000000 --- a/lib/memory/tracked_ptr.hpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * File: memory/tracked_ptr.hpp - * Purpose: Custom smart pointer implementation in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#pragma once - -#include -#include -#include -#include - -namespace snu::memory -{ - template - class tracked_allocator; - - template - class tracked_mgr; - - template - class tracked_ptr; - - template - class tracked_allocator - { - public: - std::atomic allocated_count_ = 0; - std::atomic deallocated_count_ = 0; - - public: - template - void retain(T*& ptr, U&&... args) - { - ptr = new T(args...); - - if (ptr) - { - ++allocated_count_; - } - else - { - throw std::bad_alloc(); - } - } - - void dispose(T* ptr) - { - if (ptr) - { - if (allocated_count_) - --allocated_count_; - - ++deallocated_count_; - - delete ptr; - ptr = nullptr; - } - } - }; - - template - class tracked_mgr - { - private: - tracked_allocator allocator_; - - public: - const tracked_allocator& allocator() - { - return allocator_; - } - - template - T* retain(U&&... args) - { - T* ptr = nullptr; - allocator_.retain(ptr, std::forward(args)...); - return ptr; - } - - void dispose(T* ptr) - { - allocator_.dispose(ptr); - } - }; - - template > - class tracked_ptr - { - public: - static Mgr& manager() - { - static Mgr mgr; - return mgr; - } - - public: - template - explicit tracked_ptr(U&&... args) - : ptr_(nullptr) - { - ptr_ = tracked_ptr::manager().retain(std::forward(args)...); - } - - ~tracked_ptr() noexcept - { - this->reset(); - } - - tracked_ptr(const tracked_ptr&) = delete; - tracked_ptr& operator=(const tracked_ptr&) = delete; - - public: - void reset() - { - if (ptr_) - { - tracked_ptr::manager().dispose(ptr_); - ptr_ = nullptr; - } - } - - T* get() const - { - return ptr_; - } - - T* data() - { - return ptr_; - } - - T& operator*() const - { - return *ptr_; - } - - T* operator->() const - { - return ptr_; - } - - explicit operator bool() const - { - return ptr_ != nullptr; - } - - void swap(tracked_ptr& other) - { - std::swap(ptr_, other.ptr_); - } - - public: - tracked_ptr(tracked_ptr&& other) noexcept - : ptr_(other.ptr_) - { - other.ptr_ = nullptr; - } - - tracked_ptr& operator=(tracked_ptr&& other) noexcept - { - if (this != &other) - { - this->reset(); - ptr_ = other.ptr_; - other.ptr_ = nullptr; - } - - return *this; - } - - private: - T* ptr_ = nullptr; - }; - - template - inline auto make_tracked(T arg) -> tracked_ptr { - return tracked_ptr(std::forward(arg)); - } - - - template - inline auto make_tracked(T&&... arg) -> tracked_ptr { - return tracked_ptr(std::forward(arg)...); - } - - template - inline void swap(tracked_ptr& a, tracked_ptr& b) - { - a.swap(b); - } -} // namespace snu::memory \ No newline at end of file diff --git a/lib/utility/cgi.hpp b/lib/utility/cgi.hpp deleted file mode 100644 index 068adf1..0000000 --- a/lib/utility/cgi.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * File: cgi.hpp - * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss all rights reserved. - */ - -#ifndef _SNU_CGI_HPP -#define _SNU_CGI_HPP - -#include -#include -#include - -namespace snu -{ - namespace cgi - { - /// @brief CGI Writer class, writes to stdout; as CGI expects. - class writer final - { - writer& eval_(const std::string& mime, const std::stringstream& ss) noexcept - { - std::printf("Content-Type: %s\r\n", mime.c_str()); - std::printf("Server: %s\r\n", "snu-cpp-library"); - std::printf("Content-Length: %ld\r\n\r\n", ss.str().size()); - std::printf("%s", ss.str().c_str()); - - return *this; - } - - public: - explicit writer() = default; - ~writer() = default; - - writer& operator=(const writer&) = default; - writer(const writer&) = default; - - public: - writer& eval_html(const std::stringstream& ss_html) - { - return this->eval_("text/html", ss_html); - } - - writer& eval_xml(const std::stringstream& ss_html) - { - return this->eval_("application/xml", ss_html); - } - - writer& eval_json(const std::stringstream& ss_html) - { - return this->eval_("application/json", ss_html); - } - - writer& eval_js(const std::stringstream& ss_html) - { - return this->eval_("text/javascript", ss_html); - } - }; - } // namespace cgi -} // namespace snu - -#endif // ifndef _SNU_CGI_HPP \ No newline at end of file diff --git a/lib/utility/crc32.hpp b/lib/utility/crc32.hpp deleted file mode 100644 index de78d4e..0000000 --- a/lib/utility/crc32.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * File: embfs.hpp - * Purpose: Embedded File System. - * Author: Amlal El Mahrouss, - * Copyright 2025, Amlal El Mahrouss all rights reserved. - */ - -#ifndef _SNU_CRC32_HPP -#define _SNU_CRC32_HPP - -#include -#include - -/// @brief Crc32 implementation in C++ -/// @author Amlal EL Mahrouss (founder@snu.systems) - -namespace snu::crc32 -{ - namespace details - { - inline constexpr const std::uint16_t g_crc_sz = 256; - - inline std::uint32_t g_crc_table[g_crc_sz] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; - /// - - inline std::uint32_t - calculate_crc32_(const char* in, size_t len) noexcept - { - if (!in || *in == 0) - return ~0; - - std::uint32_t crc = 0xffffffff; - - while ((len--) > 0) - crc = (crc >> 8) ^ g_crc_table[(crc ^ *(in++)) & 0xFF]; - - return ~crc; - } - } // namespace details -} // namespace snu::crc32 - -#endif // !_SNU_CRC32_HPP \ No newline at end of file diff --git a/lib/utility/embfs.hpp b/lib/utility/embfs.hpp deleted file mode 100644 index 8d5dbdf..0000000 --- a/lib/utility/embfs.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * File: embfs.hpp - * Purpose: Embedded File System. - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss all rights reserved. - */ - -#ifndef _SNU_EMBFS_HPP -#define _SNU_EMBFS_HPP - -#include -#include - -/// @brief A filesystem designed for tiny storage medias. -/// @author Amlal EL Mahrouss (founder@snu.systems) - -namespace snu::embfs -{ - namespace details - { - struct embfs_superblock; - struct embfs_inode; - - inline constexpr const size_t _superblock_name_len = 16; - inline constexpr const size_t _superblock_reserve_len = 462; - inline constexpr const size_t _inode_name_len = 128; - inline constexpr const size_t _inode_arr_len = 12; - inline constexpr const size_t _inode_lookup_len = 8; - -#ifdef EMBFS_28BIT_LBA - typedef std::uint32_t lba_t; -#elif defined(EMBFS_48BIT_LBA) - typedef std::uint64_t lba_t; -#else - typedef std::uint32_t lba_t; -#endif - - typedef std::int16_t sword_t; - typedef std::int32_t sdword_t; - - typedef std::uint8_t utf8_char_t; - - /// @brief Superblock data structure - struct embfs_superblock - { - sword_t s_block_mag; - sdword_t s_num_inodes; - sdword_t s_part_size; - sdword_t s_part_used; - sdword_t s_version; - sword_t s_sector_sz; - lba_t s_inode_start; - lba_t s_inode_end; - utf8_char_t s_name[_superblock_name_len]; - utf8_char_t s_reserved[_superblock_reserve_len]; - }; - - /// @brief Indexed node structure. - /// @brief i_name file name - /// @brief i_size_virt, i_size_phys: virtual and physical (sector count) size. - /// @brief i_offset direct block pointer. - /// @brief i_checksum crc32 checksum. - /// @brief i_flags_perms flags and permissions - /// @brief i_acl_* ACL to keep track of inode allocation status. - struct embfs_inode - { - utf8_char_t i_name[_inode_name_len]; - sword_t i_size_virt, i_size_phys; - lba_t i_offset[_inode_lookup_len]; - sword_t i_checksum, i_flags_perms; - lba_t i_acl_creat, i_acl_edit, i_acl_delet; - }; - - /// @brief Indexed node linear array. - typedef embfs_inode embfs_inode_arr_t[_inode_arr_len]; - } // namespace details -} // namespace snu::embfs - -#endif // ifndef _SNU_EMBFS_HPP \ No newline at end of file diff --git a/tests/tracked_ptr/CMakeLists.txt b/tests/tracked_ptr/CMakeLists.txt deleted file mode 100644 index d7e119f..0000000 --- a/tests/tracked_ptr/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(TrackedPtrTests) - -include(FetchContent) -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip -) - -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) - -enable_testing() - -add_executable(TrackedPtrTest tracked_ptr_test.cc) -target_link_libraries(TrackedPtrTest gtest_main) - -set_property(TARGET TrackedPtrTest PROPERTY CXX_STANDARD 20) -target_include_directories(TrackedPtrTest PUBLIC ../../) - -include(GoogleTest) -gtest_discover_tests(TrackedPtrTest) diff --git a/tests/tracked_ptr/tracked_ptr_test.cc b/tests/tracked_ptr/tracked_ptr_test.cc deleted file mode 100644 index 82d77f8..0000000 --- a/tests/tracked_ptr/tracked_ptr_test.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* - * File: tests/tracked_ptr_test.cc - * Purpose: Custom smart pointer unit tests in C++ - * Author: Amlal El Mahrouss (founder@snu.systems) - * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. - */ - -#include -#include - -TEST(TrackedPtrTest, BasicTrackedPtrUsage) { - snu::memory::tracked_ptr ptr = snu::memory::make_tracked(42); - - ASSERT_TRUE(ptr); - EXPECT_EQ(*ptr, 42); - - snu::memory::tracked_ptr ptr2 = std::move(ptr); - - ASSERT_FALSE(ptr); - ASSERT_TRUE(ptr2); - - EXPECT_EQ(*ptr2, 42); - - ptr2.reset(); - ASSERT_FALSE(ptr2); -} \ No newline at end of file -- cgit v1.2.3