Otawa  0.10
otawa::Bag< T > Class Template Reference

#include <otawa/util/Bag.h>

Public Member Functions

 Bag (void)
 Empty array constructor. More...
 
 Bag (const Bag &bag)
 Clone constructor. More...
 
 Bag (int c, const T *a)
 Constructor using a raw array. More...
 
 Bag (int c, T *a)
 Constructor using a raw array. More...
 
 Bag (const genstruct::Vector< T > &v)
 Constructor from a vector. More...
 
 Bag (Pair< int, T * > p)
 Construction from a pair (array count, array base). More...
 
 Bag (const Give< T > &g)
 Construction from a given array. More...
 
 ~Bag (void)
 
bool isEmpty (void) const
 Test if the bag is empty. More...
 
 operator bool (void) const
 
int count (void) const
 Get the count of items in the bag. More...
 
int size (void) const
 Same as count(). More...
 
const T & get (int i) const
 Get the ith item of the bag. More...
 
T & get (int i)
 Get the ith item of the bag. More...
 
const T & operator[] (int i) const
 
T & operator[] (int i)
 
Bagoperator= (const Bag &bag)
 
Bagoperator= (const genstruct::Vector< T > &v)
 
Bagoperator= (Pair< int, T * > p)
 
Bagoperator= (const Give< T > &g)
 
void clear (void)
 Clear the content of the bag. More...
 

Private Member Functions

void copy (int c, const T *a)
 
void copy (const genstruct::Vector< T > &v)
 

Private Attributes

int cnt
 
T * arr
 

Detailed Description

template<class T>
class otawa::Bag< T >

Parameters
TType of stored items. This light parametric class is dedicated to the storage of small sets of simple items hooked to a property. It may be used as a normal array but the stored objects will be deleted when the property is removed.

Normal work of the Bag class is to perform a copy of the arguments passed to the constructor and it will manage the new allocated array. If a transfer of array is needed (the array has been allocated by another class but the responsibility for releasing the array is transfered to the Bag), the array must be passed through a small Give object. Give objects may be built from a pair (array count, array pointer) but also from a elm::genstruct::Vector (in this case, the array is detached).

Constructor & Destructor Documentation

template<class T >
otawa::Bag< T >::Bag ( void  )
inline

Empty array constructor.

template<class T >
otawa::Bag< T >::Bag ( const Bag< T > &  bag)
inline

Clone constructor.

Parameters
bagBag to clone.

References otawa::Bag< T >::arr, otawa::Bag< T >::cnt, and copy().

template<class T >
otawa::Bag< T >::Bag ( int  c,
const T *  a 
)
inline

Constructor using a raw array.

Parameters
cCount of items in the array.
aBase pointer of the array.

References copy().

template<class T >
otawa::Bag< T >::Bag ( int  c,
T *  a 
)
inline

Constructor using a raw array.

Parameters
cCount of items in the array.
aBase pointer of the array.

References copy().

template<class T >
otawa::Bag< T >::Bag ( const genstruct::Vector< T > &  v)
inline

Constructor from a vector.

Parameters
vVector to copy items from.

References copy().

template<class T >
otawa::Bag< T >::Bag ( Pair< int, T * >  p)
inline

Construction from a pair (array count, array base).

Parameters
pPair to build from.

References copy(), elm::Pair< T1, T2 >::fst, and elm::Pair< T1, T2 >::snd.

template<class T >
otawa::Bag< T >::Bag ( const Give< T > &  g)
inline

Construction from a given array.

The current Bag object becomes responsible for freeing the array passed in g.

Parameters
gGiven array.
template<class T >
otawa::Bag< T >::~Bag ( void  )
inline

References clear().

Member Function Documentation

template<class T >
void otawa::Bag< T >::clear ( void  )
inline

Clear the content of the bag.

After this call, the bag is empty.

template<class T >
void otawa::Bag< T >::copy ( int  c,
const T *  a 
)
inlineprivate

References elm::array::copy().

template<class T >
void otawa::Bag< T >::copy ( const genstruct::Vector< T > &  v)
inlineprivate
template<class T >
int otawa::Bag< T >::count ( void  ) const
inline

Get the count of items in the bag.

Returns
Count of items.
template<class T >
const T & otawa::Bag< T >::get ( int  i) const
inline

Get the ith item of the bag.

Parameters
iIndex of the looked item.
Returns
ith item.
template<class T >
T & otawa::Bag< T >::get ( int  i)
inline

Get the ith item of the bag.

Parameters
iIndex of the looked item.
Returns
ith item.
template<class T >
bool otawa::Bag< T >::isEmpty ( void  ) const
inline

Test if the bag is empty.

Returns
True if the bag is empty, false else.
template<class T >
otawa::Bag< T >::operator bool ( void  ) const
inline
template<class T >
Bag& otawa::Bag< T >::operator= ( const Bag< T > &  bag)
inline
template<class T >
Bag& otawa::Bag< T >::operator= ( const genstruct::Vector< T > &  v)
inline

References clear(), and copy().

template<class T >
Bag& otawa::Bag< T >::operator= ( Pair< int, T * >  p)
inline
template<class T >
Bag& otawa::Bag< T >::operator= ( const Give< T > &  g)
inline
template<class T >
const T& otawa::Bag< T >::operator[] ( int  i) const
inline
template<class T >
T& otawa::Bag< T >::operator[] ( int  i)
inline
template<class T >
int otawa::Bag< T >::size ( void  ) const
inline

Same as count().

Member Data Documentation

template<class T >
T* otawa::Bag< T >::arr
private
template<class T >
int otawa::Bag< T >::cnt
private

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