This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d46e38cf chore: Add cpp binding Google style clang-format && format 
the code (#3581)
6d46e38cf is described below

commit 6d46e38cfee97c1c4a0a74a50d6cdeab705e73c5
Author: Jack Drogon <[email protected]>
AuthorDate: Tue Nov 14 17:23:48 2023 +0800

    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(-)

diff --git a/bindings/cpp/.clang-format b/bindings/cpp/.clang-format
new file mode 100644
index 000000000..0e6bbdf3c
--- /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 10b73cf27..714cba7b9 100644
--- a/bindings/cpp/include/opendal.hpp
+++ b/bindings/cpp/include/opendal.hpp
@@ -18,17 +18,18 @@
  */
 
 #pragma once
-#include "lib.rs.h"
 
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/iostreams/concepts.hpp>
-#include <boost/iostreams/stream.hpp>
 #include <memory>
 #include <optional>
 #include <string>
 #include <unordered_map>
 #include <vector>
 
+#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 @@ public:
 
   Lister lister(std::string_view path);
 
-private:
+ private:
   std::optional<rust::Box<opendal::ffi::Operator>> operator_;
 };
 
@@ -202,14 +203,14 @@ private:
  */
 class Reader
     : public boost::iostreams::device<boost::iostreams::input_seekable> {
-public:
+ public:
   Reader(rust::Box<opendal::ffi::Reader> &&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<opendal::ffi::Reader> raw_reader_;
 };
 
@@ -225,13 +226,13 @@ private:
  */
 class ReaderStream
     : public boost::iostreams::stream<boost::reference_wrapper<Reader>> {
-public:
+ public:
   ReaderStream(Reader &&reader)
       : boost::iostreams::stream<boost::reference_wrapper<Reader>>(
             boost::ref(reader_)),
         reader_(std::move(reader)) {}
 
-private:
+ private:
   Reader reader_;
 };
 
@@ -248,7 +249,7 @@ private:
  * @endcode
  */
 class Lister {
-public:
+ public:
   Lister(rust::Box<opendal::ffi::Lister> &&lister)
       : raw_lister_(std::move(lister)) {}
 
@@ -259,7 +260,7 @@ public:
    * 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 @@ public:
              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<Entry> current_entry_;
 
@@ -305,7 +306,7 @@ public:
   ListerIterator begin() { return ListerIterator(*this); }
   ListerIterator end() { return ListerIterator(*this, true); }
 
-private:
+ private:
   rust::Box<opendal::ffi::Lister> 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 a81af91cd..01bb99813 100644
--- a/bindings/cpp/src/opendal.cpp
+++ b/bindings/cpp/src/opendal.cpp
@@ -157,13 +157,13 @@ std::optional<std::string> 
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 445e62584..8d3da07f8 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 <ctime>
 #include <optional>
 #include <random>
@@ -26,8 +24,11 @@
 #include <unordered_map>
 #include <vector>
 
+#include "gtest/gtest.h"
+#include "opendal.hpp"
+
 class OpendalTest : public ::testing::Test {
-protected:
+ protected:
   opendal::Operator op;
 
   std::string scheme;

Reply via email to