Skip to content

Commit

Permalink
Make on TextLogLevel PascalCase (instead of SCREAMING CASE) to avoid …
Browse files Browse the repository at this point in the history
…clashes with preprocessor defines (#4152)

### What

Considered also just using lower case on these (nobody would do `#define
debug`, ... RIGHT?). But they are _enum - like_ constants so all-caps
felt appropriate.

### 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 [demo.rerun.io](https://demo.rerun.io/pr/4152) (if
applicable)
* [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/4152)
- [Docs
preview](https://rerun.io/preview/ff8b29947f85102e649b7cb2ed651228888d3bf1/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/ff8b29947f85102e649b7cb2ed651228888d3bf1/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
Wumpf authored Nov 6, 2023
1 parent ce2493c commit 8a97416
Show file tree
Hide file tree
Showing 208 changed files with 905 additions and 582 deletions.
7 changes: 7 additions & 0 deletions CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,18 @@ class Rect {
}
```

### Constants & Enums

Constants & enum values have PascalCase names.

When possible, use `constexpr` for (global & struct/class scoped) constants.

### String handling
Whenever possible we use `std::string_view` to pass strings.

To accommodate for this and other languages, strings on the C interface are almost never expected to be null-terminated and are always passed along with a byte length using `rr_string`.


### Misc
We don't add `inline` before class/struct member functions if they are inlined in the class/struct definition.

Expand Down
30 changes: 15 additions & 15 deletions crates/re_types_builder/src/codegen/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ impl QuotedObject {
// Putting non-POD types in a union requires C++11.
//
// enum class Rotation3DTag : uint8_t {
// NONE = 0,
// None = 0,
// Quaternion,
// AxisAngle,
// };
Expand Down Expand Up @@ -722,7 +722,7 @@ impl QuotedObject {
let comment = quote_doc_comment(
"Having a special empty state makes it possible to implement move-semantics. \
We need to be able to leave the object in a state which we can run the destructor on.");
let tag_name = format_ident!("NONE");
let tag_name = format_ident!("None");
quote! {
#NEWLINE_TOKEN
#comment
Expand Down Expand Up @@ -854,7 +854,7 @@ impl QuotedObject {
let destructor_match_arms = std::iter::once({
let comment = quote_comment("Nothing to destroy");
quote! {
case detail::#tag_typename::NONE: {
case detail::#tag_typename::None: {
#NEWLINE_TOKEN
#comment
} break;
Expand Down Expand Up @@ -948,7 +948,7 @@ impl QuotedObject {
switch (other._tag) {
#(#placement_new_arms)*

case detail::#tag_typename::NONE: {
case detail::#tag_typename::None: {
// there is nothing to copy
} break;
}
Expand All @@ -967,7 +967,7 @@ impl QuotedObject {
#trivial_memcpy
} break;

case detail::#tag_typename::NONE: {
case detail::#tag_typename::None: {
// there is nothing to copy
} break;
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ impl QuotedObject {
struct #pascal_case_ident {
#(#constants_hpp;)*

#pascal_case_ident() : _tag(detail::#tag_typename::NONE) {}
#pascal_case_ident() : _tag(detail::#tag_typename::None) {}

#copy_constructor

Expand Down Expand Up @@ -1235,7 +1235,7 @@ fn new_arrow_array_builder_method(
},
definition_body: quote! {
if (memory_pool == nullptr) {
return Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null.");
return rerun::Error(ErrorCode::UnexpectedNullArgument, "Memory pool is null.");
}
#NEWLINE_TOKEN
#NEWLINE_TOKEN
Expand Down Expand Up @@ -1264,18 +1264,18 @@ fn fill_arrow_array_builder_method(
docs: "Fills an arrow array builder with an array of this type.".into(),
declaration: MethodDeclaration {
is_static: true,
return_type: quote! { Error },
return_type: quote! { rerun::Error },
// TODO(andreas): Pass in validity map.
name_and_parameters: quote! {
fill_arrow_array_builder(arrow::#arrow_builder_type* #builder, const #type_ident* elements, size_t num_elements)
},
},
definition_body: quote! {
if (builder == nullptr) {
return Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null.");
return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null.");
}
if (elements == nullptr) {
return Error(ErrorCode::UnexpectedNullArgument, "Cannot serialize null pointer to arrow array.");
return rerun::Error(ErrorCode::UnexpectedNullArgument, "Cannot serialize null pointer to arrow array.");
}
#NEWLINE_TOKEN
#NEWLINE_TOKEN
Expand Down Expand Up @@ -1415,7 +1415,7 @@ fn quote_fill_arrow_array_builder(
quote! {
(void)num_elements;
if (true) { // Works around unreachability compiler warning.
return Error(ErrorCode::NotImplemented, "TODO(andreas) Handle nullable extensions");
return rerun::Error(ErrorCode::NotImplemented, "TODO(andreas) Handle nullable extensions");
}
}
} else {
Expand Down Expand Up @@ -1470,7 +1470,7 @@ fn quote_fill_arrow_array_builder(
let error = format!("Failed to serialize {}::{}: nullable list types in unions not yet implemented", obj.name, variant.name);
quote! {
(void)#variant_builder;
return Error(ErrorCode::NotImplemented, #error);
return rerun::Error(ErrorCode::NotImplemented, #error);
}
} else if arrow_builder_type == "ListBuilder" {
let field_name = format_ident!("{}", variant.snake_case_name());
Expand Down Expand Up @@ -1522,15 +1522,15 @@ fn quote_fill_arrow_array_builder(
let error = format!("Failed to serialize {}::{}: objects ({:?}) in unions not yet implemented", obj.name, variant.name, element_type);
quote! {
(void)#variant_builder;
return Error(ErrorCode::NotImplemented, #error);
return rerun::Error(ErrorCode::NotImplemented, #error);
}
}
}
} else {
let error = format!("Failed to serialize {}::{}: {} in unions not yet implemented", obj.name, variant.name, arrow_builder_type);
quote! {
(void)#variant_builder;
return Error(ErrorCode::NotImplemented, #error);
return rerun::Error(ErrorCode::NotImplemented, #error);
}
}
} else {
Expand Down Expand Up @@ -1559,7 +1559,7 @@ fn quote_fill_arrow_array_builder(
#NEWLINE_TOKEN
#NEWLINE_TOKEN
switch (union_instance._tag) {
case detail::#tag_name::NONE: {
case detail::#tag_name::None: {
ARROW_RETURN_NOT_OK(variant_builder_untyped->AppendNull());
} break;
#(#tag_cases)*
Expand Down
2 changes: 1 addition & 1 deletion docs/code-examples/text_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ int main() {
const auto rec = rerun::RecordingStream("rerun_example_text_log");
rec.spawn().exit_on_failure();

rec.log("log", rerun::TextLog("Application started.").with_level(rerun::TextLogLevel::INFO));
rec.log("log", rerun::TextLog("Application started.").with_level(rerun::TextLogLevel::Info));
}
14 changes: 7 additions & 7 deletions docs/code-examples/text_log_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ void loguru_to_rerun(void* user_data, const loguru::Message& message) {

rerun::TextLogLevel level;
if (message.verbosity == loguru::Verbosity_FATAL) {
level = rerun::TextLogLevel::CRITICAL;
level = rerun::TextLogLevel::Critical;
} else if (message.verbosity == loguru::Verbosity_ERROR) {
level = rerun::TextLogLevel::ERROR;
level = rerun::TextLogLevel::Error;
} else if (message.verbosity == loguru::Verbosity_WARNING) {
level = rerun::TextLogLevel::WARN;
level = rerun::TextLogLevel::Warning;
} else if (message.verbosity == loguru::Verbosity_INFO) {
level = rerun::TextLogLevel::INFO;
level = rerun::TextLogLevel::Info;
} else if (message.verbosity == loguru::Verbosity_1) {
level = rerun::TextLogLevel::DEBUG;
level = rerun::TextLogLevel::Debug;
} else if (message.verbosity == loguru::Verbosity_2) {
level = rerun::TextLogLevel::TRACE;
level = rerun::TextLogLevel::Trace;
} else {
level = rerun::TextLogLevel(std::to_string(message.verbosity));
}
Expand All @@ -38,7 +38,7 @@ int main() {
// Log a text entry directly:
rec.log(
"logs",
rerun::TextLog("this entry has loglevel TRACE").with_level(rerun::TextLogLevel::TRACE)
rerun::TextLog("this entry has loglevel TRACE").with_level(rerun::TextLogLevel::Trace)
);

loguru::add_callback(
Expand Down
8 changes: 6 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ py-test = { cmd = "python -m pytest -vv rerun_py/tests/unit", depends_on = [
cpp-clean = "rm -rf build CMakeCache.txt CMakeFiles"
cpp-build-all = { depends_on = [
"cpp-prepare",
"cpp-build-tests",
"cpp-build-examples",
"cpp-build-doc-examples",
"cpp-build-examples",
"cpp-build-roundtrips",
"cpp-build-tests",
] }
cpp-build-tests = { cmd = "cmake --build build --config Debug --target rerun_sdk_tests", depends_on = [
"cpp-prepare",
] }
cpp-build-roundtrips = { cmd = "cmake --build build --config Debug --target roundtrips", depends_on = [
"cpp-prepare",
] }
cpp-build-examples = { cmd = "cmake --build build --config Debug --target examples", depends_on = [
"cpp-prepare",
] }
Expand Down
14 changes: 7 additions & 7 deletions rerun_cpp/src/rerun/archetypes/text_log.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions rerun_cpp/src/rerun/blueprint/auto_space_views.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/blueprint/auto_space_views.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions rerun_cpp/src/rerun/blueprint/panel_view.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/blueprint/panel_view.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions rerun_cpp/src/rerun/blueprint/space_view_component.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/blueprint/space_view_component.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions rerun_cpp/src/rerun/blueprint/space_view_maximized.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rerun_cpp/src/rerun/blueprint/space_view_maximized.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8a97416

Please sign in to comment.