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