PLearn 0.1
Public Types | Public Member Functions
PLearn::Array< T > Class Template Reference

#include <Array_decl.h>

Inheritance diagram for PLearn::Array< T >:
Inheritance graph
[legend]
Collaboration diagram for PLearn::Array< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T * iterator

Public Member Functions

 Array (int the_size=0, int extra_space=10)
 Array (const T &elem1)
 Array (const T &elem1, const T &elem2)
 Array (const Array< T > &other)
 Array (const TVec< T > &other)
 Array (const vector< T > &other)
 operator bool () const
 To allow if(v) statements.
bool operator! () const
 To allow if(!v) statements.
Array< T > subArray (int start, int len)
void clear ()
void operator= (const Array< T > &other)
void operator= (const TVec< T > &other)
 NOTE: operator= COPIES THE TVec STRUCTURE BUT NOT THE DATA (use operator<< to copy data)
void operator= (const vector< T > &other)
void view (const TVec< T > &other)
 Makes this array a shared view of the given TVec.
void print (ostream &out) const
 C++ stream output.
int findFirstOccurence (const T &elem)
void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Deep copy of an array is not the same as for a TVec, because the shallow copy automatically creates a new storage.
void write (ostream &out_) const
void read (istream &in_)
 operator char * () const
 used by Hash (VERY DIRTY: TO BE REMOVED [Pascal])
size_t byteLength () const

Detailed Description

template<class T>
class PLearn::Array< T >

Definition at line 62 of file Array_decl.h.


Member Typedef Documentation

template<class T>
typedef T* PLearn::Array< T >::iterator

Reimplemented from PLearn::TVec< T >.

Reimplemented in PLearn::VarArray.

Definition at line 76 of file Array_decl.h.


Constructor & Destructor Documentation

template<class T>
PLearn::Array< T >::Array ( int  the_size = 0,
int  extra_space = 10 
) [inline, explicit]

Definition at line 78 of file Array_decl.h.

        : TVec<T>(the_size+extra_space)
    { length_ = the_size; }
template<class T>
PLearn::Array< T >::Array ( const T &  elem1) [inline]

Definition at line 82 of file Array_decl.h.

        : TVec<T>(1)
    { (*this)[0] = elem1; }
template<class T>
PLearn::Array< T >::Array ( const T &  elem1,
const T &  elem2 
) [inline]

Definition at line 86 of file Array_decl.h.

        : TVec<T>(2)
    {
        (*this)[0] = elem1;
        (*this)[1] = elem2;
    }
template<class T>
PLearn::Array< T >::Array ( const Array< T > &  other) [inline]

Definition at line 93 of file Array_decl.h.

        : TVec<T>(other.length())
    {
        length_ = other.size();
        offset_ = other.offset();
        iterator array = data();
        for(int i=0; i<length_; i++)
            array[i] = other[i];
    }
template<class T>
PLearn::Array< T >::Array ( const TVec< T > &  other) [inline]

Definition at line 103 of file Array_decl.h.

        : TVec<T>(other.copy())
    {}
template<class T>
PLearn::Array< T >::Array ( const vector< T > &  other) [inline]

Definition at line 107 of file Array_decl.h.

        : TVec<T>(other.size())
    {
        iterator array = data();
        for (int i = 0; i < length_; ++i)
            array[i] = other[i];
    }

Member Function Documentation

template<class T>
size_t PLearn::Array< T >::byteLength ( ) const [inline]

Reimplemented from PLearn::TVec< T >.

Definition at line 292 of file Array_decl.h.

{ return this->size()*sizeof(T); }
template<class T>
void PLearn::Array< T >::clear ( ) [inline]

Definition at line 135 of file Array_decl.h.

Referenced by PLearn::LocalizedFeaturesLayerVariable::build_(), and PLearn::rebalanceNClasses().

    { length_ = 0; }

Here is the caller graph for this function:

template<class T>
int PLearn::Array< T >::findFirstOccurence ( const T &  elem) [inline]

Definition at line 250 of file Array_decl.h.

    {
        for(int i=0;i<this->array_size;i++)
            if(elem==this->array[i])
                return i;
        return -1;
    }
