Remove utils/enumerate.hpp

This was only used in one place, was probably not portable to additional cases, and is done much better using the MAKE_ENUM macro.
This commit is contained in:
Celtic Minstrel 2016-03-19 22:03:22 -04:00
parent 8122039707
commit d0c716a22d
5 changed files with 9 additions and 260 deletions

View file

@ -1502,7 +1502,6 @@
91ECD5D41BA11A6400B25CF1 /* mp_replay_controller.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = mp_replay_controller.hpp; sourceTree = "<group>"; };
91EF6BFB1C9E22E400E2A733 /* boost_function_guarded.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = boost_function_guarded.hpp; sourceTree = "<group>"; };
91EF6BFC1C9E22E400E2A733 /* const_clone.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = const_clone.hpp; sourceTree = "<group>"; };
91EF6BFD1C9E22E400E2A733 /* enumerate.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = enumerate.hpp; sourceTree = "<group>"; };
91EF6BFE1C9E22E400E2A733 /* foreach.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = foreach.hpp; sourceTree = "<group>"; };
91EF6BFF1C9E22E400E2A733 /* iterator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = iterator.hpp; sourceTree = "<group>"; };
91EF6C001C9E22E400E2A733 /* reference_counter.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = reference_counter.hpp; sourceTree = "<group>"; };
@ -3521,7 +3520,6 @@
children = (
91EF6BFB1C9E22E400E2A733 /* boost_function_guarded.hpp */,
91EF6BFC1C9E22E400E2A733 /* const_clone.hpp */,
91EF6BFD1C9E22E400E2A733 /* enumerate.hpp */,
91EF6BFE1C9E22E400E2A733 /* foreach.hpp */,
91EF6BFF1C9E22E400E2A733 /* iterator.hpp */,
91EF6C001C9E22E400E2A733 /* reference_counter.hpp */,

View file

