Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
directly use ament_clang_format rules
Browse files Browse the repository at this point in the history
Signed-off-by: James Smith <james@foxglove.dev>
  • Loading branch information
james-rms committed Nov 22, 2022
1 parent d6a68c5 commit a7bde0f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 103 deletions.
24 changes: 2 additions & 22 deletions rosbag2_storage_mcap/.clang-format
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
---
Language: Cpp
Standard: c++17
BasedOnStyle: Google

AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
TabWidth: 2
ContinuationIndentWidth: 2
UseTab: Never
BreakConstructorInitializers: BeforeComma
BraceWrapping:
AfterClass: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
BreakBeforeBraces: Custom
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false
DerivePointerAlignment: false
FixNamespaceComments: true
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 2
DerivePointerAlignment: false
PointerAlignment: Middle
ReflowComments: false
SortIncludes: true
IndentPPDirectives: BeforeHash

IncludeCategories:
- Regex: '^"'
Priority: 1
- Regex: "^<mcap"
Priority: 2
- Regex: "^<.*/"
Priority: 3
- Regex: "^<.*"
Priority: 4
...
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#ifndef ROSBAG2_STORAGE_MCAP__MESSAGE_DEFINITION_CACHE_HPP_
#define ROSBAG2_STORAGE_MCAP__MESSAGE_DEFINITION_CACHE_HPP_

#include "visibility_control.hpp"

#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>

#include "visibility_control.hpp"

namespace rosbag2_storage_mcap::internal
{

Expand Down Expand Up @@ -56,15 +56,9 @@ class DefinitionNotFoundError : public std::exception
std::string name_;

public:
explicit DefinitionNotFoundError(std::string name)
: name_(std::move(name))
{
}
explicit DefinitionNotFoundError(std::string name) : name_(std::move(name)) {}

const char * what() const noexcept override
{
return name_.c_str();
}
const char * what() const noexcept override { return name_.c_str(); }
};

class MessageDefinitionCache final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define ROSBAG2_STORAGE_MCAP_EXPORT __attribute__((dllexport))
#define ROSBAG2_STORAGE_MCAP_IMPORT __attribute__((dllimport))
#else
#define ROSBAG2_STORAGE_MCAP_EXPORT __declspec(dllexport)
#define ROSBAG2_STORAGE_MCAP_IMPORT __declspec(dllimport)
#endif
#ifdef ROSBAG2_STORAGE_MCAP_BUILDING_DLL
#define ROSBAG2_STORAGE_MCAP_PUBLIC ROSBAG2_STORAGE_MCAP_EXPORT
#else
#define ROSBAG2_STORAGE_MCAP_PUBLIC ROSBAG2_STORAGE_MCAP_IMPORT
#endif
#ifdef __GNUC__
#define ROSBAG2_STORAGE_MCAP_EXPORT __attribute__((dllexport))
#define ROSBAG2_STORAGE_MCAP_IMPORT __attribute__((dllimport))
#else
#define ROSBAG2_STORAGE_MCAP_EXPORT __attribute__((visibility("default")))
#define ROSBAG2_STORAGE_MCAP_IMPORT
#if __GNUC__ >= 4
#define ROSBAG2_STORAGE_MCAP_PUBLIC __attribute__((visibility("default")))
#else
#define ROSBAG2_STORAGE_MCAP_PUBLIC
#endif
#define ROSBAG2_STORAGE_MCAP_EXPORT __declspec(dllexport)
#define ROSBAG2_STORAGE_MCAP_IMPORT __declspec(dllimport)
#endif
#ifdef ROSBAG2_STORAGE_MCAP_BUILDING_DLL
#define ROSBAG2_STORAGE_MCAP_PUBLIC ROSBAG2_STORAGE_MCAP_EXPORT
#else
#define ROSBAG2_STORAGE_MCAP_PUBLIC ROSBAG2_STORAGE_MCAP_IMPORT
#endif
#else
#define ROSBAG2_STORAGE_MCAP_EXPORT __attribute__((visibility("default")))
#define ROSBAG2_STORAGE_MCAP_IMPORT
#if __GNUC__ >= 4
#define ROSBAG2_STORAGE_MCAP_PUBLIC __attribute__((visibility("default")))
#else
#define ROSBAG2_STORAGE_MCAP_PUBLIC
#endif
#endif

#endif // ROSBAG2_STORAGE_MCAP__VISIBILITY_CONTROL_HPP_
58 changes: 21 additions & 37 deletions rosbag2_storage_mcap/src/mcap_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,34 @@
#include "rosbag2_storage_mcap/message_definition_cache.hpp"

#ifdef ROSBAG2_STORAGE_MCAP_HAS_YAML_HPP
#include "rosbag2_storage/yaml.hpp"
#include "rosbag2_storage/yaml.hpp"
#else
// COMPATIBILITY(foxy, galactic) - this block is available in rosbag2_storage/yaml.hpp in H
#ifdef _WIN32
// This is necessary because of a bug in yaml-cpp's cmake
#define YAML_CPP_DLL
// This is necessary because yaml-cpp does not always use dllimport/dllexport consistently
#pragma warning(push)
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)
#endif
#include "yaml-cpp/yaml.h"
#ifdef _WIN32
#pragma warning(pop)
#endif
// COMPATIBILITY(foxy, galactic) - this block is available in rosbag2_storage/yaml.hpp in H
#ifdef _WIN32
// This is necessary because of a bug in yaml-cpp's cmake
#define YAML_CPP_DLL
// This is necessary because yaml-cpp does not always use dllimport/dllexport consistently
#pragma warning(push)
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)
#endif
#include "yaml-cpp/yaml.h"
#ifdef _WIN32
#pragma warning(pop)
#endif
#endif

#include <mcap/mcap.hpp>

#include <algorithm>
#include <filesystem>
#include <mcap/mcap.hpp>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#ifdef ROSBAG2_STORAGE_MCAP_HAS_STORAGE_FILTER_TOPIC_REGEX
#include <regex>
#include <regex>
#endif

#define DECLARE_YAML_VALUE_MAP(KEY_TYPE, VALUE_TYPE, ...) \
Expand Down Expand Up @@ -85,10 +84,7 @@ namespace
// Simple wrapper with default constructor for use by YAML
struct McapWriterOptions : mcap::McapWriterOptions
{
McapWriterOptions()
: mcap::McapWriterOptions("ros2")
{
}
McapWriterOptions() : mcap::McapWriterOptions("ros2") {}
};

} // namespace
Expand Down Expand Up @@ -415,10 +411,7 @@ rosbag2_storage::BagMetadata MCAPStorage::get_metadata()
return metadata_;
}

std::string MCAPStorage::get_relative_file_path() const
{
return relative_path_;
}
std::string MCAPStorage::get_relative_file_path() const { return relative_path_; }

uint64_t MCAPStorage::get_bagfile_size() const
{
Expand All @@ -433,10 +426,7 @@ uint64_t MCAPStorage::get_bagfile_size() const
}
}

std::string MCAPStorage::get_storage_identifier() const
{
return "mcap";
}
std::string MCAPStorage::get_storage_identifier() const { return "mcap"; }

/** BaseReadInterface **/
bool MCAPStorage::read_and_enqueue_message()
Expand Down Expand Up @@ -596,21 +586,15 @@ void MCAPStorage::set_filter(const rosbag2_storage::StorageFilter & storage_filt
reset_iterator();
}

void MCAPStorage::reset_filter()
{
set_filter(rosbag2_storage::StorageFilter());
}
void MCAPStorage::reset_filter() { set_filter(rosbag2_storage::StorageFilter()); }

void MCAPStorage::seek(const rcutils_time_point_value_t & time_stamp)
{
reset_iterator(time_stamp);
}

/** ReadWriteInterface **/
uint64_t MCAPStorage::get_minimum_split_file_size() const
{
return 1024;
}
uint64_t MCAPStorage::get_minimum_split_file_size() const { return 1024; }

/** BaseWriteInterface **/
void MCAPStorage::write(std::shared_ptr<const rosbag2_storage::SerializedBagMessage> msg)
Expand Down
10 changes: 5 additions & 5 deletions rosbag2_storage_mcap/src/message_definition_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include "rosbag2_storage_mcap/message_definition_cache.hpp"

#include <rcutils/logging_macros.h>

#include <ament_index_cpp/get_package_share_directory.hpp>
#include <ament_index_cpp/get_resource.hpp>
#include <ament_index_cpp/get_resources.hpp>
#include <rcutils/logging_macros.h>

#include <fstream>
#include <functional>
#include <optional>
Expand Down Expand Up @@ -121,9 +121,9 @@ static std::string delimiter(const DefinitionIdentifier & definition_identifier)
}

MessageSpec::MessageSpec(Format format, std::string text, const std::string & package_context)
: dependencies(parse_dependencies(format, text, package_context))
, text(std::move(text))
, format(format)
: dependencies(parse_dependencies(format, text, package_context)),
text(std::move(text)),
format(format)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
#include "rosbag2_cpp/writer.hpp"
#include "rosbag2_cpp/writers/sequential_writer.hpp"
#ifdef ROSBAG2_STORAGE_MCAP_HAS_STORAGE_OPTIONS
#include "rosbag2_storage/storage_options.hpp"
#include "rosbag2_storage/storage_options.hpp"
using StorageOptions = rosbag2_storage::StorageOptions;
#else
#include "rosbag2_cpp/storage_options.hpp"
#include "rosbag2_cpp/storage_options.hpp"
using StorageOptions = rosbag2_cpp::StorageOptions;
#endif
#include "rosbag2_test_common/temporary_directory_fixture.hpp"
#include "std_msgs/msg/string.hpp"

#include <gmock/gmock.h>

#include <memory>
#include <string>

#include "rosbag2_test_common/temporary_directory_fixture.hpp"
#include "std_msgs/msg/string.hpp"

using namespace ::testing; // NOLINT
using TemporaryDirectoryFixture = rosbag2_test_common::TemporaryDirectoryFixture;

Expand Down Expand Up @@ -130,9 +130,9 @@ TEST_F(TemporaryDirectoryFixture, can_write_mcap_with_zstd_configured_from_yaml)
msg.data = message_data;

rosbag2_cpp::Writer writer{std::make_unique<rosbag2_cpp::writers::SequentialWriter>()};
#ifndef ROSBAG2_STORAGE_MCAP_WRITER_CREATES_DIRECTORY
#ifndef ROSBAG2_STORAGE_MCAP_WRITER_CREATES_DIRECTORY
rcpputils::fs::create_directories(uri);
#endif
#endif
writer.open(options, rosbag2_cpp::ConverterOptions{});
writer.create_topic(topic_metadata);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "gmock/gmock.h"
#include "rosbag2_storage_mcap/message_definition_cache.hpp"

#include <set>
#include <string>

#include "gmock/gmock.h"
#include "rosbag2_storage_mcap/message_definition_cache.hpp"

using rosbag2_storage_mcap::internal::Format;
using rosbag2_storage_mcap::internal::MessageDefinitionCache;
using rosbag2_storage_mcap::internal::parse_dependencies;
Expand Down

0 comments on commit a7bde0f

Please sign in to comment.