| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * \file | ||
| 3 | * \brief Various utility functions. | ||
| 4 | *//* | ||
| 5 | * Copyright 2007 Johan Engelen <goejendaagh@zonnet.nl> | ||
| 6 | * Copyright 2006 Michael G. Sloan <mgsloan@gmail.com> | ||
| 7 | * | ||
| 8 | * This library is free software; you can redistribute it and/or | ||
| 9 | * modify it either under the terms of the GNU Lesser General Public | ||
| 10 | * License version 2.1 as published by the Free Software Foundation | ||
| 11 | * (the "LGPL") or, at your option, under the terms of the Mozilla | ||
| 12 | * Public License Version 1.1 (the "MPL"). If you do not alter this | ||
| 13 | * notice, a recipient may use your version of this file under either | ||
| 14 | * the MPL or the LGPL. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the LGPL along with this library | ||
| 17 | * in the file COPYING-LGPL-2.1; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | * You should have received a copy of the MPL along with this library | ||
| 20 | * in the file COPYING-MPL-1.1 | ||
| 21 | * | ||
| 22 | * The contents of this file are subject to the Mozilla Public License | ||
| 23 | * Version 1.1 (the "License"); you may not use this file except in | ||
| 24 | * compliance with the License. You may obtain a copy of the License at | ||
| 25 | * http://www.mozilla.org/MPL/ | ||
| 26 | * | ||
| 27 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY | ||
| 28 | * OF ANY KIND, either express or implied. See the LGPL or the MPL for | ||
| 29 | * the specific language governing rights and limitations. | ||
| 30 | * | ||
| 31 | */ | ||
| 32 | |||
| 33 | #ifndef LIB2GEOM_SEEN_UTILS_H | ||
| 34 | #define LIB2GEOM_SEEN_UTILS_H | ||
| 35 | |||
| 36 | #include <cstddef> | ||
| 37 | #include <vector> | ||
| 38 | #include <boost/operators.hpp> | ||
| 39 | |||
| 40 | namespace Geom { | ||
| 41 | |||
| 42 | // Throw these errors instead of aserting so code can handle them if needed. | ||
| 43 | using ErrorCode = int; | ||
| 44 | enum Errors : ErrorCode { | ||
| 45 | GEOM_ERR_INTERSECGRAPH, | ||
| 46 | }; | ||
| 47 | |||
| 48 | void binomial_coefficients(std::vector<size_t>& bc, std::size_t n); | ||
| 49 | |||
| 50 | struct EmptyClass {}; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * @brief Noncommutative multiplication helper. | ||
| 54 | * Generates operator*(T, U) from operator*=(T, U). Does not generate operator*(U, T) | ||
| 55 | * like boost::multipliable does. This makes it suitable for noncommutative cases, | ||
| 56 | * such as transforms. | ||
| 57 | */ | ||
| 58 | template <class T, class U, class B = EmptyClass> | ||
| 59 | struct MultipliableNoncommutative : B | ||
| 60 | { | ||
| 61 | 2328846 | friend T operator*(T const &lhs, U const &rhs) { | |
| 62 |
1/2✓ Branch 2 taken 2178000 times.
✗ Branch 3 not taken.
|
4627507 | T nrv(lhs); nrv *= rhs; return nrv; |
| 63 | ✗ | } | |
| 64 | }; | ||
| 65 | |||
| 66 | /** @brief Null output iterator | ||
| 67 | * Use this if you want to discard a result returned through an output iterator. */ | ||
| 68 | struct NullIterator | ||
| 69 | : public boost::output_iterator_helper<NullIterator> | ||
| 70 | { | ||
| 71 | NullIterator() {} | ||
| 72 | |||
| 73 | template <typename T> | ||
| 74 | void operator=(T const &) {} | ||
| 75 | }; | ||
| 76 | |||
| 77 | /** @brief Get the next iterator in the container with wrap-around. | ||
| 78 | * If the iterator would become the end iterator after incrementing, | ||
| 79 | * return the begin iterator instead. */ | ||
| 80 | template <typename Iter, typename Container> | ||
| 81 | 284 | Iter cyclic_next(Iter i, Container &c) { | |
| 82 | ++i; | ||
| 83 |
3/4✓ Branch 2 taken 142 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 21 times.
✓ Branch 6 taken 121 times.
|
568 | if (i == c.end()) { |
| 84 |
1/2✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
|
84 | i = c.begin(); |
| 85 | } | ||
| 86 | 284 | return i; | |
| 87 | } | ||
| 88 | |||
| 89 | /** @brief Get the previous iterator in the container with wrap-around. | ||
| 90 | * If the passed iterator is the begin iterator, return the iterator | ||
| 91 | * just before the end iterator instead. */ | ||
| 92 | template <typename Iter, typename Container> | ||
| 93 | 34 | Iter cyclic_prior(Iter i, Container &c) { | |
| 94 |
3/4✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 21 times.
|
68 | if (i == c.begin()) { |
| 95 |
1/2✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
26 | i = c.end(); |
| 96 | } | ||
| 97 | --i; | ||
| 98 | 34 | return i; | |
| 99 | } | ||
| 100 | |||
| 101 | } // end namespace Geom | ||
| 102 | |||
| 103 | #endif // LIB2GEOM_SEEN_UTILS_H | ||
| 104 | |||
| 105 | /* | ||
| 106 | Local Variables: | ||
| 107 | mode:c++ | ||
| 108 | c-file-style:"stroustrup" | ||
| 109 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) | ||
| 110 | indent-tabs-mode:nil | ||
| 111 | fill-column:99 | ||
| 112 | End: | ||
| 113 | */ | ||
| 114 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : | ||
| 115 |