ECMAScript data-model via JavaScriptCore.

#include <JSCDataModel.h>

Inheritance diagram for uscxml::JSCDataModel:
[legend]
Collaboration diagram for uscxml::JSCDataModel:
[legend]

Public Member Functions

virtual void addExtension (DataModelExtension *ext)
 Register an extension to get data into and out of the data-model. More...
 
virtual void assign (const std::string &location, const Data &data, const std::map< std::string, std::string > &attr=std::map< std::string, std::string >())
 Assign a data object to a location in the data-model. More...
 
virtual std::shared_ptr< DataModelImplcreate (DataModelCallbacks *callbacks)
 The Factory wants to instantiate a new instance. More...
 
virtual bool evalAsBool (const std::string &expr)
 Evaluate a given expression as a boolean. More...
 
virtual Data evalAsData (const std::string &expr)
 Return a string as an evaluated Data object. More...
 
virtual Data getAsData (const std::string &content)
 Return a string as an unevaluated Data object. More...
 
virtual uint32_t getLength (const std::string &expr)
 Evaluate the given expression as something iterable and return its length. More...
 
virtual std::list< std::string > getNames ()
 Return a list of names to be matched by the datamodel attribute in SCXML.
 
virtual void init (const std::string &location, const Data &data, const std::map< std::string, std::string > &attr=std::map< std::string, std::string >())
 Initialize a variable / location in the data-model with a given data object. More...
 
virtual bool isDeclared (const std::string &expr)
 Determine whether a given variable / location is declared. More...
 
virtual bool isValidSyntax (const std::string &expr)
 Determine whether a given string constitutes valid syntax in the data-model's language. More...
 
virtual void setEvent (const Event &event)
 Set the given event as _event in the data-model's global scope. More...
 
virtual void setForeach (const std::string &item, const std::string &array, const std::string &index, uint32_t iteration)
 Set a given item to the object at a given index for one iteration. More...
 
- Public Member Functions inherited from uscxml::DataModelImpl
size_t replaceExpressions (std::string &content)
 Experimental extension to have dynamic content in string literals. More...
 

Protected Member Functions

JSValueRef evalAsValue (const std::string &expr, bool dontThrow=false)
 
JSValueRef getDataAsValue (const Data &data)
 
JSValueRef getNodeAsValue (const XERCESC_NS::DOMNode *node)
 
Data getValueAsData (const JSValueRef value)
 
void handleException (JSValueRef exception)
 

Static Protected Member Functions

