summaryrefslogtreecommitdiffstats
path: root/src/uscxml
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-08-04 21:39:39 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-08-04 21:39:39 (GMT)
commit83ef70ebc7527240f56e2e601777a613bce6e47e (patch)
treec520fec5b446672b69353a0b37460631840b4219 /src/uscxml
parent932916f952f302a46e41841ccf95ec1b7851b302 (diff)
downloaduscxml-83ef70ebc7527240f56e2e601777a613bce6e47e.zip
uscxml-83ef70ebc7527240f56e2e601777a613bce6e47e.tar.gz
uscxml-83ef70ebc7527240f56e2e601777a613bce6e47e.tar.bz2
Beautified flattened state-machine ids
Diffstat (limited to 'src/uscxml')
-rw-r--r--src/uscxml/Factory.cpp2
-rw-r--r--src/uscxml/debug/SCXMLDotWriter.cpp67
-rw-r--r--src/uscxml/debug/SCXMLDotWriter.h2
-rw-r--r--src/uscxml/transform/ChartToFSM.cpp30
-rw-r--r--src/uscxml/transform/FlatStateIdentifier.h204
5 files changed, 190 insertions, 115 deletions
diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp
index e9b651f..3bad07f 100644
--- a/src/uscxml/Factory.cpp
+++ b/src/uscxml/Factory.cpp
@@ -228,6 +228,7 @@ void Factory::registerPlugins() {
registerInvoker(invoker);
}
#endif
+#endif
#ifdef MILES_FOUND
{
@@ -334,7 +335,6 @@ void Factory::registerPlugins() {
// registerIOProcessor(ioProcessor);
}
#endif
-#endif
#ifdef CURL_HAS_SMTP
{
diff --git a/src/uscxml/debug/SCXMLDotWriter.cpp b/src/uscxml/debug/SCXMLDotWriter.cpp
index be053d7..1b9555e 100644
--- a/src/uscxml/debug/SCXMLDotWriter.cpp
+++ b/src/uscxml/debug/SCXMLDotWriter.cpp
@@ -454,6 +454,59 @@ void SCXMLDotWriter::writePerEventPorts(std::ostream& os, const DotState& dotSta
}
+std::string SCXMLDotWriter::htmlLabelForId(const std::string& stateId, int minRows) {
+ FlatStateIdentifier flatId(stateId);
+
+ std::list<std::string>::const_iterator listIter;
+ std::stringstream labelSS;
+ std::string seperator;
+
+ labelSS << "<b>active: </b>";
+ labelSS << "{";
+ for (listIter = flatId.getActive().begin(); listIter != flatId.getActive().end(); listIter++) {
+ labelSS << seperator << *listIter;
+ seperator = ", ";
+ }
+ labelSS << "}";
+
+ if (flatId.getVisited().size() > 0) {
+ minRows--;
+
+ labelSS << "<br /><b>init: </b>";
+
+ labelSS << "{";
+ seperator = "";
+ for (listIter = flatId.getVisited().begin(); listIter != flatId.getVisited().end(); listIter++) {
+ labelSS << seperator << *listIter;
+ seperator = ", ";
+ }
+ labelSS << "}";
+ }
+
+ if (flatId.getHistory().size() > 0) {
+ minRows--;
+
+ seperator = "";
+ std::string histSeperator = "<br /> ";
+
+ labelSS << "<br /><b>history: </b>";
+
+ std::map<std::string, std::list<std::string> >::const_iterator histIter;
+ for (histIter = flatId.getHistory().begin(); histIter != flatId.getHistory().end(); histIter++) {
+ labelSS << histSeperator << histIter->first << ": {";
+
+ for (listIter = histIter->second.begin(); listIter != histIter->second.end(); listIter++) {
+ labelSS << seperator << *listIter;
+ seperator = ", ";
+ }
+ labelSS << "}";
+ seperator = "";
+ }
+ }
+ return labelSS.str();
+}
+
+
void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const DotState& dotState, int stateLines) {
// std::multimap<std::string, Arabica::DOM::Element<std::string> > targets; // key is remote node, transition is element
@@ -499,7 +552,7 @@ void SCXMLDotWriter::writePerTargetPorts(std::ostream& os, const DotState& dotSt
_edges.insert(edge);
std::stringstream outPortSS;
- outPortSS << (_isFlat ? FlatStateIdentifier::toHTMLLabel(targetId) : "<b>" + targetId + "</b>" );
+ outPortSS << (_isFlat ? htmlLabelForId(targetId) : "<b>" + targetId + "</b>" );
if (_isFlat) {
outPortSS << "<br /><b>events: </b>{";
@@ -751,11 +804,11 @@ std::string SCXMLDotWriter::nameForNode(const Node<std::string>& node) {
if (InterpreterImpl::isFinal(elem) && _isFlat) {
// ignore visited and history with final elements
FlatStateIdentifier flatId(elem.getAttribute("id"));
- return "<b>" + flatId.active.front() + "</b>";
+ return "<b>" + flatId.getActive().front() + "</b>";
}
if (elem.hasAttribute("id") && _isFlat) {
- elemName = FlatStateIdentifier::toHTMLLabel(elem.getAttribute("id"));
+ elemName = htmlLabelForId(elem.getAttribute("id"));
if (elemName.size() > 0)
return elemName;
} else if (elem.getTagName() == "scxml") {
@@ -790,7 +843,13 @@ std::string SCXMLDotWriter::idForNode(const Node<std::string>& node) {
if (InterpreterImpl::isFinal(elem) && _isFlat) {
// ignore visited and history with final elements
FlatStateIdentifier flatId(elem.getAttribute("id"));
- return flatId.activeId();
+
+ std::stringstream activeSS;
+ activeSS << "active-";
+ for (std::list<std::string>::const_iterator activeIter = flatId.getActive().begin(); activeIter != flatId.getActive().end(); activeIter++) {
+ activeSS << *activeIter << "-";
+ }
+ return activeSS.str();
}
if (elem.hasAttribute("name")) {
diff --git a/src/uscxml/debug/SCXMLDotWriter.h b/src/uscxml/debug/SCXMLDotWriter.h
index 61fbfad..04cd0fd 100644
--- a/src/uscxml/debug/SCXMLDotWriter.h
+++ b/src/uscxml/debug/SCXMLDotWriter.h
@@ -130,6 +130,8 @@ public:
virtual void beforeTakingTransition(Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, bool moreComing);
virtual void beforeMicroStep(Interpreter interpreter);
+ static std::string htmlLabelForId(const std::string& stateId, int minRows = 0);
+
static void toDot(const std::string& filename,
Interpreter interpreter,
const Arabica::DOM::Element<std::string>& transition = Arabica::DOM::Element<std::string>()) {
diff --git a/src/uscxml/transform/ChartToFSM.cpp b/src/uscxml/transform/ChartToFSM.cpp
index 83b8195..9665b56 100644
--- a/src/uscxml/transform/ChartToFSM.cpp
+++ b/src/uscxml/transform/ChartToFSM.cpp
@@ -18,6 +18,7 @@
*/
#include "uscxml/transform/ChartToFSM.h"
+#include "uscxml/transform/FlatStateIdentifier.h"
#include "uscxml/Factory.h"
#include <DOM/io/Stream.hpp>
@@ -1009,33 +1010,8 @@ GlobalState::GlobalState(const Arabica::XPath::NodeSet<std::string>& activeState
historyIter->second.to_document_order();
}
- // create a unique identifier for a global configuration
- std::ostringstream idSS;
- idSS << "active-";
- for (int i = 0; i < activeStates.size(); i++) {
- if (!InterpreterImpl::isFinal(Element<std::string>(activeStates[i])))
- isFinal = false;
- idSS << ATTR_CAST(activeStates[i], "id") << "-";
- }
- idSS << ";";
- idSS << "entered-";
- for (int i = 0; i < alreadyEnteredStates.size(); i++) {
- idSS << ATTR_CAST(alreadyEnteredStates[i], "id") << "-";
- }
- idSS << ";";
-
- for(std::map<std::string, Arabica::XPath::NodeSet<std::string> >::const_iterator histIter = historyStates.begin();
- histIter != historyStates.end();
- histIter++) {
- const Arabica::XPath::NodeSet<std::string>& histStates = histIter->second;
- idSS << "history--";
- idSS << histIter->first << "-";
- for (int i = 0; i < histStates.size(); i++) {
- idSS << ATTR_CAST(histStates[i], "id") << "-";
- }
- }
-
- stateId = idSS.str();
+ FlatStateIdentifier flatStateId(activeStates, alreadyEnteredStates, historyStates);
+ stateId = flatStateId.getStateId();
}
GlobalTransition::GlobalTransition(const Arabica::XPath::NodeSet<std::string>& transitionSet, DataModel dataModel) {
diff --git a/src/uscxml/transform/FlatStateIdentifier.h b/src/uscxml/transform/FlatStateIdentifier.h
index 2ee0443..3a9ee49 100644
--- a/src/uscxml/transform/FlatStateIdentifier.h
+++ b/src/uscxml/transform/FlatStateIdentifier.h
@@ -20,134 +20,172 @@
#ifndef FLATSTATEIDENTIFIER_H_E9534AF9
#define FLATSTATEIDENTIFIER_H_E9534AF9
+#include "uscxml/Common.h"
+#include "uscxml/DOMUtils.h"
+
+#include <XPath/XPath.hpp>
#include <sstream>
#include <string>
#include <list>
#include <map>
+#include <boost/algorithm/string.hpp>
+
namespace uscxml {
class USCXML_API FlatStateIdentifier {
public:
- FlatStateIdentifier(const std::string& identifier) {
+ FlatStateIdentifier(const Arabica::XPath::NodeSet<std::string>& activeStates,
+ const Arabica::XPath::NodeSet<std::string>& alreadyEnteredStates,
+ const std::map<std::string, Arabica::XPath::NodeSet<std::string> >& historyStates) {
+ for (int i = 0; i < activeStates.size(); i++) {
+ active.push_back(ATTR_CAST(activeStates[i], "id"));
+ }
+
+ for (int i = 0; i < alreadyEnteredStates.size(); i++) {
+ visited.push_back(ATTR_CAST(alreadyEnteredStates[i], "id"));
+ }
+
+ std::map<std::string, Arabica::XPath::NodeSet<std::string> >::const_iterator histIter;
+ for (histIter = historyStates.begin(); histIter != historyStates.end(); histIter++) {
+ for (int i = 0; i < histIter->second.size(); i++) {
+ histories[histIter->first].push_back(ATTR_CAST(histIter->second[i], "id"));
+ }
+ }
+
+ initStateId();
+ }
+
+
+ FlatStateIdentifier(const std::list<std::string>& active,
+ const std::list<std::string>& visited,
+ const std::map<std::string, std::list<std::string> >& histories) : active(active), visited(visited), histories(histories) {
+ initStateId();
+ }
+
+ FlatStateIdentifier(const std::string& identifier) : stateId(identifier) {
std::string parsedName;
// parse unique state identifier
std::stringstream elemNameSS(identifier);
std::string section;
while(std::getline(elemNameSS, section, ';')) {
- if (boost::starts_with(section, "active-")) {
- std::stringstream stateSS(section.substr(7));
+ if (boost::starts_with(section, "active:{")) {
+ // active:{s0,s1,s2}
+ std::stringstream stateSS(section.substr(8, section.size() - 9));
std::string state;
- while(std::getline(stateSS, state, '-')) {
+ while(std::getline(stateSS, state, ',')) {
if (state.length() > 0) {
active.push_back(state);
}
}
- } else if (boost::starts_with(section, "entered-")) {
- std::stringstream stateSS(section.substr(8));
+ } else if (boost::starts_with(section, "entered:{")) {
+ // entered:{s0,s1,s2}
+ std::stringstream stateSS(section.substr(9, section.size() - 10));
std::string state;
- while(std::getline(stateSS, state, '-')) {
+ while(std::getline(stateSS, state, ',')) {
if (state.length() > 0) {
visited.push_back(state);
}
}
- } else if (boost::starts_with(section, "history-")) {
- std::stringstream stateSS(section.substr(8));
+ } else if (boost::starts_with(section, "history:{")) {
+ // history:{h0:{s1,s2},h1:{s2,s3}}
+ std::string histEntries(section.substr(9, section.length() - 10));
+
std::string state;
- std::string history;
- while(std::getline(stateSS, state, '-')) {
- if (state.length() > 0) {
- if (history.size() == 0) {
- history = state;
- } else {
- histories[history].push_back(state);
- }
- } else {
- history = "";
+ size_t start = 0;
+ size_t history = 0;
+
+ while((history = histEntries.find(":", start)) != std::string::npos) {
+ std::string histName = histEntries.substr(start, history - start);
+ history++;
+
+ size_t end = histEntries.find("}", start);
+ if (end == std::string::npos)
+ continue;
+
+ std::stringstream stateSS(histEntries.substr(history + 1, end - history - 1));
+ std::string state;
+ while(std::getline(stateSS, state, ',')) {
+ histories[histName].push_back(state);
}
+
+ start = end + 2;
}
}
}
}
- std::string activeId() {
- std::stringstream activeSS;
- activeSS << "active-";
- for (std::list<std::string>::const_iterator activeIter = active.begin(); activeIter != active.end(); activeIter++) {
- activeSS << *activeIter << "-";
- }
- return activeSS.str();
+ const std::string& getStateId() {
+ return stateId;
+ }
+
+ const std::list<std::string>& getActive() {
+ return active;
+ }
+
+ const std::list<std::string>& getVisited() {
+ return visited;
+ }
+
+ const std::map<std::string, std::list<std::string> > & getHistory() {
+ return histories;
}
+protected:
std::list<std::string> active;
std::list<std::string> visited;
std::map<std::string, std::list<std::string> > histories;
+ std::string stateId;
- static std::string toHTMLLabel(const std::string& identifier, int minRows = 0) {
- FlatStateIdentifier flatId(identifier);
-
- std::list<std::string>::const_iterator listIter;
- std::stringstream labelSS;
+ void initStateId() {
+ std::stringstream stateIdSS;
+
std::string seperator;
-
-// labelSS << "<table valign=\"top\" align=\"left\" cellborder=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
-// labelSS << "<tr>";
-// labelSS << "<td balign=\"left\" align=\"left\" valign=\"top\">";
-
- labelSS << "<b>active: </b>";
- labelSS << "{";
- for (listIter = flatId.active.begin(); listIter != flatId.active.end(); listIter++) {
- labelSS << seperator << *listIter;
- seperator = ", ";
+ stateIdSS << "active:{";
+ for (std::list<std::string>::const_iterator actIter = active.begin(); actIter != active.end(); actIter++) {
+ stateIdSS << seperator << *actIter;
+ seperator = ",";
}
- labelSS << "}";
-
- if (flatId.visited.size() > 0) {
- minRows--;
-
- labelSS << "<br /><b>init: </b>";
-
- labelSS << "{";
- seperator = "";
- for (listIter = flatId.visited.begin(); listIter != flatId.visited.end(); listIter++) {
- labelSS << seperator << *listIter;
- seperator = ", ";
- }
- labelSS << "}";
+ stateIdSS << "};";
+
+ seperator = "";
+ stateIdSS << "entered:{";
+ for (std::list<std::string>::const_iterator visitIter = visited.begin(); visitIter != visited.end(); visitIter++) {
+ stateIdSS << seperator << *visitIter;
+ seperator = ",";
}
-
-#if 1
- if (flatId.histories.size() > 0) {
- minRows--;
-
- seperator = "";
- std::string histSeperator = "<br /> ";
-
- labelSS << "<br /><b>history: </b>";
-
- std::map<std::string, std::list<std::string> >::const_iterator histIter;
- for (histIter = flatId.histories.begin(); histIter != flatId.histories.end(); histIter++) {
- labelSS << histSeperator << histIter->first << ": {";
-
- for (listIter = histIter->second.begin(); listIter != histIter->second.end(); listIter++) {
- labelSS << seperator << *listIter;
- seperator = ", ";
- }
- labelSS << "}";
- seperator = "";
+ stateIdSS << "};";
+
+ seperator = "";
+ stateIdSS << "history:{";
+ for (std::map<std::string, std::list<std::string> >::const_iterator histIter = histories.begin(); histIter != histories.end(); histIter++) {
+ stateIdSS << seperator << histIter->first << ":{";
+ seperator = ",";
+ std::string itemSeperator;
+ for (std::list<std::string>::const_iterator histItemIter = histIter->second.begin(); histItemIter != histIter->second.end(); histItemIter++) {
+ stateIdSS << itemSeperator << *histItemIter;
+ itemSeperator = ",";
}
+ stateIdSS << "}";
}
-#endif
-// while(minRows-- > 0)
-// labelSS << "<tr><td valign=\"top\"></td></tr>"; // eat up rest of space
-//
-// labelSS << "</td>";
-// labelSS << "</tr>";
-// labelSS << "</table>";
- return labelSS.str();
+ stateIdSS << "}";
+
+ stateId = stateIdSS.str();
+ }
+
+#if 0
+ std::string activeId() {
+ std::stringstream activeSS;
+ activeSS << "active-";
+ for (std::list<std::string>::const_iterator activeIter = active.begin(); activeIter != active.end(); activeIter++) {
+ activeSS << *activeIter << "-";
+ }
+ return activeSS.str();
}
+#endif
+
};
}