示例#1
0
void daeMetaArrayAttribute::copy(daeElement* to, daeElement *from) {
	daeArray* toArray = (daeArray*)getWritableMemory(to);
	daeArray* fromArray = (daeArray*)getWritableMemory(from);
	daeInt typeSize = _type->getSize();
	daeInt cnt = (daeInt)fromArray->getCount();
	toArray->setRawCount( cnt );
	//memcpy( toArray->getRawData(), fromArray->getRawData(), cnt * typeSize );
	daeChar *toData = toArray->getRawData();
	daeChar *fromData = fromArray->getRawData();
	daeChar str[4096];
	for ( int i = 0; i < cnt; i++ ) {
		_type->memoryToString( fromData+i*typeSize, str, 2048 );
		_type->stringToMemory( str, toData+i*typeSize );
	}
}
daeInt
daeMetaElementAttribute::getCount(daeElement* e)
{
	if (e == NULL)
		return 0;
	return ((*((daeElementRef*)getWritableMemory(e))) != NULL);
}
示例#3
0
daeInt
daeMetaAttribute::getCount(daeElement* e)
{
	if (e == NULL)
		return 0;
	return (getWritableMemory(e) != NULL);
}
示例#4
0
void
daeMetaArrayAttribute::set(daeElement* e, daeString s)
{
	if( _type->getTypeEnum() == daeAtomicType::FloatType || _type->getTypeEnum() == daeAtomicType::DoubleType ) {
		if ( strcmp(s, "NaN") == 0 ) {
			char msg[256];
			sprintf(msg, "NaN encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
			daeErrorHandler::get()->handleWarning(msg);
		}
		else if ( strcmp(s, "INF") == 0 ) {
			s = "999999.9";
			//quick workaround for http://sourceforge.net/tracker/index.php?func=detail&aid=1530106&group_id=157838&atid=805424
			//char msg[256];
			//sprintf(msg, "INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
			//daeErrorHandler::get()->handleWarning( msg );
		}
		else if ( strcmp(s, "-INF") == 0 ) {
			s = "-999999.9";
			//quick workaround for http://sourceforge.net/tracker/index.php?func=detail&aid=1530106&group_id=157838&atid=805424
			//char msg[256];
			//sprintf(msg, "-INF encountered while setting %s attribute in %s element.\n", (daeString)_name, (daeString)_container->getName() );
			//daeErrorHandler::get()->handleWarning( msg );
		}
	}
	daeArray* array = (daeArray*)getWritableMemory(e);
	daeInt typeSize = _type->getSize();
	daeInt cnt = (daeInt)array->getCount();
	array->setRawCount(++cnt);
	_type->stringToMemory((char*)s, array->getRawData()+(cnt-1)*typeSize);
}
daeElement *
daeMetaElementArrayAttribute::placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after )
{
	if ((parent == NULL)||(child == NULL))
		return NULL;
	if ( child->getMeta() != _elementType || strcmp( child->getElementName(), _name ) != 0 ) {
		return NULL;
	}
	daeElement *p = child->getParentElement();
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
	if ( _maxOccurs != -1 && (daeInt)era->getCount()-offset >= _maxOccurs ) {
		return NULL;
	}
	removeElement( p, child );
	child->setParentElement( parent );

	if ( before != NULL && before->getMeta() == _elementType ) {
		size_t idx(0);
		if ( era->find( before, idx ) == DAE_OK ) {
			era->insertAt( idx, child );
		}
	}
	else if ( after != NULL && after->getMeta() == _elementType ) {
		size_t idx(0);
		if ( era->find( after, idx ) == DAE_OK ) {
			era->insertAt( idx+1, child );
		}
	}
	else {
		era->append(child);
	}
	ordinal = _ordinalOffset;

	return child;
}
daeElement *
daeMetaElementAttribute::placeElement(daeElement* parent, daeElement* child, daeUInt &ordinal, daeInt offset, daeElement* before, daeElement *after )
{
	(void)offset;
	(void)before;
	(void)after;
	if ((parent == NULL)||(child == NULL))
		return NULL;
	if ( child->getMeta() != _elementType || strcmp( child->getElementName(), _name ) != 0 ) {
		return NULL;
	}
	if (child->getParentElement() == parent) {
		//I Don't know why this gets called when the child already has this as parent.
		return child;
	}
	daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
	
	if ( *er != NULL )
	{
		return NULL;
	}

	daeElement::removeFromParent( child );
	child->setParentElement( parent );

	*er = child;
	ordinal = _ordinalOffset;

	return child;
}
void daeMetaElementArrayAttribute::getChildren( daeElement *parent, daeElementRefArray &array ) {
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
	size_t cnt = era->getCount();
	for ( size_t x = 0; x < cnt; x++ ) {
		array.appendUnique( era->get(x) );
	}
}
void
daeMetaElementArrayAttribute::setDocument( daeElement * parent, daeDocument* c )
{
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory( parent );
	for ( unsigned int i = 0; i < era->getCount(); i++ ) {
		era->get(i)->setDocument( c );
	}
}
void
daeMetaElementAttribute::setDocument( daeElement * parent, daeDocument* c )
{
	daeElementRef* er = (daeElementRef*)getWritableMemory( parent );
	if ( ((daeElement*)(*er)) != NULL ) {
		(*er)->setDocument( c );
	}
}
示例#10
0
void
daeMetaArrayAttribute::set(daeElement* e, daeString s)
{
	daeArray* array = (daeArray*)getWritableMemory(e);
	daeInt typeSize = _type->getSize();
	daeInt cnt = (daeInt)array->getCount();
	array->setRawCount(++cnt);
	_type->stringToMemory((char*)s, array->getRawData()+(cnt-1)*typeSize);
}
void daeMetaElementAttribute::set(daeElement* e, daeString s)
{
	//_type->stringToMemory((char*)s, getWritableMemory(e));
	daeElementRef *ref = (daeElementRef*)(getWritableMemory(e));
	if ((*ref) == NULL) {
		(*ref) = _elementType->create();
	}
	(*ref)->getMeta()->getValueAttribute()->stringToMemory((*ref), s);
}
示例#12
0
daeMemoryRef
daeMetaArrayAttribute::get(daeElement* e, daeInt index)
{
	if (e == NULL)
		return NULL;
	daeArray* era = (daeArray*)getWritableMemory(e);
	if (era == NULL || index >= (daeInt)era->getCount() )
		return NULL;
	return era->getRawData()+(index*era->getElementSize());
}
示例#13
0
daeInt
daeMetaArrayAttribute::getCount(daeElement *e)
{
	if (e == NULL)
		return 0;
	daeArray* era = (daeArray*)getWritableMemory(e);
	if (era == NULL)
		return 0;
	return (daeInt)era->getCount();
}
示例#14
0
void
daeMetaArrayAttribute::resolve(daeElementRef element)
{
	daeArray* era = (daeArray*)getWritableMemory(element);
	size_t cnt = era->getCount();
	for ( size_t i = 0; i < cnt; i++ )
	{
		_type->resolve( element, era->getRawData()+(i*era->getElementSize()) );
	}
}
daeMemoryRef
daeMetaElementArrayAttribute::get(daeElement* e, daeInt index)
{
	if (e == NULL)
		return NULL;
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(e);
	if (era == NULL || index >= (daeInt)era->getCount() )
		return NULL;
	return (daeMemoryRef)&(era->get(index));
}
// These are the opposite of the placeElement functions above
daeBool
daeMetaElementAttribute::removeElement(daeElement* parent, daeElement* child)
{
	(void)child; // silence unused variable warning

	if ((parent == NULL)||(child == NULL ))
		return false;

	daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
	if ( *er != child )  {
		return false;
	}
	*er = NULL;
	return true;
}
daeBool
daeMetaElementArrayAttribute::removeElement(daeElement* parent,
										   daeElement* child)
{
	if ((parent == NULL)||(child == NULL))
		return false ;
	
	daeElementRefArray* era = (daeElementRefArray*)getWritableMemory(parent);
/*	if ( (daeInt)era->getCount() <= _minOccurs ) {
		return false;
	}*/
	daeInt error = era->remove(child);
	if ( error != DAE_OK ) {
		return false;
	}
	return true;
}
示例#18
0
void
daeMetaAttribute::set(daeElement* e, daeString s)
{
	_type->stringToMemory((char*)s, getWritableMemory(e));
}
示例#19
0
void daeMetaAttribute::copy(daeElement* to, daeElement *from) {
	daeChar str[4096];
	_type->memoryToString( getWritableMemory(from), str, 4096 );
	_type->stringToMemory( str, getWritableMemory( to ) );
	//memcpy( getWritableMemory( to ), getWritableMemory( from ), getSize() );
}
示例#20
0
daeMemoryRef
daeMetaAttribute::get(daeElement *e, daeInt index)
{
	(void)index; 
	return getWritableMemory(e);
}
示例#21
0
void
daeMetaAttribute::resolve(daeElementRef element)
{
	if (_type != NULL)
		_type->resolve(element, getWritableMemory(element) );
}
void daeMetaElementAttribute::getChildren( daeElement *parent, daeElementRefArray &array ) {
	daeElementRef* er = (daeElementRef*)getWritableMemory(parent);
	if ( *er != NULL ) {
		array.appendUnique( *er );
	}
}
void daeMetaElementAttribute::copy(daeElement* to, daeElement *from) {
	daeElement *cpy = (*(daeElementRef*)(getWritableMemory(from)))->clone();
	(*(daeElementRef*)(getWritableMemory(to))) = cpy;
}