From 6d46e38cfee97c1c4a0a74a50d6cdeab705e73c5 Mon Sep 17 00:00:00 2001 From: Jack Drogon Date: Tue, 14 Nov 2023 17:23:48 +0800 Subject: [PATCH] chore: Add cpp binding Google style clang-format && format the code (#3581) --- bindings/cpp/.clang-format | 3 +++ bindings/cpp/include/opendal.hpp | 33 ++++++++++++++++--------------- bindings/cpp/src/opendal.cpp | 16 +++++++-------- bindings/cpp/tests/basic_test.cpp | 7 ++++--- 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 bindings/cpp/.clang-format diff --git a/bindings/cpp/.clang-format b/bindings/cpp/.clang-format new file mode 100644 index 000000000000..0e6bbdf3ccac --- /dev/null +++ b/bindings/cpp/.clang-format @@ -0,0 +1,3 @@ +--- +Language: Cpp +BasedOnStyle: Google diff --git a/bindings/cpp/include/opendal.hpp b/bindings/cpp/include/opendal.hpp index 10b73cf27b80..714cba7b9a9f 100644 --- a/bindings/cpp/include/opendal.hpp +++ b/bindings/cpp/include/opendal.hpp @@ -18,17 +18,18 @@ */ #pragma once -#include "lib.rs.h" -#include -#include -#include #include #include #include #include #include +#include "boost/date_time/posix_time/posix_time.hpp" +#include "boost/iostreams/concepts.hpp" +#include "boost/iostreams/stream.hpp" +#include "lib.rs.h" + namespace opendal { /** @@ -76,7 +77,7 @@ class Lister; * @brief Operator is the entry for all public APIs. */ class Operator { -public: + public: Operator() = default; /** @@ -187,7 +188,7 @@ class Operator { Lister lister(std::string_view path); -private: + private: std::optional> operator_; }; @@ -202,14 +203,14 @@ class Operator { */ class Reader : public boost::iostreams::device { -public: + public: Reader(rust::Box &&reader) : raw_reader_(std::move(reader)) {} std::streamsize read(void *s, std::streamsize n); std::streampos seek(std::streamoff off, std::ios_base::seekdir way); -private: + private: rust::Box raw_reader_; }; @@ -225,13 +226,13 @@ class Reader */ class ReaderStream : public boost::iostreams::stream> { -public: + public: ReaderStream(Reader &&reader) : boost::iostreams::stream>( boost::ref(reader_)), reader_(std::move(reader)) {} -private: + private: Reader reader_; }; @@ -248,7 +249,7 @@ class ReaderStream * @endcode */ class Lister { -public: + public: Lister(rust::Box &&lister) : raw_lister_(std::move(lister)) {} @@ -259,7 +260,7 @@ class Lister { * Lister. */ class ListerIterator { - public: + public: using iterator_category = std::input_iterator_tag; using value_type = Entry; using difference_type = std::ptrdiff_t; @@ -284,11 +285,11 @@ class Lister { other.current_entry_ != std::nullopt; } - protected: + protected: // Only used for end iterator ListerIterator(Lister &lister, bool /*end*/) : lister_(lister) {} - private: + private: Lister &lister_; std::optional current_entry_; @@ -305,7 +306,7 @@ class Lister { ListerIterator begin() { return ListerIterator(*this); } ListerIterator end() { return ListerIterator(*this, true); } -private: + private: rust::Box raw_lister_; }; -} // namespace opendal \ No newline at end of file +} // namespace opendal diff --git a/bindings/cpp/src/opendal.cpp b/bindings/cpp/src/opendal.cpp index a81af91cd232..01bb99813d08 100644 --- a/bindings/cpp/src/opendal.cpp +++ b/bindings/cpp/src/opendal.cpp @@ -157,13 +157,13 @@ std::optional parse_optional_string(ffi::OptionalString &&s) { ffi::SeekDir to_rust_seek_dir(std::ios_base::seekdir dir) { switch (dir) { - case std::ios_base::beg: - return ffi::SeekDir::Start; - case std::ios_base::cur: - return ffi::SeekDir::Current; - case std::ios_base::end: - return ffi::SeekDir::End; - default: - throw std::runtime_error("invalid seekdir"); + case std::ios_base::beg: + return ffi::SeekDir::Start; + case std::ios_base::cur: + return ffi::SeekDir::Current; + case std::ios_base::end: + return ffi::SeekDir::End; + default: + throw std::runtime_error("invalid seekdir"); } } \ No newline at end of file diff --git a/bindings/cpp/tests/basic_test.cpp b/bindings/cpp/tests/basic_test.cpp index 445e62584027..8d3da07f8d98 100644 --- a/bindings/cpp/tests/basic_test.cpp +++ b/bindings/cpp/tests/basic_test.cpp @@ -17,8 +17,6 @@ * under the License. */ -#include "opendal.hpp" -#include "gtest/gtest.h" #include #include #include @@ -26,8 +24,11 @@ #include #include +#include "gtest/gtest.h" +#include "opendal.hpp" + class OpendalTest : public ::testing::Test { -protected: + protected: opendal::Operator op; std::string scheme;