Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

matrixseq.h

Go to the documentation of this file.
00001 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00030 #ifndef MATRIXSEQ_H
00031 #define MATRIXSEQ_H
00032 
00033 //#include <valarray>
00034 #include <vector>
00035 #include <cstddef>
00036 #include <exception>
00037 
00038 #include <simthetic/misc.h>
00039 #include <simthetic/signals.h>
00040 
00041 #include "matrix.h"
00042 
00043 namespace mimo {
00044 
00045 /* Template matrix sequence class. Don't use this directly, only use
00046  * the typedefs below. */
00047 template<class elemT, class Attr, 
00048      class Cont = std::vector<elemT> > class MSequence;
00049 template<class elemT, class Attr, class Cont> class MSequenceStorage;
00050 template<class elemT, class Attr, class Cont> class MSequenceAccess;
00051 
00052 /* Template attributes class, which is internally used for the
00053  * matrix/vector sequences to store the matrix/vector
00054  * dimensions. Don't use this outside of the sequence classes. */
00055 template<class elemT> class MSeqAttrT;
00056 template<class elemT> class VSeqAttrT;
00057 template<class elemT> class MFreqSeqAttrT;
00058 template<class elemT> class VTimeSeqAttrT;
00059 template<class elemT> class MTimeSeqAttrT;
00060 //typedef MSeqAttrT<CMatrix> MSeqAttr;
00061 //typedef VSeqAttrT<CVector> VSeqAttr;
00062 
00065 typedef MSequence<CMatrix, MSeqAttrT<CMatrix> > CMatrixSeq;
00066 
00069 typedef MSequence<CMatrix, MFreqSeqAttrT<CMatrix> > MatrixFreqSignal;
00070 
00073 typedef MSequence<CVector, VSeqAttrT<CVector> > CVectorSeq;
00074 
00077 typedef MSequence<CVector, VTimeSeqAttrT<CVector> > VectorTimeSignal;
00078 
00081 typedef MSequence<CMatrix, MTimeSeqAttrT<CMatrix> > MatrixTimeSignal;
00082 
00084 //typedef MSequence<Matrix, MSeqAttrT<Matrix> > MatrixSeq;
00085 //typedef MSequence<Vector, VSeqAttrT<Vector> > VectorSeq;
00086 
00087 
00105 template<class elemT, class Attr, class Cont, class Stor, class Accs>
00106 class MSequenceBase 
00107    : public simth::SignalSequenceBase<elemT, Attr, Cont, Stor, Accs>
00108 {
00109    public:
00110 
00112       typedef Stor storage_type;
00114       typedef Accs access_type;
00115 
00116       typedef elemT value_type;
00117       typedef Attr attributes_type;
00118       typedef Cont container_type;
00119     
00120       typedef typename container_type::iterator iterator;
00121       typedef typename container_type::const_iterator const_iterator;
00122 
00123       typedef typename container_type::reference reference;
00124       typedef typename container_type::const_reference const_reference;
00125 
00135       MSequenceBase(iterator iterStart, iterator iterEnd, storage_type &seq);
00136 
00142       MSequenceBase(storage_type &seq);
00143 
00144     
00147       virtual ~MSequenceBase() = 0;
00148 
00149 
00154       MSequenceBase<value_type, attributes_type, container_type,
00155             storage_type, access_type>&
00156       operator=(const MSequenceBase<value_type, attributes_type,
00157         container_type, storage_type, access_type> &seq);
00158 
00159    protected:
00160 
00167       MSequenceBase();
00168 
00169    private:
00172       typedef simth::SignalSequenceBase<elemT, Attr, Cont, Stor, Accs> 
00173         base_type;
00174 };
00175 
00193 template<class elemT, class Attr, class Cont> 
00194 class MSequence : public MSequenceBase<elemT, Attr, Cont, 
00195                        MSequenceStorage<elemT, Attr, Cont>,
00196                        MSequenceAccess<elemT, Attr, Cont> >
00197 {
00198    public:
00200       typedef MSequenceStorage<elemT,Attr,Cont> storage_type;
00202       typedef MSequenceAccess<elemT,Attr,Cont> access_type;
00203 
00204       typedef elemT value_type;
00205       typedef Attr attributes_type;
00206       typedef Cont container_type;
00207 
00208       typedef typename container_type::iterator iterator;
00209       typedef typename container_type::const_iterator const_iterator;
00210 
00211       typedef typename container_type::reference reference;
00212       typedef typename container_type::const_reference const_reference;
00213 
00219       typedef MSequenceBase<elemT, Attr, Cont, 
00220                 storage_type, access_type> base_type;
00221 
00231       MSequence(iterator iterStart, iterator iterEnd, storage_type &seq);
00232 
00238       MSequence(storage_type &seq);
00239 
00240 
00244    virtual ~MSequence() = 0;
00245 
00246    protected:
00247       MSequence() : base_type() {};
00248 
00249 };
00250 
00261 template<class elemT, class Attr, class Cont> 
00262 class MSequenceStorage : public MSequence<elemT, Attr, Cont>
00263 {
00264   public:
00265     typedef typename Cont::iterator iterator;
00266     typedef typename Cont::const_iterator const_iterator;
00267 
00268     typedef typename Cont::reference reference;
00269     typedef typename Cont::const_reference const_reference;
00270 
00271     typedef elemT value_type;
00272     typedef Attr attributes_type;
00273     typedef Cont container_type;
00274 
00276     MSequenceStorage();
00277 
00284     MSequenceStorage(size_t size, const value_type &val = value_type());
00285 
00290     MSequenceStorage(const MSequence<value_type,attributes_type,container_type> &seq);
00291 
00293     virtual ~MSequenceStorage();
00294 
00299       /*MSequenceStorage<value_type, attributes_type, container_type>&
00300     operator=(const MSequence<value_type, attributes_type,
00301     container_type> &seq);*/
00302       
00305     size_t capacity() const { return ownStorage.capacity(); }
00306 
00315     virtual void resize(size_t i);
00316 
00324     attributes_type& wAttributes();
00325 
00330     const attributes_type& rAttributes() const { return attributes_; }
00331 
00337     void lock() {lock_ = true;}
00338 
00342     void unlock() {lock_= false;}
00343 
00346     bool isLocked() const {return lock_;}
00347 
00348   private:
00349     container_type ownStorage; //must be created on the heap!
00350     attributes_type attributes_ ;
00351     bool lock_;  
00352         
00353     void invariante() const;
00354   private:
00355     typedef MSequence<elemT,Attr,Cont> base_type;
00356 };
00357 
00372 template<class elemT, class Attr, class Cont> 
00373 class MSequenceAccess : public MSequence<elemT, Attr, Cont>
00374 {
00375    private:
00376       typedef MSequence<elemT,Attr,Cont> base_type;
00377 
00378    public:
00379       typedef typename base_type::value_type value_type;
00380       typedef typename base_type::attributes_type attributes_type;    
00381       typedef typename base_type::container_type container_type;
00382       
00383       typedef typename base_type::iterator iterator;
00384       typedef typename base_type::const_iterator const_iterator;
00385 
00386       typedef typename base_type::reference reference;
00387       typedef typename base_type::const_reference const_reference;
00388 
00389       typedef typename base_type::storage_type storage_type;
00390        
00400       MSequenceAccess(iterator iterStart, iterator iterEnd, storage_type &seq)
00401      : base_type (iterStart, iterEnd, seq) {};
00402 
00407       MSequenceAccess(const MSequence<elemT,Attr,Cont>& seq)
00408      : base_type (seq) {};
00409 };
00410 
00411 
00412 
00416 template<class elemT>
00417 class MSeqAttrT {
00418    private:
00419       int dim1, dim2;
00420       elemT _default_elem;
00421    public:
00423       MSeqAttrT(int dim1_ = 0, int dim2_ = 0);
00428       MSeqAttrT(const elemT&);
00429 
00431       virtual ~MSeqAttrT() {};
00432 
00435       const elemT& defaultElem() const;
00437       bool operator==(const MSeqAttrT<elemT>& a) const 
00438       { return (dim1 == a.dim1) && (dim2 == a.dim2); }
00440       bool operator!=(const MSeqAttrT<elemT>& a) const 
00441       { return !operator==(a); }
00442 };
00443 
00444 template<class elemT>
00445 class MFreqSeqAttrT : public MSeqAttrT<elemT>, 
00446               public simth::FreqSignalAttributes
00447 {
00448    public:
00450       MFreqSeqAttrT(int dim1_ = 0, int dim2_ = 0)
00451      : MSeqAttrT<elemT>(dim1_, dim2_) {};
00452 
00457       MFreqSeqAttrT(const elemT& default_elem)
00458      : MSeqAttrT<elemT>(default_elem) {};
00459 
00461       bool operator==(const MFreqSeqAttrT<elemT>& a) const; 
00463       bool operator!=(const MFreqSeqAttrT<elemT>& a) const; 
00464 };
00465 
00466 template<class elemT>
00467 class MTimeSeqAttrT : public MSeqAttrT<elemT>, 
00468               public simth::TimeSignalAttributes
00469 {
00470    public:
00472       MTimeSeqAttrT(int dim1_ = 0, int dim2_ = 0)
00473      : MSeqAttrT<elemT>(dim1_, dim2_) {};
00474 
00479       MTimeSeqAttrT(const elemT& default_elem)
00480      : MSeqAttrT<elemT>(default_elem) {};
00481 
00483       bool operator==(const MTimeSeqAttrT<elemT>& a) const; 
00485       bool operator!=(const MTimeSeqAttrT<elemT>& a) const; 
00486 };
00487 
00488 
00492 template<class elemT>
00493 class VSeqAttrT {
00494    private:
00495       int dim;
00496       elemT _default_elem;
00497    public:
00499       VSeqAttrT(int dim_ = 0);
00504       VSeqAttrT(const elemT&);
00505 
00507       virtual ~VSeqAttrT() {};
00508 
00510       VSeqAttrT<elemT>& operator=(const simth::NoAttributes& a)
00511       { return *this; };
00512 
00515       const elemT& defaultElem() const;
00517       bool operator==(const VSeqAttrT<elemT>& a) const 
00518       { return (dim == a.dim); }
00519       bool operator==(const simth::NoAttributes& a) const 
00520       { return true; }
00522       bool operator!=(const VSeqAttrT<elemT>& a) const 
00523       { return !operator==(a); }
00524       bool operator!=(const simth::NoAttributes& a) const 
00525       { return !operator==(a); }
00526 };
00527 
00528 template<class elemT>
00529 class VTimeSeqAttrT : public VSeqAttrT<elemT>, 
00530               public simth::TimeSignalAttributes
00531 {
00532    public:
00534       VTimeSeqAttrT(int dim_ = 0) 
00535      : VSeqAttrT<elemT>(dim_) {};
00536 
00541       VTimeSeqAttrT(const elemT& default_elem) 
00542      : VSeqAttrT<elemT>(default_elem) {};
00543 
00545       VTimeSeqAttrT<elemT>& operator=(const simth::TimeSignalAttributes& a);
00546 
00548       bool operator==(const VTimeSeqAttrT<elemT>& a) const; 
00549       bool operator==(const simth::TimeSignalAttributes& a) const; 
00551       bool operator!=(const VTimeSeqAttrT<elemT>& a) const; 
00552       bool operator!=(const simth::TimeSignalAttributes& a) const; 
00553 };
00554 
00555 } // namespace mimo
00556 
00557 #endif // MATRIXSEQ_H

Generated on Tue Aug 9 14:43:10 2005 for mimolib by  doxygen 1.4.1