diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-30 18:21:11 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-30 18:21:11 (GMT) |
commit | 8544230e7902f2a204877dd9ed4dc8e6115be120 (patch) | |
tree | 2e34430b1dd2136391d442a5dfda6e9a4a148f12 | |
parent | aa635ecc06213bfb7f4f6c62cbb8e99832d99d48 (diff) | |
download | uscxml-8544230e7902f2a204877dd9ed4dc8e6115be120.zip uscxml-8544230e7902f2a204877dd9ed4dc8e6115be120.tar.gz uscxml-8544230e7902f2a204877dd9ed4dc8e6115be120.tar.bz2 |
Removed conditional SWIG compile and polished PHP API
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/bindings/swig/php/uscxml.i | 33 | ||||
-rw-r--r-- | src/bindings/swig/php/uscxmlNativePHP.php | 422 | ||||
-rw-r--r-- | src/uscxml/Interpreter.h | 25 |
4 files changed, 260 insertions, 221 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 68b196a..8cdbb75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -327,6 +327,7 @@ if (NOT WIN32) set(XML_LIBRARIES ${LIBXML2_LIBRARIES}) if (NOT APPLE) list (APPEND USCXML_CORE_LIBS "rt") + list (APPEND USCXML_CORE_LIBS "rt") // yes it's needed twice e.g. on ubuntu endif() list (APPEND USCXML_CORE_LIBS "dl") list (APPEND USCXML_CORE_LIBS "pthread") diff --git a/src/bindings/swig/php/uscxml.i b/src/bindings/swig/php/uscxml.i index 5dd59b9..0ab248e 100644 --- a/src/bindings/swig/php/uscxml.i +++ b/src/bindings/swig/php/uscxml.i @@ -16,6 +16,10 @@ %ignore operator<; %ignore operator=; +%template(StringMap) std::map<std::string, std::string>; +%template(StringVector) std::vector<std::string>; +%template(Params) std::map<std::string, std::vector<std::string> >; + //************************************************** // This ends up in the generated wrapper code //************************************************** @@ -45,13 +49,37 @@ void*** tsrm_ls; // Beautify interpreter class //*********************************************** -%ignore uscxml::Interpreter::isAtomic(Arabica::DOM::Node<std::string>); +%extend uscxml::Interpreter { + std::vector<std::string> getConfiguration() { + std::vector<std::string> config; + Arabica::XPath::NodeSet<std::string> configNodes = self->getConfiguration(); + for (int i = 0; i < configNodes.size(); i++) { + config.push_back(ATTR(configNodes[i], "id")); + } + return config; + } +} +%ignore uscxml::Interpreter::getConfiguration(); + +%extend uscxml::Interpreter { + std::vector<std::string> getBasicConfiguration() { + std::vector<std::string> config; + Arabica::XPath::NodeSet<std::string> configNodes = self->getBasicConfiguration(); + for (int i = 0; i < configNodes.size(); i++) { + config.push_back(ATTR(configNodes[i], "id")); + } + return config; + } +} +%ignore uscxml::Interpreter::getBasicConfiguration(); + %extend uscxml::Interpreter { bool isAtomic(const std::string stateId) { Arabica::DOM::Node<std::string> state = self->getState(stateId); return self->isAtomic(state); } } +%ignore uscxml::Interpreter::isAtomic(Arabica::DOM::Node<std::string>); //*********************************************** // Parse the header file to generate wrappers @@ -62,6 +90,3 @@ void*** tsrm_ls; %include "../../../uscxml/concurrency/BlockingQueue.h" %template(ParentQueue) uscxml::concurrency::BlockingQueue<uscxml::SendRequest>; -%template(NameList) std::map<std::string, std::string>; -%template(ParamList) std::vector<std::string>; -%template(Params) std::map<std::string, std::vector<std::string> >; diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index 61e7c2e..a47e76f 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -35,6 +35,197 @@ abstract class uscxmlNativePHP { } /* PHP Proxy Classes */ +class StringMap { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __construct($arg1=null) { + if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__string_t') { + $this->_cPtr=$arg1; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_StringMap(); break; + default: $this->_cPtr=new_StringMap($arg1); + } + } + + function size() { + return StringMap_size($this->_cPtr); + } + + function clear() { + StringMap_clear($this->_cPtr); + } + + function get($key) { + return StringMap_get($this->_cPtr,$key); + } + + function set($key,$x) { + StringMap_set($this->_cPtr,$key,$x); + } + + function del($key) { + StringMap_del($this->_cPtr,$key); + } + + function has_key($key) { + return StringMap_has_key($this->_cPtr,$key); + } + + function is_empty() { + return StringMap_is_empty($this->_cPtr); + } +} + +class StringVector { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __construct($n=null) { + if (is_resource($n) && get_resource_type($n) === '_p_std__vectorT_std__string_t') { + $this->_cPtr=$n; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_StringVector(); break; + default: $this->_cPtr=new_StringVector($n); + } + } + + function size() { + return StringVector_size($this->_cPtr); + } + + function capacity() { + return StringVector_capacity($this->_cPtr); + } + + function reserve($n) { + StringVector_reserve($this->_cPtr,$n); + } + + function clear() { + StringVector_clear($this->_cPtr); + } + + function push($x) { + StringVector_push($this->_cPtr,$x); + } + + function is_empty() { + return StringVector_is_empty($this->_cPtr); + } + + function pop() { + return StringVector_pop($this->_cPtr); + } + + function get($i) { + return StringVector_get($this->_cPtr,$i); + } + + function set($i,$val) { + StringVector_set($this->_cPtr,$i,$val); + } +} + +class Params { + public $_cPtr=null; + protected $_pData=array(); + + function __set($var,$value) { + if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); + $this->_pData[$var] = $value; + } + + function __isset($var) { + if ($var === 'thisown') return true; + return array_key_exists($var, $this->_pData); + } + + function __get($var) { + if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); + return $this->_pData[$var]; + } + + function __construct($arg1=null) { + if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__vectorT_std__string_t_t') { + $this->_cPtr=$arg1; + return; + } + switch (func_num_args()) { + case 0: $this->_cPtr=new_Params(); break; + default: $this->_cPtr=new_Params($arg1); + } + } + + function size() { + return Params_size($this->_cPtr); + } + + function clear() { + Params_clear($this->_cPtr); + } + + function get($key) { + $r=Params_get($this->_cPtr,$key); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new StringVector($r); + } + return $r; + } + + function set($key,$x) { + Params_set($this->_cPtr,$key,$x); + } + + function del($key) { + Params_del($this->_cPtr,$key); + } + + function has_key($key) { + return Params_has_key($this->_cPtr,$key); + } + + function is_empty() { + return Params_is_empty($this->_cPtr); + } +} + class Data { public $_cPtr=null; protected $_pData=array(); @@ -159,7 +350,7 @@ class Event { function __get($var) { if ($var === 'data') return new Data(Event_data_get($this->_cPtr)); - if ($var === 'namelist') return new NameList(Event_namelist_get($this->_cPtr)); + if ($var === 'namelist') return new StringMap(Event_namelist_get($this->_cPtr)); $func = 'Event_'.$var.'_get'; if (function_exists($func)) return call_user_func($func,$this->_cPtr); if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); @@ -305,7 +496,7 @@ class Event { if (is_resource($r)) { $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); if (class_exists($c)) return new $c($r); - return new NameList($r); + return new StringMap($r); } return $r; } @@ -315,7 +506,7 @@ class Event { if (is_resource($r)) { $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); if (class_exists($c)) return new $c($r); - return new ParamList($r); + return new StringVector($r); } return $r; } @@ -335,7 +526,7 @@ class Event { if (is_resource($r)) { $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); if (class_exists($c)) return new $c($r); - return new ParamList($r); + return new StringVector($r); } return $r; } @@ -665,16 +856,6 @@ class Interpreter { return $r; } - function getConfiguration() { - $r=Interpreter_getConfiguration($this->_cPtr); - if (is_resource($r)) { - $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); - if (class_exists($c)) return new $c($r); - return new ParamList($r); - } - return $r; - } - function setConfiguration($states) { Interpreter_setConfiguration($this->_cPtr,$states); } @@ -776,7 +957,7 @@ class Interpreter { if (is_resource($r)) { $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); if (class_exists($c)) return new $c($r); - return new ParamList($r); + return new StringVector($r); } return $r; } @@ -833,6 +1014,26 @@ class Interpreter { return Interpreter_getUUID(); } + function getConfiguration() { + $r=Interpreter_getConfiguration($this->_cPtr); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new StringVector($r); + } + return $r; + } + + function getBasicConfiguration() { + $r=Interpreter_getBasicConfiguration($this->_cPtr); + if (is_resource($r)) { + $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); + if (class_exists($c)) return new $c($r); + return new StringVector($r); + } + return $r; + } + function isAtomic($stateId=null) { switch (func_num_args()) { case 0: $r=Interpreter_isAtomic($this->_cPtr); break; @@ -961,196 +1162,5 @@ class ParentQueue { } } -class NameList { - public $_cPtr=null; - protected $_pData=array(); - - function __set($var,$value) { - if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); - $this->_pData[$var] = $value; - } - - function __isset($var) { - if ($var === 'thisown') return true; - return array_key_exists($var, $this->_pData); - } - - function __get($var) { - if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); - return $this->_pData[$var]; - } - - function __construct($arg1=null) { - if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__string_t') { - $this->_cPtr=$arg1; - return; - } - switch (func_num_args()) { - case 0: $this->_cPtr=new_NameList(); break; - default: $this->_cPtr=new_NameList($arg1); - } - } - - function size() { - return NameList_size($this->_cPtr); - } - - function clear() { - NameList_clear($this->_cPtr); - } - - function get($key) { - return NameList_get($this->_cPtr,$key); - } - - function set($key,$x) { - NameList_set($this->_cPtr,$key,$x); - } - - function del($key) { - NameList_del($this->_cPtr,$key); - } - - function has_key($key) { - return NameList_has_key($this->_cPtr,$key); - } - - function is_empty() { - return NameList_is_empty($this->_cPtr); - } -} - -class ParamList { - public $_cPtr=null; - protected $_pData=array(); - - function __set($var,$value) { - if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); - $this->_pData[$var] = $value; - } - - function __isset($var) { - if ($var === 'thisown') return true; - return array_key_exists($var, $this->_pData); - } - - function __get($var) { - if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); - return $this->_pData[$var]; - } - - function __construct($n=null) { - if (is_resource($n) && get_resource_type($n) === '_p_std__vectorT_std__string_t') { - $this->_cPtr=$n; - return; - } - switch (func_num_args()) { - case 0: $this->_cPtr=new_ParamList(); break; - default: $this->_cPtr=new_ParamList($n); - } - } - - function size() { - return ParamList_size($this->_cPtr); - } - - function capacity() { - return ParamList_capacity($this->_cPtr); - } - - function reserve($n) { - ParamList_reserve($this->_cPtr,$n); - } - - function clear() { - ParamList_clear($this->_cPtr); - } - - function push($x) { - ParamList_push($this->_cPtr,$x); - } - - function is_empty() { - return ParamList_is_empty($this->_cPtr); - } - - function pop() { - return ParamList_pop($this->_cPtr); - } - - function get($i) { - return ParamList_get($this->_cPtr,$i); - } - - function set($i,$val) { - ParamList_set($this->_cPtr,$i,$val); - } -} - -class Params { - public $_cPtr=null; - protected $_pData=array(); - - function __set($var,$value) { - if ($var === 'thisown') return swig_uscxmlNativePHP_alter_newobject($this->_cPtr,$value); - $this->_pData[$var] = $value; - } - - function __isset($var) { - if ($var === 'thisown') return true; - return array_key_exists($var, $this->_pData); - } - - function __get($var) { - if ($var === 'thisown') return swig_uscxmlNativePHP_get_newobject($this->_cPtr); - return $this->_pData[$var]; - } - - function __construct($arg1=null) { - if (is_resource($arg1) && get_resource_type($arg1) === '_p_std__mapT_std__string_std__vectorT_std__string_t_t') { - $this->_cPtr=$arg1; - return; - } - switch (func_num_args()) { - case 0: $this->_cPtr=new_Params(); break; - default: $this->_cPtr=new_Params($arg1); - } - } - - function size() { - return Params_size($this->_cPtr); - } - - function clear() { - Params_clear($this->_cPtr); - } - - function get($key) { - $r=Params_get($this->_cPtr,$key); - if (is_resource($r)) { - $c=substr(get_resource_type($r), (strpos(get_resource_type($r), '__') ? strpos(get_resource_type($r), '__') + 2 : 3)); - if (class_exists($c)) return new $c($r); - return new ParamList($r); - } - return $r; - } - - function set($key,$x) { - Params_set($this->_cPtr,$key,$x); - } - - function del($key) { - Params_del($this->_cPtr,$key); - } - - function has_key($key) { - return Params_has_key($this->_cPtr,$key); - } - - function is_empty() { - return Params_is_empty($this->_cPtr); - } -} - ?> diff --git a/src/uscxml/Interpreter.h b/src/uscxml/Interpreter.h index 1394d59..d88fe10 100644 --- a/src/uscxml/Interpreter.h +++ b/src/uscxml/Interpreter.h @@ -150,6 +150,17 @@ public: tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); return _configuration; } + + Arabica::XPath::NodeSet<std::string> getBasicConfiguration() { + tthread::lock_guard<tthread::recursive_mutex> lock(_mutex); + Arabica::XPath::NodeSet<std::string> basicConfig; + for (int i = 0; i < _configuration.size(); i++) { + if (isAtomic(_configuration[i])) + basicConfig.push_back(_configuration[i]); + } + return basicConfig; + } + void setConfiguration(const std::vector<std::string>& states) { _userDefinedStartConfiguration = states; } @@ -415,21 +426,13 @@ public: return _impl->getCurrentEvent(); } -#ifndef SWIG Arabica::XPath::NodeSet<std::string> getConfiguration() { return _impl->getConfiguration(); } -#else - // simplified access to state names for language bindings - std::vector<std::string> getConfiguration() { - std::vector<std::string> stateNames; - Arabica::XPath::NodeSet<std::string> nodeSet = _impl->getConfiguration(); - for (int i = 0; i < nodeSet.size(); i++) { - stateNames.push_back(ATTR(nodeSet[i], "id")); - } - return stateNames; + + Arabica::XPath::NodeSet<std::string> getBasicConfiguration() { + return _impl->getBasicConfiguration(); } -#endif void setConfiguration(const std::vector<std::string>& states) { return _impl->setConfiguration(states); |