/usr/include/polymake/polytope/CubeFacets.h is in libpolymake-dev-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* Copyright (c) 1997-2018
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.polymake.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, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
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.
--------------------------------------------------------------------------------
*/
#ifndef POLYMAKE_POLYTOPE_CUBE_FACETS_H
#define POLYMAKE_POLYTOPE_CUBE_FACETS_H
#include "polymake/GenericSet.h"
namespace polymake { namespace polytope {
template <typename E>
class CubeFacet_iterator {
public:
typedef std::forward_iterator_tag iterator_category;
typedef E value_type;
typedef const E& reference;
typedef const E* pointer;
typedef ptrdiff_t difference_type;
typedef CubeFacet_iterator iterator;
typedef iterator const_iterator;
CubeFacet_iterator() { }
CubeFacet_iterator(typename pm::function_argument<E>::type cur_arg,
typename pm::function_argument<E>::type step_arg,
typename pm::function_argument<E>::type end_arg)
: cur(cur_arg), lim(cur_arg+step_arg), step(step_arg), end(end_arg) { }
reference operator* () const { return cur; }
pointer operator-> () const { return &cur; }
iterator& operator++ () {
if (++cur == lim) {
cur += step;
lim += (step<<1);
}
return *this;
}
const iterator operator++ (int) { iterator copy=*this; operator++(); return copy; }
bool at_end() const { return cur==end; }
bool operator== (const iterator& it) const { return cur==it.cur; }
bool operator!= (const iterator& it) const { return !operator==(it); }
protected:
E cur, lim, step, end;
};
/// Virtual container enumerating the verices in a facet of a cube
template <typename E>
class CubeFacet
: public GenericSet< CubeFacet<E>, E, operations::cmp> {
public:
typedef E value_type;
typedef const E& const_reference;
typedef const_reference reference;
CubeFacet() { }
CubeFacet(typename pm::function_argument<E>::type start_arg,
typename pm::function_argument<E>::type step_arg,
typename pm::function_argument<E>::type size_arg)
: start(start_arg), step(step_arg), _size(size_arg) { }
typedef CubeFacet_iterator<E> iterator;
typedef iterator const_iterator;
iterator begin() const { return iterator(start, step, start+_size); }
iterator end() const { return iterator(start+_size, step, start+_size); }
reference front() const { return start; }
const E& size() const { return _size; }
bool empty() const { return !_size; }
protected:
E start, step, _size;
};
template <typename E>
class CubeFacets_iterator : protected CubeFacet<E> {
public:
typedef std::forward_iterator_tag iterator_category;
typedef CubeFacet<E> value_type;
typedef const value_type& reference;
typedef const value_type* pointer;
typedef ptrdiff_t difference_type;
typedef CubeFacets_iterator iterator;
typedef iterator const_iterator;
CubeFacets_iterator() { }
CubeFacets_iterator(typename pm::function_argument<E>::type start_arg,
typename pm::function_argument<E>::type step_arg,
typename pm::function_argument<E>::type size_arg)
: value_type(start_arg,step_arg,size_arg), start(start_arg) { }
reference operator* () const { return *this; }
pointer operator-> () const { return this; }
iterator& operator++ () {
if (value_type::start == start) {
value_type::start += this->step;
} else {
value_type::start=start; this->step<<=1;
}
return *this;
}
const iterator operator++ (int) { iterator copy=*this; operator++(); return copy; }
bool operator== (const iterator& it) const
{
return this->step==it.step && value_type::start==it.value_type::start;
}
bool operator!= (const iterator& it) const { return !operator==(it); }
bool at_end() const { return this->step==this->_size; }
protected:
E start;
};
template <typename E>
class CubeFacets {
public:
typedef CubeFacets_iterator<E> iterator;
typedef iterator const_iterator;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference const_reference;
typedef const_reference reference;
/** @param dim_arg dimension of the cube
@param start_arg index of the first vertex
*/
explicit CubeFacets(int dim_arg, typename pm::function_argument<E>::type start_arg=E(0))
: start(start_arg), dim(dim_arg) { }
int size() const { return 2*dim; }
bool empty() const { return dim==0; }
iterator begin() const { return iterator(start, E(1), E(1)<<dim); }
iterator end() const { return iterator(start, E(1)<<dim, E(1)<<dim); }
const value_type front() const { return value_type(start, E(1), E(1)<<dim); }
protected:
E start;
int dim;
};
} }
namespace pm {
template <typename E>
struct check_iterator_feature<polymake::polytope::CubeFacet_iterator<E>, end_sensitive> : std::true_type { };
template <typename E>
struct check_iterator_feature<polymake::polytope::CubeFacets_iterator<E>, end_sensitive> : std::true_type { };
}
#endif // POLYMAKE_POLYTOPE_CUBE_FACETS_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|