Example #1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool EventParameters::add(Pick* pick) {
	if ( pick == NULL )
		return false;

	// Element has already a parent
	if ( pick->parent() != NULL ) {
		SEISCOMP_ERROR("EventParameters::add(Pick*) -> element has already a parent");
		return false;
	}

	if ( PublicObject::IsRegistrationEnabled() ) {
		Pick* pickCached = Pick::Find(pick->publicID());
		if ( pickCached ) {
			if ( pickCached->parent() ) {
				if ( pickCached->parent() == this )
					SEISCOMP_ERROR("EventParameters::add(Pick*) -> element with same publicID has been added already");
				else
					SEISCOMP_ERROR("EventParameters::add(Pick*) -> element with same publicID has been added already to another object");
				return false;
			}
			else
				pick = pickCached;
		}
	}

	// Add the element
	_picks.push_back(pick);
	pick->setParent(this);

	// Create the notifiers
	if ( Notifier::IsEnabled() ) {
		NotifierCreator nc(OP_ADD);
		pick->accept(&nc);
	}

	// Notify registered observers
	childAdded(pick);
	
	return true;
}
Example #2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool EventParameters::updateChild(Object* child) {
	Pick* pickChild = Pick::Cast(child);
	if ( pickChild != NULL ) {
		Pick* pickElement
			= Pick::Cast(PublicObject::Find(pickChild->publicID()));
		if ( pickElement && pickElement->parent() == this ) {
			*pickElement = *pickChild;
			return true;
		}
		return false;
	}

	Amplitude* amplitudeChild = Amplitude::Cast(child);
	if ( amplitudeChild != NULL ) {
		Amplitude* amplitudeElement
			= Amplitude::Cast(PublicObject::Find(amplitudeChild->publicID()));
		if ( amplitudeElement && amplitudeElement->parent() == this ) {
			*amplitudeElement = *amplitudeChild;
			return true;
		}
		return false;
	}

	Reading* readingChild = Reading::Cast(child);
	if ( readingChild != NULL ) {
		Reading* readingElement
			= Reading::Cast(PublicObject::Find(readingChild->publicID()));
		if ( readingElement && readingElement->parent() == this ) {
			*readingElement = *readingChild;
			return true;
		}
		return false;
	}

	Origin* originChild = Origin::Cast(child);
	if ( originChild != NULL ) {
		Origin* originElement
			= Origin::Cast(PublicObject::Find(originChild->publicID()));
		if ( originElement && originElement->parent() == this ) {
			*originElement = *originChild;
			return true;
		}
		return false;
	}

	FocalMechanism* focalMechanismChild = FocalMechanism::Cast(child);
	if ( focalMechanismChild != NULL ) {
		FocalMechanism* focalMechanismElement
			= FocalMechanism::Cast(PublicObject::Find(focalMechanismChild->publicID()));
		if ( focalMechanismElement && focalMechanismElement->parent() == this ) {
			*focalMechanismElement = *focalMechanismChild;
			return true;
		}
		return false;
	}

	Event* eventChild = Event::Cast(child);
	if ( eventChild != NULL ) {
		Event* eventElement
			= Event::Cast(PublicObject::Find(eventChild->publicID()));
		if ( eventElement && eventElement->parent() == this ) {
			*eventElement = *eventChild;
			return true;
		}
		return false;
	}

	return false;
}