In the interface of ICapeThermoMaterial, I need to use SetPresentPhases & GetPresentPhases, they all have the parameter "phaseStatus", it is a CapeArrayEnumeration type, like the following:
enum eCapePhaseStatus
{
CAPE_UNKNOWNPHASESTATUS = 0,
CAPE_ATEQUILIBRIUM = 1,
CAPE_ESTIMATES = 2
};
My building environment is Visual C++ 2005, so my code like this:
VARIANT phaseLabels,phaseStatus;
phaseLabels.vt=VT_EMPTY;
phaseStatus.vt=VT_EMPTY;
pThermoMaterial->GetPresentPhases(&phaseLabels,&phaseStatus); // the pThermoMaterial is a smart pointer to the ICapeThermoMaterial ,has been initialized.
Then the PME will return the phaseLabels and phaseStaus, I know the phaseLabels' type is VT_BSTR, but what is phaseStatus' ? VT_I4 , VT_INT or VT_R8 ?
What is the VARIANT's value type of enumeration
Re: What is the VARIANT's value type of enumeration
This information is sadly lacking from the standard specifications.
If you pass an enumeration object to others, I would use VT_I4. If you interpret enumeration objects passed to you from others, I would be ready to interpret the most common integer types: VT_I2, VT_I4, VT_UI2, VT_UI4, VT_INT, VT_UINT. The real type VT_R8 does not make too much sense in this context.
I have yet to see any other interpretation than VT_I4 as this corresponds to CapeInteger.
Similar confusion exists over the data type of dimensionality of the parameters. This has now been settled upon and should be VT_R8. However, when interpreting data from other sources, I would be ready to deal with other numeric types, especially VT_I4.
If you pass an enumeration object to others, I would use VT_I4. If you interpret enumeration objects passed to you from others, I would be ready to interpret the most common integer types: VT_I2, VT_I4, VT_UI2, VT_UI4, VT_INT, VT_UINT. The real type VT_R8 does not make too much sense in this context.
I have yet to see any other interpretation than VT_I4 as this corresponds to CapeInteger.
Similar confusion exists over the data type of dimensionality of the parameters. This has now been settled upon and should be VT_R8. However, when interpreting data from other sources, I would be ready to deal with other numeric types, especially VT_I4.
Re: What is the VARIANT's value type of enumeration
Would that call for an item in an Errata and Clarifications document, starting with the Errata and Clarifications document for Thermo 1.1 even if this issue appears within other CAPE-OPEN specifications?
Re: What is the VARIANT's value type of enumeration
Yes - actually this belongs to the M&T Sig.
Re: What is the VARIANT's value type of enumeration
I am not sure that an Errata and Clarifications document is needed in this case. This is more of a a "How to" question, and it would seem that the forum is an appropriate location for that.
First off, in C++, enums are integer data types. The SAFEARRAY can be an integer array, and the VARIANT of type VT_ARRAY | VT_I4. I have created some C++ code in VS2008. I am including the main program and two functions: one returns a SAFEARRAY by reference and the other returns a VARIANT wrapping the SAFEARRAY. The code I have to create the SAFEARRAY, and wrap it waith a VARIANT looks like this...
The calling code looks like this...
When I run this, both retrievedStatuses and retrievedStatuses2 contain an array of CapePhaseStatus enum data.
First off, in C++, enums are integer data types. The SAFEARRAY can be an integer array, and the VARIANT of type VT_ARRAY | VT_I4. I have created some C++ code in VS2008. I am including the main program and two functions: one returns a SAFEARRAY by reference and the other returns a VARIANT wrapping the SAFEARRAY. The code I have to create the SAFEARRAY, and wrap it waith a VARIANT looks like this...
Code: Select all
//This code defines the CapePhaseStatus enumeration.
typedef enum CapePhaseStatus{
CAPE_UNKNOWNPHASESTATUS = 0,
CAPE_ATEQUILIBRIUM = 1,
CAPE_ESTIMATES = 2
} PhaseStatus;
Code: Select all
// This class creates the SAFEARRAY and VARIANT
class TestSafeArray
{
public:
TestSafeArray(void){};
~TestSafeArray(void);
HRESULT CreateSafeArray(SAFEARRAY** phaseStatus)
{
// Create an array of Phases Statuses
CapePhaseStatus statuses[6];
statuses[0] = CAPE_ATEQUILIBRIUM;
statuses[1] = CAPE_ESTIMATES;
statuses[2] = CAPE_UNKNOWNPHASESTATUS;
statuses[3] = CAPE_ATEQUILIBRIUM;
statuses[4] = CAPE_ESTIMATES;
statuses[5] = CAPE_UNKNOWNPHASESTATUS;
// Create D array of long integers.
SAFEARRAYBOUND sabdBounds[1] = { sizeof(statuses)/sizeof(CapePhaseStatus), 0};
SAFEARRAY* retVal = SafeArrayCreate(VT_I4, 1, sabdBounds);
retVal->cLocks++;
// Fill array with values
retVal->pvData = &statuses;
*phaseStatus = retVal;
return S_OK;
}
HRESULT CreateVariantArray(VARIANT** phaseStatus)
{
VARIANT *retVal = new VARIANT();
VariantInit(retVal);
retVal->vt = VT_ARRAY | VT_I4;
this->CreateSafeArray(&retVal->parray);
*phaseStatus = retVal;
return S_OK;
}
};
Code: Select all
int _tmain(int argc, _TCHAR* argv[])
{
// Create an instance of the class that makes the enum arrays...
TestSafeArray* tester = new TestSafeArray();
// Try as SafeArray...
SAFEARRAY *pSafeArray;
tester->CreateSafeArray(&pSafeArray);
// Get an array of ints from the SafeArray
SAFEARRAYBOUND arrayBounds = pSafeArray->rgsabound[0];
int lowerBound = (int)arrayBounds.lLbound;
int elements = (int)arrayBounds.cElements;
int *intValues = (int*)pSafeArray->pvData;
// convert the ints to CapePhaseStatuses
CapePhaseStatus retrievedStatuses[10];
for (int i = lowerBound; i < lowerBound+elements; i++)
{
int temp = intValues[i];
retrievedStatuses[i] = (CapePhaseStatus)temp;
}
pSafeArray->cLocks--;
// Now do as a VARIANT...
VARIANT *pVariant;
tester->CreateVariantArray(&pVariant);
// Get an array of ints from the SafeArray
arrayBounds = pVariant->parray->rgsabound[0];
lowerBound = (int)arrayBounds.lLbound;
elements = (int)arrayBounds.cElements;
intValues = (int*)pVariant->parray->pvData;
CapePhaseStatus retrievedStatuses2[10];
for (int i = lowerBound; i < lowerBound+elements; i++)
{
int temp = intValues[i];
retrievedStatuses2[i] = (CapePhaseStatus)temp;
}
pVariant->parray->cLocks--;
return 0;
}
Re: What is the VARIANT's value type of enumeration
It would help to state that enumeration types are to be treated as CapeInteger then. Which makes sense, but it is not clear as CAPE-OPEN is not built upon C++ assumptions.First off, in C++, enums are integer data types.
I do agree that this is the most sensible data type and all implementations seem to be using that as it is.