Autogenerate compression type code

This commit is contained in:
Marcus Holland-Moritz 2022-11-05 18:45:48 +01:00
parent 03829e6da4
commit 87271666ac
3 changed files with 54 additions and 13 deletions

View File

@ -33,19 +33,12 @@
#include <utility>
#include <vector>
#include "dwarfs/compression.h"
namespace dwarfs {
class option_map;
// TODO: move this to fstypes.h?
enum class compression_type : uint8_t {
NONE = 0,
LZMA = 1,
ZSTD = 2,
LZ4 = 3,
LZ4HC = 4,
};
class bad_compression_ratio_error : public std::runtime_error {
public:
bad_compression_ratio_error()

View File

@ -0,0 +1,46 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
// clang-format off
#define DWARFS_COMPRESSION_TYPE_LIST(DWARFS_COMPRESSION_TYPE, SEPARATOR) \
DWARFS_COMPRESSION_TYPE(NONE, 0) SEPARATOR \
DWARFS_COMPRESSION_TYPE(LZMA, 1) SEPARATOR \
DWARFS_COMPRESSION_TYPE(ZSTD, 2) SEPARATOR \
DWARFS_COMPRESSION_TYPE(LZ4, 3) SEPARATOR \
DWARFS_COMPRESSION_TYPE(LZ4HC, 4)
// clang-format on
namespace dwarfs {
enum class compression_type : uint8_t {
#define DWARFS_COMPRESSION_TYPE_ENUMERATION_(name, value) name = value
#define DWARFS_COMMA_ ,
DWARFS_COMPRESSION_TYPE_LIST(DWARFS_COMPRESSION_TYPE_ENUMERATION_,
DWARFS_COMMA_)
#undef DWARFS_COMPRESSION_TYPE_ENUMERATION_
#undef DWARFS_COMMA_
};
} // namespace dwarfs

View File

@ -28,6 +28,7 @@
#include <fmt/format.h>
#include "dwarfs/compression.h"
#include "dwarfs/fstypes.h"
namespace dwarfs {
@ -44,10 +45,11 @@ const std::map<section_type, std::string_view> sections{
};
const std::map<compression_type, std::string_view> compressions{
#define COMPRESSION_TYPE_(x) {compression_type::x, #x}
COMPRESSION_TYPE_(NONE), COMPRESSION_TYPE_(LZMA), COMPRESSION_TYPE_(ZSTD),
COMPRESSION_TYPE_(LZ4), COMPRESSION_TYPE_(LZ4HC)
#undef COMPRESSION_TYPE_
#define DWARFS_COMPRESSION_TYPE_(name, value) {compression_type::name, #name}
#define DWARFS_COMMA_ ,
DWARFS_COMPRESSION_TYPE_LIST(DWARFS_COMPRESSION_TYPE_, DWARFS_COMMA_)
#undef DWARFS_COMPRESSION_TYPE_
#undef DWARFS_COMMA_
};
template <typename HT>