Skip to content

Commit

Permalink
chore: Add cpp binding Google style clang-format && format the code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDrogon authored Nov 14, 2023
1 parent b908c66 commit 6d46e38
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
3 changes: 3 additions & 0 deletions bindings/cpp/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
Language: Cpp
BasedOnStyle: Google
33 changes: 17 additions & 16 deletions bindings/cpp/include/opendal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down Expand Up @@ -76,7 +77,7 @@ class Lister;
* @brief Operator is the entry for all public APIs.
*/
class Operator {
public:
public:
Operator() = default;

/**
Expand Down Expand Up @@ -187,7 +188,7 @@ class Operator {

Lister lister(std::string_view path);

private:
private:
std::optional<rust::Box<opendal::ffi::Operator>> operator_;
};

Expand All @@ -202,14 +203,14 @@ class Operator {
*/
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_;
};

Expand All @@ -225,13 +226,13 @@ class Reader
*/
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_;
};

Expand All @@ -248,7 +249,7 @@ class ReaderStream
* @endcode
*/
class Lister {
public:
public:
Lister(rust::Box<opendal::ffi::Lister> &&lister)
: raw_lister_(std::move(lister)) {}

Expand All @@ -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;
Expand All @@ -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<Entry> current_entry_;

Expand All @@ -305,7 +306,7 @@ class Lister {
ListerIterator begin() { return ListerIterator(*this); }
ListerIterator end() { return ListerIterator(*this, true); }

private:
private:
rust::Box<opendal::ffi::Lister> raw_lister_;
};
} // namespace opendal
} // namespace opendal
16 changes: 8 additions & 8 deletions bindings/cpp/src/opendal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
7 changes: 4 additions & 3 deletions bindings/cpp/tests/basic_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
* under the License.
*/

#include "opendal.hpp"
#include "gtest/gtest.h"
#include <ctime>
#include <optional>
#include <random>
#include <string>
#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;
Expand Down

0 comments on commit 6d46e38

Please sign in to comment.