1 /*
2  *  Copyright (C) 2011-2016  OpenDungeons Team
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef CREATURESKILLMANAGER_H
19 #define CREATURESKILLMANAGER_H
20 
21 #include <cstdint>
22 #include <iosfwd>
23 #include <string>
24 
25 class CreatureSkill;
26 
27 //! \brief Factory class to register a new mood modifier
28 class CreatureSkillFactory
29 {
30 public:
~CreatureSkillFactory()31     virtual ~CreatureSkillFactory()
32     {}
33 
34     virtual CreatureSkill* createCreatureSkill() const = 0;
35 
36     virtual const std::string& getCreatureSkillName() const = 0;
37 };
38 
39 class CreatureSkillManager
40 {
41 friend class CreatureSkillRegister;
42 
43 public:
CreatureSkillManager()44     CreatureSkillManager()
45     {}
46 
~CreatureSkillManager()47     virtual ~CreatureSkillManager()
48     {}
49 
50     static CreatureSkill* clone(const CreatureSkill* skill);
51     static CreatureSkill* load(std::istream& is);
52     //! \brief Handles the Skill deletion
53     static void dispose(const CreatureSkill* skill);
54     static void write(const CreatureSkill& skill, std::ostream& os);
55     static void getFormatString(const CreatureSkill& skill, std::string& format);
56     static bool areEqual(const CreatureSkill& skill1, const CreatureSkill& skill2);
57 
58 private:
59     static void registerFactory(const CreatureSkillFactory* factory);
60     static void unregisterFactory(const CreatureSkillFactory* factory);
61 };
62 
63 class CreatureSkillRegister
64 {
65 public:
CreatureSkillRegister(const CreatureSkillFactory * factoryToRegister)66     CreatureSkillRegister(const CreatureSkillFactory* factoryToRegister) :
67         mCreatureSkillFactory(factoryToRegister)
68     {
69         CreatureSkillManager::registerFactory(mCreatureSkillFactory);
70     }
~CreatureSkillRegister()71     ~CreatureSkillRegister()
72     {
73         CreatureSkillManager::unregisterFactory(mCreatureSkillFactory);
74         delete mCreatureSkillFactory;
75     }
76 
77 private:
78     const CreatureSkillFactory* mCreatureSkillFactory;
79 };
80 
81 #endif // CREATURESKILLMANAGER_H
82