template<class T >
void PLearn::Array< T >::makeDeepCopyFromShallowCopy ( CopiesMap copies)

Deep copy of an array is not the same as for a TVec, because the shallow copy automatically creates a new storage.

Reimplemented from PLearn::TVec< T >.

Reimplemented in PLearn::VarArray.

Definition at line 222 of file Array_impl.h.

References PLearn::deepCopyField(), and i.

Referenced by PLearn::deepCopyField().

{
    // Shallow copy of an array, contrarily to TVec, already makes a shallow copy of the elements, so we
    // don't want to call deepCopyField(storage, copies) as TVec does, but simply deepCopyField()
    // of each of the storage's elements.
    if (storage.isNotNull())
        for (int i = 0; i < storage->size(); i++)
            deepCopyField(storage->data[i], copies);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T>
PLearn::Array< T >::operator bool ( ) const [inline]

To allow if(v) statements.

Definition at line 116 of file Array_decl.h.

    { return length_>0; }
template<class T>
PLearn::Array< T >::operator char * ( ) const [inline]

used by Hash (VERY DIRTY: TO BE REMOVED [Pascal])

Reimplemented from PLearn::TVec< T >.

Definition at line 287 of file Array_decl.h.

{ if(this->isNull()) return 0; else return (char*)data(); }
template<class T>
bool PLearn::Array< T >::operator! ( ) const [inline]

To allow if(!v) statements.

Reimplemented from PLearn::TVec< T >.

Definition at line 120 of file Array_decl.h.

    { return length_==0; }
template<class T>
void PLearn::Array< T >::operator= ( const Array< T > &  other) [inline]

Definition at line 138 of file Array_decl.h.

Referenced by PLearn::Array< char * >::view().

    {
        resize(other.size());
        iterator array = data();
        for(int i=0; i<length_; i++)
            array[i] = other[i];
    }

Here is the caller graph for this function:

template<class T>
void PLearn::Array< T >::operator= ( const vector< T > &  other) [inline]

Definition at line 154 of file Array_decl.h.

    {
        resize(other.size());
        iterator array = data();
        for(int i = 0; i < length_; ++i)
            array[i] = other[i];
    }
template<class T>
void PLearn::Array< T >::operator= ( const TVec< T > &  other) [inline]

NOTE: operator= COPIES THE TVec STRUCTURE BUT NOT THE DATA (use operator<< to copy data)

Reimplemented from PLearn::TVec< T >.

Definition at line 146 of file Array_decl.h.

    {
        resize(other.size());
        iterator array = data();
        for(int i=0; i<length_; i++)
            array[i] = other[i];
    }
template<class T>
void PLearn::Array< T >::print ( ostream &  out) const [inline]

C++ stream output.

the data is printed on a single row, no newline

Reimplemented from PLearn::TVec< T >.

Definition at line 243 of file Array_decl.h.

    {
        iterator array = data();
        for(int i=0; i<length_; i++)
            out << array[i] << endl;
    }
template<class T>
void PLearn::Array< T >::read ( istream &  in_) [inline]

Reimplemented in PLearn::VarArray.

Definition at line 280 of file Array_decl.h.

    {
        PStream in(&in_);
        in >> *this;
    }
template<class T>
Array<T> PLearn::Array< T >::subArray ( int  start,
int  len 
) [inline]

Definition at line 123 of file Array_decl.h.

    {
        if (start+len>length_)
            PLERROR("Array::subArray start(%d)+len(%d)>size(%d)", start,len,length_);
        Array<T> newarray(len);
        iterator new_ar = newarray.data();
        iterator array = data();
        for (int i=0;i<len;i++)
            new_ar[i] = array[start+i];
        return newarray;
    }
template<class T>
void PLearn::Array< T >::view ( const TVec< T > &  other) [inline]

Makes this array a shared view of the given TVec.

Definition at line 163 of file Array_decl.h.

    {
        TVec<T>::operator=(other);
    }
template<class T>
void PLearn::Array< T >::write ( ostream &  out_) const [inline]

Reimplemented in PLearn::VarArray.

Definition at line 264 of file Array_decl.h.

Referenced by PLearn::VMatrix::saveStats().

    {
        PStream out(&out_);
        out << *this;
    }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines