Skip to content

Commit d277e27

Browse files
committed
add cpp example
1 parent 20e06e2 commit d277e27

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

examples/cpp/stdio/CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required(VERSION 3.16...3.27)
2+
3+
# If you use the example outside of the Rerun SDK you need to specify
4+
# where the rerun_c build is to be found by setting the `RERUN_CPP_URL` variable.
5+
# This can be done by passing `-DRERUN_CPP_URL=<path to rerun_sdk_cpp zip>` to cmake.
6+
if(DEFINED RERUN_REPOSITORY)
7+
add_executable(example_stdio main.cpp)
8+
rerun_strict_warning_settings(example_stdio)
9+
else()
10+
project(example_stdio LANGUAGES CXX)
11+
12+
add_executable(example_stdio main.cpp)
13+
14+
# Set the path to the rerun_c build.
15+
set(RERUN_CPP_URL "https://github.com/rerun-io/rerun/releases/latest/download/rerun_cpp_sdk.zip" CACHE STRING "URL to the rerun_cpp zip.")
16+
option(RERUN_FIND_PACKAGE "Whether to use find_package to find a preinstalled rerun package (instead of using FetchContent)." OFF)
17+
18+
if(RERUN_FIND_PACKAGE)
19+
find_package(rerun_sdk REQUIRED)
20+
else()
21+
# Download the rerun_sdk
22+
include(FetchContent)
23+
FetchContent_Declare(rerun_sdk URL ${RERUN_CPP_URL})
24+
FetchContent_MakeAvailable(rerun_sdk)
25+
endif()
26+
27+
# Rerun requires at least C++17, but it should be compatible with newer versions.
28+
set_property(TARGET example_stdio PROPERTY CXX_STANDARD 17)
29+
endif()
30+
31+
# Link against rerun_sdk.
32+
target_link_libraries(example_stdio PRIVATE rerun_sdk)

examples/cpp/stdio/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Standard Input/Output example
3+
python: https://github.com/rerun-io/rerun/tree/latest/examples/python/stdio/main.py?speculative-link
4+
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/stdio/src/main.rs?speculative-link
5+
cpp: https://github.com/rerun-io/rerun/tree/latest/examples/cpp/stdio/main.cpp?speculative-link
6+
thumbnail: https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/480w.png
7+
---
8+
9+
<picture>
10+
<img src="https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/full.png" alt="">
11+
<source media="(max-width: 480px)" srcset="https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/480w.png">
12+
<source media="(max-width: 768px)" srcset="https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/768w.png">
13+
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/1024w.png">
14+
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/stdio/25c5aba992d4c8b3861386d8d9539a4823dca117/1200w.png">
15+
</picture>
16+
17+
Demonstrates how to log data to standard output with the Rerun SDK, and then visualize it from standard input with the Rerun Viewer.
18+
19+
To build it from a checkout of the repository (requires a Rust toolchain):
20+
```bash
21+
just cpp-build-examples
22+
echo 'hello from stdin!' | ./build/debug/examples/cpp/stdio/example_stdio | rerun
23+
```

examples/cpp/stdio/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
#include <rerun.hpp>
5+
#include <rerun/demo_utils.hpp>
6+
7+
using rerun::demo::grid3d;
8+
9+
int main() {
10+
const auto rec = rerun::RecordingStream("rerun_example_stdio");
11+
rec.stdout().exit_on_failure();
12+
13+
std::string input;
14+
std::string line;
15+
while (std::getline(std::cin, line)) {
16+
input += line + '\n';
17+
}
18+
19+
rec.log("stdin", rerun::TextDocument(input));
20+
}

0 commit comments

Comments
 (0)