OpenXcom  1.0
Open-source clone of the original X-Com
OptionInfo.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <yaml-cpp/yaml.h>
21 #include <string>
22 #include <map>
23 #include <SDL.h>
24 
25 namespace OpenXcom
26 {
27 
28 enum OptionType { OPTION_BOOL, OPTION_INT, OPTION_STRING, OPTION_KEY };
29 
36 {
37 private:
38  std::string _id, _desc, _cat;
39  OptionType _type;
40  union { bool *b; int *i; std::string *s; SDLKey *k; } _ref;
41  union { bool b; int i; const char *s; SDLKey k; } _def; // can't put strings in unions
42 public:
44  OptionInfo(const std::string &id, bool *option, bool def, const std::string &desc = "", const std::string &cat = "");
46  OptionInfo(const std::string &id, int *option, int def, const std::string &desc = "", const std::string &cat = "");
48  OptionInfo(const std::string &id, SDLKey *option, SDLKey def, const std::string &desc = "", const std::string &cat = "");
50  OptionInfo(const std::string &id, std::string *option, const char *def, const std::string &desc = "", const std::string &cat = "");
52  bool *asBool() const;
54  int *asInt() const;
56  std::string *asString() const;
58  SDLKey *asKey() const;
60  void load(const YAML::Node &node) const;
62  void load(const std::map<std::string, std::string> &map) const;
64  void save(YAML::Node &node) const;
66  void reset() const;
68  OptionType type() const;
70  std::string description() const;
72  std::string category() const;
73 };
74 
75 }
int * asInt() const
Gets an int option pointer.
Definition: OptionInfo.cpp:238
Helper class that ties metadata to particular options to help in serializing and stuff.
Definition: OptionInfo.h:35
std::string category() const
Gets the option category.
Definition: OptionInfo.cpp:214
std::string description() const
Gets the option description.
Definition: OptionInfo.cpp:204
bool * asBool() const
Gets a bool option pointer.
Definition: OptionInfo.cpp:224
OptionInfo(const std::string &id, bool *option, bool def, const std::string &desc="", const std::string &cat="")
Creates a bool option.
Definition: OptionInfo.cpp:34
void reset() const
Resets the option to default.
Definition: OptionInfo.cpp:171
SDLKey * asKey() const
Gets a key option pointer.
Definition: OptionInfo.cpp:252
void save(YAML::Node &node) const
Saves the option to YAML.
Definition: OptionInfo.cpp:149
void load(const YAML::Node &node) const
Loads the option from YAML.
Definition: OptionInfo.cpp:86
OptionType type() const
Gets the option type.
Definition: OptionInfo.cpp:194
std::string * asString() const
Gets a string option pointer.
Definition: OptionInfo.cpp:266
Definition: BaseInfoState.cpp:40