Fcitx
option_details.h
1 /*
2  * SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_CONFIG_OPTION_DETAILS_H_
8 #define _FCITX_CONFIG_OPTION_DETAILS_H_
9 
10 #include <memory>
11 #include <string>
12 #include <vector>
13 #include <fcitx-config/fcitxconfig_export.h>
14 #include <fcitx-config/rawconfig.h>
15 
16 namespace fcitx {
17 
18 class Configuration;
19 
20 class FCITXCONFIG_EXPORT OptionBase {
21 public:
22  OptionBase(Configuration *parent, std::string path,
23  std::string description);
24  virtual ~OptionBase();
25 
26  const std::string &path() const;
27  const std::string &description() const;
28  virtual std::string typeString() const = 0;
29  virtual void reset() = 0;
30  virtual bool isDefault() const = 0;
31 
32  virtual void marshall(RawConfig &config) const = 0;
33  virtual bool unmarshall(const RawConfig &config, bool partial) = 0;
34  virtual std::unique_ptr<Configuration> subConfigSkeleton() const = 0;
35 
36  virtual bool equalTo(const OptionBase &other) const = 0;
37  virtual void copyFrom(const OptionBase &other) = 0;
38  bool operator==(const OptionBase &other) const { return equalTo(other); }
39  bool operator!=(const OptionBase &other) const {
40  return !operator==(other);
41  }
42 
43  virtual bool skipDescription() const = 0;
44  virtual bool skipSave() const = 0;
45  virtual void dumpDescription(RawConfig &config) const;
46 
47 private:
48  Configuration *parent_;
49  std::string path_;
50  std::string description_;
51 };
52 
53 class FCITXCONFIG_EXPORT OptionBaseV2 : public OptionBase {
54 public:
55  using OptionBase::OptionBase;
56  virtual void syncDefaultValueToCurrent() = 0;
57 };
58 
59 class FCITXCONFIG_EXPORT OptionBaseV3 : public OptionBaseV2 {
60 public:
61  using OptionBaseV2::OptionBaseV2;
62  ~OptionBaseV3() override;
63 };
64 
65 template <typename T>
66 struct RemoveVector {
67  using type = T;
68 };
69 
70 template <typename T>
71 struct RemoveVector<std::vector<T>> {
72  using type = typename RemoveVector<T>::type;
73 };
74 
75 template <typename T>
76 void dumpDescriptionHelper(RawConfig & /*unused*/, T * /*unused*/) {}
77 
78 } // namespace fcitx
79 
80 #endif // _FCITX_CONFIG_OPTION_DETAILS_H_
Definition: action.cpp:17
Definition: matchrule.h:78