forked from apache/opendal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add basic example for cpp binding (apache#3108)
* chore: add basic example for cpp binding Signed-off-by: silver-ymz <[email protected]> * typo Signed-off-by: silver-ymz <[email protected]> * typo Signed-off-by: silver-ymz <[email protected]> * use exist commit Signed-off-by: silver-ymz <[email protected]> --------- Signed-off-by: silver-ymz <[email protected]>
- Loading branch information
1 parent
4b02228
commit d2e923c
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(opendal-cpp-examples) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
opendal-cpp | ||
GIT_REPOSITORY https://github.com/apache/incubator-opendal.git | ||
GIT_TAG 4b02228f7fe9a7c0f21a1660fee95716910c7a0a | ||
SOURCE_SUBDIR bindings/cpp | ||
) | ||
FetchContent_MakeAvailable(opendal-cpp) | ||
|
||
add_executable(basic-example basic.cpp) | ||
target_link_libraries(basic-example opendal_cpp) | ||
include_directories(basic-example opendal_cpp) | ||
|
||
if(APPLE) | ||
target_link_libraries(basic-example "-framework CoreFoundation -framework Security") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# OpenDAL Cpp Examples | ||
|
||
Thank you for using OpenDAL Cpp Core! | ||
|
||
## Run Examples | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
./basic-example | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "opendal.hpp" | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
int main() { | ||
char s[] = "memory"; | ||
std::vector<uint8_t> data = {'a', 'b', 'c'}; | ||
|
||
// Init operator | ||
opendal::Operator op = opendal::Operator(s); | ||
|
||
// Write data to operator | ||
op.write("test", data); | ||
|
||
// Read data from operator | ||
auto res = op.read("test"); // res == data | ||
|
||
// Using reader | ||
auto reader = op.reader("test"); | ||
opendal::ReaderStream stream(reader); | ||
std::string res2; | ||
stream >> res2; // res2 == "abc" | ||
} |