Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VARIABLE_H_INCLUDED
00018 #define VARIABLE_H_INCLUDED
00019
00020 #include "config.hpp"
00021
00022 #include <utility>
00023
00024 class game_state;
00025 class unit_map;
00026
00027
00028
00029
00030
00031
00032 class vconfig
00033 {
00034 private:
00035
00036
00037
00038
00039
00040
00041 #if __GNUC__ == 4 && __GNUC_MINOR__ == 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
00042 template<class T1, class T2>
00043 friend class std::pair;
00044 #endif
00045
00046 vconfig();
00047 vconfig(const config* cfg, const config* cache_key);
00048 public:
00049 vconfig(const vconfig& v);
00050 explicit vconfig(const config &cfg, bool is_volatile=false);
00051 ~vconfig();
00052
00053 static vconfig empty_vconfig();
00054 static vconfig unconstructed_vconfig();
00055
00056 vconfig& operator=(const vconfig& cfg);
00057
00058 bool null() const { return cfg_ == NULL; }
00059 bool is_volatile() const { return cache_key_ != NULL; }
00060 const config& get_config() const { return *cfg_; }
00061 const config get_parsed_config() const;
00062
00063 typedef std::vector<vconfig> child_list;
00064 child_list get_children(const std::string& key) const;
00065 vconfig child(const std::string& key) const;
00066 bool has_child(const std::string& key) const;
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 const config::attribute_value operator[](const std::string &key) const
00081 { return expand(key); }
00082 config::attribute_value expand(const std::string&) const;
00083 bool has_attribute(const std::string& key) const { return cfg_->has_attribute(key); }
00084 bool empty() const { return (null() || cfg_->empty()); }
00085
00086 struct all_children_iterator
00087 {
00088 struct pointer_proxy;
00089
00090 typedef std::pair<std::string, vconfig> value_type;
00091 typedef std::forward_iterator_tag iterator_category;
00092 typedef int difference_type;
00093 typedef const pointer_proxy pointer;
00094 typedef const value_type reference;
00095 typedef config::all_children_iterator Itor;
00096 explicit all_children_iterator(const Itor &i, const config *cache_key = NULL);
00097
00098 all_children_iterator& operator++();
00099 all_children_iterator operator++(int);
00100
00101 reference operator*() const;
00102 pointer operator->() const;
00103
00104 std::string get_key() const;
00105 vconfig get_child() const;
00106 void disable_insertion() { inner_index_ = -1; }
00107
00108 bool operator==(const all_children_iterator &i) const;
00109 bool operator!=(const all_children_iterator &i) const
00110 { return !operator==(i); }
00111
00112 private:
00113 Itor i_;
00114 int inner_index_;
00115 const config* cache_key_;
00116 };
00117
00118 struct recursion_error : public config::error {
00119 recursion_error(const std::string& msg) : error(msg) {}
00120 };
00121
00122
00123 all_children_iterator ordered_begin() const;
00124 all_children_iterator ordered_end() const;
00125
00126 private:
00127 const config* cfg_;
00128 const config* cache_key_;
00129 };
00130
00131 struct vconfig::all_children_iterator::pointer_proxy
00132 {
00133 value_type p;
00134 const value_type *operator->() const { return &p; }
00135 };
00136
00137 namespace variable
00138 {
00139
00140
00141
00142
00143 class manager
00144 {
00145 public:
00146 ~manager();
00147 };
00148
00149 }
00150
00151
00152
00153 class scoped_wml_variable
00154 {
00155 public:
00156 scoped_wml_variable(const std::string& var_name);
00157 virtual ~scoped_wml_variable();
00158 const std::string& name() const { return var_name_; }
00159 virtual void activate() = 0;
00160 config &store(const config &var_value = config());
00161 bool activated() const { return activated_; }
00162 private:
00163 config previous_val_;
00164 const std::string var_name_;
00165 bool activated_;
00166 };
00167
00168 class scoped_weapon_info : public scoped_wml_variable
00169 {
00170 public:
00171 scoped_weapon_info(const std::string& var_name, const config &data)
00172 : scoped_wml_variable(var_name), data_(data) {}
00173 void activate();
00174 private:
00175 config const &data_;
00176 };
00177
00178 class scoped_xy_unit : public scoped_wml_variable
00179 {
00180 public:
00181 scoped_xy_unit(const std::string& var_name, const int x, const int y, const unit_map& umap)
00182 : scoped_wml_variable(var_name), x_(x), y_(y), umap_(umap) {}
00183 void activate();
00184 private:
00185 const int x_, y_;
00186 const unit_map& umap_;
00187 };
00188
00189 class scoped_recall_unit : public scoped_wml_variable
00190 {
00191 public:
00192 scoped_recall_unit(const std::string& var_name, const std::string& player,
00193 unsigned int recall_index) : scoped_wml_variable(var_name), player_(player),
00194 recall_index_(recall_index) {}
00195 void activate();
00196 private:
00197 const std::string player_;
00198 unsigned int recall_index_;
00199 };
00200
00201
00202 struct variable_info
00203 {
00204 typedef config::child_itors array_range;
00205
00206
00207
00208
00209
00210 enum TYPE { TYPE_SCALAR,
00211 TYPE_ARRAY,
00212 TYPE_CONTAINER,
00213 TYPE_UNSPECIFIED };
00214
00215 variable_info(const std::string& varname, bool force_valid=true,
00216 TYPE validation_type=TYPE_UNSPECIFIED);
00217
00218 TYPE vartype;
00219 bool is_valid;
00220 std::string key;
00221 bool explicit_index;
00222 size_t index;
00223 config *vars;
00224
00225
00226
00227
00228
00229 config::attribute_value &as_scalar();
00230 config& as_container();
00231 array_range as_array();
00232 };
00233
00234 #endif