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

Represents a MATLAB character string value. More...

#include <mexWoRB.h>

Public Member Functions

 String (const mxArray *arg, const char *argDesc)
 Constructs the instance from the given MATLAB character array.
 String (const mxArray *obj, mwIndex index, const char *fieldName)
 Constructs the instance from the given MATLAB structure field.
 ~String ()
 Destructor.
 operator const char * () const
 Gets pointer to internal character string.
mxArray * toMxArray ()
 Converts the instance to MATLAB string.
bool operator== (const char *v)
 Returns true if this instance has the same contents as the given string.
bool operator!= (const char *v)
 Returns true if this instance does not have the same contents as the given string.

Private Member Functions

void Initialize (const mxArray *arg, const char *argDesc)
 Initializes the instance from a MATLAB mxArray.

Private Attributes

char * value

Detailed Description

Represents a MATLAB character string value.

Definition at line 456 of file mexWoRB.h.


Constructor & Destructor Documentation

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

Constructs the instance from the given MATLAB character array.

Definition at line 481 of file mexWoRB.h.

References Initialize().

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

Constructs the instance from the given MATLAB structure field.

Definition at line 488 of file mexWoRB.h.

References Initialize().

        {
            Initialize( mxGetField( obj, index, fieldName ), fieldName );
        }
Mex::String::~String ( ) [inline]

Destructor.

Does nothing. MATLAB automatically frees all data allocated by mxMalloc.

Definition at line 496 of file mexWoRB.h.

        {
        }

Member Function Documentation

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

Initializes the instance from a MATLAB mxArray.

Definition at line 462 of file mexWoRB.h.

References WoRB::SevereError(), and value.

Referenced by String().

        {
            if ( arg == NULL || ! mxIsChar( arg ) ) {
                // If we couldn't parse character string, return an error
                WoRB::SevereError( "WoRB:parseString:invarg",
                    "'%s' must be a character array.", 
                    argDesc
                );
            }

            mwSize len = mxGetNumberOfElements( arg );
            value = (char*)mxMalloc( len + 1 );
            mxGetString( arg, value, len + 1 );
        }
Mex::String::operator const char * ( ) const [inline]

Gets pointer to internal character string.

Definition at line 502 of file mexWoRB.h.

References value.

        {
            return value;
        }
bool Mex::String::operator!= ( const char *  v) [inline]

Returns true if this instance does not have the same contents as the given string.

Definition at line 528 of file mexWoRB.h.

References operator==().

        {
            return ! operator ==( v );
        }
bool Mex::String::operator== ( const char *  v) [inline]

Returns true if this instance has the same contents as the given string.

Definition at line 516 of file mexWoRB.h.

References value.

Referenced by operator!=().

        {
            for ( const char* p = value; *p && *v; ++p, ++v ) {
                if ( *p != *v ) {
                    return false;
                }
            }
            return true;
        }
mxArray* Mex::String::toMxArray ( ) [inline]

Converts the instance to MATLAB string.

Definition at line 509 of file mexWoRB.h.

References value.

        {
            return mxCreateString( value );
        }

Field Documentation

char* Mex::String::value [private]

Definition at line 458 of file mexWoRB.h.

Referenced by Initialize(), operator const char *(), operator==(), and toMxArray().


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