KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
kjb::Index_range Class Reference

#include <l_index.h>

Classes

struct  End_type
 

Public Member Functions

 Index_range ()
 
 Index_range (size_t index)
 
 Index_range (int index)
 
 Index_range (const std::string &str)
 
 Index_range (const char *str)
 
 Index_range (const Index_range &src)
 
Index_rangeoperator= (const Index_range &other)
 
std::vector< size_t > expand () const
 
void swap (Index_range &other)
 
 Index_range (const Int_vector &v)
 
template<class Int_type >
 Index_range (typename std::vector< Int_type > v)
 
template<class Int_type >
 Index_range (std::list< Int_type > v)
 
 Index_range (size_t first, size_t end, size_t interval=1)
 
 Index_range (size_t first, End_type end, size_t interval=1)
 
Index_rangeconcat (Index_range &other)
 
size_t max () const
 
 ~Index_range ()
 
 Index_range (bool all_elements)
 
size_t operator[] (size_t i) const
 
size_t size () const
 
bool all () const
 

Static Public Attributes

static const Index_range ALL = Index_range(true)
 
static const End_type END
 

Protected Attributes

std::vector< Range_element * > ranges_
 
bool all_
 

Detailed Description

Object for specifying sets of matrix and vector indices. Ranges need not be contiguous or ordered, and values need not be unique. This object is indended to be passed to the subscript operator of Matrix and Vector, which will return sub-matrices and sub-vectors.

Contains a special constant, Index_range::all, which is an alias for an Index_range containing all indices of the Matrix/Vector, in ascending order.

Objects of this type are rarely created explicitly, but will be implicitly converted in calls to the subscript operator

v["2:5"] = Vector(1.0, 1.0, 2.0, 2.0);
Note
This class is designed to be as lightweight as possible in terms of storage. For example, Index_range("1:10000000") takes the same space as Index_range("1:2");

Constructor & Destructor Documentation

kjb::Index_range::Index_range ( )
inline

empty range

kjb::Index_range::Index_range ( size_t  index)
inline

Create a single-element range

kjb::Index_range::Index_range ( int  index)
inline

Create a single-element range

kjb::Index_range::Index_range ( const std::string &  str)
inline

Receives matlab-style strings like "1:3,4:2:10,15"

kjb::Index_range::Index_range ( const char *  str)
inline
kjb::Index_range::Index_range ( const Index_range src)
inline
kjb::Index_range::Index_range ( const Int_vector v)
template<class Int_type >
kjb::Index_range::Index_range ( typename std::vector< Int_type >  v)
inline
template<class Int_type >
kjb::Index_range::Index_range ( std::list< Int_type >  v)
inline
kjb::Index_range::Index_range ( size_t  first,
size_t  end,
size_t  interval = 1 
)
inline
kjb::Index_range::Index_range ( size_t  first,
End_type  end,
size_t  interval = 1 
)
inline
kjb::Index_range::~Index_range ( )
inline
kjb::Index_range::Index_range ( bool  all_elements)
inlineexplicit

Member Function Documentation

bool kjb::Index_range::all ( ) const
inline
Index_range& kjb::Index_range::concat ( Index_range other)
inline
std::vector<size_t> kjb::Index_range::expand ( ) const
inline

Convert the set of indices into a vector and return it.

Index_range can store large ranges symbolically, allowing it to represent an arbitrarilly large number of indices, while memory consumption remains constant. Calling this method for large ranges will require lots of memory, as all indices will be stored explicitly.

size_t kjb::Index_range::max ( ) const
inline
Index_range& kjb::Index_range::operator= ( const Index_range other)
inline
size_t kjb::Index_range::operator[] ( size_t  i) const
inline
size_t kjb::Index_range::size ( ) const
inline
void kjb::Index_range::swap ( Index_range other)
inline

Member Data Documentation

const Index_range kjb::Index_range::ALL = Index_range(true)
static
bool kjb::Index_range::all_
protected
const End_type kjb::Index_range::END
static
std::vector<Range_element*> kjb::Index_range::ranges_
protected

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