コード例 #1
0
ファイル: pollresult.cpp プロジェクト: VlinderSoftware/rtimdb
	unsigned int PollResult::size() const noexcept
	{
		if (!size_known_)
		{
			awaitTransactionDone();
			// class 0 returns the values of all the mapped points. We do not allow 
			// (by design, not enforced) the mapping to change after initialization,
			// so the size of the mapping is the size of the class 0 response.
			class_0_size_ = descriptor_.poll_class_0_ ? consumer_->getMappingSize() : 0;
			// for classes 1, 2 and 3, it's slightly more complicated: we return any  
			// event that has occurred to lead to the version of the database
			// we're polling, so we can't just count the total number of events:
			// we need to count the events for which the version <= ours 
			// (DataStore::startTransaction does a post-increment on the version)
			class_1_size_ = descriptor_.poll_class_1_ ? getEventCount(EventClass::class_1__) : 0;
			class_2_size_ = descriptor_.poll_class_1_ ? getEventCount(EventClass::class_2__) : 0;
			class_3_size_ = descriptor_.poll_class_1_ ? getEventCount(EventClass::class_3__) : 0;
			result_size_ = class_0_size_ + class_1_size_ + class_2_size_ + class_3_size_;
			size_known_ = true;
		}
		else
		{ /* memo-ized: we already know the answer */ }

		return result_size_;
	}
コード例 #2
0
ファイル: TestEvent.cpp プロジェクト: punitkoura/viking
int main()
{
{
	auto s = std::make_shared<vik::EventSource>();
	auto l = std::make_shared<EventListenerTester>();

	// intentionally not using the vik::Event constructor
	// because it requires GameApp to be defined, which means
	// including a bazillion other files.
	BogusEvent bogusEvent;

	// test no events
	l->resetEventCount();
	s->onEvent(bogusEvent);
	test_assert(l->getEventCount() == 0);

	l->resetEventCount();
	// test adding listener
	s->addListener(l);
	// test sending events
	s->onEvent(bogusEvent);
	s->onEvent(bogusEvent);
	s->onEvent(bogusEvent);
	test_assert(l->getEventCount() == 3);
	// test removing listener
	l->resetEventCount();
	s->removeListener(l);
	s->onEvent(bogusEvent);
	test_assert(l->getEventCount() == 0);

	// test listener being removed by being destroyed
	{
		auto l2 = std::make_shared<EventListenerTester>();
		s->addListener(l2);
	}
	s->onEvent(bogusEvent);
}
	generateReport();
}
コード例 #3
0
ファイル: MxmlMeasure.cpp プロジェクト: ahwitz/verovio
bool MxmlMeasure::parseMeasure(xml_node mel) {
	bool output = true;
	vector<vector<int> > staffVoiceCounts;
	setStartTimeOfMeasure();

	HumNum starttime = getStartTime();
	HumNum st   = starttime;
	HumNum maxst = starttime;

	xml_node nextel;
	for (auto el = mel.first_child(); el; el = el.next_sibling()) {
		MxmlEvent* event = new MxmlEvent(this);
		m_events.push_back(event);
		nextel = el.next_sibling();
		output &= event->parseEvent(el, nextel, starttime);
		starttime += event->getDuration();
		if (starttime > maxst) {
			maxst = starttime;
		}
	}
	setDuration(maxst - st);

	// Should no longer be needed:
	// calculateDuration();

   bool needdummy = false;

   MxmlMeasure* pmeasure = getPreviousMeasure();
   if (getTimeSigDur() <= 0) {
      if (pmeasure) {
         setTimeSigDur(pmeasure->getTimeSigDur());
      }
   }

   if (getDuration() == 0) {
      if (pmeasure) {
         setDuration(pmeasure->getTimeSigDur());
      } else {
         setTimeSigDur(getTimeSigDur());
      }
      needdummy = true;
   }

	// Maybe check for overfull measures around here

   if (needdummy || getEventCount() == 0) {
      // if the duration of the measure is zero, then set the duration
      // of the measure to the duration of the time signature
      // This is needed for certain cases of multi-measure rests, where no
      // full-measure rest is given in the measure (Sibelius does this).
      setDuration(getTimeSigDur());
		addDummyRest();
   }

   // Neeed to check for empty voice/layers occuring lower in the
   // voice index list than layers which contain notes.  For example
   // if voice/layer 2 contains notes, but voice/layer 1 does not, then
   // a dummy full-measure rest should fill voice/layer 1.  The voice
   // layer 1 should be filled with the duration of the measure according
   // to the other voice/layers in the measure.  This is done later
   // after a voice analysis has been done in
   // musicxml2hum_interface::insertMeasure(), specifically:
	// musicxml2hum_interface::checkForDummyRests().

	sortEvents();

	return output;
}