File indexing completed on 2024-04-21 05:43:47

0001 /***************************************************************************
0002  *   Copyright (C) 2006 by Alan Grimes   *
0003  *   agrimes@speakeasy.net   *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *(at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef QVECTOR_H__KTECHLAB_
0022 #define QVECTOR_H__KTECHLAB_
0023 
0024 #ifndef CUI
0025 #define CUI const unsigned int
0026 #endif
0027 
0028 #define EPSILON 0.000001
0029 
0030 class QuickVector
0031 {
0032 public:
0033     QuickVector(CUI m_in);
0034     ~QuickVector();
0035     QuickVector(const QuickVector *old); // ye olde copy constructor.
0036 
0037     double &operator[](const int i)
0038     {
0039         changed = true;
0040         return values[i];
0041     }
0042     double operator[](const int i) const
0043     {
0044         return values[i];
0045     }
0046 
0047     // accessors
0048     // we use accessors so that we can provide range checking.
0049     // we use Smalltalk style naming conventions.
0050     double at(CUI m_a) const;
0051     bool atPut(CUI m_a, const double val);
0052     bool atAdd(CUI m_a, const double val);
0053 
0054     unsigned int size() const
0055     {
0056         return m;
0057     }
0058 
0059     // utility functions:
0060     //  void fillWithRandom();
0061     void fillWithZeros();
0062     bool swapElements(CUI m_a, CUI m_b);
0063 
0064     // Vector arithmetic.
0065     QuickVector &operator=(const QuickVector &y);
0066     QuickVector &operator*=(const double y);
0067     QuickVector &operator*=(const QuickVector &y);
0068     QuickVector &operator+=(const QuickVector &y);
0069     QuickVector &operator-(const QuickVector &y) const;
0070 
0071     // debugging
0072     void dumpToAux() const;
0073 
0074     /**
0075      * Returns true if the vector has changed since setUnchanged was last called
0076      */
0077     inline bool isChanged() const
0078     {
0079         return changed;
0080     }
0081     /**
0082      * Sets the changed status to false.
0083      */
0084     inline void setUnchanged()
0085     {
0086         changed = false;
0087     }
0088 
0089 private:
0090     // We don't have a default vector size so therefore we lock the default constructor.
0091     QuickVector() {};
0092     unsigned int m;
0093     bool changed;
0094     double *values;
0095 };
0096 
0097 #endif // QVECTOR_H__KTECHLAB_