GCpp general purpose C++ library  version 1.0
GInterval Class Reference

#include <GInterval.hh>

Public Member Functions

template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
virtual GIntervalClone () const
 
virtual const char * ClassName () const
 
 GInterval ()
 
 GInterval (int i)
 
 GInterval (int i1, int i2)
 
 GInterval (const string &s)
 
 GInterval (const GInterval &original)
 
virtual ~GInterval ()
 
GIntervaloperator= (const GInterval &original)
 
int GetMin () const
 
int GetMax () const
 
void SetMin (int i)
 
void SetMax (int i)
 
bool IsEmpty () const
 
string GetString () const
 
string GetStringPar () const
 
int GetValNumber () const
 
virtual bool operator== (const GInterval &item)
 
GInterval Overlap (const GInterval &inter) const
 
bool IsInside (const GInterval &inter, const bool exclude=false) const
 
bool Contains (const GInterval &inter, const bool exclude=false) const
 
bool Touches (const GInterval &inter) const
 

Static Public Member Functions

static const char * StaticClassName ()
 

Protected Attributes

int i_min
 Interval lower bound.
 
int i_max
 Interval upper bound.
 

Static Private Attributes

static string c_range = ":"
 Range character identification.
 

Detailed Description

This class defines an interval between 2 integer values. The bounds belong to the interval. If the upper bound is smaller than the lower bound, the interval is considered empty.

Constructor & Destructor Documentation

GInterval::GInterval ( )
inline

Default constructor: empty interval.

References i_max, and i_min.

GInterval::GInterval ( int  i)
inline

Constructor from an interger value: the interval contains only 1 value.

Parameters
ivalue (lower and upper bound)

References i_max, and i_min.

GInterval::GInterval ( int  i1,
int  i2 
)
inline

Constructor from bounds.

Parameters
i1lower bound
i2upper bound

References i_max, and i_min.

GInterval::GInterval ( const string &  s)

Constructor from a string definition. The definition should look like min:max, or (min:max).

Parameters
sinterval definition string

References c_range, GString::GetSubstring(), i_max, i_min, GString::NoEndSpace(), and GString::ReadInt().

GInterval::GInterval ( const GInterval inter)
inline

Copy constructor.

Parameters
interinterval to copy

References i_max, and i_min.

GInterval::~GInterval ( )
inlinevirtual

Destructor.

Member Function Documentation

bool GInterval::Contains ( const GInterval inter,
const bool  exclude = false 
) const

The function returns true if the interval contains the argument interval.

Parameters
interinterval in which inclusion is tested
excludeindicates that bounds must be excluded

References IsInside().

int GInterval::GetMax ( ) const
inline

Get the interval upper bound.

References i_max.

Referenced by GIntervalList::Add(), IsInside(), operator==(), Overlap(), GIntervalList::Remove(), and Touches().

int GInterval::GetMin ( ) const
inline

Get the interval lower bound.

References i_min.

Referenced by GIntervalList::Add(), IsInside(), operator==(), Overlap(), GIntervalList::Remove(), and Touches().

string GInterval::GetString ( ) const

Return a string definition of the interval.

References c_range, GGetString(), i_max, i_min, and IsEmpty().

Referenced by GetStringPar().

string GInterval::GetStringPar ( ) const
inline

Return a string with interval definition, enclosed in parenthesis.

References GetString().

Referenced by GIntervalList::Add(), and GIntervalList::Remove().

int GInterval::GetValNumber ( ) const
inline

Return the number of values in the interval.

References i_max, i_min, and IsEmpty().

bool GInterval::IsEmpty ( ) const
inline

Return true if the interval does not contain any value (if the upper bound is smaller than the lower bound.

References i_max, and i_min.

Referenced by GIntervalList::Add(), GetString(), GetValNumber(), IsInside(), operator==(), Overlap(), GIntervalList::Remove(), and Touches().

bool GInterval::IsInside ( const GInterval inter,
const bool  exclude = false 
) const

The function returns true if the interval is included in the argument interval.

Parameters
interinterval in which inclusion is tested
excludeindicates that bounds must be excluded

References GetMax(), GetMin(), and IsEmpty().

Referenced by Contains().

template<class Q >
bool GInterval::IsInstanceOf ( ) const
inline

Macro from GCpp library that defines the following functions:

  • ClassName(): return the real class name of the object
  • StaticClassName(): return the used class name of the object (that may be a base class of the real object).
  • IsInstanceOf<T>(): return true if the current object is an instance of the template class name argument
  • Clone(): return an allocated copy of the object.
GInterval & GInterval::operator= ( const GInterval inter)
inline

Affectation operator

Parameters
interinterval to copy

References i_max, and i_min.

bool GInterval::operator== ( const GInterval inter)
virtual

Comparison operator.

Parameters
interInterval to compare

References GetMax(), GetMin(), i_max, i_min, and IsEmpty().

GInterval GInterval::Overlap ( const GInterval inter) const

Function returning the overlap with the argument interval

Parameters
interInterval for which we get the overlap

References GetMax(), GetMin(), IsEmpty(), SetMax(), and SetMin().

void GInterval::SetMax ( int  i)
inline

Set the interval upper bound.

Parameters
inew bound value

References i_max.

Referenced by GIntervalList::Add(), and Overlap().

void GInterval::SetMin ( int  i)
inline

Set the interval lower bound.

Parameters
inew bound value

References i_min.

Referenced by GIntervalList::Add(), and Overlap().

bool GInterval::Touches ( const GInterval inter) const

The function returns true if the intervals are just next one to the other.

Parameters
interinterval with which continuity is tested

References GetMax(), GetMin(), and IsEmpty().


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