Skip to content

Commit

Permalink
refactor (touch #1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Jan 8, 2024
1 parent a6767e0 commit 0bb6ec0
Show file tree
Hide file tree
Showing 12 changed files with 1,442 additions and 14 deletions.
3 changes: 2 additions & 1 deletion far2l/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ src/bookmarks/BookmarksLegacy.cpp

src/cfg/AllXLats.cpp
src/cfg/config.cpp
src/cfg/ConfigSaveLoad.cpp
src/cfg/ConfigOpt.cpp
src/cfg/ConfigOptEdit.cpp
src/cfg/ConfigRW.cpp
src/cfg/ConfigLegacy.cpp
src/cfg/HotkeyLetterDialog.cpp
Expand Down
698 changes: 698 additions & 0 deletions far2l/src/cfg/ConfigOpt.cpp

Large diffs are not rendered by default.

109 changes: 109 additions & 0 deletions far2l/src/cfg/ConfigOpt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once

/*
config.cpp
Конфигурация
*/
/*
Copyright (c) 1996 Eugene Roshal
Copyright (c) 2000 Far Group
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

struct ConfigOpt
{
const char *section;
const char *key;
WORD bin_size; // used only with _type == T_BIN
bool save; // =true - будет записываться в ConfigOptSave()

enum T
{
T_INVALID = 0,
T_STR,
T_BIN,
T_DWORD,
T_INT,
T_BOOL,
} type : 8;

union V
{
FARString *str;
BYTE *bin;
DWORD *dw;
int *i;
bool *b;
void *p;
} value;

union D
{
const wchar_t *str;
const BYTE *bin;
DWORD dw;
int i;
bool b;
void *p;
} def;

constexpr ConfigOpt(bool save_, const char *section_, const char *key_, WORD size_, BYTE *data_bin_, const BYTE *def_bin_)
: section{section_}, key{key_}, bin_size{size_}, save{save_},
type{T_BIN}, value{.bin = data_bin_}, def{.bin = def_bin_}
{ }

constexpr ConfigOpt(bool save_, const char *section_, const char *key_, FARString *data_str_, const wchar_t *def_str_)
: section{section_}, key{key_}, bin_size{0}, save{save_},
type{T_STR}, value{.str = data_str_}, def{.str = def_str_}
{ }

constexpr ConfigOpt(bool save_, const char *section_, const char *key_, DWORD *data_dw_, DWORD def_dw_)
: section{section_}, key{key_}, bin_size{0}, save{save_},
type{T_DWORD}, value{.dw = data_dw_}, def{.dw = def_dw_}
{ }

constexpr ConfigOpt(bool save_, const char *section_, const char *key_, int *data_i_, int def_i_)
: section{section_}, key{key_}, bin_size{0}, save{save_},
type{T_INT}, value{.i = data_i_}, def{.i = def_i_}
{ }

constexpr ConfigOpt(bool save_, const char *section_, const char *key_, bool *data_b_, bool def_b_)
: section{section_}, key{key_}, bin_size{0}, save{save_},
type{T_BOOL}, value{.b = data_b_}, def{.b = def_b_}
{ }

constexpr ConfigOpt()
: section(nullptr), key(nullptr), bin_size(0), save(false),
type{T_INVALID}, value{.p = nullptr}, def{.p = nullptr}
{ }

const bool Valid() const
{
return type != T_INVALID;
}
};

extern const ConfigOpt g_cfg_opts[];

0 comments on commit 0bb6ec0

Please sign in to comment.