home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / octave-2.1.23 / liboctave / MDiagArray2.h < prev    next >
C/C++ Source or Header  |  2000-01-15  |  5KB  |  164 lines

  1. // Template array classes with like-type math ops
  2. /*
  3.  
  4. Copyright (C) 1996, 1997 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22. */
  23.  
  24. #if defined (__GNUG__)
  25. #pragma interface
  26. #endif
  27.  
  28. #if !defined (octave_MDiagArray2_h)
  29. #define octave_MDiagArray2_h 1
  30.  
  31. #include "DiagArray2.h"
  32. #include "MArray2.h"
  33.  
  34. #if defined (LTGT)
  35. #undef LTGT
  36. #endif
  37.  
  38. #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL)
  39. #define LTGT
  40. #else
  41.  
  42. #define LTGT <>
  43.  
  44. template <class T>
  45. class MDiagArray2;
  46.  
  47. template <typename T> MDiagArray2<T>&
  48. operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b);
  49.  
  50. template <typename T> MDiagArray2<T>&
  51. operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b);
  52.  
  53. template <typename T> MDiagArray2<T> 
  54. operator * (const MDiagArray2<T>& a, const T& s);
  55.  
  56. template <typename T> MDiagArray2<T> 
  57. operator / (const MDiagArray2<T>& a, const T& s);
  58.  
  59. template <typename T> MDiagArray2<T> 
  60. operator * (const T& s, const MDiagArray2<T>& a);
  61.  
  62. template <typename T> MDiagArray2<T>
  63. operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b); 
  64.  
  65. template <typename T> MDiagArray2<T>
  66. operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
  67.  
  68. template <typename T> MDiagArray2<T>
  69. product (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
  70.  
  71. template <typename T> MDiagArray2<T> 
  72. operator - (const MDiagArray2<T>& a);
  73. #endif
  74.  
  75. // Two dimensional diagonal array with math ops.
  76.  
  77. template <class T>
  78. class MDiagArray2 : public DiagArray2<T>
  79. {
  80. protected:
  81.  
  82.   MDiagArray2 (T *d, int r, int c) : DiagArray2<T> (d, r, c) { }
  83.  
  84. public:
  85.   
  86.   MDiagArray2 (void) : DiagArray2<T> () { }
  87.   MDiagArray2 (int r, int c) : DiagArray2<T> (r, c) { }
  88.   MDiagArray2 (int r, int c, const T& val) : DiagArray2<T> (r, c, val) { }
  89.   MDiagArray2 (const Array<T>& a) : DiagArray2<T> (a) { }
  90.   MDiagArray2 (const DiagArray2<T>& a) : DiagArray2<T> (a) { }
  91.   MDiagArray2 (const MDiagArray2<T>& a) : DiagArray2<T> (a) { }
  92.  
  93.   ~MDiagArray2 (void) { }
  94.  
  95.   MDiagArray2<T>& operator = (const MDiagArray2<T>& a)
  96.     {
  97.       DiagArray2<T>::operator = (a);
  98.       return *this;
  99.     }
  100.  
  101.   operator MArray2<T> () const
  102.     {
  103.       MArray2<T> retval (nr, nc,  T (0));
  104.  
  105.       int len = nr < nc ? nr : nc;
  106.  
  107.       for (int i = 0; i < len; i++)
  108.     retval.xelem (i, i) = xelem (i, i);
  109.  
  110.       return retval;
  111.     }
  112.  
  113.   // element by element MDiagArray2 by MDiagArray2 ops
  114.  
  115.   friend MDiagArray2<T>&
  116.   operator += LTGT (MDiagArray2<T>& a, const MDiagArray2<T>& b);
  117.  
  118.   friend MDiagArray2<T>&
  119.   operator -= LTGT (MDiagArray2<T>& a, const MDiagArray2<T>& b);
  120.  
  121.   // element by element MDiagArray2 by scalar ops
  122.  
  123.   friend MDiagArray2<T> operator * LTGT (const MDiagArray2<T>& a, const T& s);
  124.   friend MDiagArray2<T> operator / LTGT (const MDiagArray2<T>& a, const T& s);
  125.  
  126.   // element by element scalar by MDiagArray2 ops
  127.  
  128.   friend MDiagArray2<T> operator * LTGT (const T& s, const MDiagArray2<T>& a);
  129.  
  130.   // element by element MDiagArray2 by MDiagArray2 ops
  131.  
  132.   friend MDiagArray2<T>
  133.   operator + LTGT (const MDiagArray2<T>& a, const MDiagArray2<T>& b); 
  134.  
  135.   friend MDiagArray2<T>
  136.   operator - LTGT (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
  137.  
  138.   friend MDiagArray2<T>
  139.   product LTGT (const MDiagArray2<T>& a, const MDiagArray2<T>& b);
  140.  
  141.   friend MDiagArray2<T> operator - LTGT (const MDiagArray2<T>& a);
  142. };
  143.  
  144. #undef LTGT
  145.  
  146. #define INSTANTIATE_MDIAGARRAY_FRIENDS(T) \
  147.   template MDiagArray2<T>& operator += (MDiagArray2<T>& a, const MDiagArray2<T>& b); \
  148.   template MDiagArray2<T>& operator -= (MDiagArray2<T>& a, const MDiagArray2<T>& b); \
  149.   template MDiagArray2<T> operator * (const MDiagArray2<T>& a, const T& s); \
  150.   template MDiagArray2<T> operator / (const MDiagArray2<T>& a, const T& s); \
  151.   template MDiagArray2<T> operator * (const T& s, const MDiagArray2<T>& a); \
  152.   template MDiagArray2<T> operator + (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
  153.   template MDiagArray2<T> operator - (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
  154.   template MDiagArray2<T> product (const MDiagArray2<T>& a, const MDiagArray2<T>& b); \
  155.   template MDiagArray2<T> operator - (const MDiagArray2<T>& a);
  156.  
  157. #endif
  158.  
  159. /*
  160. ;;; Local Variables: ***
  161. ;;; mode: C++ ***
  162. ;;; End: ***
  163. */
  164.