GemaLuaCoreLib
The GeMA Lua Core library
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
GmLuaAccessorIndex< T, I > Class Template Referenceabstract

A helper class for implementing the common behaviour between GmLuaValueAccessor, GmLuaCellAccessor and GmLuaDiscontinuityAccessor on top of GmLuaAccessorBase by adding a second template parameter to represent the index used to represent a value inside the accessor (which can be an integer, a cell or a discontinuity) More...

#include <gmLuaValueAccessor.h>

Inheritance diagram for GmLuaAccessorIndex< T, I >:
Inheritance graph
[legend]
Collaboration diagram for GmLuaAccessorIndex< T, I >:
Collaboration graph
[legend]

Public Member Functions

virtual void fillMetatable (lua_State *L, int index)
 Prepares the object metatable for calling methods.
 
- Public Member Functions inherited from GmLuaAccessorBase< T >
virtual ~GmLuaAccessorBase ()
 Destructor.
 
virtual QString toString () const
 Default method used by the __tostring metamethod to capture the result of tostring() over an object.
 
T * accessor () const
 Returns the wrapped accessor.
 
- Public Member Functions inherited from GmLuaObject
virtual ~GmLuaObject ()
 Destrutor.
 
virtual void populateMetatable (lua_State *L, int index)
 Fills the object metatable to allow for the proxy to export its methods.
 
QVariant ptrToVariant ()
 Constructs a QVariant storing a POINTER to the current object.
 
void ref ()
 Increments the object reference count. Use with care.
 
- Public Member Functions inherited from LuaProxy::Base
virtual void * getClassMetatableID ()=0
 

Protected Member Functions

 GmLuaAccessorIndex (T *ac, const GmLogCategory &logger, bool ownership)
 Constructor. Receives the ValueAccessor to be wrapped. More...
 
virtual I parseIndex (lua_State *L, int stackPos, QString fname) const =0
 Returns the value used as index in accessor calls (either an int, a CmCell* or a GmDiscontinuity*) More...
 
- Protected Member Functions inherited from GmLuaAccessorBase< T >
 GmLuaAccessorBase (T *ac, const GmLogCategory &logger, bool ownership)
 Constructor. Receives the ValueAccessor to be wrapped. More...
 
void parseCoord (lua_State *L, int stackPos, QString fname, GmVector &coord)
 An auxiliary function used to parse a coordinate table / object from the lua stack. More...
 
void parseOptions (lua_State *L, int stackPos, Options &opt)
 Aux function to parse print options for the valueStr() call if the object at stackPos is a table.
 
void pushResult (lua_State *L, const double *val)
 Pushes an accessor result on the stack. Value can be pushed as a number (scalar) or as a matrix.
 
- Protected Member Functions inherited from GmLuaObject
 GmLuaObject (const GmLogCategory &logger)
 Construtor protegido. Somente classes derivadas devem ser instanciadas.
 
virtual const char * typeName () const =0
 Returns the object type as will be stored in the object metatable.
 

Private Member Functions

int isDefValue (lua_State *L)
 Returns true if the value at the specified index is equal to the default value. More...
 
int isFunction (lua_State *L)
 Returns true if the value at the specified index is a function. More...
 
int setValue (lua_State *L)
 Updates the value at the specified position. The given value can be a scalar, a vector or a matrix. Vectors and matrices can be represented by lua Tables or by vector/matrix objects. If the accessor supports functions, the value can also be a function name. It can also be a string if the accessor supports a constant map. More...
 
int setValueAsDef (lua_State *L)
 Updates the value at the specified position with the default value. More...
 
int functionId (lua_State *L)
 Returns the name of the function in the given index or an empty string if this is not a function.
 

Additional Inherited Members

- Protected Attributes inherited from GmLuaAccessorBase< T >
T * _ac
 The wrapped value accessor object.
 
bool _owner
 Do we own the accessor?
 
- Protected Attributes inherited from GmLuaObject
const GmLogCategory_logger
 A logger used by the proxy when needed.
 
QAtomicInteger< int > _refCount
 Lua objects are reference counted to enable sharing them among different states. This is needed to allow for passing objects as parameters in a parallel call. The garbage collection method releases memory only for the last reference.
 

Detailed Description

template<class T, class I>
class GmLuaAccessorIndex< T, I >

A helper class for implementing the common behaviour between GmLuaValueAccessor, GmLuaCellAccessor and GmLuaDiscontinuityAccessor on top of GmLuaAccessorBase by adding a second template parameter to represent the index used to represent a value inside the accessor (which can be an integer, a cell or a discontinuity)

Should not be instanced by user code. Although a template, its implementation is on the cpp file since all the needed specializations are known.

Constructor & Destructor Documentation

◆ GmLuaAccessorIndex()

template<class T, class I >
GmLuaAccessorIndex< T, I >::GmLuaAccessorIndex ( T *  ac,
const GmLogCategory logger,
bool  ownership 
)
protected

Constructor. Receives the ValueAccessor to be wrapped.

Due to its nature, wrapped accessors WILL be DELETED together with the proxy. THIS IS A DIFFERENT BEHAVIOUR from other kinds of proxy Lua objects

Member Function Documentation

◆ isDefValue()

template<class T , class I >
int GmLuaAccessorIndex< T, I >::isDefValue ( lua_State *  L)
private

Returns true if the value at the specified index is equal to the default value.

IMPORTANT: Following Lua spirit, the index is ONE based (and not zero based as in C) for ValueAccessor objects, a cell proxy for CellAccesor objects and a discontinuity proxy for DiscontinuityAccessor objects.

◆ isFunction()

template<class T , class I >
int GmLuaAccessorIndex< T, I >::isFunction ( lua_State *  L)
private

Returns true if the value at the specified index is a function.

IMPORTANT: Following Lua spirit, the index is ONE based (and not zero based as in C) for ValueAccessor objects, a cell proxy for CellAccesor objects and a discontinuity proxy for DiscontinuityAccessor objects.

◆ parseIndex()

template<class T, class I>
virtual I GmLuaAccessorIndex< T, I >::parseIndex ( lua_State *  L,
int  stackPos,
QString  fname 
) const
protectedpure virtual

Returns the value used as index in accessor calls (either an int, a CmCell* or a GmDiscontinuity*)

On errors, should emit a message using luaL_error() (and so, not returning at all)

Implemented in GmLuaDiscontinuityAccessor, GmLuaCellAccessor, and GmLuaValueAccessor.

◆ setValue()

template<class T , class I >
int GmLuaAccessorIndex< T, I >::setValue ( lua_State *  L)
private

Updates the value at the specified position. The given value can be a scalar, a vector or a matrix. Vectors and matrices can be represented by lua Tables or by vector/matrix objects. If the accessor supports functions, the value can also be a function name. It can also be a string if the accessor supports a constant map.

Stack parameters: index, [dim], value (either a scalar, a table, an object or a function/constant name). IMPORTANT: Following Lua spirit, the index is ONE based (and not zero based as in C) for ValueAccessor objects, a cell proxy for CellAccesor objects and a discontinuity proxy for DiscontinuityAccessor objects. If a dimension is given, it is also ONE based.

◆ setValueAsDef()

template<class T , class I >
int GmLuaAccessorIndex< T, I >::setValueAsDef ( lua_State *  L)
private

Updates the value at the specified position with the default value.

Stack parameters: index IMPORTANT: Following Lua spirit, the index is ONE based (and not zero based as in C) for ValueAccessor objects, a cell proxy for CellAccesor objects and a discontinuity proxy for DiscontinuityAccessor objects.


The documentation for this class was generated from the following files: