diff --git a/rosbag2_compression/CMakeLists.txt b/rosbag2_compression/CMakeLists.txt index ef7341adf9..728e8d1515 100644 --- a/rosbag2_compression/CMakeLists.txt +++ b/rosbag2_compression/CMakeLists.txt @@ -56,6 +56,7 @@ target_compile_definitions(${PROJECT_NAME}_zstd add_library(${PROJECT_NAME} SHARED + src/rosbag2_compression/compression_factory.cpp src/rosbag2_compression/compression_options.cpp src/rosbag2_compression/sequential_compression_reader.cpp src/rosbag2_compression/sequential_compression_writer.cpp) diff --git a/rosbag2_compression/include/rosbag2_compression/compression_factory.hpp b/rosbag2_compression/include/rosbag2_compression/compression_factory.hpp new file mode 100644 index 0000000000..1db1ab7c6d --- /dev/null +++ b/rosbag2_compression/include/rosbag2_compression/compression_factory.hpp @@ -0,0 +1,67 @@ +// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_HPP_ +#define ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_HPP_ + +#include +#include + +#include "base_compressor_interface.hpp" +#include "base_decompressor_interface.hpp" +#include "compression_options.hpp" +#include "visibility_control.hpp" + +namespace rosbag2_compression +{ + +/** + * Implementation of CompressionFactory. + * This class implements methods for creating instances of a BaseCompressionInterface and + * BaseDecompressionInterface. + * This class should only be used by CompressionFactory. + */ +class CompressionFactoryImpl; + +class ROSBAG2_COMPRESSION_PUBLIC CompressionFactory +{ +public: + CompressionFactory(); + ~CompressionFactory(); + + /** + * Create a compressor based on the specified compression format. + * + * \param compression_format The compression format as a string. + * \return A unique pointer to the newly created compressor. + */ + std::unique_ptr + create_compressor(const std::string & compression_format); + + /** + * Create a decompressor based on the specified compression format. + * + * \param compression_format The compression format as a string. + * \return A unique pointer to the newly created decompressor. + */ + std::unique_ptr + create_decompressor(const std::string & compression_format); + +private: + std::unique_ptr impl_; +}; + +} // namespace rosbag2_compression + +#endif // ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_HPP_ diff --git a/rosbag2_compression/src/rosbag2_compression/compression_factory.cpp b/rosbag2_compression/src/rosbag2_compression/compression_factory.cpp new file mode 100644 index 0000000000..0efd1be1a1 --- /dev/null +++ b/rosbag2_compression/src/rosbag2_compression/compression_factory.cpp @@ -0,0 +1,42 @@ +// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "rosbag2_compression/compression_factory.hpp" + +#include "compression_factory_impl.hpp" + +namespace rosbag2_compression +{ + +CompressionFactory::CompressionFactory() +: impl_(new CompressionFactoryImpl()) {} + +CompressionFactory::~CompressionFactory() = default; + +std::unique_ptr +CompressionFactory::create_compressor(const std::string & compression_format) +{ + return impl_->create_compressor(compression_format); +} + +std::unique_ptr +CompressionFactory::create_decompressor(const std::string & compression_format) +{ + return impl_->create_decompressor(compression_format); +} + +} // namespace rosbag2_compression diff --git a/rosbag2_compression/src/rosbag2_compression/compression_factory_impl.hpp b/rosbag2_compression/src/rosbag2_compression/compression_factory_impl.hpp new file mode 100644 index 0000000000..ba923f003b --- /dev/null +++ b/rosbag2_compression/src/rosbag2_compression/compression_factory_impl.hpp @@ -0,0 +1,49 @@ +// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_IMPL_HPP_ +#define ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_IMPL_HPP_ + +#include +#include + +#include "rosbag2_compression/compression_factory.hpp" + +namespace rosbag2_compression +{ + +/// Implementation of the CompressionFactory. See CompressionFactory for documentation. +class CompressionFactoryImpl +{ +public: + CompressionFactoryImpl() = default; + ~CompressionFactoryImpl() = default; + + /// See CompressionFactory::create_compressor for documentation. + std::unique_ptr + create_compressor(const std::string &) + { + throw std::logic_error{"Not implemented"}; + } + + /// See CompressionFactory::create_decompressor for documentation. + std::unique_ptr + create_decompressor(const std::string &) + { + throw std::logic_error{"Not implemented"}; + } +}; +} // namespace rosbag2_compression + +#endif // ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_IMPL_HPP_