|
From: <ob...@us...> - 2011-12-11 21:16:15
|
Revision: 1222
http://scstudio.svn.sourceforge.net/scstudio/?rev=1222&view=rev
Author: obouda
Date: 2011-12-11 21:16:08 +0000 (Sun, 11 Dec 2011)
Log Message:
-----------
Z120 export canonization:
- introduced a template class BasicStringListPrinter and its specialization StringListPrinter
- node list after the "connect" keyword is now sorted
Modified Paths:
--------------
trunk/src/data/Z120/z120.h
trunk/src/data/Z120/z120_save.cpp
trunk/tests/time_constraints/proper_neg13.mpr.result
trunk/tests/time_constraints/proper_neg13.mpr.result1
trunk/tests/time_constraints/proper_neg21.mpr.result
trunk/tests/time_constraints/proper_neg22.mpr.result
trunk/tests/time_constraints/proper_neg23.mpr.result
trunk/tests/time_constraints/proper_neg24.mpr.result
trunk/tests/time_constraints/proper_neg25.mpr.result
trunk/tests/time_constraints/proper_neg26.mpr.result
trunk/tests/time_constraints/proper_neg26.mpr.result.1
trunk/tests/time_constraints/proper_neg27.mpr.result
trunk/tests/time_constraints/proper_neg27.mpr.result.1
trunk/tests/time_constraints/proper_neg6.mpr.result
trunk/tests/time_constraints/proper_neg7.mpr.result
trunk/tests/time_constraints/proper_neg9.mpr.result
trunk/tests/z120_test/z120_time22.mpr.result
trunk/tests/z120_test/z120_time23.mpr.result
trunk/tests/z120_test/z120_time24.mpr.result
trunk/tests/z120_test/z120_time25.mpr.result
Added Paths:
-----------
trunk/tests/string_list_printer_test.cpp
Modified: trunk/src/data/Z120/z120.h
===================================================================
--- trunk/src/data/Z120/z120.h 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/src/data/Z120/z120.h 2011-12-11 21:16:08 UTC (rev 1222)
@@ -87,8 +87,8 @@
//! export a HMSC drawing
int save_hmsc(std::ostream& stream, const HMscPtr& hmsc);
- void print_element_attributes(std::ostream& stream,
- const MscElementPtr& element);
+ template<class OutputStreamType>
+ void print_element_attributes(OutputStreamType& stream, const MscElementPtr& element);
// print global comments
// note: used when the comment is attached to BMsc or HMsc
Modified: trunk/src/data/Z120/z120_save.cpp
===================================================================
--- trunk/src/data/Z120/z120_save.cpp 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/src/data/Z120/z120_save.cpp 2011-12-11 21:16:08 UTC (rev 1222)
@@ -23,8 +23,10 @@
#include <map>
#include <ostream>
#include <iterator>
+#include <sstream>
#include "data/Z120/z120.h"
+#include "data/Z120/string_list_printer.h"
// list of ITU-T Z.120 keywords that must not be used as names
static const char* keywords[] =
@@ -221,7 +223,7 @@
{
//TODO print warning that the comment is not valid
// print_report(RS_WARNING, stringize() << L"Comment text \"" << TOWSTRING(value) << L"\" is not allowed");
-
+
// double the apostrophe
os << "''";
}
@@ -267,6 +269,7 @@
return os;
}
+
ExportFormatter::PreconditionList Z120::get_preconditions(MscPtr msc) const
{
ExportFormatter::PreconditionList result;
@@ -320,7 +323,8 @@
return 1; // unexpected pointer
}
-void Z120::print_element_attributes(std::ostream& stream, const MscElementPtr& element)
+template<class OutputStreamType>
+void Z120::print_element_attributes(OutputStreamType& stream, const MscElementPtr& element)
{
switch(element->get_marked())
{
@@ -342,7 +346,7 @@
pos != attributes.end(); pos++)
{
stream << *pos;
-
+
if(*pos == "membership_counter")
stream << " " << element->get_attribute("membership_counter", -1);
}
@@ -389,7 +393,7 @@
void print_absolute_time(std::ostream& stream, AbsoluteTimePtr abs)
{
const std::list< MscTimeInterval<double> > constraints = abs->get_interval_set().get_set();
-
+
for(std::list< MscTimeInterval<double> >::const_iterator it = constraints.begin();
it != constraints.end(); it++)
{
@@ -757,26 +761,26 @@
<< L"Warning: HMSC node without successors violates the Z.120 standard.");
}
+ // output canonization: output the list of nodes in the lexicographic order
+ BasicStringListPrinter<int> succ_printer(" connect", ",");
+
for(NodeRelationPtrVector::const_iterator spos = predecessor_node->get_successors().begin();
spos != predecessor_node->get_successors().end(); spos++)
{
SuccessorNode *successor = (*spos)->get_successor();
- // is it a first item being printed?
- if(spos == predecessor_node->get_successors().begin())
- stream << " connect";
- else
- stream << ",";
+ print_element_attributes(succ_printer.get_current_stream(), *spos);
- print_element_attributes(stream, *spos);
-
HMscNode *successor_node = dynamic_cast<HMscNode*>(successor);
- stream << " L" << node_id_map.get_id(successor_node);
+ succ_printer << " L" << node_id_map.get_id(successor_node);
+ succ_printer.commit_item(node_id_map.get_id(successor_node));
// add successors of this node to the stack
// note: std::list<>::push_back doesn't invalidate iterators
push_back_if_unique<HMscNodePtr>(node_stack, successor_node);
}
+
+ succ_printer.print(stream);
}
print_comments(stream, *npos);
Added: trunk/tests/string_list_printer_test.cpp
===================================================================
--- trunk/tests/string_list_printer_test.cpp (rev 0)
+++ trunk/tests/string_list_printer_test.cpp 2011-12-11 21:16:08 UTC (rev 1222)
@@ -0,0 +1,136 @@
+#include <iostream>
+#include <sstream>
+
+#include "data/Z120/string_list_printer.h"
+
+#define TEST_BEGIN(prologue) {\
+ std::stringstream teststream; \
+ std::cout << prologue << std::endl;
+
+#define TEST_BEGIN_W(prologue) {\
+ std::wstringstream teststream; \
+ std::cout << prologue << std::endl;
+
+#define TEST_END(expected) \
+ std::cout << std::endl; \
+ if (teststream.str() == expected) \
+ std::cout << "TEST PASSED"; \
+ else \
+ { \
+ std::cout << "TEST FAILED" << std::endl; \
+ std::cout << "Expected: \"" << expected << "\"" << std::endl; \
+ std::cout << "Result: \"" << teststream.str() << "\""; \
+ errors++; \
+ } \
+ std::cout << std::endl << std::endl; \
+ }
+
+#define TEST_END_W(expected) \
+ std::cout << std::endl; \
+ if (teststream.str() == expected) \
+ std::cout << "TEST PASSED"; \
+ else \
+ { \
+ std::cout << "TEST FAILED" << std::endl; \
+ std::wcout << "Expected: \"" << expected << "\"" << std::endl; \
+ std::wcout << "Result: \"" << teststream.str() << "\""; \
+ errors++; \
+ } \
+ std::cout << std::endl << std::endl; \
+ }
+
+void custom_printing_func(std::stringstream& out)
+{
+ out << "/attributes/";
+}
+
+
+int main()
+{
+ int errors = 0;
+
+ TEST_BEGIN("Simple usage example");
+ StringListPrinter printer("connect: ", ", ", ";\n");
+ printer.add_item("L2");
+ printer.add_item("L1");
+ printer.add_item("L0");
+ printer.add_item("L1");
+ printer.print(teststream);
+ printer.print(std::cout);
+ TEST_END("connect: L0, L1, L1, L2;\n");
+
+
+ TEST_BEGIN("Items may also be specified by consecutive filling operations");
+ StringListPrinter printer;
+ printer.set_item_separator(","); // an alternative way for specifying parameters
+ printer << 'L';
+ printer << 42;
+ printer.commit_item(); // adds item "L42"
+ printer << 'L';
+ printer << 13;
+ printer.commit_item(); // adds item "L13"
+ // the stream for filling current item can be had for other functions directly
+ // printing to a stream:
+ custom_printing_func(printer.get_current_stream());
+ printer << "L50";
+ printer.commit_item();
+ printer.print(teststream);
+ printer.print(std::cout);
+ TEST_END("/attributes/L50,L13,L42");
+
+
+ TEST_BEGIN("Note the last item is placed as the first item, as \"[\" < \"L\". If some order should be "\
+ "directed, a custom key may be specified both for add_item() and commit_item() methods");
+ StringListPrinter printer;
+ printer.add_item("abc", "2");
+ printer << "def";
+ printer.commit_item("3");
+ printer.add_item("xyz", "1");
+ printer.print(teststream);
+ printer.print(std::cout);
+ TEST_END("xyzabcdef");
+
+ TEST_BEGIN("...even with integer keys, using the basic template class");
+ BasicStringListPrinter<int> printer;
+ printer.add_item("abc", 2);
+ printer << "def";
+ printer.commit_item(3);
+ printer.add_item("xyz", 1);
+ printer.print(teststream);
+ printer.print(std::cout);
+ TEST_END("xyzabcdef");
+
+ TEST_BEGIN("The printer may print to anything overloading operator <<");
+ StringListPrinter printer;
+ printer.add_item("a").add_item("b").add_item("c");
+ std::stringstream ss;
+ printer.print(ss);
+ teststream << ss.str();
+ std::cout << ss.str();
+ TEST_END("abc");
+
+ TEST_BEGIN("... even another StringListPrinter");
+ StringListPrinter sub1("sub1head ", ", ", " sub1tail");
+ sub1.add_item("A").add_item("B").add_item("C");
+ StringListPrinter sub2("sub2head ", ", ", " sub2tail");
+ sub2.add_item("X").add_item("Y").add_item("Z");
+ StringListPrinter main("mainhead ", "; ", " maintail"); // do not confuse with "Mein Teil" by Rammstein ;-)
+ sub1.print(main.get_current_stream());
+ main.commit_item();
+ sub2.print(main.get_current_stream());
+ main.commit_item();
+ main.print(teststream);
+ TEST_END("mainhead sub1head A, B, C sub1tail; sub2head X, Y, Z sub2tail maintail");
+
+ TEST_BEGIN_W("For the cases lexicographic ordering is not suitable, a custom comparator (both "\
+ "for items and keys) may be specified as a template argument. Similarly, the item "\
+ "and key datatypes are also templated");
+ BasicStringListPrinter<int, wchar_t, std::greater<int>, std::less<std::wstring> > printer(L"head ");
+ // printer now uses wstrings, integers as keys; sorting by keys is descending:
+ printer.add_item(L"abc", 3).add_item(L"def", 1).add_item(L"xyz", 2);
+ printer.print(teststream);
+ printer.print(std::wcout);
+ TEST_END_W(L"head abcxyzdef");
+
+ return errors;
+}
Property changes on: trunk/tests/string_list_printer_test.cpp
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: trunk/tests/time_constraints/proper_neg13.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg13.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg13.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -16,7 +16,7 @@
connect L4;
L2: reference NAME time [0,inf);
connect L5;
-L4: connect L5, L3;
+L4: connect L3, L5;
L5: connect L6;
/* MARKED */
L3: reference NAME2 connect L6;
Modified: trunk/tests/time_constraints/proper_neg13.mpr.result1
===================================================================
--- trunk/tests/time_constraints/proper_neg13.mpr.result1 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg13.mpr.result1 2011-12-11 21:16:08 UTC (rev 1222)
@@ -16,7 +16,7 @@
connect L4;
L2: reference NAME time [0,inf);
connect L5;
-L4: connect L5, L3;
+L4: connect L3, L5;
L5: connect L6;
/* MARKED */
L3: reference NAME2 connect L6;
Modified: trunk/tests/time_constraints/proper_neg21.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg21.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg21.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -16,7 +16,7 @@
L1: reference NAME time [0,inf);
bottom/* MARKED */
bottom L3 [0,inf);
- connect L4, L3, L5;
+ connect L3, L4, L5;
L4: connect L1, L3;
L3: reference NAME time [0,inf);
top/* MARKED */
@@ -26,7 +26,7 @@
L6: final;
/* MARKED */
L2: reference A connect L0, L7;
-L7: connect L5, L3;
+L7: connect L3, L5;
endmsc;
msc NAME;
inst asd;
Modified: trunk/tests/time_constraints/proper_neg22.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg22.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg22.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
L1: reference NAME time [0,inf);
connect L4;
L4: final;
Modified: trunk/tests/time_constraints/proper_neg23.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg23.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg23.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
L1: reference NAME time [0,inf);
connect L4;
L4: final;
Modified: trunk/tests/time_constraints/proper_neg24.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg24.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg24.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
L1: reference NAME time [0,inf);
connect L4;
L4: final;
Modified: trunk/tests/time_constraints/proper_neg25.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg25.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg25.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -13,9 +13,9 @@
top/* MARKED */
bottom L4 [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
L1: reference NAME time [0,inf);
- connect L5, L4;
+ connect L4, L5;
L5: final;
/* MARKED */
L4: reference A connect L5;
Modified: trunk/tests/time_constraints/proper_neg26.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg26.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg26.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
@@ -47,7 +47,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
Modified: trunk/tests/time_constraints/proper_neg26.mpr.result.1
===================================================================
--- trunk/tests/time_constraints/proper_neg26.mpr.result.1 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg26.mpr.result.1 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
@@ -28,7 +28,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
Modified: trunk/tests/time_constraints/proper_neg27.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg27.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg27.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -12,7 +12,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
@@ -46,7 +46,7 @@
connect L2, L3;
/* MARKED */
L2: reference NAME connect L3;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference B connect L4;
L4: final;
Modified: trunk/tests/time_constraints/proper_neg27.mpr.result.1
===================================================================
--- trunk/tests/time_constraints/proper_neg27.mpr.result.1 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg27.mpr.result.1 2011-12-11 21:16:08 UTC (rev 1222)
@@ -11,7 +11,7 @@
connect L2, L3;
/* MARKED */
L2: reference NAME connect L3;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference B connect L4;
L4: final;
@@ -24,7 +24,7 @@
/* MARKED */
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1;
+L3: connect L1, L2;
/* MARKED */
L1: reference NAME time [0,inf);
connect L4, L5;
Modified: trunk/tests/time_constraints/proper_neg6.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg6.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg6.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -9,7 +9,7 @@
top L4 [0,inf);
connect L4;
L3: final;
-L4: reference bMSC4 connect L3, L2, L4;
+L4: reference bMSC4 connect L2, L3, L4;
endmsc;
msc bMSC1;
inst p;
Modified: trunk/tests/time_constraints/proper_neg7.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg7.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg7.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -9,7 +9,7 @@
bottom L4 [0,inf);
connect L4;
L3: final;
-L4: reference bMSC4 connect L3, L2, L4;
+L4: reference bMSC4 connect L2, L3, L4;
endmsc;
msc bMSC1;
inst p;
Modified: trunk/tests/time_constraints/proper_neg9.mpr.result
===================================================================
--- trunk/tests/time_constraints/proper_neg9.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/time_constraints/proper_neg9.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -9,7 +9,7 @@
bottom L4 [0,inf);
connect L4;
L3: final;
-L4: reference bMSC connect L3, L2, L4;
+L4: reference bMSC connect L2, L3, L4;
endmsc;
msc bMSC;
inst p;
Modified: trunk/tests/z120_test/z120_time22.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_time22.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/z120_test/z120_time22.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -10,7 +10,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L2, L1, L4;
+L3: connect L1, L2, L4;
L1: reference NAME time [0,inf);
connect L5;
L4: condition mark connect L3;
Modified: trunk/tests/z120_test/z120_time23.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_time23.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/z120_test/z120_time23.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -10,7 +10,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L4, L2, L1;
+L3: connect L1, L2, L4;
L1: reference NAME time [0,inf);
connect L5;
L4: condition mark connect L3;
Modified: trunk/tests/z120_test/z120_time24.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_time24.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/z120_test/z120_time24.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -10,7 +10,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L4, L2, L1;
+L3: connect L1, L2, L4;
L1: reference NAME time [0,inf);
connect L5;
L4: condition mark connect L3;
Modified: trunk/tests/z120_test/z120_time25.mpr.result
===================================================================
--- trunk/tests/z120_test/z120_time25.mpr.result 2011-12-10 00:47:45 UTC (rev 1221)
+++ trunk/tests/z120_test/z120_time25.mpr.result 2011-12-11 21:16:08 UTC (rev 1222)
@@ -10,7 +10,7 @@
connect L2, L3;
L2: reference NAME time [0,inf);
connect L1;
-L3: connect L4, L1, L2;
+L3: connect L1, L2, L4;
L1: reference NAME time [0,inf);
connect L5;
L4: condition mark connect L3;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|