qvector.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Alan Grimes   *
00003  *   agrimes@speakeasy.net   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *(at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef QVECTOR_H
00022 #define QVECTOR_H
00023 
00024 #ifndef CUI
00025 #define CUI     const unsigned int
00026 #endif
00027 
00028 #define EPSILON 0.000001
00029 
00030 class QuickVector {
00031 public :
00032          QuickVector(CUI m_in);
00033         ~QuickVector();
00034          QuickVector(const QuickVector *old); // ye olde copy constructor.
00035 
00036         double & operator[]( const int i ) { changed = true; return values[i]; }
00037         const double operator[]( const int i ) const { return values[i]; }
00038 
00039 // accessors
00040 // we use accessors so that we can provide range checking.
00041 // we use Smalltalk style naming conventions.
00042         double at(CUI m_a) const;
00043         bool atPut(CUI m_a, const double val);
00044         bool atAdd(CUI m_a, const double val);
00045 
00046         unsigned int size() const;
00047 
00048 // utility functions:
00049 //      void fillWithRandom();
00050         void fillWithZeros();
00051         bool swapelements(CUI m_a, CUI m_b);
00052 
00053 // Vector arithmetic.
00054 
00055         QuickVector *operator*=(const double *y);
00056         QuickVector *operator*=(const QuickVector *y);
00057         QuickVector *operator+=(const QuickVector *y);
00058         QuickVector *operator-(const QuickVector *y) const;
00059 
00060 // debugging
00061         void dumpToAux() const;
00062 
00066         inline bool isChanged() const { return changed; }
00070         inline void setUnchanged() { changed=false; }
00071 
00072 private :
00073 // We don't have a default vector size so therefore we lock the default constructor.
00074         QuickVector() {};
00075         unsigned int m;
00076         bool changed;
00077         double *values;
00078 };
00079 
00080 #endif

Generated on Tue May 8 17:05:32 2007 for KTechLab by  doxygen 1.5.1