World of Rigid Bodies (WoRB)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Mex::Logical Class Reference

Represents a MATLAB logical value. More...

#include <mexWoRB.h>

Public Member Functions

 Logical (const mxArray *arg, const char *argDesc, bool defaultValue=false)
 Constructs the instance from the given MATLAB array of doubles.
 Logical (const mxArray *obj, mwIndex index, const char *fieldName, bool defaultValue=false)
 Constructs the instance from the given MATLAB structure field.
bool operator! () const
 operator bool () const
mxArray * toMxArray ()
 Converts the instance to MATLAB logical scalar.
Logicaloperator= (bool v)
 Sets the new value.

Private Member Functions

void Initialize (const mxArray *arg, const char *argDesc, bool defaultValue)
 Initializes the instance from a MATLAB array of doubles.

Private Attributes

bool value

Detailed Description

Represents a MATLAB logical value.

Definition at line 375 of file mexWoRB.h.


Constructor & Destructor Documentation

Mex::Logical::Logical ( const mxArray *  arg,
const char *  argDesc,
bool  defaultValue = false 
) [inline]

Constructs the instance from the given MATLAB array of doubles.

Definition at line 415 of file mexWoRB.h.

References Initialize().

        {
            Initialize( arg, argDesc, defaultValue );
        }
Mex::Logical::Logical ( const mxArray *  obj,
mwIndex  index,
const char *  fieldName,
bool  defaultValue = false 
) [inline]

Constructs the instance from the given MATLAB structure field.

Definition at line 422 of file mexWoRB.h.

References Initialize().

        {
            Initialize( mxGetField( obj, index, fieldName ), fieldName, defaultValue );
        }

Member Function Documentation

void Mex::Logical::Initialize ( const mxArray *  arg,
const char *  argDesc,
bool  defaultValue 
) [inline, private]

Initializes the instance from a MATLAB array of doubles.

Definition at line 381 of file mexWoRB.h.

References WoRB::SevereError(), and value.

Referenced by Logical().

        {
            if ( arg == NULL ) {
                value = defaultValue;
                return;
            }

            // Parse value from different argument types
            // int ndim = mxGetNumberOfDimensions( arg );
            mwSize len = mxGetNumberOfElements( arg );

            if ( mxIsLogicalScalar( arg ) && len >= 1 ) 
            {
                value = mxGetLogicals( arg )[0];
                return;
            }
            else if ( mxIsDouble( arg ) && ! mxIsComplex( arg ) && len >= 1 )
            {
                double* data = mxGetPr( arg );
                value = data != NULL && data[0] != 0;
                return;
            }

            // If we couldn't parse logical value, return an error
            WoRB::SevereError( "WoRB:parseLogical:invarg",
                "'%s' must be a logical value or a real number.", 
                argDesc
            );
        }
Mex::Logical::operator bool ( ) const [inline]

Definition at line 433 of file mexWoRB.h.

References value.

        {
            return value;
        }
bool Mex::Logical::operator! ( ) const [inline]

Definition at line 428 of file mexWoRB.h.

References value.

        {
            return !value;
        }
Logical& Mex::Logical::operator= ( bool  v) [inline]

Sets the new value.

Definition at line 447 of file mexWoRB.h.

References value.

        {
            value = v;
            return* this;
        }
mxArray* Mex::Logical::toMxArray ( ) [inline]

Converts the instance to MATLAB logical scalar.

Definition at line 440 of file mexWoRB.h.

References value.

        {
            return mxCreateLogicalScalar( value );
        }

Field Documentation

bool Mex::Logical::value [private]

Definition at line 377 of file mexWoRB.h.

Referenced by Initialize(), operator bool(), operator!(), operator=(), and toMxArray().


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