ROSE  0.9.9.139
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Sawyer::Container::Interval< T > Class Template Reference

Description

template<class T>
class Sawyer::Container::Interval< T >

Range of values delimited by endpoints.

This class represents a range of contiguous values by specifying the lower and upper end points, both of which are included in the range. Alternatively, a range may be empty; the default constructor creates empty ranges. The value type, T, is intended to be an unsigned integer type. Signed integers may be used, but the caller should be prepared to handle negative sizes due to overflow (see size). Non-integer types are not recommended since some methods (e.g., size) assume that n and n+1 are adjacent values, which is not the case for floating point.

Values of this type are immutable except for the assignment operator; operations like intersection return a new object rather than modifying an existing object.

Definition at line 33 of file Interval.h.

#include <Interval.h>

Inheritance diagram for Sawyer::Container::Interval< T >:
Inheritance graph
[legend]

Classes

class  ConstIterator
 Bidirectional forward iterator. More...
 

Public Types

typedef T Value
 
typedef ConstIterator const_iterator
 
typedef ConstIterator iterator
 

Public Member Functions

 Interval ()
 Constructs an empty interval. More...
 
 Interval (const Interval &other)
 Copy-constructs an interval. More...
 
 Interval (T value)
 Constructs a singleton interval. More...
 
Intervaloperator= (const Interval &other)
 Assignment from an interval. More...
 
Intervaloperator= (T value)
 Assignment from a scalar. More...
 
least () const
 Returns lower limit. More...
 
greatest () const
 Returns upper limit. More...
 
bool isEmpty () const
 True if interval is empty. More...
 
bool isSingleton () const
 True if interval is a singleton. More...
 
bool isWhole () const
 True if interval covers entire space. More...
 
bool isOverlapping (const Interval &other) const
 True if two intervals overlap. More...
 
bool isContaining (const Interval &other) const
 Containment predicate. More...
 
Value size () const
 Size of interval. More...
 
Interval hull (const Interval &other) const
 Hull. More...
 
Interval hull (T value) const
 Hull. More...
 
std::pair< Interval, Intervalsplit (T splitPoint) const
 Split interval in two. More...
 
Interval join (const Interval &right) const
 Creates an interval by joining two adjacent intervals. More...
 
ConstIterator begin () const
 Iterator positioned at the least value. More...
 
ConstIterator end () const
 Iterator positioned one past the greatest value. More...
 
boost::iterator_range< ConstIteratorvalues () const
 Iterator range for values. More...
 
 operator unspecified_bool () const
 Type for Boolean context. More...
 
bool isLeftAdjacent (const Interval &right) const
 Adjacency predicate. More...
 
bool isRightAdjacent (const Interval &left) const
 Adjacency predicate. More...
 
bool isAdjacent (const Interval &other) const
 Adjacency predicate. More...
 
bool isLeftOf (const Interval &right) const
 Relative position predicate. More...
 
bool isRightOf (const Interval &left) const
 Relative position predicate. More...
 
bool operator== (const Interval &other) const
 Equality test. More...
 
bool operator!= (const Interval &other) const
 Equality test. More...
 
Interval intersection (const Interval &other) const
 Intersection. More...
 
Interval operator& (const Interval &other) const
 Intersection. More...
 

Static Public Member Functions

static Interval hull (T v1, T v2)
 Construct an interval from two endpoints. More...
 
static Interval baseSize (T lo, T size)
 Construct an interval from one endpoint and a size. More...
 
static Interval whole ()
 Construct an interval that covers the entire domain. More...
 

Constructor & Destructor Documentation

template<class T>
Sawyer::Container::Interval< T >::Interval ( )
inline
template<class T>
Sawyer::Container::Interval< T >::Interval ( const Interval< T > &  other)
inline

Copy-constructs an interval.

Definition at line 132 of file Interval.h.

template<class T>
Sawyer::Container::Interval< T >::Interval ( value)
inline

Constructs a singleton interval.

Definition at line 135 of file Interval.h.

Member Function Documentation

template<class T>
static Interval Sawyer::Container::Interval< T >::hull ( v1,
v2 
)
inlinestatic
template<class T>
static Interval Sawyer::Container::Interval< T >::baseSize ( lo,
size 
)
inlinestatic

Construct an interval from one endpoint and a size.

Returns the smallest interval that contains lo (inclusive) through lo + size (exclusive). If size is zero then an empty interval is created, in which case lo is irrelevant.

Definition at line 161 of file Interval.h.

Referenced by Rose::BinaryAnalysis::Partitioner2::DataBlock::extent().