static JSValueRef jsExtension (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 
static JSValueRef jsIn (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 
static JSValueRef jsInvokerGetProp (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 
static bool jsInvokerHasProp (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
 
static void jsInvokerListProps (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
 
static JSValueRef jsIOProcessorGetProp (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception)
 
static bool jsIOProcessorHasProp (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
 
static void jsIOProcessorListProps (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
 
static JSValueRef jsPrint (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
 

Protected Attributes

JSGlobalContextRef _ctx
 
Event _event
 
std::set< DataModelExtension * > _extensions
 
std::string _name
 
std::string _sessionId
 
- Protected Attributes inherited from uscxml::DataModelImpl
DataModelCallbacks_callbacks
 

Static Protected Attributes

static std::mutex _initMutex
 
static JSClassDefinition jsExtensionClassDef = { 0, 0, "Extension", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsExtension, 0, 0, 0 }
 
static JSClassDefinition jsInClassDef = { 0, 0, "In", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsIn, 0, 0, 0 }
 
static JSClassDefinition jsInvokersClassDef = { 0, 0, "invokers", 0, 0, 0, 0, 0, jsInvokerHasProp, jsInvokerGetProp, 0, 0, jsInvokerListProps, 0, 0, 0, 0 }
 
static JSClassDefinition jsIOProcessorsClassDef = { 0, 0, "ioProcessors", 0, 0, 0, 0, 0, jsIOProcessorHasProp, jsIOProcessorGetProp, 0, 0, jsIOProcessorListProps, 0, 0, 0, 0 }
 
static JSClassDefinition jsPrintClassDef = { 0, 0, "print", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsPrint, 0, 0, 0 }
 

Member Function Documentation

void uscxml::JSCDataModel::addExtension ( DataModelExtension ext)
virtual
Todo:
This is currently unsupported

Reimplemented from uscxml::DataModelImpl.

void uscxml::JSCDataModel::assign ( const std::string &  location,
const Data data,
const std::map< std::string, std::string > &  attr = std::map< std::string, std::string >() 
)
virtual

There are different occurences in the SCXML IRP tests, e.g.

test147:
<data id="Var1" expr="0"/>

test150:
<data id="Var3">
[1,2,3]
</data>

test277:
<data id="Var1" expr="return"/>
Parameters
locationA variable or locatio to assign to.
dataThe Data object with the respective data.
attrAdditional attributes of the XML assign element.

test157: We need to evaluate, as this will not throw for 'continue' = Var[5] in

Implements uscxml::DataModelImpl.

std::shared_ptr< DataModelImpl > uscxml::JSCDataModel::create ( DataModelCallbacks callbacks)
virtual

This function will have to initialize the object. The actual constructor is called from within here. The only one who calls the constructor directly is the Factory for the prototype object.

Parameters
callbacksThe callbacks available to the datamodel
Returns
A shared pointer with an initialized instance

Implements uscxml::DataModelImpl.

bool uscxml::JSCDataModel::evalAsBool ( const std::string &  expr)
virtual

This function is a subset of evalAsData() but saves on creating and copying a Data object.

Parameters
exprAn expression in the data-model's language.
Returns
Whether the expression evaluates as true

Implements uscxml::DataModelImpl.

Data uscxml::JSCDataModel::evalAsData ( const std::string &  content)
virtual
Parameters
contentA string with a literal, eppression or compound data-structure in the data-model's language.
Returns
An evaluated structure representing the given compound or literal.

Implements uscxml::DataModelImpl.

Data uscxml::JSCDataModel::getAsData ( const std::string &  content)
virtual
Parameters
contentA string with a literal, eppression or compound data-structure in the data-model's language.
Returns
An unevaluated structure representing the given compound or literal.

Implements uscxml::DataModelImpl.

uint32_t uscxml::JSCDataModel::getLength ( const std::string &  expr)
virtual
Parameters
exprAnything that possibly evaluates to an enumerable object.
Returns
The number of items in the enumerable object.

Implements uscxml::DataModelImpl.

void uscxml::JSCDataModel::init ( const std::string &  location,
const Data data,
const std::map< std::string, std::string > &  attr = std::map< std::string, std::string >() 
)
virtual

This is, semantically, very close to assign() but does not assume the location to be declared first.

Parameters
locationA variable or locatio to assign to.
dataThe Data object with the respective data.
attrAdditional attributes of the XML data element.

Implements uscxml::DataModelImpl.

bool uscxml::JSCDataModel::isDeclared ( const std::string &  expr)
virtual
Parameters
exprThe variable / location to check.
Todo:
Is this still used?

Implements uscxml::DataModelImpl.

bool uscxml::JSCDataModel::isValidSyntax ( const std::string &  expr)
virtual
Parameters
exprA string, supposedly containing an expression of the data-model.
Returns
Whether expr is in L(DM).

Reimplemented from uscxml::DataModelImpl.

void uscxml::JSCDataModel::setEvent ( const Event event)
virtual
Parameters
eventThe event as it was dequeued from either the internal or external queue.

Implements uscxml::DataModelImpl.

void uscxml::JSCDataModel::setForeach ( const std::string &  item,
const std::string &  array,
const std::string &  index,
uint32_t  iteration 
)
virtual
Parameters
itemA variable or location to assign the current object to.
arrayAn expression evalating to an enumerable object.
indexA variable or location to set the current index at.
iterationThe current iteration index.

Implements uscxml::DataModelImpl.


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