The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
variable_info.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 by David White <[email protected]>
3  Copyright (C) 2005 - 2016 by Philippe Plantier <[email protected]>
4 
5  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #ifndef VARIABLE_INFO_HPP
18 #define VARIABLE_INFO_HPP
19 
20 /** Information on a WML variable. */
21 #include <string>
22 #include "config.hpp"
23 #include "variable_info_detail.hpp"
24 
25 class invalid_variablename_exception : public std::exception
26 {
27 public:
28  invalid_variablename_exception() : std::exception() {}
29  const char* what() const throw()
30  {
31  return "invalid_variablename_exception";
32  }
33 };
34 
35 template<const variable_info_detail::variable_info_type vit>
37 {
38 public:
39 
41  /// Doesn't throw
42  variable_info(const std::string& varname, t_config& vars);
45  /// Doesn't throw
46  bool explicit_index() const;
47  /// might throw invalid_variablename_exception
48  bool exists_as_attribute() const;
49  /// might throw invalid_variablename_exception
50  bool exists_as_container() const;
51 
52  /**
53  might throw invalid_variablename_exception
54  NOTE:
55  If vit == vit_const, then the lifime of the returned const attribute_value& might end with the lifetime of this object.
56  */
58  /// might throw invalid_variablename_exception
60  /// might throw invalid_variablename_exception
62 
63 protected:
66  void throw_on_invalid() const;
67  bool valid_;
68  void calculate_value();
69 };
70 
71 /// Extends variable_info with methods that can only be applied if vit != vit_const
72 template<const variable_info_detail::variable_info_type vit>
74 {
75 public:
76  non_const_variable_info(const std::string& name, config& game_vars) : variable_info<vit>(name, game_vars) {}
78 
79  /// clears the vale this object points to
80  /// if only_tables = true it will not clear attribute values.
81  /// might throw invalid_variablename_exception
82  void clear(bool only_tables = false) const;
83 
84  // the following 4 functions are used by [set_variables]
85  // they destroy the passed vector. (make it empty).
86 
87  /// @return: the new appended range
88  /// might throw invalid_variablename_exception
89  config::child_itors append_array(std::vector<config> childs) const;
90  /// @return: the new inserted range
91  /// might throw invalid_variablename_exception
92  config::child_itors insert_array(std::vector<config> childs) const;
93  /// @return: the new range
94  /// might throw invalid_variablename_exception
95  config::child_itors replace_array(std::vector<config> childs) const;
96  /// merges
97  /// might throw invalid_variablename_exception
98  void merge_array(std::vector<config> childs) const;
99 };
100 
101 
102 /**
103  this variable accessor will create a childtable when resolving name if it doesn't exist yet.
104 */
106 /**
107  this variable accessor will throw an exception when trying to access a non existent table.
108  Note that the other types can throw too if name is invlid like '..[[[a'.
109 */
111 /**
112  this variable accessor is takes a const reference and is guaranteed to not change the config.
113 */
115 
116 #endif
non_const_variable_info(const std::string &name, config &game_vars)
bool explicit_index() const
Doesn't throw.
variable_info_detail::maybe_const< vit, config::attribute_value >::type & as_scalar() const
might throw invalid_variablename_exception NOTE: If vit == vit_const, then the lifime of the returned...
variable_info_detail::maybe_const< vit, config::child_itors >::type as_array() const
might throw invalid_variablename_exception
void merge_array(std::vector< config > childs) const
merges might throw invalid_variablename_exception
bool exists_as_container() const
might throw invalid_variablename_exception
void clear(bool only_tables=false) const
clears the vale this object points to if only_tables = true it will not clear attribute values...
variable_info< variable_info_detail::vit_const > variable_access_const
this variable accessor is takes a const reference and is guaranteed to not change the config...
Extends variable_info with methods that can only be applied if vit != vit_const.
non_const_variable_info< variable_info_detail::vit_throw_if_not_existent > variable_access_throw
this variable accessor will throw an exception when trying to access a non existent table...
config::child_itors replace_array(std::vector< config > childs) const
STL namespace.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string name_
void calculate_value()
variable_info(const std::string &varname, t_config &vars)
Doesn't throw.
non_const_variable_info< variable_info_detail::vit_create_if_not_existent > variable_access_create
this variable accessor will create a childtable when resolving name if it doesn't exist yet...
variable_info_detail::maybe_const< vit, config >::type & as_container() const
might throw invalid_variablename_exception
std::pair< child_iterator, child_iterator > child_itors
Definition: config.hpp:213
Information on a WML variable.
variable_info_detail::maybe_const< vit, config >::type t_config
GLuint const GLchar * name
Definition: glew.h:1782
variable_info_detail::variable_info_state< vit > state_
config::child_itors insert_array(std::vector< config > childs) const
std::string get_error_message() const
config::child_itors append_array(std::vector< config > childs) const
void throw_on_invalid() const
bool exists_as_attribute() const
might throw invalid_variablename_exception
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
const char * what() const
GLsizei const GLcharARB ** string
Definition: glew.h:4503