Skip to content

Commit

Permalink
Add compression factory stubs (#311)
Browse files Browse the repository at this point in the history
* Add compression factory stubs

Signed-off-by: Anas Abou Allaban <aabouallaban@pm.me>
  • Loading branch information
Anas Abou Allaban committed Mar 6, 2020
1 parent fafbe76 commit e79efb0
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions rosbag2_compression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>

#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<rosbag2_compression::BaseCompressorInterface>
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<rosbag2_compression::BaseDecompressorInterface>
create_decompressor(const std::string & compression_format);

private:
std::unique_ptr<CompressionFactoryImpl> impl_;
};

} // namespace rosbag2_compression

#endif // ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_HPP_
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>

#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<rosbag2_compression::BaseCompressorInterface>
CompressionFactory::create_compressor(const std::string & compression_format)
{
return impl_->create_compressor(compression_format);
}

std::unique_ptr<rosbag2_compression::BaseDecompressorInterface>
CompressionFactory::create_decompressor(const std::string & compression_format)
{
return impl_->create_decompressor(compression_format);
}

} // namespace rosbag2_compression
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <string>

#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<rosbag2_compression::BaseCompressorInterface>
create_compressor(const std::string &)
{
throw std::logic_error{"Not implemented"};
}

/// See CompressionFactory::create_decompressor for documentation.
std::unique_ptr<rosbag2_compression::BaseDecompressorInterface>
create_decompressor(const std::string &)
{
throw std::logic_error{"Not implemented"};
}
};
} // namespace rosbag2_compression

#endif // ROSBAG2_COMPRESSION__COMPRESSION_FACTORY_IMPL_HPP_

0 comments on commit e79efb0

Please sign in to comment.