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

Represents a MATLAB scalar double value. More...

#include <mexWoRB.h>

Public Member Functions

 Scalar (const mxArray *arg, const char *argDesc)
 Constructs the instance from the given MATLAB array of doubles.
 Scalar (const mxArray *obj, mwIndex index, const char *fieldName)
 Constructs the instance from the given MATLAB structure field.
 operator double () const
 operator int () const
 operator unsigned () const
 operator double & ()
mxArray * toMxArray ()
 Converts the instance to MATLAB real scalar.

Private Member Functions

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

Private Attributes

double value

Detailed Description

Represents a MATLAB scalar double value.

Definition at line 298 of file mexWoRB.h.


Constructor & Destructor Documentation

Mex::Scalar::Scalar ( const mxArray *  arg,
const char *  argDesc 
) [inline]

Constructs the instance from the given MATLAB array of doubles.

Definition at line 333 of file mexWoRB.h.

References Initialize().

        {
            Initialize( arg, argDesc );
        }
Mex::Scalar::Scalar ( const mxArray *  obj,
mwIndex  index,
const char *  fieldName 
) [inline]

Constructs the instance from the given MATLAB structure field.

Definition at line 340 of file mexWoRB.h.

References Initialize().

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

Member Function Documentation

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

Initializes the instance from a MATLAB array of doubles.

Definition at line 304 of file mexWoRB.h.

References WoRB::SevereError(), and value.

Referenced by Scalar().

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

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

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

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

Definition at line 345 of file mexWoRB.h.

References value.

        {
            return value;
        }
Mex::Scalar::operator double & ( ) [inline]

Definition at line 360 of file mexWoRB.h.

References value.

        {
            return value;
        }
Mex::Scalar::operator int ( ) const [inline]

Definition at line 350 of file mexWoRB.h.

References value.

        {
            return int( value );
        }
Mex::Scalar::operator unsigned ( ) const [inline]

Definition at line 355 of file mexWoRB.h.

References value.

        {
            return unsigned( value );
        }
mxArray* Mex::Scalar::toMxArray ( ) [inline]

Converts the instance to MATLAB real scalar.

Definition at line 367 of file mexWoRB.h.

References value.

        {
            return mxCreateDoubleScalar( value );
        }

Field Documentation


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