diff --git a/src/variable_info.cpp b/src/variable_info.cpp index 6eaaabec918..6b35febb9f4 100644 --- a/src/variable_info.cpp +++ b/src/variable_info.cpp @@ -24,7 +24,7 @@ #include -using namespace variable_info_3_detail; +using namespace variable_info_detail; /// general helpers namespace @@ -50,7 +50,7 @@ namespace } } - template + template typename maybe_const::type& get_child_at(typename maybe_const::type& cfg, const std::string& key, int index = 0); template<> @@ -132,12 +132,12 @@ namespace throw std::range_error("Failed to convert the TVisitor::param_type type"); } - template + template class variable_info_visitor { public: typedef TResult result_type; - typedef variable_info_3_state& param_type; + typedef variable_info_state& param_type; #define DEFAULTHANDLER(name) result_type name(param_type) const { throw invalid_variablename_exception(); } DEFAULTHANDLER(from_start) DEFAULTHANDLER(from_named) @@ -146,12 +146,12 @@ namespace #undef DEFAULTHANDLER }; - template + template class variable_info_visitor_const { public: typedef TResult result_type; - typedef const variable_info_3_state& param_type; + typedef const variable_info_state& param_type; #define DEFAULTHANDLER(name) result_type name(param_type) const { throw invalid_variablename_exception(); } DEFAULTHANDLER(from_start) DEFAULTHANDLER(from_named) @@ -181,7 +181,7 @@ namespace } /// Adds a '.' to the current variable - template + template class get_variable_key_visitor : public variable_info_visitor { @@ -221,7 +221,7 @@ namespace /// appens a [index] to the variable. /// we only support from_named since [index][index2] or a.length[index] both doesn't make sense. - template + template class get_variable_index_visitor : public variable_info_visitor { @@ -241,7 +241,7 @@ namespace namespace { ///tries to convert it to an (maybe const) attribute value - template + template class as_skalar_visitor : public variable_info_visitor_const::type&> { @@ -274,7 +274,7 @@ namespace /// tries to convert to a (const) config&, unlike range based operation this also supports 'from_start' /// Note: Currently getting the 'from_start' case here is impossible, becasue we always apply at least one string key. - template + template class as_container_visitor : public variable_info_visitor_const::type&> { @@ -297,7 +297,7 @@ namespace namespace { - template + template class as_range_visitor_base2 : public variable_info_visitor_const { @@ -317,7 +317,7 @@ namespace { const THandler& handler_; }; - template + template class as_range_visitor_base : public as_range_visitor_base2 { @@ -347,7 +347,7 @@ namespace { } }; - template + template class variable_as_array_h { public: @@ -452,7 +452,7 @@ namespace { /// misc namespace { - template + template class clear_value_visitor : public variable_info_visitor_const { @@ -474,7 +474,7 @@ namespace bool only_tables_; }; - template + template class exists_as_container_visitor : public variable_info_visitor_const { @@ -498,8 +498,8 @@ namespace }; } -template -variable_info_3::variable_info_3(const std::string& varname, t_config& vars) +template +variable_info::variable_info(const std::string& varname, t_config& vars) : name_(varname) , state_(vars) , valid_(true) @@ -514,13 +514,13 @@ variable_info_3::variable_info_3(const std::string& varname, t_config& vars } } -template -variable_info_3::~variable_info_3() +template +variable_info::~variable_info() { } -template -void variable_info_3::calculate_value() +template +void variable_info::calculate_value() { // this->state_ is initialized in the constructor. size_t previous_index = 0; @@ -563,36 +563,36 @@ void variable_info_3::calculate_value() } } -template -bool variable_info_3::explicit_index() const +template +bool variable_info::explicit_index() const { throw_on_invalid(); return this->state_.type_ == state_start || this->state_.type_ == state_indexed; } -template -typename maybe_const::type& variable_info_3::as_scalar() const +template +typename maybe_const::type& variable_info::as_scalar() const { throw_on_invalid(); return apply_visitor(as_skalar_visitor(), this->state_); } -template -typename maybe_const::type& variable_info_3::as_container() const +template +typename maybe_const::type& variable_info::as_container() const { throw_on_invalid(); return apply_visitor(as_container_visitor(), this->state_); } -template -typename maybe_const::type variable_info_3::as_array() const +template +typename maybe_const::type variable_info::as_array() const { throw_on_invalid(); return apply_visitor(as_range_visitor_base >(variable_as_array_h()), this->state_); } -template -void variable_info_3::throw_on_invalid() const +template +void variable_info::throw_on_invalid() const { if(!this->valid_) { @@ -601,74 +601,74 @@ void variable_info_3::throw_on_invalid() const } template<> -std::string variable_info_3::get_error_message() const +std::string variable_info::get_error_message() const { return "Cannot resolve variablename '" + this->name_ + "' for reading."; } template<> -std::string variable_info_3::get_error_message() const +std::string variable_info::get_error_message() const { return "Cannot resolve variablename '" + this->name_ + "' for writing."; } template<> -std::string variable_info_3::get_error_message() const +std::string variable_info::get_error_message() const { return "Cannot resolve variablename '" + this->name_ + "' for writing without creating new childs."; } -template -void non_const_variable_info_3::clear(bool only_tables) const +template +void non_const_variable_info::clear(bool only_tables) const { this->throw_on_invalid(); return apply_visitor(clear_value_visitor(only_tables), this->state_); } -template -config::child_itors non_const_variable_info_3::append_array(std::vector childs) const +template +config::child_itors non_const_variable_info::append_array(std::vector childs) const { this->throw_on_invalid(); return apply_visitor(as_range_visitor_base(append_range_h(childs)), this->state_); } -template -config::child_itors non_const_variable_info_3::insert_array(std::vector childs) const +template +config::child_itors non_const_variable_info::insert_array(std::vector childs) const { this->throw_on_invalid(); return apply_visitor(as_range_visitor_base(insert_range_h(childs)), this->state_); } -template -config::child_itors non_const_variable_info_3::replace_array(std::vector childs) const +template +config::child_itors non_const_variable_info::replace_array(std::vector childs) const { this->throw_on_invalid(); return apply_visitor(as_range_visitor_base(replace_range_h(childs)), this->state_); } -template -void non_const_variable_info_3::merge_array(std::vector childs) const +template +void non_const_variable_info::merge_array(std::vector childs) const { this->throw_on_invalid(); apply_visitor(as_range_visitor_base(merge_range_h(childs)), this->state_); } -template -bool variable_info_3::exists_as_attribute() const +template +bool variable_info::exists_as_attribute() const { this->throw_on_invalid(); return (this->state_.type_ == state_temporary) || ((this->state_.type_ == state_named) && this->state_.child_->has_attribute(this->state_.key_)); } -template -bool variable_info_3::exists_as_container() const +template +bool variable_info::exists_as_container() const { this->throw_on_invalid(); return apply_visitor(exists_as_container_visitor(), this->state_); } ///explicit instantiations -template class variable_info_3; -template class variable_info_3; -template class variable_info_3; -template class non_const_variable_info_3; -template class non_const_variable_info_3; +template class variable_info; +template class variable_info; +template class variable_info; +template class non_const_variable_info; +template class non_const_variable_info; diff --git a/src/variable_info.hpp b/src/variable_info.hpp index 51bb4404168..5241927a697 100644 --- a/src/variable_info.hpp +++ b/src/variable_info.hpp @@ -32,15 +32,15 @@ public: } }; -template -class variable_info_3 +template +class variable_info { public: - typedef typename variable_info_3_detail::maybe_const::type t_config; + typedef typename variable_info_detail::maybe_const::type t_config; /// Doesn't throw - variable_info_3(const std::string& varname, t_config& vars); - ~variable_info_3(); + variable_info(const std::string& varname, t_config& vars); + ~variable_info(); std::string get_error_message() const; /// Doesn't throw bool explicit_index() const; @@ -54,27 +54,27 @@ public: NOTE: If vit == vit_const, then the lifime of the returned const attribute_value& might end with the lifetime of this object. */ - typename variable_info_3_detail::maybe_const::type &as_scalar() const; + typename variable_info_detail::maybe_const::type &as_scalar() const; /// might throw invalid_variablename_exception - typename variable_info_3_detail::maybe_const::type & as_container() const; + typename variable_info_detail::maybe_const::type & as_container() const; /// might throw invalid_variablename_exception - typename variable_info_3_detail::maybe_const::type as_array() const; //range may be empty + typename variable_info_detail::maybe_const::type as_array() const; //range may be empty protected: std::string name_; - variable_info_3_detail::variable_info_3_state state_; + variable_info_detail::variable_info_state state_; void throw_on_invalid() const; bool valid_; void calculate_value(); }; -/// Extends variable_info_3 with methods that can only be applied if vit != vit_const -template -class non_const_variable_info_3 : public variable_info_3, variable_info_3_detail::enable_if_non_const::type +/// Extends variable_info with methods that can only be applied if vit != vit_const +template +class non_const_variable_info : public variable_info, variable_info_detail::enable_if_non_const::type { public: - non_const_variable_info_3(const std::string& name, config& game_vars) : variable_info_3(name, game_vars) {} - ~non_const_variable_info_3() {} + non_const_variable_info(const std::string& name, config& game_vars) : variable_info(name, game_vars) {} + ~non_const_variable_info() {} /// clears the vale this object points to /// if only_tables = true it will not clear attribute values. @@ -102,15 +102,15 @@ public: /** this variable accessor will create a childtable when resolving name if it doesnt exist yet. */ -typedef non_const_variable_info_3 variable_access_create; +typedef non_const_variable_info variable_access_create; /** this variable accessor will throw an exception when trying to access a non existent table. Note that the other types can throw too if name is invlid like '..[[[a'. */ -typedef non_const_variable_info_3 variable_access_throw; +typedef non_const_variable_info variable_access_throw; /** this variable accessor is takes a const reference and is guaranteed to not change the config. */ -typedef variable_info_3 variable_access_const; +typedef variable_info variable_access_const; #endif diff --git a/src/variable_info_detail.hpp b/src/variable_info_detail.hpp index a46125a53a1..c7564591645 100644 --- a/src/variable_info_detail.hpp +++ b/src/variable_info_detail.hpp @@ -19,12 +19,12 @@ #include #include "config.hpp" -namespace variable_info_3_detail +namespace variable_info_detail { - enum variable_info_3_type {vit_const, vit_create_if_not_existent, vit_throw_if_not_existent, }; - enum variable_info_3_state_type { + enum variable_info_type {vit_const, vit_create_if_not_existent, vit_throw_if_not_existent, }; + enum variable_info_state_type { state_start = 0, // for internal use - // only used at the 'starting_pos' of the variable_info_3::calculate_value algorithm + // only used at the 'starting_pos' of the variable_info::calculate_value algorithm state_named, // the result of .someval this can eigher man an attribute value or an // child range state_indexed, // the result of .someval[index] this is never an attribute value, @@ -34,7 +34,7 @@ namespace variable_info_3_detail }; //Special case of boost::enable_if - template + template struct enable_if_non_const { typedef enable_if_non_const type; @@ -45,7 +45,7 @@ namespace variable_info_3_detail { }; - template + template struct maybe_const { typedef T type; @@ -64,12 +64,12 @@ namespace variable_info_3_detail }; - template - struct variable_info_3_state + template + struct variable_info_state { typedef typename maybe_const::type t_child; - variable_info_3_state(t_child& vars) + variable_info_state(t_child& vars) : child_(&vars) , key_() , index_(0) @@ -89,8 +89,8 @@ namespace variable_info_3_detail // Then we store the result here. config::attribute_value temp_val_; - // See the definition of 'variable_info_3_state_type' - variable_info_3_state_type type_; + // See the definition of 'variable_info_state_type' + variable_info_state_type type_; }; }