From 3ad5a9241486b8fa785d37c92892919d1cda8ec0 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 2 Nov 2019 17:13:18 +0200 Subject: [PATCH] genesys: Move conversion of ScanMethod to option strings to enums.cpp --- backend/Makefile.am | 2 +- backend/genesys/enums.cpp | 73 +++++++++++++++++++++++++++++++++++++ backend/genesys/enums.h | 3 ++ backend/genesys/genesys.cpp | 26 ------------- backend/genesys/genesys.h | 4 ++ 5 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 backend/genesys/enums.cpp diff --git a/backend/Makefile.am b/backend/Makefile.am index be35cd265..be56c5515 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -491,7 +491,7 @@ libgenesys_la_SOURCES = genesys/genesys.cpp genesys/genesys.h \ genesys/command_set.h \ genesys/conv.h genesys/conv.cpp \ genesys/device.h genesys/device.cpp \ - genesys/enums.h \ + genesys/enums.h genesys/enums.cpp \ genesys/error.h genesys/error.cpp \ genesys/fwd.h \ genesys/gl646.cpp genesys/gl646.h genesys/gl646_registers.h \ diff --git a/backend/genesys/enums.cpp b/backend/genesys/enums.cpp new file mode 100644 index 000000000..6869d78b6 --- /dev/null +++ b/backend/genesys/enums.cpp @@ -0,0 +1,73 @@ +/* sane - Scanner Access Now Easy. + + Copyright (C) 2019 Povilas Kanapickas + + This file is part of the SANE package. + + This program 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 2 of the + License, or (at your option) any later version. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA. + + As a special exception, the authors of SANE give permission for + additional uses of the libraries contained in this release of SANE. + + The exception is that, if you link a SANE library with other files + to produce an executable, this does not by itself cause the + resulting executable to be covered by the GNU General Public + License. Your use of that executable is in no way restricted on + account of linking the SANE library code into it. + + This exception does not, however, invalidate any other reasons why + the executable file might be covered by the GNU General Public + License. + + If you submit changes to SANE to the maintainers to be included in + a subsequent release, you agree by submitting the changes that + those changes may be distributed with this exception intact. + + If you write modifications of your own for SANE, it is your choice + whether to permit this exception to apply to your modifications. + If you do not wish that, delete this exception notice. +*/ + +#define DEBUG_DECLARE_ONLY + +#include "enums.h" +#include "genesys.h" + +namespace genesys { + +const char* scan_method_to_option_string(ScanMethod method) +{ + switch (method) { + case ScanMethod::FLATBED: return STR_FLATBED; + case ScanMethod::TRANSPARENCY: return STR_TRANSPARENCY_ADAPTER; + case ScanMethod::TRANSPARENCY_INFRARED: return STR_TRANSPARENCY_ADAPTER_INFRARED; + } + throw SaneException("Unknown scan method %d", static_cast(method)); +} + +ScanMethod option_string_to_scan_method(const std::string& str) +{ + if (str == STR_FLATBED) { + return ScanMethod::FLATBED; + } else if (str == STR_TRANSPARENCY_ADAPTER) { + return ScanMethod::TRANSPARENCY; + } else if (str == STR_TRANSPARENCY_ADAPTER_INFRARED) { + return ScanMethod::TRANSPARENCY_INFRARED; + } + throw SaneException("Unknown scan method option %s", str.c_str()); +} + +} // namespace genesys diff --git a/backend/genesys/enums.h b/backend/genesys/enums.h index 60aff1cf0..f1d322194 100644 --- a/backend/genesys/enums.h +++ b/backend/genesys/enums.h @@ -71,6 +71,9 @@ inline void serialize(std::ostream& str, ScanMethod& x) serialize(str, value); } +const char* scan_method_to_option_string(ScanMethod method); +ScanMethod option_string_to_scan_method(const std::string& str); + enum class ScanColorMode : unsigned { LINEART = 0, HALFTONE, diff --git a/backend/genesys/genesys.cpp b/backend/genesys/genesys.cpp index f0d5a230a..528772ac8 100644 --- a/backend/genesys/genesys.cpp +++ b/backend/genesys/genesys.cpp @@ -97,10 +97,6 @@ namespace { StaticInit> s_devices; } // namespace -#define STR_FLATBED SANE_I18N("Flatbed") -#define STR_TRANSPARENCY_ADAPTER SANE_I18N("Transparency Adapter") -#define STR_TRANSPARENCY_ADAPTER_INFRARED SANE_I18N("Transparency Adapter Infrared") - static SANE_String_Const mode_list[] = { SANE_VALUE_SCAN_MODE_COLOR, SANE_VALUE_SCAN_MODE_GRAY, @@ -3404,28 +3400,6 @@ static unsigned pick_resolution(const std::vector& resolutions, unsign return best_res; } -static const char* scan_method_to_option_string(ScanMethod method) -{ - switch (method) { - case ScanMethod::FLATBED: return STR_FLATBED; - case ScanMethod::TRANSPARENCY: return STR_TRANSPARENCY_ADAPTER; - case ScanMethod::TRANSPARENCY_INFRARED: return STR_TRANSPARENCY_ADAPTER_INFRARED; - } - throw SaneException("Unknown scan method %d", static_cast(method)); -} - -static ScanMethod option_string_to_scan_method(const std::string& str) -{ - if (str == STR_FLATBED) { - return ScanMethod::FLATBED; - } else if (str == STR_TRANSPARENCY_ADAPTER) { - return ScanMethod::TRANSPARENCY; - } else if (str == STR_TRANSPARENCY_ADAPTER_INFRARED) { - return ScanMethod::TRANSPARENCY_INFRARED; - } - throw SaneException("Unknown scan method option %s", str.c_str()); -} - static void calc_parameters(Genesys_Scanner* s) { DBG_HELPER(dbg); diff --git a/backend/genesys/genesys.h b/backend/genesys/genesys.h index 7e2569bb8..890984fdc 100644 --- a/backend/genesys/genesys.h +++ b/backend/genesys/genesys.h @@ -78,6 +78,10 @@ #define SANE_I18N(text) text #endif +#define STR_FLATBED SANE_I18N("Flatbed") +#define STR_TRANSPARENCY_ADAPTER SANE_I18N("Transparency Adapter") +#define STR_TRANSPARENCY_ADAPTER_INFRARED SANE_I18N("Transparency Adapter Infrared") + namespace genesys { /** List of SANE options