/usr/include/ThePEG/Utilities/Interval.h is in libthepeg-dev 1.8.0-1.1.
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 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 | // -*- C++ -*-
//
// Interval.h is a part of ThePEG - Toolkit for HEP Event Generation
// Copyright (C) 1999-2011 Leif Lonnblad
//
// ThePEG is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef ThePEG_Interval_H
#define ThePEG_Interval_H
// This is the declaration of the Interval class.
#include <utility>
#include <vector>
#include "Interval.fh"
#include "ThePEG/Utilities/UnitIO.h"
namespace ThePEG {
template <typename T, typename CMP>
/**
* An <code>Interval</code> object is used to represent an interval
* <code>[ lower(), upper() )</code> where the ordering is defined by
* the <code>bool operator()(const T &, const T &) const</code> member
* of the CMP class (by defaut less<T>).
*/
class Interval {
public:
/**
* Construct an empty interval.
*/
Interval() : theLimits(pair<T,T>()) {}
/**
* Construct interval [dn,up).
*/
Interval(T dn, T up) : theLimits(pair<T,T>(dn, up)) {}
/**
* Test for equality.
*/
bool operator==(const Interval & i) const {
return lower() == i.lower() && upper() == i.upper();
}
/**
* Test for ordering.
* @return true if <code>lower() < i.lower()</code> or <code>lower()
* == i.lower()</code> and <code>upper() < i.upper()</code>.
*/
bool operator<(const Interval & i) const {
return cmp(lower(), i.lower()) ||
( lower() == i.lower() && cmp(upper(), i.upper()) );
}
/**
* Check consistency ie. that lower() < upper().
*/
bool check() const { return cmp(lower(), upper()); }
/**
* Returns true if x is within the interval.
*/
bool operator()(T x) const { return includes(x); }
/**
* Returns true if x is within the interval.
*/
bool includes(T x) const { return !cmp(x, lower()) && cmp(x, upper()); }
/**
* Returns true if the whole of i is within the interval.
*/
bool includes(const Interval<T,CMP> & i) const {
return includes(i.lower()) && !cmp(upper(), i.upper());
}
/**
* If x is in the interval return the interval [x,upper()) and
* change this interval to [lower(),x). If x is not within the
* interval, return [0,0) and leave this interval as it is.
*/
Interval<T,CMP> chopUpper(T x) {
Interval<T,CMP> r;
if ( includes(x) ) {
r.lower(x);
r.upper(upper());
upper(x);
}
return r;
}
/**
* If x is in the interval return the interval [lower(),x) and
* change this interval to [x,upper()). If x is not within the
* interval, return [0,0) and leave this interval as it is.
*/
Interval<T,CMP> chopLower(T x) {
Interval<T,CMP> r;
if ( includes(x) ) {
r.lower(lower());
r.upper(x);
lower(x);
}
return r;
}
/**
* If this interval operlaps with i return the overlapping interval.
*/
Interval<T,CMP> overlap(const Interval & i) const {
Interval<T,CMP> res;
if ( operator==(i) ) res = i;
if ( includes(i.upper()) || includes(i.lower()) )
res = Interval<T,CMP>(max(lower(),i.lower()), min(upper(), i.upper()));
return res;
}
/**
* If this interval operlaps with i return the union of the two
* intervals.
*/
Interval<T,CMP> sum(const Interval & i) const {
Interval<T,CMP> res;
if ( operator==(i) ) res = i;
if ( includes(i.upper()) || includes(i.lower()) )
res = Interval<T,CMP>(min(lower(),i.lower()), max(upper(), i.upper()));
return res;
}
/**
* Return the upper limit of the interval.
*/
T upper() const { return theLimits.second; }
/**
* Return the lower limit of the interval.
*/
T lower() const { return theLimits.first; }
/**
* Set the upper limit of the interval.
*/
void upper(T up) { theLimits.second = up; }
/**
* Set the lower limit of the interval.
*/
void lower(T dn) { theLimits.first = dn; }
/**
* Check if any of the values in the iterator given range is
* included in this interval.
*/
template <typename Iterator>
bool check(Iterator first, Iterator last);
/**
* Check if all of the values in the given iterator range is
* included in this interval.
*/
template <typename Iterator>
bool checkAll(Iterator first, Iterator last);
/**
* If x is in the given interval, split the given interval in two,
* otherwise return an empty list.
*/
std::vector< Interval<T,CMP> > split(Interval<T,CMP>, T x);
/**
* For each value in the given range is in the given interval, split
* the interval in two, otherwise return an empty list.
*/
template<typename Iterator>
std::vector< Interval<T,CMP> > split(Interval<T,CMP>,
Iterator first, Iterator last);
private:
/** The lower and upper limit of this interval */
std::pair<T,T> theLimits;
/** The object used for comparisons. */
static CMP cmp;
};
/** An interval of doubles. */
typedef Interval<double> DInterval;
/** Helper function to create an interval of a type determined by the
* parameters. */
template <typename T, typename CMP>
inline Interval<T,CMP> makeInterval(T dn, T up) { return Interval<T,CMP>(dn, up); }
/** Ouptut an interval to a stream. */
template <typename OStream, typename T, typename CMP>
inline OStream & operator<<(OStream & os, const Interval<T,CMP> & i) {
os << i.lower() << i.upper();
return os;
}
/** Input an interval from a stream. */
template <typename IStream, typename T, typename CMP>
inline IStream & operator>>(IStream & is, Interval<T,CMP> & i) {
T up, dn;
is >> dn >> up;
i.lower(dn);
i.upper(up);
return is;
}
/** Output an interval of a diminsionful type to a stream using the
* given unit.
* @param os the output stream.
* @param i the interval.
* @param u the unit. */
template <typename OStream, typename T, typename CMP, typename UT>
void ounitstream(OStream & os, const Interval<T,CMP> & i, UT & u) {
os << ounit(i.lower(), u) << ounit(i.upper(), u);
}
/** Input an interval of a diminsionful type from a stream using the
* given unit.
* @param is the input stream.
* @param i the interval.
* @param u the unit. */
template <typename IStream, typename T, typename CMP, typename UT>
void iunitstream(IStream & is, Interval<T,CMP> & i, UT & u) {
T low, upp;
is >> iunit(low, u) >> iunit(upp, u);
i = Interval<T,CMP>(low, upp);
}
}
#ifndef ThePEG_TEMPLATES_IN_CC_FILE
#include "Interval.tcc"
#endif
#endif /* ThePEG_Interval_H */
|