template<class T>
static Interval Sawyer::Container::Interval< T >::whole ( )
inlinestatic
template<class T>
Interval& Sawyer::Container::Interval< T >::operator= ( const Interval< T > &  other)
inline

Assignment from an interval.

Definition at line 172 of file Interval.h.

template<class T>
Interval& Sawyer::Container::Interval< T >::operator= ( value)
inline

Assignment from a scalar.

Definition at line 179 of file Interval.h.

template<class T>
T Sawyer::Container::Interval< T >::least ( ) const
inline

Returns lower limit.

Definition at line 185 of file Interval.h.

Referenced by Rose::BinaryAnalysis::Strings::EncodedString::address(), Sawyer::Container::AddressMapConstraints< AddressMap >::at(), Sawyer::Container::Interval< Address >::begin(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::changeAccess(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::checkConsistency(), Sawyer::Container::BitVectorSupport::compare(), Sawyer::Container::BitVectorSupport::compareSigned(), Sawyer::Container::DenseIntegerSet< size_t >::DenseIntegerSet(), Sawyer::Container::Interval< Address >::end(), Sawyer::Container::DenseIntegerSet< size_t >::erase(), Sawyer::Container::DenseIntegerSet< size_t >::exists(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::findFreeSpace(), Sawyer::Container::BitVectorSupport::fromInteger(), Sawyer::Container::Interval< Address >::hull(), Sawyer::Container::DenseIntegerSet< size_t >::insert(), Sawyer::Container::Interval< Address >::intersection(), Sawyer::Container::IntervalSet< AddressInterval >::invert(), Sawyer::Container::Interval< Address >::isAdjacent(), Sawyer::Container::Interval< Address >::isContaining(), Sawyer::Container::Interval< Address >::isLeftAdjacent(), Sawyer::Container::Interval< Address >::isLeftOf(), Sawyer::Container::Interval< Address >::isRightAdjacent(), Sawyer::Container::Interval< Address >::isRightOf(), Sawyer::Container::Interval< Address >::join(), Sawyer::Container::BitVectorSupport::leastSignificantClearBit(), Sawyer::Container::BitVectorSupport::leastSignificantSetBit(), Sawyer::Container::BitVectorSupport::mostSignificantClearBit(), Sawyer::Container::BitVectorSupport::mostSignificantSetBit(), Sawyer::Container::AddressMapConstraints< AddressMap >::print(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::read(), Sawyer::Container::BitVectorSupport::rotateRight(), Sawyer::Container::BitVectorSupport::shiftLeft(), Sawyer::Container::BitVectorSupport::shiftRight(), Sawyer::Container::BitVectorSupport::signExtend(), Sawyer::Container::Interval< Address >::split(), Sawyer::Container::BitVectorSupport::toInteger(), Sawyer::Container::BitVectorSupport::traverse(), Sawyer::Container::BitVectorSupport::traverse2(), Sawyer::Container::AddressMapConstraints< AddressMap >::within(), and Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::write().

template<class T>
T Sawyer::Container::Interval< T >::greatest ( ) const
inline

Returns upper limit.

Definition at line 191 of file Interval.h.

Referenced by Sawyer::Container::AddressMapConstraints< AddressMap >::at(), Sawyer::Container::Interval< Address >::begin(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::checkConsistency(), Sawyer::Container::BitVectorSupport::compare(), Sawyer::Container::BitVectorSupport::compareSigned(), Sawyer::Container::DenseIntegerSet< size_t >::DenseIntegerSet(), Sawyer::Container::Interval< Address >::end(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::findFreeSpace(), Sawyer::Container::Interval< Address >::hull(), Sawyer::Container::DenseIntegerSet< size_t >::insert(), Sawyer::Container::Interval< Address >::intersection(), Sawyer::Container::IntervalSet< AddressInterval >::invert(), Sawyer::Container::Interval< Address >::isAdjacent(), Rose::BinaryAnalysis::Partitioner2::Trigger::isArmed(), Sawyer::Container::Interval< Address >::isContaining(), Sawyer::Container::Interval< Address >::isLeftAdjacent(), Sawyer::Container::Interval< Address >::isLeftOf(), Sawyer::Container::Interval< Address >::isRightAdjacent(), Sawyer::Container::Interval< Address >::isRightOf(), Sawyer::Container::Interval< Address >::join(), Sawyer::Container::AddressMapConstraints< AddressMap >::print(), Sawyer::Container::BitVectorSupport::shiftRightArithmetic(), Sawyer::Container::BitVectorSupport::signExtend(), Sawyer::Container::Interval< Address >::split(), Sawyer::Container::BitVectorSupport::traverse(), and Sawyer::Container::AddressMapConstraints< AddressMap >::within().

template<class T>
bool Sawyer::Container::Interval< T >::isEmpty ( ) const
inline

True if interval is empty.

Definition at line 197 of file Interval.h.

Referenced by Sawyer::Container::Interval< Address >::begin(), Sawyer::Container::BitVectorSupport::compare(), Sawyer::Container::BitVectorSupport::compareSigned(), Sawyer::Container::DenseIntegerSet< size_t >::DenseIntegerSet(), Sawyer::Container::Interval< Address >::end(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::findFreeSpace(), Sawyer::Container::BitVectorSupport::fromInteger(), Sawyer::Container::Interval< Address >::greatest(), Sawyer::Container::Interval< Address >::hull(), Sawyer::Container::DenseIntegerSet< size_t >::insert(), Sawyer::Container::Interval< Address >::intersection(), Sawyer::Container::IntervalSet< AddressInterval >::invert(), Sawyer::Container::Interval< Address >::isAdjacent(), Rose::BinaryAnalysis::Partitioner2::Trigger::isArmed(), Sawyer::Container::Interval< Address >::isContaining(), Sawyer::Container::Interval< Address >::isLeftAdjacent(), Sawyer::Container::Interval< Address >::isLeftOf(), Sawyer::Container::Interval< Address >::isOverlapping(), Sawyer::Container::Interval< Address >::isRightAdjacent(), Sawyer::Container::Interval< Address >::isRightOf(), Sawyer::Container::Interval< Address >::join(), Sawyer::Container::Interval< Address >::least(), Sawyer::Container::Interval< Address >::operator unspecified_bool(), Sawyer::Container::AddressMapConstraints< AddressMap >::print(), Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::read(), Sawyer::Container::BitVectorSupport::rotateLeft(), Sawyer::Container::BitVectorSupport::rotateRight(), Sawyer::Container::BitVectorSupport::shiftRightArithmetic(), Sawyer::Container::BitVectorSupport::signExtend(), Sawyer::Container::Interval< Address >::size(), Sawyer::Container::Interval< Address >::split(), Sawyer::Container::BitVectorSupport::traverse(), Sawyer::Container::BitVectorSupport::traverse2(), Sawyer::Container::AddressMapConstraints< AddressMap >::within(), and Sawyer::Container::AddressMap< rose_addr_t, uint8_t >::write().

template<class T>
bool Sawyer::Container::Interval< T >::isSingleton ( ) const
inline

True if interval is a singleton.

Definition at line 200 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::isWhole ( ) const
inline
template<class T>
bool Sawyer::Container::Interval< T >::isOverlapping ( const Interval< T > &  other) const
inline

True if two intervals overlap.

An empty interval never overlaps with any other interval, empty or not.

Definition at line 208 of file Interval.h.

Referenced by Sawyer::Container::BitVectorSupport::swap().

template<class T>
bool Sawyer::Container::Interval< T >::isContaining ( const Interval< T > &  other) const
inline

Containment predicate.

Returns true if this interval contains all of the other interval. An empty interval is always contained in any other interval, even another empty interval.

Definition at line 216 of file Interval.h.

Referenced by Rose::BinaryAnalysis::Partitioner2::Trigger::shouldTrigger().

template<class T>
bool Sawyer::Container::Interval< T >::isLeftAdjacent ( const Interval< T > &  right) const
inline

Adjacency predicate.

Returns true if the two intervals are adjacent. An empty interval is adjacent to all other intervals, including another empty interval.

Definition at line 227 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::isRightAdjacent ( const Interval< T > &  left) const
inline

Adjacency predicate.

Returns true if the two intervals are adjacent. An empty interval is adjacent to all other intervals, including another empty interval.

Definition at line 230 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::isAdjacent ( const Interval< T > &  other) const
inline

Adjacency predicate.

Returns true if the two intervals are adjacent. An empty interval is adjacent to all other intervals, including another empty interval.

Definition at line 233 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::isLeftOf ( const Interval< T > &  right) const
inline

Relative position predicate.

Returns true if the intervals do not overlap and one is positioned left or right of the other. Empty intervals are considered to be both left and right of the other.

Definition at line 246 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::isRightOf ( const Interval< T > &  left) const
inline

Relative position predicate.

Returns true if the intervals do not overlap and one is positioned left or right of the other. Empty intervals are considered to be both left and right of the other.

Definition at line 249 of file Interval.h.

template<class T>
Value Sawyer::Container::Interval< T >::size ( void  ) const
inline
template<class T>
bool Sawyer::Container::Interval< T >::operator== ( const Interval< T > &  other) const
inline

Equality test.

Two intervals are equal if they have the same lower and upper bound, and unequal if either bound differs. Two empty ranges are considered to be equal.

Definition at line 265 of file Interval.h.

template<class T>
bool Sawyer::Container::Interval< T >::operator!= ( const Interval< T > &  other) const
inline

Equality test.

Two intervals are equal if they have the same lower and upper bound, and unequal if either bound differs. Two empty ranges are considered to be equal.

Definition at line 268 of file Interval.h.

template<class T>
Interval Sawyer::Container::Interval< T >::intersection ( const Interval< T > &  other) const
inline

Intersection.

Returns an interval which is the intersection of this interval with another.

Definition at line 278 of file Interval.h.

Referenced by Sawyer::Container::IntervalSetMap< I, S >::erase(), Sawyer::Container::IntervalSetMap< I, S >::insert(), Sawyer::Container::Interval< Address >::isOverlapping(), and Sawyer::Container::Interval< Address >::operator&().

template<class T>
Interval Sawyer::Container::Interval< T >::operator& ( const Interval< T > &  other) const
inline

Intersection.

Returns an interval which is the intersection of this interval with another.

Definition at line 283 of file Interval.h.

template<class T>
Interval Sawyer::Container::Interval< T >::hull ( const Interval< T > &  other) const
inline

Hull.

Returns the smallest interval that contains both this interval and the other interval.

See also
join

Definition at line 293 of file Interval.h.

template<class T>
Interval Sawyer::Container::Interval< T >::hull ( value) const
inline

Hull.

Returns the smallest interval that contains both this interval and another value.

Definition at line 306 of file Interval.h.

template<class T>
std::pair<Interval, Interval> Sawyer::Container::Interval< T >::split ( splitPoint) const
inline

Split interval in two.

Returns two interval by splitting this interval so that splitPoint is in the left returned interval. If the split is not a member of this interval then one of the two returned intervals will be empty, depending on whether the split point is less than or greater than this interval. If this interval is empty then both returned intervals will be empty regardless of the split point.

Definition at line 320 of file Interval.h.

template<class T>
Interval Sawyer::Container::Interval< T >::join ( const Interval< T > &  right) const
inline

Creates an interval by joining two adjacent intervals.

Concatenates this interval with the right interval and returns the result. This is similar to hull except when neither interval is empty then the greatest value of this interval must be one less than the least value of the right interval.

See also
hull

Definition at line 339 of file Interval.h.

template<class T>
ConstIterator Sawyer::Container::Interval< T >::begin ( ) const
inline

Iterator positioned at the least value.

Returns an iterator positioned at this interval's least value. If this interval is empty then the returned iterator's atEnd predicate will always return true. Iterators are useful for accessing the values of an interval because they have special logic to avoid arithmetic overflows which can happen if the interval's least and/or greatest value happens to also be the least or greatest value representable by type T. See ConstIterator for details.

Definition at line 361 of file Interval.h.

Referenced by Sawyer::Container::Interval< Address >::values().

template<class T>
ConstIterator Sawyer::Container::Interval< T >::end ( ) const
inline

Iterator positioned one past the greatest value.

Returns an iterator positioned one past this interval's least value even if such a value cannot be represented by type T. If this interval is empty then the returned iterator's atEnd predicate will always return true. Iterators are useful for accessing the values of an interval because they have special logic to avoid arithmetic overflows which can happen if the interval's least and/or greatest value happens to also be the least or greatest value representable by type T. See ConstIterator for details.

Definition at line 372 of file Interval.h.

Referenced by Sawyer::Container::Interval< Address >::values().

template<class T>
boost::iterator_range<ConstIterator> Sawyer::Container::Interval< T >::values ( ) const
inline

Iterator range for values.

Definition at line 377 of file Interval.h.

template<class T>
Sawyer::Container::Interval< T >::operator unspecified_bool ( ) const
inline

Type for Boolean context.

Implicit conversion to a type that can be used in a boolean context such as an if or while statement. For instance:

if (Interval<unsigned> x = doSomething(...)) {
// this is reached only if x is non-empty
}

The inteval evaluates to true if it is non-empty, and false if it is empty.

Definition at line 399 of file Interval.h.


The documentation for this class was generated from the following file: