Move tconst_clone to its own file.
This allows code outside of the gui code to use it as well.
This commit is contained in:
parent
a46cc6ed2a
commit
4ed714ea78
4 changed files with 93 additions and 68 deletions
|
@ -181,68 +181,6 @@ struct tconst_duplicator<const T, U>
|
|||
typedef const U type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper struct to clone the constness of one type to another.
|
||||
*
|
||||
* It's function is similar to the @ref tconst_duplicator, but a bit more
|
||||
* flexible.
|
||||
*
|
||||
* @warning It seems @c *this in a const member function is not a const object,
|
||||
* use @c this, which is a pointer to a const object.
|
||||
*
|
||||
* @tparam D The destination type, it should have no
|
||||
* cv-qualifier and not be a pointer or
|
||||
* reference.
|
||||
* @tparam S The source type, this type may be a pointer
|
||||
* or reference and obviously is allowed to have
|
||||
* a cv-qualifier, although @c volatile has no
|
||||
* effect.
|
||||
* @tparam E The enable parameter for
|
||||
* @ref boost::enable_if.
|
||||
*/
|
||||
template<
|
||||
class D
|
||||
, class S
|
||||
, typename E = void
|
||||
>
|
||||
struct tconst_clone
|
||||
{
|
||||
/** The destination type, possibly const qualified. */
|
||||
typedef D type;
|
||||
|
||||
/** A reference to the destination type, possibly const qualified. */
|
||||
typedef D& reference;
|
||||
|
||||
/** A pointer to the destination type, possibly const qualified. */
|
||||
typedef D* pointer;
|
||||
};
|
||||
|
||||
/**
|
||||
* The specialised version of @ref tconst_clone.
|
||||
*
|
||||
* This version is used when the @p S is const-qualified.
|
||||
*/
|
||||
template<
|
||||
class D
|
||||
, class S
|
||||
>
|
||||
struct tconst_clone<
|
||||
D
|
||||
, S
|
||||
, typename boost::enable_if<
|
||||
boost::is_const<
|
||||
typename boost::remove_pointer<
|
||||
typename boost::remove_reference<S>::type
|
||||
>::type
|
||||
>
|
||||
>::type
|
||||
>
|
||||
{
|
||||
typedef const D type;
|
||||
typedef const D& reference;
|
||||
typedef const D* pointer;
|
||||
};
|
||||
|
||||
/** Returns the current mouse position. */
|
||||
tpoint get_mouse_position();
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "gui/auxiliary/log.hpp"
|
||||
#include "gui/widgets/grid.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "utils/const_clone.tpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -44,7 +45,7 @@ struct tpane_implementation
|
|||
* @tparam W A pointer to the pane.
|
||||
*/
|
||||
template<class W>
|
||||
static typename tconst_clone<twidget, W>::pointer
|
||||
static typename utils::tconst_clone<twidget, W>::pointer
|
||||
find_at(
|
||||
W pane
|
||||
, tpoint coordinate
|
||||
|
@ -59,7 +60,7 @@ struct tpane_implementation
|
|||
return NULL;
|
||||
}
|
||||
|
||||
typedef typename tconst_clone<tpane::titem, W>::reference thack;
|
||||
typedef typename utils::tconst_clone<tpane::titem, W>::reference thack;
|
||||
BOOST_FOREACH(thack item, pane->items_) {
|
||||
|
||||
if(item.grid->get_visible() == twidget::INVISIBLE) {
|
||||
|
@ -91,10 +92,10 @@ struct tpane_implementation
|
|||
* @tparam W A pointer to the pane.
|
||||
*/
|
||||
template<class W>
|
||||
static typename tconst_clone<tgrid, W>::pointer
|
||||
static typename utils::tconst_clone<tgrid, W>::pointer
|
||||
grid(W pane, const unsigned id)
|
||||
{
|
||||
typedef typename tconst_clone<tpane::titem, W>::reference thack;
|
||||
typedef typename utils::tconst_clone<tpane::titem, W>::reference thack;
|
||||
BOOST_FOREACH(thack item, pane->items_) {
|
||||
|
||||
if(item.id == id) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "gui/widgets/viewport.hpp"
|
||||
|
||||
#include "gui/auxiliary/log.hpp"
|
||||
#include "utils/const_clone.tpp"
|
||||
|
||||
#define LOG_SCOPE_HEADER "tviewport [" + id() + "] " + __func__
|
||||
#define LOG_HEADER LOG_SCOPE_HEADER + ':'
|
||||
|
@ -40,7 +41,7 @@ struct tviewport_implementation
|
|||
* @tparam W A pointer to the pane.
|
||||
*/
|
||||
template<class W>
|
||||
static typename tconst_clone<twidget, W>::pointer
|
||||
static typename utils::tconst_clone<twidget, W>::pointer
|
||||
find_at(
|
||||
W viewport
|
||||
, tpoint coordinate
|
||||
|
@ -66,7 +67,7 @@ struct tviewport_implementation
|
|||
}
|
||||
|
||||
template<class W>
|
||||
static typename tconst_clone<twidget, W>::pointer
|
||||
static typename utils::tconst_clone<twidget, W>::pointer
|
||||
find(
|
||||
W viewport
|
||||
, const std::string& id
|
||||
|
|
85
src/utils/const_clone.tpp
Normal file
85
src/utils/const_clone.tpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2012 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 as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef UTILS_CONST_CLONE_HPP_INCLUDED
|
||||
#define UTILS_CONST_CLONE_HPP_INCLUDED
|
||||
|
||||
namespace utils {
|
||||
|
||||
/**
|
||||
* Helper struct to clone the constness of one type to another.
|
||||
*
|
||||
* It's function is similar to the @ref tconst_duplicator, but a bit more
|
||||
* flexible.
|
||||
*
|
||||
* @warning It seems @c *this in a const member function is not a const object,
|
||||
* use @c this, which is a pointer to a const object.
|
||||
*
|
||||
* @tparam D The destination type, it should have no
|
||||
* cv-qualifier and not be a pointer or
|
||||
* reference.
|
||||
* @tparam S The source type, this type may be a pointer
|
||||
* or reference and obviously is allowed to have
|
||||
* a cv-qualifier, although @c volatile has no
|
||||
* effect.
|
||||
* @tparam E The enable parameter for
|
||||
* @ref boost::enable_if.
|
||||
*/
|
||||
template<
|
||||
class D
|
||||
, class S
|
||||
, typename E = void
|
||||
>
|
||||
struct tconst_clone
|
||||
{
|
||||
/** The destination type, possibly const qualified. */
|
||||
typedef D type;
|
||||
|
||||
/** A reference to the destination type, possibly const qualified. */
|
||||
typedef D& reference;
|
||||
|
||||
/** A pointer to the destination type, possibly const qualified. */
|
||||
typedef D* pointer;
|
||||
};
|
||||
|
||||
/**
|
||||
* The specialised version of @ref tconst_clone.
|
||||
*
|
||||
* This version is used when the @p S is const-qualified.
|
||||
*/
|
||||
template<
|
||||
class D
|
||||
, class S
|
||||
>
|
||||
struct tconst_clone<
|
||||
D
|
||||
, S
|
||||
, typename boost::enable_if<
|
||||
boost::is_const<
|
||||
typename boost::remove_pointer<
|
||||
typename boost::remove_reference<S>::type
|
||||
>::type
|
||||
>
|
||||
>::type
|
||||
>
|
||||
{
|
||||
typedef const D type;
|
||||
typedef const D& reference;
|
||||
typedef const D* pointer;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue