OpenXcom  1.0
Open-source clone of the original X-Com
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 #include <algorithm>
27 
28 namespace OpenXcom
29 {
30 
31 enum OptionType { OPTION_BOOL, OPTION_INT, OPTION_STRING, OPTION_KEY };
32 
39 {
40 private:
41  std::string _id, _desc, _cat;
42  OptionType _type;
43  union { bool *b; int *i; std::string *s; SDLKey *k; } _ref;
44  union { bool b; int i; const char *s; SDLKey k; } _def; // can't put strings in unions
45 public:
47  OptionInfo(const std::string &id, bool *option, bool def, const std::string &desc = "", const std::string &cat = "");
49  OptionInfo(const std::string &id, int *option, int def, const std::string &desc = "", const std::string &cat = "");
51  OptionInfo(const std::string &id, SDLKey *option, SDLKey def, const std::string &desc = "", const std::string &cat = "");
53  OptionInfo(const std::string &id, std::string *option, const char *def, const std::string &desc = "", const std::string &cat = "");
55  bool *asBool() const;
57  int *asInt() const;
59  std::string *asString() const;
61  SDLKey *asKey() const;
63  void load(const YAML::Node &node) const;
65  void load(const std::map<std::string, std::string> &map) const;
67  void save(YAML::Node &node) const;
69  void reset() const;
71  OptionType type() const;
73  std::string description() const;
75  std::string category() const;
76 };
77 
78 }
79 
80 #endif
Helper class that ties metadata to particular options to help in serializing and stuff.
Definition: OptionInfo.h:39
void load(const YAML::Node &node) const
Loads the option from YAML.
Definition: OptionInfo.cpp:85
std::string * asString() const
Gets a string option pointer.
Definition: OptionInfo.cpp:265
bool * asBool() const
Gets a bool option pointer.
Definition: OptionInfo.cpp:223
void save(YAML::Node &node) const
Saves the option to YAML.
Definition: OptionInfo.cpp:148
void reset() const
Resets the option to default.
Definition: OptionInfo.cpp:170
std::string description() const
Gets the option description.
Definition: OptionInfo.cpp:203
int * asInt() const
Gets an int option pointer.
Definition: OptionInfo.cpp:237
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
SDLKey * asKey() const
Gets a key option pointer.
Definition: OptionInfo.cpp:251
std::string category() const
Gets the option category.
Definition: OptionInfo.cpp:213
OptionType type() const
Gets the option type.
Definition: OptionInfo.cpp:193
COPYING:
Definition: BaseInfoState.cpp:41