From 3304264990b96c09b174716ecb8da63d24457ae8 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 21 Dec 2019 14:50:03 +0300 Subject: utils/ -> aesxx/utils/ --- utils/helpers/bmp.hpp | 57 --------------------------- utils/helpers/command_line.hpp | 87 ------------------------------------------ utils/helpers/file.hpp | 69 --------------------------------- 3 files changed, 213 deletions(-) delete mode 100644 utils/helpers/bmp.hpp delete mode 100644 utils/helpers/command_line.hpp delete mode 100644 utils/helpers/file.hpp (limited to 'utils/helpers') diff --git a/utils/helpers/bmp.hpp b/utils/helpers/bmp.hpp deleted file mode 100644 index b4b283b..0000000 --- a/utils/helpers/bmp.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2016 Egor Tensin -// This file is part of the "AES tools" project. -// For details, see https://github.com/egor-tensin/aes-tools. -// Distributed under the MIT License. - -#include - -#include -#include - -#include -#include -#include - -namespace bmp -{ - class BmpFile - { - public: - BmpFile(std::vector&& buffer) - : buffer{std::move(buffer)} - , header_size{extract_pixels_offset()} - { } - - const void* get_buffer() const { return buffer.data(); } - - std::size_t get_size() const { return buffer.size(); } - - std::size_t get_header_size() const { return header_size; } - - const void* get_pixels() const - { - return buffer.data() + get_header_size(); - } - - std::size_t get_pixels_size() const - { - return get_size() - get_header_size(); - } - - void replace_pixels(std::vector&& pixels) - { - buffer.resize(get_header_size() + pixels.size()); - std::memcpy(buffer.data() + get_header_size(), pixels.data(), pixels.size()); - } - - private: - std::size_t extract_pixels_offset() const - { - const auto header = reinterpret_cast(get_buffer()); - return header->bfOffBits; - } - - std::vector buffer; - std::size_t header_size; - }; -} diff --git a/utils/helpers/command_line.hpp b/utils/helpers/command_line.hpp deleted file mode 100644 index 2e4d803..0000000 --- a/utils/helpers/command_line.hpp +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2017 Egor Tensin -// This file is part of the "AES tools" project. -// For details, see https://github.com/egor-tensin/aes-tools. -// Distributed under the MIT License. - -#pragma once - -#include -#include - -#include -#include -#include -#include - -namespace command_line -{ - class SettingsParser - { - public: - explicit SettingsParser(const std::string& argv0) - : prog_name{extract_filename(argv0)} - { - visible.add_options() - ("help,h", - "show this message and exit"); - } - - virtual ~SettingsParser() = default; - - virtual const char* get_short_description() const - { - return "[--option VALUE]..."; - } - - virtual void parse(int argc, char* argv[]) - { - boost::program_options::options_description all; - all.add(hidden).add(visible); - boost::program_options::variables_map vm; - boost::program_options::store( - boost::program_options::command_line_parser{argc, argv} - .options(all) - .positional(positional) - .run(), - vm); - if (vm.count("help")) - exit_with_usage = true; - else - boost::program_options::notify(vm); - } - - bool exit_with_usage = false; - - void usage() const - { - std::cout << *this; - } - - void usage_error(const std::exception& e) const - { - std::cerr << "usage error: " << e.what() << '\n'; - std::cerr << *this; - } - - protected: - boost::program_options::options_description hidden; - boost::program_options::options_description visible; - boost::program_options::positional_options_description positional; - - private: - static std::string extract_filename(const std::string& path) - { - return boost::filesystem::path{path}.filename().string(); - } - - const std::string prog_name; - - friend std::ostream& operator<<(std::ostream& os, const SettingsParser& parser) - { - const auto short_descr = parser.get_short_description(); - os << "usage: " << parser.prog_name << ' ' << short_descr << '\n'; - os << parser.visible; - return os; - } - }; -} diff --git a/utils/helpers/file.hpp b/utils/helpers/file.hpp deleted file mode 100644 index 48e4c51..0000000 --- a/utils/helpers/file.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2016 Egor Tensin -// This file is part of the "AES tools" project. -// For details, see https://github.com/egor-tensin/aes-tools. -// Distributed under the MIT License. - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace file -{ - inline std::size_t cast_to_size_t(std::streamoff size) - { - if (size < 0) - throw std::range_error{"file::cast_to_size_t: something went really wrong"}; - typedef std::make_unsigned::type unsigned_streamoff; - if (static_cast(size) > std::numeric_limits::max()) - throw std::range_error{"file::cast_to_size_t: this file is too large"}; - return static_cast(size); - } - - inline std::size_t get_file_size(const std::string& path) - { - std::ifstream ifs; - ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - ifs.open(path, std::ifstream::binary | std::ifstream::ate); - return cast_to_size_t(ifs.tellg()); - } - - inline std::vector read_file(const std::string& path) - { - const auto size = get_file_size(path); - - std::ifstream ifs; - ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); - ifs.open(path, std::ifstream::binary); - - std::vector src_buf; - src_buf.reserve(size); - src_buf.assign( - std::istreambuf_iterator{ifs}, - std::istreambuf_iterator{}); - return src_buf; - } - - inline void write_file( - const std::string& path, - const void* buffer, - const std::size_t size) - { - std::ofstream ofs; - ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit); - ofs.open(path, std::ofstream::binary); - ofs.write(reinterpret_cast(buffer), size); - } - - inline void write_file( - const std::string& path, - const std::vector& src) - { - write_file(path, src.data(), src.size()); - } -} -- cgit v1.2.3