VR-Link API Documentation for HLA Evolved
Creating a New State Repository

We first create a new subclass of DtStateRepository called TestStateRepository, in testSR.h and testSR.cxx.

This class is used to store the state of both local and reflected objects of our Test class.

The class definition is listed below. We provide inspector and mutator functions to access the state data, an override of the virtual printData() function that prints the current state data, and an override of the virtual clone() function that returned a new'ed instance of this class. We represent state data in the same way as in the FOM, but this is not strictly necessary. We could perform a non-trivial conversion in FOM mapping code instead.


/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/
#pragma once

#if DtHLA

#include <vl/stateRep.h>
#include <matrix/vlVector.h>

class TestStateRepository : public DtStateRepository
{
public:
   
   TestStateRepository();
   
   virtual ~TestStateRepository();
   
   TestStateRepository(const TestStateRepository& orig);

   TestStateRepository& operator=(const TestStateRepository& orig);

   virtual DtStateRepository* clone(bool copy) const; 

   virtual void printData() const;

   virtual void printDataToStream(std::ostream& stream) const;


   virtual void setNumber(int num);
   virtual int number() const;

   virtual void setVector(const DtVector& vec);
   virtual const DtVector& vector() const;

public:

   static DtStateRepository* create(); 

protected:
   
   int myNum;
   DtVector myVec;
};

#endif


/*********************************************************************
** Copyright (c) 1992-2010 VT MAK
** All rights reserved.
*********************************************************************/


#if DtHLA

#include "testSR.h"
#include <vlutil/vlPrintUtil.h>
#include <vlutil/vlPrint.h>
#include <iostream>

TestStateRepository::TestStateRepository() :
   DtStateRepository(),
   myNum(0),
   myVec()
{
}

TestStateRepository::~TestStateRepository()
{
}

TestStateRepository::TestStateRepository(const TestStateRepository& orig) :
   DtStateRepository(orig),
   myNum(orig.myNum),
   myVec(orig.myVec)
{
}

TestStateRepository& TestStateRepository::operator=(
   const TestStateRepository& orig)
{
   // Guard against assignment to yourself.
   if (this == &orig)
   {
      return *this;
   }

   DtStateRepository::operator=(orig);
   myNum = orig.myNum;
   myVec = orig.myVec;

   return *this;
}

DtStateRepository* TestStateRepository::clone(bool copy) const
{
   if (copy)
   {
      return new TestStateRepository(*this);
   }
   else
   {
      return new TestStateRepository();
   }
}

void TestStateRepository::printData() const
{
   printDataToStream(DtInfo);
}

void TestStateRepository::printDataToStream(std::ostream& stream) const
{
   DtPrintAttribute(stream,"Number: ", number());
   DtPrintAttribute(stream,"Vector: ", vector().string());
}

// Accessor functions are typically pretty straightforward.

void TestStateRepository::setNumber(int num)
{
   myNum = num;
}

int TestStateRepository::number() const
{
   return myNum;
}

void TestStateRepository::setVector(const DtVector& vec)
{
   myVec = vec;
}

const DtVector& TestStateRepository::vector() const
{
   return myVec;
}

DtStateRepository* TestStateRepository::create()
{
   return new TestStateRepository();
}

#endif

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)