Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make on TextLogLevel PascalCase (instead of SCREAMING CASE) to avoid clashes with preprocessor defines #4152

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading