1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/**************************************************************************
* *
* Regina - A Normal Surface Theory Calculator *
* Computational Engine *
* *
* Copyright (c) 1999-2011, Ben Burton *
* For further details contact Ben Burton (bab@debian.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; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* You should have received a copy of the GNU General Public *
* License along with this program; if not, write to the Free *
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
**************************************************************************/
/* end stub */
/*! \file utilities/boostutils.h
* \brief Miscellaneous utility classes taken or modified from the
* Boost C++ libraries.
*
* The Boost copyright notices are as follows.
*
* <b>Type Traits:</b>
*
* (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
*
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
* <b>Reference Wrappers:</b>
*
* Copyright (C) 1999, 2000 Jaakko Jrvi (jaakko.jarvi@cs.utu.fi)<br>
* Copyright (C) 2001, 2002 Peter Dimov<br>
* Copyright (C) 2002 David Abrahams
*
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
* <b>Next, Prior and Non-Copyable:</b>
*
* Contributed by Dave Abrahams
*
* (C) Copyright Boost.org 1999-2003.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#ifndef __BOOSTUTILS_H
#ifndef __DOXYGEN
#define __BOOSTUTILS_H
#endif
#include "regina-core.h"
namespace regina {
/**
* Miscellaneous utility classes taken or modified from the Boost C++
* libraries.
*
* See the boostutils.h file documentation for Boost license details.
*/
namespace boost {
/**
* \weakgroup utilities
* @{
*/
/**
* A template class used to remove the indirection from a pointer type.
*
* If <tt>T</tt> is a pointer type, then
* \code remove_pointer<T>::type \endcode
* removes the top-level indirection from <tt>T</tt>; otherwise
* <tt>T</tt> remains unchanged. For example <tt>int*</tt> becomes
* <tt>int</tt>, but <tt>int&</tt> remains unchanged.
*
* \ifacespython Not present.
*
* @author This class was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <typename T>
struct remove_pointer {
typedef T type;
/**< The template argument with the top-level indirection
* removed if it is a pointer type. */
};
#ifndef __DOXYGEN
/**
* Specialisations of remove_pointer:
*/
template <typename T>
struct remove_pointer<T*> {
typedef T type;
};
template <typename T>
struct remove_pointer<T* const> {
typedef T type;
};
template <typename T>
struct remove_pointer<T* volatile> {
typedef T type;
};
template <typename T>
struct remove_pointer<T* const volatile> {
typedef T type;
};
#endif
/**
* A wrapper allowing references to be passed through generic functions.
* This class is for use with the Standard Template Library.
*
* The primary advantage of this class is its implicit conversion to
* type <tt>T&</tt>. Thus it can be passed to routines expecting
* references to <tt>T</tt> but can also be passed by reference itself.
*
* See global routines ::ref() and ::cref() for simple creation of these
* wrappers.
*
* \ifacespython Not present.
*
* @author This class was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <class T>
class reference_wrapper {
public:
typedef T type;
/**< The data type being referenced by this wrapper. */
private:
T* t_;
/**< A pointer to the object being referenced. */
public:
/**
* Creates a new wrapper to reference the given object.
*
* @param t the object to be referenced.
*/
explicit reference_wrapper(type& t) : t_(&t) {
}
/**
* Returns a reference to the object being referenced.
* This routine provides an implicit conversion to type
* <tt>T&</tt>.
*
* @return the corresonding reference.
*/
operator type& () const {
return *t_;
}
/**
* Returns a reference to the object being referenced.
*
* @return the corresonding reference.
*/
type& get() const {
return *t_;
}
/**
* Returns a pointer to the object being referenced.
*
* @return the corresponding pointer.
*/
type* get_pointer() const {
return t_;
}
};
/**
* Returns a wrapper for the given reference. See reference_wrapper for
* further details.
*
* \ifacespython Not present.
*
* @param t the reference to wrap.
* @return the corresponding wrapper.
*
* @author This routine was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <class T>
inline reference_wrapper<T> const ref(T& t) {
return reference_wrapper<T>(t);
}
/**
* Returns a wrapper for the given const reference. See reference_wrapper for
* further details.
*
* \ifacespython Not present.
*
* @param t the reference to wrap.
* @return the corresponding wrapper.
*
* @author This routine was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <class T>
inline reference_wrapper<T const> const cref(T const& t) {
return reference_wrapper<T const>(t);
}
/**
* Returns the iterator prior to the given iterator.
* This function avoids having to explicitly create a temporary to
* decrement.
*
* Only the decrement operator <tt>--it</tt> needs to be defined.
*
* \ifacespython Not present.
*
* @param it the iterator to examine.
* @return the iterator prior to the given iterator.
*
* @author This routine was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <class T>
inline T prior(T it) {
return --it;
}
/**
* Returns the iterator following the given iterator.
* This function avoids having to explicitly create a temporary to
* increment.
*
* Only the increment operator <tt>++it</tt> needs to be defined.
*
* \ifacespython Not present.
*
* @param it the iterator to examine.
* @return the iterator following the given iterator.
*
* @author This routine was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
template <class T>
inline T next(T it) {
return ++it;
}
/**
* A base class that guarantees that derived classes cannot be copied.
* This is done by defining a private copy constructor and a private
* copy assignment operator.
*
* \ifacespython Not present.
*
* @author This class was taken and modified from the Boost C++ libraries
* (<tt>http://www.boost.org/</tt>).
*/
class REGINA_API noncopyable {
protected:
/**
* A constructor which does nothing.
*/
noncopyable() {}
/**
* A destructor which does nothing.
*/
~noncopyable() {}
private:
/**
* An inaccessable copy constructor.
*/
noncopyable(const noncopyable&) {}
/**
* An inaccessible copy assignment operator.
*/
const noncopyable& operator = (const noncopyable&) { return *this; }
};
/*@}*/
} } // namespace regina::boost
#endif
|