示例#1
0
文件: bond.cpp 项目: alinelena/aten
// Retrieve desired value
bool BondVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("BondVariable::retrieveAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for Bond type.\n", i);
		Messenger::exit("BondVariable::retrieveAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;
	// Check for correct lack/presence of array index given
	if ((accessorData[i].arraySize == 0) && hasArrayIndex)
	{
		Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name));
		Messenger::exit("BondVariable::retrieveAccessor");
		return false;
	}
	else if ((accessorData[i].arraySize > 0) && (hasArrayIndex))
	{
		if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize))
		{
			Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize);
			Messenger::exit("BondVariable::retrieveAccessor");
			return false;
		}
	}
	// Get current data from ReturnValue
	bool result = true;
	Bond* ptr = (Bond*) rv.asPointer(VTypes::BondData, result);
	if ((!result) || (ptr == NULL))
	{
		Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BondData));
		result = false;
	}
	if (result) switch (acc)
	{
		case (BondVariable::I):
			rv.set(VTypes::AtomData, ptr->atomI());
			break;
		case (BondVariable::J):
			rv.set(VTypes::AtomData, ptr->atomJ());
			break;
		case (BondVariable::Order):
			rv.set(ptr->order());
			break;
		case (BondVariable::Type):
			rv.set(Bond::bondType(ptr->type()));
			break;
		default:
			printf("Internal Error: Access to member '%s' has not been defined in BondVariable.\n", qPrintable(accessorData[i].name));
			result = false;
			break;
	}
	Messenger::exit("BondVariable::retrieveAccessor");
	return result;
}
示例#2
0
文件: bond.cpp 项目: alinelena/aten
// Set desired value
bool BondVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex)
{
	Messenger::enter("BondVariable::setAccessor");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nAccessors))
	{
		printf("Internal Error: Accessor id %i is out of range for Bond type.\n", i);
		Messenger::exit("BondVariable::setAccessor");
		return false;
	}
	Accessors acc = (Accessors) i;

	// Check for correct lack/presence of array index given to original accessor, and nature of new value
	bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex);
	if (!result)
	{
		Messenger::exit("BondVariable::setAccessor");
		return false;
	}

	// Get current data from ReturnValue
	Bond* ptr = (Bond*) sourcerv.asPointer(VTypes::BondData, result);
	Bond::BondType bt;
	if ((!result) || (ptr == NULL))
	{
		Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BondData));
		result = false;
	}
	Model* ptrParent = ptr->atomI()->parent();
	if (result) switch (acc)
	{
		case (BondVariable::Type):
			bt = Bond::bondType(newValue.asString(), true);
			if (bt == Bond::nBondTypes) break;
			ptrParent->changeBond(ptr, bt);
			break;
		default:
			printf("BondVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name));
			result = false;
			break;
	}
	Messenger::exit("BondVariable::setAccessor");
	return result;
}