|
From: <ma...@us...> - 2010-09-07 21:31:17
|
Revision: 883
http://scstudio.svn.sourceforge.net/scstudio/?rev=883&view=rev
Author: madzin
Date: 2010-09-07 21:31:10 +0000 (Tue, 07 Sep 2010)
Log Message:
-----------
add absolut time to msc structure and modify z120 parser and z120 save
Modified Paths:
--------------
trunk/src/data/Z120/Context.cpp
trunk/src/data/Z120/Context.h
trunk/src/data/Z120/Context_Impl.h
trunk/src/data/Z120/Z120.g
trunk/src/data/Z120/z120_save.cpp
trunk/src/data/msc.h
trunk/src/data/time.h
Added Paths:
-----------
trunk/tests/z120_test/z120_time11.mpr.result1
Modified: trunk/src/data/Z120/Context.cpp
===================================================================
--- trunk/src/data/Z120/Context.cpp 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/Z120/Context.cpp 2010-09-07 21:31:10 UTC (rev 883)
@@ -92,6 +92,7 @@
context->time_first = unknown;
context->time_second = unknown;
context->time_event = false;
+ context->absolut_time = false;
}
/*
@@ -491,11 +492,50 @@
context->z->print_report(RS_ERROR, TOWSTRING(report));
}
-void add_time_fun(struct Context* context, char* time)
+void clear_time(struct Context* context)
{
+ context->time = "";
+}
+
+void add_time_fun(struct Context* context, char* time_part)
+{
+ context->time += time_part;
+}
+
+void duplicate_time_point(struct Context* context)
+{
+ if(context->absolut_first_set)
+ context->absolut_second_border = context->absolut_first_border;
+}
+
+void set_time_fun(struct Context* context, char* time)
+{
context->time = time;
}
+void set_absolut_time_false_fun(struct Context* context)
+{
+ context->absolut_time = false;
+}
+
+void set_absolut_time_true_fun(struct Context* context)
+{
+ context->absolut_time = true;
+}
+
+void set_absolut_first_or_second_true_fun(struct Context* context)
+{
+ context->absolut_time = true;
+
+ if(!context->absolut_first_set)
+ {
+ context->absolut_first_set = true;
+ context->absolut_first_border = true;
+ }
+ else
+ context->absolut_second_border = true;
+}
+
void set_origin_fun(struct Context* context)
{
context->origin = true;
@@ -932,6 +972,12 @@
void add_time_relation_event_fun(struct Context* context)
{
+ if(context->absolut_time)
+ {
+ add_event_absolut_time_fun(context);
+ return ;
+ }
+
TimeRelationEventPtr relation;
try
{
@@ -970,6 +1016,22 @@
}
}
+void add_event_absolut_time_fun(struct Context* context)
+{
+ //checking the corectness of syntax of the absolut time
+ if(!(context->absolut_first_border == context->absolut_second_border))
+ {
+ context->z->print_report(RS_ERROR, stringize() << L"Warning: wrong definition of absolut time");
+ }
+
+ context->current_event->add_absolut_time(*(new MscTimeIntervalSet<double>(context->time)));
+
+ context->absolut_first_border = false;
+ context->absolut_second_border = false;
+ context->absolut_first_set = false;
+ context->absolut_time = false;
+}
+
/*
* Set name of event which is in time relation with the event
*/
Modified: trunk/src/data/Z120/Context.h
===================================================================
--- trunk/src/data/Z120/Context.h 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/Z120/Context.h 2010-09-07 21:31:10 UTC (rev 883)
@@ -58,8 +58,20 @@
void bug_report_fun(struct Context* context, char* report);
-void add_time_fun(struct Context* context, char* time);
+void clear_time(struct Context* context);
+void add_time_fun(struct Context* context, char* time_part);
+
+void duplicate_time_point(struct Context* context);
+
+void set_time_fun(struct Context* context, char* time);
+
+void set_absolut_time_false_fun(struct Context* context);
+
+void set_absolut_time_true_fun(struct Context* context);
+
+void set_absolut_first_or_second_true_fun(struct Context* context);
+
void set_origin_fun(struct Context* context);
void set_time_dest_fun(struct Context* context);
@@ -99,6 +111,8 @@
void add_time_relation_event_fun(struct Context* context);
+void add_event_absolut_time_fun(struct Context* context);
+
void set_time_reference_event_fun(struct Context* context, char* name);
void create_future_time_relations(struct Context* context);
Modified: trunk/src/data/Z120/Context_Impl.h
===================================================================
--- trunk/src/data/Z120/Context_Impl.h 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/Z120/Context_Impl.h 2010-09-07 21:31:10 UTC (rev 883)
@@ -69,6 +69,10 @@
std::string time;
bool origin;
bool time_dest;
+ bool absolut_time;
+ bool absolut_first_border;
+ bool absolut_first_set;
+ bool absolut_second_border;
/*
* Error handling
Modified: trunk/src/data/Z120/Z120.g
===================================================================
--- trunk/src/data/Z120/Z120.g 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/Z120/Z120.g 2010-09-07 21:31:10 UTC (rev 883)
@@ -1089,7 +1089,10 @@
* Extend the Z120 standart with negative time interval
*/
time_point:
- ('@')? ('-')? (expression | 'inf') //inf has been added for accept inf in time definition but it should be in expression to
+ ('@' { set_absolut_first_or_second_true_fun(context); } )?
+ ('-' { add_time_fun(context, "-"); } )?
+ (expression { add_time_fun(context, (char*) $expression.text->chars); }
+ | 'inf' { add_time_fun(context, "inf"); } ) //inf has been added for accept inf in time definition but it should be in expression to
;
@@ -1112,15 +1115,14 @@
// ----- Time Interval
time_interval:
+ {
+ clear_time(context);
+ set_absolut_time_false_fun(context);
+ }
(interval_label)?
( (('@')? ('(' | '[') (time_point)? ',')=> bounded_time
- {
- add_time_fun(context, (char*) $bounded_time.text->chars);
- } (measurement)?
- | singular_time
- {
- add_time_fun(context, (char*) $singular_time.text->chars);
- })
+ (measurement)?
+ | singular_time )
;
/*
@@ -1144,24 +1146,42 @@
;
singular_time:
- (
-'[' time_point ']' addition_time?)
+ ('[' { add_time_fun(context, "["); }
+ time_point { duplicate_time_point(context); }
+ ']' { add_time_fun(context, "]"); }
+ addition_time? )
| measurement
;
bounded_time:
- ('@')? ('(' | '[')
- (time_point)? ',' (time_point)?
- (')' | ']') addition_time?
+ ('@' { set_absolut_time_true_fun(context); })?
+ left_bracket { add_time_fun(context, (char*) $left_bracket.text->chars); }
+ time_borders
+ right_bracket { add_time_fun(context, (char*) $right_bracket.text->chars); }
+ (addition_time)?
;
+left_bracket:
+ ('(' | '[')
+;
+
+time_borders:
+ (time_point)?
+ ',' { add_time_fun(context, ","); }
+ (time_point)?
+;
+
+right_bracket:
+ (')' | ']')
+;
/*
* Extend the Z120 standart with new definition of time interval.
*
* It supports definition as a chain of intervals connected with +
*/
addition_time:
- '+' ( (('@')? ('(' | '[') (time_point)? ',')=> bounded_time | singular_time)
+ '+' { add_time_fun(context, "+"); }
+ ( (('@')? ('(' | '[') (time_point)? ',')=> bounded_time | singular_time)
;
Modified: trunk/src/data/Z120/z120_save.cpp
===================================================================
--- trunk/src/data/Z120/z120_save.cpp 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/Z120/z120_save.cpp 2010-09-07 21:31:10 UTC (rev 883)
@@ -363,12 +363,52 @@
}
}
+void print_absolut_time(std::ostream& stream, const MscTimeIntervalSetD& interval)
+{
+ const std::list< MscTimeInterval<double> > constraints = interval.get_set();
+
+ for(std::list< MscTimeInterval<double> >::const_iterator it = constraints.begin();
+ it != constraints.end(); it++)
+ {
+ if(it->get_begin_value() != it->get_end_value())
+ {
+ if (it->get_begin_closed())
+ stream << "@[";
+ else
+ stream << "(";
+
+ stream << it->get_begin() << "," << it->get_end();
+
+ if (it->get_end_closed())
+ stream << "]";
+ else
+ stream << ")";
+ }
+ else
+ stream << "[@" << it->get_begin() << "]";
+ }
+}
+
void Z120::print_time_relations(std::ostream& stream, PtrIDMap<EventPtr>& event_id_map,
const EventPtr& event)
{
size_t printed = 0;
const TimeRelationEventPtrList& relations = event->get_time_relations();
+ const MscTimeIntervalSetDList& absolut_times = event->get_absolut_times();
+ // process all absolut time constraints
+ for(MscTimeIntervalSetDList::const_iterator apos = absolut_times.begin();
+ apos != absolut_times.end(); apos++)
+ {
+ if(!printed++)
+ stream << "time ";
+ else
+ stream << ", ";
+
+ //do not used the print function of MscTimeInterval due to [@3]
+ print_absolut_time(stream, *apos);
+ }
+
// process all time relations
for(TimeRelationEventPtrList::const_iterator rpos = relations.begin();
rpos != relations.end(); rpos++)
Modified: trunk/src/data/msc.h
===================================================================
--- trunk/src/data/msc.h 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/msc.h 2010-09-07 21:31:10 UTC (rev 883)
@@ -139,6 +139,7 @@
typedef boost::intrusive_ptr<TimeRelationRefNode> TimeRelationRefNodePtr;
typedef std::set<TimeRelationRefNodePtr> TimeRelationRefNodePtrSet;
typedef MscTimeIntervalSet<double> MscTimeIntervalSetD;
+typedef std::list<MscTimeIntervalSetD> MscTimeIntervalSetDList;
#endif
@@ -1601,6 +1602,7 @@
#ifdef _TIME_H_
TimeRelationEventPtrList m_time_relations;
+ MscTimeIntervalSetDList m_absolut_time;
#endif
/**
@@ -1674,7 +1676,34 @@
m_time_relations.clear();
}
+ void add_absolut_time(const MscTimeIntervalSetD& absolut_time)
+ {
+ m_absolut_time.push_back(absolut_time);
+ }
+ void remove_absolut_time(const MscTimeIntervalSetD& absolut_time)
+ {
+ MscTimeIntervalSetDList::iterator pos =
+ std::find(m_absolut_time.begin(), m_absolut_time.end(), absolut_time);
+
+ if(pos != m_absolut_time.end())
+ m_absolut_time.erase(pos);
+ }
+
+ void set_absolut_time(const MscTimeIntervalSetDList& list)
+ {
+ m_absolut_time = list;
+ }
+
+ const MscTimeIntervalSetDList& get_absolut_times() const
+ {
+ return m_absolut_time;
+ }
+
+ void clear_absolut_times()
+ {
+ m_absolut_time.clear();
+ }
#endif
/**
Modified: trunk/src/data/time.h
===================================================================
--- trunk/src/data/time.h 2010-09-07 16:00:50 UTC (rev 882)
+++ trunk/src/data/time.h 2010-09-07 21:31:10 UTC (rev 883)
@@ -1266,7 +1266,7 @@
m_set.clear();
}
- IntervalList& get_set()
+ const IntervalList& get_set() const
{
return m_set;
}
Added: trunk/tests/z120_test/z120_time11.mpr.result1
===================================================================
--- trunk/tests/z120_test/z120_time11.mpr.result1 (rev 0)
+++ trunk/tests/z120_test/z120_time11.mpr.result1 2010-09-07 21:31:10 UTC (rev 883)
@@ -0,0 +1,39 @@
+Warning 09: Reference to nonexisting MSC: Fish
+OK: z120_time11 is correct, should be correct
+
+mscdocument z120_time11;
+msc Main;
+initial connect L0;
+L0: connect L1, L2;
+L1: reference Subprocess connect L3, L4;
+L2: reference Subprocess time [1,2);
+ top top L3 [2,4], bottom L1 (1,10);
+ connect L1;
+L3: reference Fish connect L4;
+L4: final;
+endmsc;
+msc Subprocess;
+inst P1;
+inst P2;
+P1: instance;
+out NAME,0 to P2;
+label e0;
+out NAME,1 to P2;
+time e1 [7];
+label e1;
+in NAME,2 from P2;
+endinstance;
+P2: instance;
+concurrent;
+label e2;
+in NAME,0 from P1 before e3;
+time e4 [12];
+label e3;
+in NAME,1 from P1;
+endconcurrent;
+label e4;
+out NAME,2 to P1;
+endinstance;
+endmsc;
+msc Fish;
+endmsc;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|