VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Test Interaction Decoder

TestDecoder, defined in testDec.cxx, is derived from DtInteractionDecoder.

Macros help out in the declaration and definition of the decoding functions for individual parameters. The "simple" implementation provided by the macros for a decoding function is to get a pointer to the parameter data from an RTI::ParameterHandleValuePairSet, cast it to a pointer to an appropriate "Net" type, then pass it to one of the interaction class's mutator functions. The implicit cast from the "Net" type to the type expected by the mutator functions will perform byte swapping if necessary.

The TestDecoder constructor just adds its decoding functions to the base class's table using addDecoder().

Note
While decoding functions are implemented as static member functions of the TestDecoder class, this was not strictly necessary - we could have written them as ordinary global function instead. But by implementing them as static members of the class, we can take advantage of some VR-Link macros.

/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/
#if DtHLA
#pragma once
#define DtDECLARE_TEST_ATTR_DECODER(attrName) \
DtDECLARE_ATTR_DECODER(TestStateRepository, attrName)
#define DtDEFINE_SIMPLE_TEST_ATTR_DECODER( \
attrName, netType, inspector) \
DtDEFINE_SIMPLE_TEST_ATTR_DECODER_WITH_CAST( \
attrName, netType, inspector, (netType))
#define DtDEFINE_SIMPLE_TEST_ATTR_DECODER_WITH_CAST( \
attrName, netType, mutator, castExpr) \
DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
TestDecoder, TestStateRepository, \
attrName, netType, mutator, castExpr)
{
public:
DtExerciseConn* exConn,
DtObjClassDesc* classDesc);
virtual ~TestDecoder();
protected:
};
#endif

/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/
#if DtHLA
#include "testDec.h"
#include "testSR.h"
#include <vlutil/vlPrint.h>
// Default constructor
DtExerciseConn* exConn,
DtObjClassDesc* classDesc) :
DtHlaStateDecoder(exConn, classDesc)
{
// Register the individual decoding functions for Test's attributes with
// the object. The decoding functions have names like decodeNumber and
// decodeVector. The macro expands to look like this:
// addDecoder("Number", (DtAttributeDecoder) decodeNumber);
}
{
}
// Decoding functions
// The DtDEFINE_SIMPLE_ATTR_DECODER macro can be used to define a "simple"
// decoding function. Expanded, a decoding function looks like this:
//
// void TestDecoder::decodeNumber(TestStateRepository* stateRep,
// const RTI::AttributeHandleValuePairSet& attrs,
// int index)
// {
// RTI::ULong length = 0;
// // Get value from RTI representation into netVal.
// DtNetInt32* netVal = (DtNetInt32*) attrs.getValuePointer(index, length);
// // Check for size mismatch
// if (length > sizeof(DtNetInt32))
// {
// DtWarn("Size of value decoded for attribute %s (%d)\n",
// "Number", length);
// DtWarn(" is larger than size of %s (%d)\n",
// "DtNetInt32", sizeof(DtNetInt32));
// }
// // Pass the value to the mutator function, assuming the "net" type can
// // be implicitly cast to the native type expected by the mutator.
// stateRep->setNumber(*netVal);
// }
#endif

Document ID: Generated on Tue Aug 10 00:12:31 EDT 2021 from SVN revision 232765
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)