Skip to content

Commit

Permalink
Implement order assignment to functional events
Browse files Browse the repository at this point in the history
Event trees manage the order of functional events.
The order implicitly deduced
from the order of functional event addition into event trees.

Issue #150
  • Loading branch information
rakhimov committed May 4, 2017
1 parent e24745b commit 31bb064
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/event_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ void EventTree::Add(SequencePtr sequence) {
}

void EventTree::Add(FunctionalEventPtr functional_event) {
assert(functional_event->order() == 0 && "Non-unique functional event.");
auto& unordered_event = *functional_event;
mef::AddElement<ValidationError>(std::move(functional_event),
&functional_events_,
"Duplicate functional event: ");
unordered_event.order(functional_events_.size());
}

void EventTree::Add(NamedBranchPtr branch) {
Expand Down
14 changes: 14 additions & 0 deletions src/event_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,24 @@ class Sequence : public Element {
/// Sequences are defined in event trees but referenced in other constructs.
using SequencePtr = std::shared_ptr<Sequence>;

class EventTree; // Manages the order assignment to functional events.

/// Representation of functional events in event trees.
class FunctionalEvent : public Element {
friend class EventTree;

public:
using Element::Element;

/// @returns The order of the functional event in the event tree.
/// @returns 0 if no order has been assigned.
int order() const { return order_; }

private:
/// Sets the functional event order.
void order(int order) { order_ = order; }

int order_ = 0; ///< The order of the functional event.
};

/// Functional events are defined in and unique to event trees.
Expand Down

0 comments on commit 31bb064

Please sign in to comment.