]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGMatrix.h
Updated JSBsim code.
[flightgear.git] / src / FDM / JSBSim / FGMatrix.h
1 /*******************************************************************************
2
3 Header: FGMatrix.h
4 Author: Originally by Tony Peden [formatted and adapted here by Jon Berndt]
5 Date started: Unknown
6
7 HISTORY
8 --------------------------------------------------------------------------------
9 ??/??/??   TP   Created
10 03/16/2000 JSB  Added exception throwing
11
12 ********************************************************************************
13 SENTRY
14 *******************************************************************************/
15
16 #ifndef FGMATRIX_H
17 #define FGMATRIX_H
18
19 /*******************************************************************************
20 INCLUDES
21 *******************************************************************************/
22
23 #include <stdlib.h>
24 #ifdef FGFS
25 #  include <simgear/compiler.h>
26 #  include STL_STRING
27 #  ifdef FG_HAVE_STD_INCLUDES
28 #    include <fstream>
29 #  else
30 #    include <fstream.h>
31 #  endif
32    FG_USING_STD(string);
33 #else
34 #  include <string>
35 #  include <fstream>
36 #endif
37
38 /*******************************************************************************
39 FORWARD DECLARATIONS
40 *******************************************************************************/
41
42 class FGColumnVector;
43
44 /*******************************************************************************
45 DECLARATION: MatrixException
46 *******************************************************************************/
47
48 using namespace std;
49
50 class MatrixException /* :  public exception */  
51 {
52 public:
53   string Message;
54 };
55
56 /*******************************************************************************
57 DECLARATION: FGMatrix
58 *******************************************************************************/
59
60 class FGMatrix
61 {
62 protected:
63   double **data;
64
65 private:
66   unsigned int rows,cols;
67   char delim;
68   int width,prec,origin;
69   void TransposeSquare(void);
70   void TransposeNonSquare(void);
71   unsigned int rowCtr, colCtr;
72
73 public:
74   FGMatrix(unsigned int r, unsigned int c);
75   FGMatrix(const FGMatrix& A);
76   ~FGMatrix(void);
77
78   FGMatrix& operator=(const FGMatrix& A);
79   inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
80
81   FGColumnVector operator*(const FGColumnVector& Col);
82
83   unsigned int Rows(void) const;
84   unsigned int Cols(void) const;
85
86   void T(void);
87   void InitMatrix(void);
88   void InitMatrix(double value);
89
90   FGMatrix operator-(const FGMatrix& B);
91   FGMatrix operator+(const FGMatrix& B);
92   FGMatrix operator*(const FGMatrix& B);
93   FGMatrix operator/(const double scalar);
94   FGMatrix& operator<<(const float ff);
95
96   friend ostream& operator<<(ostream& os, const FGMatrix& M);
97   friend istream& operator>>(istream& is, FGMatrix& M);
98
99   void operator-=(const FGMatrix &B);
100   void operator+=(const FGMatrix &B);
101   void operator*=(const FGMatrix &B);
102   void operator*=(const double scalar);
103   void operator/=(const double scalar);
104
105   friend FGMatrix operator*(double scalar,FGMatrix& A);
106
107   void SetOParams(char delim,int width,int prec, int origin=0);
108 };
109
110 /*******************************************************************************
111 DECLARATION: FGColumnVector
112 *******************************************************************************/
113
114 class FGColumnVector : public FGMatrix
115 {
116 public:
117   FGColumnVector(void);
118   FGColumnVector(int m);
119   FGColumnVector(const FGColumnVector& b);
120   ~FGColumnVector();
121
122   FGColumnVector operator*(const double scalar);
123   FGColumnVector operator/(const double scalar);
124   FGColumnVector operator+(const FGColumnVector& B);
125   float Magnitude(void); 
126   FGColumnVector Normalize(void);
127
128   friend FGColumnVector operator*(const double scalar, const FGColumnVector& A);
129
130   double& operator()(int m) const;
131 };
132
133 /******************************************************************************/
134 #endif