GemaLuaCoreLib
The GeMA Lua Core library
gmLuaMatrix.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMALUA_MATRIX_H_
25 #define _GEMALUA_MATRIX_H_
26 
27 #include "gmLuaObject.h"
28 
29 #include <gmMatrix.h>
30 #include <gmVector.h>
31 
32 class LuaTable;
33 
35 class GML_API_EXPORT GmLuaMatrix: public GmLuaObject
36 {
37 public:
38  GmLuaMatrix(GmMatrix& mat, const GmLogCategory& logger);
39  GmLuaMatrix(GmVector& vec, const GmLogCategory& logger);
40  GmLuaMatrix(int nlin, int ncol, const double* data, const GmLogCategory& logger);
41  GmLuaMatrix(LuaTable& tab, const GmLogCategory& logger);
42 
43  virtual ~GmLuaMatrix();
44 
45  // See comments on the base class
46  virtual const char* typeName() const { return "matrix"; }
47 
48  // See comments on the base class
49  virtual QString toString() const { return QString("matrix(%1x%2)").arg(_mat.n_rows).arg(_mat.n_cols); }
50 
51  virtual void fillMetatable(lua_State* L, int index);
52 
54  virtual void* getClassMetatableID() { static int classID = 0; return &classID; }
55 
57  GmMatrix& matrix() const { return _mat; }
58 
59 private:
60  int nlin (lua_State* L);
61  int ncol (lua_State* L);
62  int size (lua_State* L);
63  int at (lua_State* L);
64  int set (lua_State* L);
65  int col (lua_State* L);
66  int line (lua_State* L);
67  int setCol (lua_State* L);
68  int setLine (lua_State* L);
69  int t (lua_State* L);
70  int det (lua_State* L);
71  int equal (lua_State* L);
72  int print (lua_State* L);
73  int toTable (lua_State* L);
74  int toString(lua_State* L);
75  int solve (lua_State* L);
76  int inv (lua_State* L);
77  int dot (lua_State* L);
78  int cross (lua_State* L);
79  int norm (lua_State* L);
80  int eig_sym (lua_State* L);
81 
82  int eq (lua_State* L);
83  int unm(lua_State* L);
84 
85  static int add(lua_State* L);
86  static int sub(lua_State* L);
87  static int mul(lua_State* L);
88  static int div(lua_State* L);
89  static int mod(lua_State* L);
90 
91  static GmLuaMatrix* getOperand(lua_State* L, int index, char op, double* v);
92  static GmLuaMatrix* checkAndCreate(lua_State* L, char op, GmLuaMatrix* m1, GmLuaMatrix* m2, bool mul);
93 
94  // Warning: Do not reverse _newMat & _mat bellow. _newMat MUST be constructed before _mat for
95  // the contructors where a new matrix is allocated to work correctly.
98 };
99 
100 #endif
Declaration of the GmLuaObject class.
GmMatrix & matrix() const
Returns a reference for the internal matrix.
Definition: gmLuaMatrix.h:57
virtual const char * typeName() const
Returns the object type as will be stored in the object metatable.
Definition: gmLuaMatrix.h:46
A proxy class to export GmMatrix and GmVector methods to the Lua environment.
Definition: gmLuaMatrix.h:35
bool equal(double a, double b, double relTol=GM_DOUBLECMP_RELTOL, double absTol=GM_DOUBLECMP_ABSTOL)
virtual void * getClassMetatableID()
Returns an unique identifier to identify an user object as a GmLuaMesh object.
Definition: gmLuaMatrix.h:54
virtual void fillMetatable(lua_State *L, int index)=0
Function called by populateMetatable() to fill the metatable with exported methods by derived classes...
virtual QString toString() const
Default method used by the __tostring metamethod to capture the result of tostring() over an object.
Definition: gmLuaMatrix.h:49
void print(const GmMatrix &m, const GmLogCategory &logger, GmLogLevel level, int fieldWidth, char format, int precision)
virtual QString toString() const
Default method used by the __tostring metamethod to capture the result of tostring() over an object.
Definition: gmLuaObject.h:55
A proxy class to export object methods to the Lua environment.
Definition: gmLuaObject.h:35
GmMatrix * _newMat
A new matrix (owned by the proxy) 'wrapped' by this proxy object.
Definition: gmLuaMatrix.h:96
arma::vec GmVector
arma::mat GmMatrix
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
GmMatrix & _mat
A reference to the exported matrix, either external or pointing to _newMat.
Definition: gmLuaMatrix.h:97