-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ & Python API: add helpers for constructing an entity path (#4595)
### What Added `rr.new_entity_path`, which constructs an entity path from a list of strings. `rr.log` also accepts such a list of unescaped strings directly. In C++, `rerun::new_entity_path` has been added, e.g. `rerun::new_entity_path({"world", "unescaped string!"})`. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4595/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4595/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4595/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4595) - [Docs preview](https://rerun.io/preview/a5103b62304217c31d9c410aa435a54406e24161/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/a5103b62304217c31d9c410aa435a54406e24161/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
- Loading branch information
Showing
17 changed files
with
299 additions
and
24 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
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
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
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,20 @@ | ||
// Log a `TextDocument` | ||
|
||
#include <rerun.hpp> | ||
|
||
int main() { | ||
const auto rec = rerun::RecordingStream("rerun_example_text_document"); | ||
rec.spawn().exit_on_failure(); | ||
|
||
rec.log( | ||
R"(world/42/escaped\ string\!)", | ||
rerun::TextDocument("This entity path was escaped manually") | ||
); | ||
rec.log( | ||
rerun::new_entity_path({"world", std::to_string(42), "unescaped string!"}), | ||
rerun::TextDocument("This entity path was provided as a list of unescaped strings") | ||
); | ||
|
||
assert(rerun::escape_entity_path_part("my string!") == R"(my\ string\!)"); | ||
assert(rerun::new_entity_path({"world", "42", "my string!"}) == R"(/world/42/my\ string\!)"); | ||
} |
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,11 @@ | ||
import rerun as rr | ||
|
||
rr.init("rerun_example_entity_path", spawn=True) | ||
|
||
rr.log(r"world/42/escaped\ string\!", rr.TextDocument("This entity path was escaped manually")) | ||
rr.log( | ||
["world", 42, "unescaped string!"], rr.TextDocument("This entity path was provided as a list of unescaped strings") | ||
) | ||
|
||
assert rr.escape_entity_path_part("my string!") == r"my\ string\!" | ||
assert rr.new_entity_path(["world", 42, "my string!"]) == r"/world/42/my\ string\!" |
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,16 @@ | ||
//! Example of different ways of constructing an entity path. | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let rec = rerun::RecordingStreamBuilder::new("rerun_example_text_document").spawn()?; | ||
|
||
rec.log( | ||
r"world/42/escaped\ string\!", | ||
&rerun::TextDocument::new("This entity path was escaped manually"), | ||
)?; | ||
rec.log( | ||
rerun::entity_path!["world", 42, "unescaped string!"], | ||
&rerun::TextDocument::new("This entity path was provided as a list of unescaped strings"), | ||
)?; | ||
|
||
Ok(()) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
#include "entity_path.hpp" | ||
|
||
#include "c/rerun.h" | ||
#include "error.hpp" | ||
#include "string_utils.hpp" | ||
|
||
namespace rerun { | ||
std::string escape_entity_path_part(std::string_view unescaped) { | ||
auto escaped_c_str = _rr_escape_entity_path_part(detail::to_rr_string(unescaped)); | ||
|
||
if (escaped_c_str == nullptr) { | ||
Error(ErrorCode::InvalidStringArgument, "Failed to escape entity path part").handle(); | ||
return std::string(unescaped); | ||
} else { | ||
std::string result = escaped_c_str; | ||
_rr_free_string(escaped_c_str); | ||
return result; | ||
} | ||
} | ||
|
||
std::string new_entity_path(const std::vector<std::string_view>& path) { | ||
if (path.empty()) { | ||
return "/"; | ||
} | ||
|
||
std::string result; | ||
|
||
for (const auto& part : path) { | ||
result += "/"; | ||
result += escape_entity_path_part(part); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} // namespace rerun |
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,19 @@ | ||
#pragma once | ||
|
||
#include <string_view> | ||
#include <vector> | ||
|
||
namespace rerun { | ||
|
||
/// Escape an individual part of an entity path. | ||
/// | ||
/// For instance, `escape_entity_path_path("my image!")` will return `"my\ image\!"`. | ||
std::string escape_entity_path_part(std::string_view str); | ||
|
||
/// Construct an entity path by escaping each part of the path. | ||
/// | ||
/// For instance, `rerun::new_entity_path({"world", 42, "unescaped string!"})` will return | ||
/// `"world/42/escaped\ string\!"`. | ||
std::string new_entity_path(const std::vector<std::string_view>& path); | ||
|
||
} // namespace rerun |
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
Oops, something went wrong.