Esempio n. 1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Origin::add(Magnitude* magnitude) {
	if ( magnitude == NULL )
		return false;

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

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

	// Add the element
	_magnitudes.push_back(magnitude);
	magnitude->setParent(this);

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

	// Notify registered observers
	childAdded(magnitude);
	
	return true;
}
Esempio n. 2
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Origin::updateChild(Object* child) {
	Comment* commentChild = Comment::Cast(child);
	if ( commentChild != NULL ) {
		Comment* commentElement = comment(commentChild->index());
		if ( commentElement != NULL ) {
			*commentElement = *commentChild;
			return true;
		}
		return false;
	}

	// Do not know how to fetch child of type CompositeTime without an index

	Arrival* arrivalChild = Arrival::Cast(child);
	if ( arrivalChild != NULL ) {
		Arrival* arrivalElement = arrival(arrivalChild->index());
		if ( arrivalElement != NULL ) {
			*arrivalElement = *arrivalChild;
			return true;
		}
		return false;
	}

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

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

	return false;
}