VR-Link API Documentation for HLA 1516
hStateEncoder.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 *********************************************************************/
00005 
00008 
00009 #ifndef DtHlaStateEncoder_H_
00010 #define DtHlaStateEncoder_H_
00011 
00012 #if DtHLA 
00013 
00014 
00015 #include <vlutil/vlMachineTypes.h>
00016 
00017 #include "rtiNamespace.h"
00018 #include "rtiCompatibility.h"
00019 #include <map>
00020 
00021 class DT_DLL_VL DtExerciseConn;
00022 class DT_DLL_VL DtObjClassDesc;
00023 class DT_DLL_VL DtStateRepository;
00024 class DT_DLL_VL DtStateMsg;
00025 
00029 class DT_DLL_VL DtHlaStateEncoder
00030 {
00031 public:
00032 
00034    DtHlaStateEncoder( DtExerciseConn* exConn,
00035       DtObjClassDesc* classDesc);
00036 
00038    virtual ~DtHlaStateEncoder();
00039 
00041    DtHlaStateEncoder(const DtHlaStateEncoder& orig);
00042 
00044    DtHlaStateEncoder& operator=(const DtHlaStateEncoder& orig);
00045 
00049    typedef void (*DtAttributeEncoder)(
00050       const DtStateRepository& stateRep,
00051       RTI::AttributeHandleValuePairSet* avList,
00052       RTI::AttributeHandle handle);
00053 
00055    typedef bool (*DtAttributeChecker)(
00056       const DtStateRepository& stateRep,
00057       const DtStateRepository& asSeenByRemote);
00058 
00064    DtAttributeEncoder addEncoder(RTI::AttributeHandle hand,
00065       DtAttributeEncoder func);
00066    DtAttributeEncoder removeEncoder(RTI::AttributeHandle hand);
00067 
00074    DtAttributeEncoder addEncoder(char* name,
00075       DtAttributeEncoder func, bool complain = true);
00076    DtAttributeEncoder removeEncoder(char* name, bool complain = true);
00077 
00083    DtAttributeChecker addChecker(RTI::AttributeHandle hand,
00084       DtAttributeChecker func);
00085    DtAttributeChecker removeChecker(RTI::AttributeHandle hand);
00086 
00093    DtAttributeChecker addChecker(char* name,
00094       DtAttributeChecker func, bool complain = true);
00095    DtAttributeChecker removeChecker(char* name, bool complain = true);
00096 
00098    virtual DtAttributeEncoder encoder(const RTI::AttributeHandle &handle) ;
00099 
00101    virtual DtAttributeChecker checker(const RTI::AttributeHandle &handle) ;
00102 
00110    virtual void encode(const DtStateRepository& stateRep,
00111       const DtStateRepository& asSeenByRemote,
00112       const RTI::AttributeHandleSet& neededAttrs,
00113       const RTI::AttributeHandleSet& includeThese,
00114       DtStateMsg* msg);
00115 
00117    virtual RTI::ObjectClassHandle objectClassHandle();
00118 
00123    virtual DtHlaStateEncoder* clone(DtObjClassDesc* classDesc) const;
00124 
00126    virtual DtHlaStateEncoder* clone() const;
00127 
00128 public:
00129 
00133    static bool trueChecker(const DtStateRepository& stateRep,
00134       const DtStateRepository& asSeenByRemote);
00135 
00139    static bool falseChecker(const DtStateRepository& stateRep,
00140       const DtStateRepository& asSeenByRemote);
00141 
00142 protected:
00143 
00144    DtExerciseConn* myExConn;
00145    DtObjClassDesc* myClassDesc;
00146    RTI::ObjectClassHandle myHandle;
00147 
00150    std::map<RTI::AttributeHandle,DtAttributeEncoder> myEncoderList;
00151    std::map<RTI::AttributeHandle,DtAttributeChecker> myCheckerList;
00152 
00153 
00156    std::map<RTI::AttributeHandle,bool>  myReportedWarning;
00157 };
00158 
00159 inline RTI::ObjectClassHandle DtHlaStateEncoder::objectClassHandle()
00160 {
00161    return myHandle;
00162 }
00163 
00164 inline DtHlaStateEncoder::DtAttributeEncoder
00165    DtHlaStateEncoder::encoder(const RTI::AttributeHandle &hand) 
00166 {
00167    return myEncoderList[hand];
00168 };
00169 
00170 inline DtHlaStateEncoder::DtAttributeChecker
00171    DtHlaStateEncoder::checker(const RTI::AttributeHandle &hand) 
00172 {
00173    return myCheckerList[hand];
00174 };
00175 
00178 #define DtADD_ATTR_ENCODER(attrName) \
00179    addEncoder((char *)#attrName, (DtAttributeEncoder) encode##attrName)
00180 
00182 #define DtADD_ATTR_ENCODER_QUIET(attrName) \
00183    addEncoder((char *)#attrName, (DtAttributeEncoder) encode##attrName, false)
00184 
00188 #define DtADD_ATTR_CHECKER(attrName) \
00189    addChecker((char *)#attrName, (DtAttributeChecker) need##attrName)
00190 
00192 #define DtADD_ATTR_CHECKER_QUIET(attrName) \
00193    addChecker((char *)#attrName, (DtAttributeChecker) need##attrName, false)
00194 
00198 #define DtDECLARE_ATTR_ENCODER(stateRepClass, attrName) \
00199    static void encode##attrName(const stateRepClass& rep, \
00200       RTI::AttributeHandleValuePairSet* attrs, \
00201       RTI::AttributeHandle attrHandle) 
00202 
00205 #define DtDECLARE_ATTR_CHECKER(stateRepClass, attrName) \
00206    static bool need##attrName(const stateRepClass& stateRep, \
00207       const stateRepClass& asSeenByRemote)
00208 
00214 #define DtDEFINE_SIMPLE_ATTR_ENCODER( \
00215    encClass, stateRepClass, attrName, netType, inspector) \
00216 void encClass::encode##attrName(const stateRepClass& rep, \
00217    RTI::AttributeHandleValuePairSet* attrs, \
00218    RTI::AttributeHandle attrHandle) \
00219 { \
00220    netType netVal; \
00221    netVal = rep.inspector(); \
00222    attrs->add(attrHandle, (char*) &netVal, sizeof(netType)); \
00223 }
00224 
00225 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_ENCODER( \
00226    encClass, stateRepClass, attrName, inspector) \
00227 void encClass::encode##attrName(const stateRepClass& rep, \
00228    RTI::AttributeHandleValuePairSet* attrs, \
00229    RTI::AttributeHandle attrHandle) \
00230 { \
00231    DtGlobalObjectDesignator netVal = rep.inspector(); \
00232    attrs->add(attrHandle, (char*) netVal.string(), netVal.length()+1); \
00233 }
00234 
00240 #define DtDEFINE_SIMPLE_ATTR_CHECKER( \
00241    encClass, stateRepClass, attrName, inspector) \
00242 bool encClass::need##attrName(const stateRepClass& stateRep, \
00243    const stateRepClass& asSeenByRemote) \
00244 { \
00245    return (bool) !(stateRep.inspector() == asSeenByRemote.inspector()); \
00246 }
00247 
00248 #endif
00249 #endif
00250 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)