diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-25 12:57:06 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-25 12:57:06 +0100 |
| commit | a3b23dcaabb53b8770c6ac8cfc33c6002b815589 (patch) | |
| tree | 2e6b0ee229c39686947938162b446989928bdf91 | |
| parent | 543f288e808b575f97efd56f2d14c495b49459f3 (diff) | |
feat: add clang-format, and improved public API.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | .clang-format | 16 | ||||
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | CMakeLists.txt | 17 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/config.hpp | 9 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.hpp | 74 | ||||
| -rw-r--r-- | include/ocl/tproc/detail/rope_fwd.inl | 72 | ||||
| -rw-r--r-- | include/ocl/tproc/rope.hpp | 11 | ||||
| -rw-r--r-- | install_tproc.cmake | 16 | ||||
| -rw-r--r-- | test/rope_test/crope.test.cpp | 13 |
9 files changed, 184 insertions, 48 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..fb3cacb --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +--- +BasedOnStyle: Microsoft +AccessModifierOffset: '-4' +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: 'true' +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +BinPackParameters: 'false' +ColumnLimit: '0' +Language: Cpp +NamespaceIndentation: All +PointerAlignment: Left +ReflowComments: 'true' +SortIncludes: 'false' +UseTab: Always +... @@ -1,6 +1,10 @@ # Prerequisites *.d +# build dir +build/ +bin/ + # Emacs *~ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5218c38 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +# // ============================================================= // +# // Open C++ Libraries. +# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under BSD-3 license. +# // ============================================================= // + +cmake_minimum_required(VERSION 3.30) + +project(OCL) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + + +if (INSTALL_OCL) + include(install_tproc.cmake) +endif() diff --git a/include/ocl/tproc/detail/config.hpp b/include/ocl/tproc/detail/config.hpp index 47bd0b2..e9880fd 100644 --- a/include/ocl/tproc/detail/config.hpp +++ b/include/ocl/tproc/detail/config.hpp @@ -13,9 +13,14 @@ #include <ocl/option.hpp> #include <ocl/smart_ptr.hpp> -namespace ocl { +#include <boost/core/detail/string_view.hpp> -namespace pmr {} +namespace ocl +{ + + namespace pmr + { + } } // namespace ocl diff --git a/include/ocl/tproc/detail/rope_fwd.hpp b/include/ocl/tproc/detail/rope_fwd.hpp index c9c3567..eadefce 100644 --- a/include/ocl/tproc/detail/rope_fwd.hpp +++ b/include/ocl/tproc/detail/rope_fwd.hpp @@ -6,49 +6,53 @@ #ifndef OCL_TPROC_ROPE_FWD_HPP #define OCL_TPROC_ROPE_FWD_HPP -#include <boost/utility/string_view.hpp> -#include <memory> +#include <ocl/tproc/detail/config.hpp> /// \file rope_fwd.hpp /// \brief Basic forward definitions of the `rope` type. -namespace ocl { - -/// \brief This class implements a rope type for any **CharT** type. -/// \note Specializations are available as `crope` and `wrope`. -/// \author Amlal El Mahrouss -template <class CharT, class Traits = std::char_traits<CharT>, - class Allocator = std::allocator<CharT>> -class basic_rope final { -public: - using traits_type = Traits; - using value_type = CharT; - using allocator_type = Allocator; - using size_type = std::allocator_traits<Allocator>::size_type; - using reference = CharT &; - using const_reference = const CharT &; - using pointer = std::allocator_traits<Allocator>::pointer; - using const_pointer = std::allocator_traits<Allocator>::pointer; - - CharT *begin(); - CharT *end(); - size_type size(); - bool empty() const; - - ~basic_rope(); - basic_rope(const boost::basic_string_view<CharT> &in = {}); - -private: - struct tree_impl; - std::unique_ptr<tree_impl> impl_; -}; +namespace ocl +{ + + /// \brief This class implements a rope type for any **CharT** type. + /// \note Specializations are available as `crope` and `wrope`. + /// \author Amlal El Mahrouss + template <class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>> + class basic_rope final + { + public: + using traits_type = Traits; + using value_type = CharT; + using allocator_type = Allocator; + using size_type = std::allocator_traits<Allocator>::size_type; + using reference = CharT&; + using const_reference = const CharT&; + using pointer = std::allocator_traits<Allocator>::pointer; + using const_pointer = std::allocator_traits<Allocator>::pointer; + + CharT* begin(); + CharT* end(); + size_type size(); + bool empty() const; + + ~basic_rope(); + basic_rope(const boost::core::basic_string_view<CharT>& in = {}); + + basic_rope& operator=(const basic_rope&& rope); + basic_rope(const basic_rope&& rope); + + private: + struct tree_impl; + tree_impl* impl_{}; + }; #if __cplusplus >= 201811L -using u8rope = basic_rope<char8_t>; + using u8rope = basic_rope<char8_t>; + using u16rope = basic_rope<char16_t>; #endif -using crope = basic_rope<char>; -using wrope = basic_rope<wchar_t>; + using crope = basic_rope<char>; + using wrope = basic_rope<wchar_t>; } // namespace ocl diff --git a/include/ocl/tproc/detail/rope_fwd.inl b/include/ocl/tproc/detail/rope_fwd.inl index 2d11c14..0dd1e92 100644 --- a/include/ocl/tproc/detail/rope_fwd.inl +++ b/include/ocl/tproc/detail/rope_fwd.inl @@ -6,17 +6,73 @@ #ifndef OCL_TPROC_ROPE_FWD_INL #define OCL_TPROC_ROPE_FWD_INL -namespace ocl { +namespace ocl +{ -template <class CharT, class Traits, class Allocator> -struct basic_rope<CharT, Traits, Allocator>::tree_impl {}; + template <class CharT, class Traits, class Allocator> + struct basic_rope<CharT, Traits, Allocator>::tree_impl + { + }; -template <class CharT, class Traits, class Allocator> -basic_rope<CharT, Traits, Allocator>::~basic_rope() = default; + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::~basic_rope() + { + delete impl_; + impl_ = nullptr; + } -template <class CharT, class Traits, class Allocator> -basic_rope<CharT, Traits, Allocator>::basic_rope( - const boost::basic_string_view<CharT> &in) {} + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>& + basic_rope<CharT, Traits, Allocator>::operator=( + const basic_rope<CharT, Traits, Allocator>&& rope) + { + delete this->impl_; + this->impl_ = rope.impl_; + rope.impl_ = nullptr; + + return *this; + } + + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::basic_rope( + const basic_rope<CharT, Traits, Allocator>&& rope) + { + delete this->impl_; + this->impl_ = rope.impl_; + rope.impl_ = nullptr; + } + + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::basic_rope( + const boost::core::basic_string_view<CharT>& in) + : impl_(new tree_impl()) + { + } + + template <class CharT, class Traits, class Allocator> + CharT* basic_rope<CharT, Traits, Allocator>::begin() + { + return nullptr; + } + + template <class CharT, class Traits, class Allocator> + CharT* basic_rope<CharT, Traits, Allocator>::end() + { + return nullptr; + } + + template <class CharT, class Traits, class Allocator> + basic_rope<CharT, Traits, Allocator>::size_type + basic_rope<CharT, Traits, Allocator>::size() + { + return 0UL; + } + + template <class CharT, class Traits, class Allocator> + bool basic_rope<CharT, Traits, Allocator>::empty() const + { + return true; + } } // namespace ocl diff --git a/include/ocl/tproc/rope.hpp b/include/ocl/tproc/rope.hpp index 86f1c5e..9a072c9 100644 --- a/include/ocl/tproc/rope.hpp +++ b/include/ocl/tproc/rope.hpp @@ -8,4 +8,15 @@ #include <ocl/tproc/detail/rope_fwd.hpp> +namespace ocl::tproc +{ + + template <typename It, class Pred> + It find(It begin, It end, Pred callable); + + template <typename It, class Callable> + It find_if(It begin, It end, Callable callable); + +} // namespace ocl::tproc + #endif // __OCL_TPROC_ROPE_HPP
\ No newline at end of file diff --git a/install_tproc.cmake b/install_tproc.cmake new file mode 100644 index 0000000..2c7a604 --- /dev/null +++ b/install_tproc.cmake @@ -0,0 +1,16 @@ +# // ============================================================= // +# // Open C++ Libraries. +# // Copyright (C) 2025, Amlal El Mahrouss and OCL Authors, licensed under BSD-3 license. +# // ============================================================= // + +cmake_minimum_required(VERSION 3.30) + +project(libocl VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +install(DIRECTORY include/ DESTINATION include) + +message(STATUS "OCL.TProc has been installed.") diff --git a/test/rope_test/crope.test.cpp b/test/rope_test/crope.test.cpp index f454e12..061da98 100644 --- a/test/rope_test/crope.test.cpp +++ b/test/rope_test/crope.test.cpp @@ -10,7 +10,14 @@ #define BOOST_TEST_MODULE crope #include <boost/test/included/unit_test.hpp> -BOOST_AUTO_TEST_CASE(allocator_should_succeed) { - auto rope = ocl::crope("foo"); - BOOST_TEST(rope.empty() == false); +BOOST_AUTO_TEST_CASE(allocator_should_succeed_in_empty) +{ + auto rope = ocl::crope(""); + BOOST_TEST(rope.empty() == true); +} + +BOOST_AUTO_TEST_CASE(allocator_should_not_succeed_in_empty) +{ + auto rope = ocl::crope("foobar"); + BOOST_TEST(rope.empty() == false); } |