@ -14,12 +14,6 @@
#define GETTEXT_DOMAIN "wesnoth-lib"
#define ENUM_ENABLE_STREAM_OPERATORS_IMPLEMENTATION
#define ENUM_TYPE ::gui2::tplacer_
#define ENUM_LIST \
ENUM(horizontal, "horizontal"); \
ENUM(vertical, "vertical");
#include "gui/auxiliary/placer.hpp"
#include "asserts.hpp"
@ -30,15 +24,13 @@
namespace gui2
{
ENUM_DEFINE_STREAM_OPERATORS(::gui2::tplacer_::tgrow_direction)
tplacer_* tplacer_::build(const tgrow_direction grow_direction,
const unsigned parallel_items)
{
switch(grow_direction) {
case horizontal:
switch(grow_direction.v) {
case tgrow_direction::horizontal:
return new implementation::tplacer_horizontal_list(parallel_items);
case vertical:
case tgrow_direction::vertical:
return new implementation::tplacer_vertical_list(parallel_items);
};

View file

@ -25,6 +25,7 @@
#define GUI_AUXILIARY_PLACER_HPP_INCLUDED
#include "global.hpp"
#include "make_enum.hpp"
namespace gui2
{
@ -54,10 +55,10 @@ public:
/***** ***** Types. ***** *****/
/** The direction the placer should grow towards. */
enum tgrow_direction {
horizontal,
vertical
};
MAKE_ENUM(tgrow_direction,
(horizontal, "horizontal")
(vertical, "vertical")
)
/***** ***** Constructor, destructor, assignment. ***** *****/
@ -121,13 +122,4 @@ public:
} // namespace gui2
#include "utils/enumerate.hpp"
namespace gui2
{
ENUM_DECLARE_STREAM_OPERATORS(::gui2::tplacer_::tgrow_direction)
} // namespace gui2
#endif

View file

@ -111,7 +111,7 @@ tpane::tpane(const tbuilder_grid_ptr item_builder)
, items_()
, item_builder_(item_builder)
, item_id_generator_(0)
, placer_(tplacer_::build(tplacer_::vertical, 1))
, placer_(tplacer_::build(tplacer_::tgrow_direction::vertical, 1))
{
connect_signal<event::REQUEST_PLACEMENT>(
boost::bind(

View file

@ -1,233 +0,0 @@
/*
* Copyright (C) 2011 - 2016 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY.
*
* See the COPYING file for more details.
*/
/**
* @file
* This file stream operators for the enum types.
*
* This code helps with input or outputting enumerates. For an example of its
* usage look at @ref lib::texception::ttype.
*
* The file contains the declarations needed in the header and the
* definitions needed in the implementation.
*
* In the header the @ref ENUM_DECLARE_STREAM_OPERATORS must be 'called'
* after the @c enum is defined. (Not tested whether declaring the @c enum
* also works.)
*
* In the implementation the
* @ref ENUM_ENABLE_STREAM_OPERATORS_IMPLEMENTATION must be defined. Before
* this file is included several macros must be defined:
* - @c ENUM_TYPE must contain the type of @c enum to use.
* - @c ENUM_LIST should be a list of @c ENUM macros, where every macro has
* two parameters:
* -# The @c enum value.
* -# The string representation of the @c enum value.
* All values of the @c enum should be in this list.
*/
#ifndef LIB_STRING_ENUMERATE_TPP_INCLUDED
#define LIB_STRING_ENUMERATE_TPP_INCLUDED
#include <iosfwd>
#include <string>
/**
* Declares the stream operators for an enumerate type.
*
* The operators declared are:
* - std::ostream& operator<<(std::ostream, T);
* - void operator<<(std::string, T);
* - std::istream& operator>>(std::istream, T&);
* - void operator>>(std::string, T&);
*
* @pre std::is_enum<T>::value == true
*
* @param T The type of the enumerate.
*/
#define ENUM_DECLARE_STREAM_OPERATORS(T) \
std::ostream& \
operator<<(std::ostream& lhs, const T rhs); \
\
void \
operator<<(std::string& lhs, const T rhs); \
\
std::istream& \
operator>>(std::istream& lhs, T& rhs); \
\
void \
operator>>(const std::string& lhs, T& rhs); \
/** This macro must be set when the operators need to be defined. */
#ifdef ENUM_ENABLE_STREAM_OPERATORS_IMPLEMENTATION
#include "gettext.hpp"
#include "wml_exception.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <cassert>
#include <iostream>
/**
* Defines the stream operators for an enumerate type.
*
* This defines the operators declared with @ref ENUM_DECLARE_STREAM_OPERATORS.
* For every 'call' of @ref ENUM_DECLARE_STREAM_OPERATORS there needs to be an
* corrosponding 'call' to this macro.
*
* @param T The type of the enumerate.
*/
#define ENUM_DEFINE_STREAM_OPERATORS(T) \
std::ostream& \
operator<<(std::ostream& lhs, const T rhs) \
{ \
return detail::operator<<(lhs, rhs); \
} \
\
void \
operator<<(std::string& lhs, const T rhs) \
{ \
detail::operator<<(lhs, rhs); \
} \
\
std::istream& \
operator>>(std::istream& lhs, T& rhs) \
{ \
return detail::operator>>(lhs, rhs); \
} \
\
void \
operator>>(const std::string& lhs, T& rhs) \
{ \
detail::operator>>(lhs, rhs); \
} \
namespace detail {
/**
* Stream operator for an enumerate value.
*
* Contains the implementation details for an operator declared in
* @ref ENUM_DECLARE_STREAM_OPERATORS. This version implements:
* - std::ostream& operator<<(std::ostream, T);
*
* @pre std::is_enum<T>::value == true
*
* @param lhs The stream to write to.
* @param rhs The enumerate to write.
*
* @returns The @p lhs parameter.
*/
template<class T>
typename boost::enable_if_c<boost::is_enum<T>::value, std::ostream&>::type
operator<<(std::ostream& lhs, const T rhs)
{
std::string str;
str << rhs;
lhs << str;
return lhs;
}
/**
* Stream operator for an enumerate value.
*
* Contains the implementation details for an operator declared in
* @ref ENUM_DECLARE_STREAM_OPERATORS. This version implements:
* - void operator<<(std::string, T);
*
* @pre std::is_enum<T>::value == true
*
* @param lhs The string to write to.
* @param rhs The enumerate to write.
*/
template<class T>
typename boost::enable_if_c<boost::is_enum<T>::value>::type
operator<<(std::string& lhs, const T rhs)
{
#define ENUM(ENUMERATE, STRING) \
case ENUM_TYPE::ENUMERATE: lhs = STRING; \
return
switch(rhs) {
ENUM_LIST
}
#undef ENUM
assert(false);
}
/**
* Stream operator for an enumerate value.
*
* Contains the implementation details for an operator declared in
* @ref ENUM_DECLARE_STREAM_OPERATORS. This version implements:
* - std::istream& operator>>(std::istream, T&);
*
* @pre std::is_enum<T>::value == true
*
* @param lhs The stream to read from.
* @param rhs The enumerate to read.
*
* @returns The @p lhs parameter.
*/
template<class T>
typename boost::enable_if_c<boost::is_enum<T>::value, std::istream&>::type
operator>>(std::istream& lhs, T& rhs)
{
std::string str;
std::getline(lhs, str, '\0');
str >> rhs;
return lhs;
}
/**
* Stream operator for an enumerate value.
*
* Contains the implementation details for an operator declared in
* @ref ENUM_DECLARE_STREAM_OPERATORS. This version implements:
* - void operator>>(std::string, T&);
*
* @pre std::is_enum<T>::value == true
*
* @param lhs The string to read from.
* @param rhs The enumerate to read.
*/
template<class T>
typename boost::enable_if_c<boost::is_enum<T>::value>::type
operator>>(const std::string& lhs, T& rhs)
{
#define ENUM(enumerate, string) \
do { \
if(lhs == string) { \
rhs = ENUM_TYPE::enumerate; \
return; \
} \
} while(0)
ENUM_LIST
#undef ENUM
FAIL_WITH_DEV_MESSAGE(_("Enumerate out of range during reading."), lhs);
}
} // namespace detail
#endif
#endif