4
Copyright (C) 20052011 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
26
* \brief The structure in which we store the level variables or game variables.
27
* \author Julien Jorge
29
#ifndef __ENGINE_VAR_MAP_HPP__
30
#define __ENGINE_VAR_MAP_HPP__
32
#include "engine/class_export.hpp"
34
#include <claw/multi_type_map.hpp>
35
#include <claw/multi_type_map_visitor.hpp>
36
#include <claw/meta/type_list.hpp>
39
#include <boost/signal.hpp>
45
/** \brief The types supported by the engine. */
46
typedef claw::meta::type_list_maker
47
<int, unsigned int, bool, double, std::string>::result var_types;
50
* \brief The structure in which we store the level variables or game
53
class ENGINE_EXPORT var_map:
54
public claw::multi_type_map<std::string, var_types>
57
/** \brief The type of the parent map. */
58
typedef claw::multi_type_map<std::string, var_types> super;
60
/** \brief The types of the signals used to observe the variables. */
61
typedef claw::meta::type_list_maker
62
< boost::signal<void (int)>*, boost::signal<void (unsigned int)>*,
63
boost::signal<void (bool)>*, boost::signal<void (double)>*,
64
boost::signal<void (std::string)>* >::result signal_types;
67
* \brief The map containing the signals associated with the variables.
69
typedef claw::multi_type_map<std::string, signal_types> signal_map;
72
* \brief A function object that deletes the signal associated with a
74
* \author Julien Jorge
81
( const std::string& name, boost::signal<void (T)>* value ) const;
83
}; // class delete_signal
86
* \brief A function object that triggers the signal associated with a
88
* \author Julien Jorge
93
trigger_signal( const signal_map& m );
97
( const std::string& name, const T& value ) const;
100
/** \brief The map in which the signals are searched. */
101
const signal_map& m_signals;
103
}; // class trigger_signal
106
* \brief A function object that deletes the the signals for the variables
107
* not declared in a given var_map.
108
* \author Julien Jorge
110
class delete_signal_not_in
113
delete_signal_not_in( const var_map& m, signal_map& s );
117
( const std::string& name, const T& value ) const;
120
/** \brief The var_map in which the variables are searched. */
121
const var_map& m_map;
123
/** \brief The map in which the signals are searched. */
124
signal_map& m_signals;
126
}; // class delete_signal_not_in()
131
var_map( const var_map& that );
133
var_map& operator=( const var_map& that );
136
boost::signal<void (T)>& variable_changed( const std::string& name );
139
void set( const std::string& k, const T& v );
141
void set( const var_map& m );
143
template<typename Function>
144
void for_each( Function f );
147
/** \brief The signals triggered when the value of a variable change. */
148
signal_map m_signals;
152
} // namespace engine
155
#include "engine/variable/impl/var_map.tpp"
157
#endif // __ENGINE_VAR_MAP_HPP__