VR-Forces 4.2 Class Documentation
Space Entity Repository

This subclass of DtVrfMovingObjectStateRepository adds reader/writer variables that will store new entity information so it can be written to the order of battle file


Components of a State Repository

In DtSpaceEntityStateRepository, we must implement the following functions for our class to work correctly in the context of a VR-Forces application:

The Constructor

The constructor sets up the object to be readable and writable. State repository classes derive from DtReaderWriter, which gives them the ability to be read from file a and write to a file. The default constructor is not used.

  DtSpaceEntityParameters::DtSpaceEntityParameters(const DtString& name,
       DtReaderWriterRegistry* parentRegistry) :
       DtMovingObjectParameters(name, parentRegistry)
  {
  }
  

The type() function

The type() function returns a string that uniquely identifies the state repository class. It is used as a key in the state repository factory. State repository types are defined in vrfSRTypes.h. Make sure the string returned by your type() function does not conflict with an existing type.

  const char DtSpaceVehicleSRType[] = "space-vehicle-state-repository";
  DtString DtSpaceEntityParameters::type() const
  {
     return DtSpaceVehicleParamType;
  }
  

The creator() function

The static creator() function is registered with the state repository factory. It should return a newly created instance of the derived class.

  DtSimObjectStateRepository* DtSpaceEntityStateRepository::creator(
      const DtString& name, DtVrfObject* vrfObject,
      const DtObjectType& objectType, DtVrfObjectParameters* parameters,
      DtReaderWriterRegistry* parentRegistry)
  {
     return new DtSpaceEntityStateRepository((DtVrfObject*)vrfObject,
       ObjectType, parameters, name, parentRegistry);
  }
  

The creator function must be registered with the DtSpaceVehicleStateRepository type with the state repository factory. For details, see "Adding the New State Repository and Parameters to VR-Forces".

Adding the New Data Member to the Class

In this example, we add one member variable, myMaxHullTemperature and accessor and mutator methods for this variable. This makes it possible for any controller and actuator components to view or modify this state in the entity.

  class DtSpaceEntityStateRepository : public DtVrfMovingObjectStateRepository
  {
  public:
  . . .
     virtual void setMaxHullTemperature(DtReal temp);
     virtual DtReal maxHullTemperature() const;
  protected:
     DtReal myMaxHullTemperature;
  };
  void DtSpaceEntityStateRepository::setMaxHullTemperature(DtReal temp)
  {
     myMaxHullTemperature = temp;
  }
  DtReal DtSpaceEntityStateRepository::maxHullTemperature() const
  {
     return myMaxHullTemperature;
  }
  

Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: spaceSR.h,v $ $Revision: 1.12 $ $State: Exp $
*******************************************************************************/
//
//File: spaceSR.h
//
//Class: DtSpaceEntityStateRepository
//
//Description: This repository holds all information that is common to all the
//forms of space entities within the system. It contains a pointer
//to the space entity parameters, and provides accessors and mutators
//for all parameter values. In this example, we add a single new parameter,
//myMaxHullTemperature, representing the maximum outer hull temperature that
//this entity can sustain (e.g. such as during reentry). Any future
//controller and actuator components we build to simulate the entity's
//behavior can view or set this new parameter as necessary.
//
#ifndef DtSpaceEntityStateRepository_H_
#define DtSpaceEntityStateRepository_H_
#include <vlutil/vlMachineTypes.h>
class DtVector;
{
public:
//Constructor with parameters to set up read/writability correctly.
const DtString& name, DtReaderWriterRegistry* parentRegistry = 0);
//copy constructor
//assignment operator
//destructor
virtual bool init();
//Returns a unique string identifying the type of component,
//DtSpaceVehicleSRType (defined in spacetypes.h). Used a key in
//the state repository factory.
virtual DtString type() const;
//Override to create an instance DtSpaceEntityParameters and
//set it in myParameters data member.
virtual bool createParameters();
//Override to initialize space entity specific parameters from
//our parameters object.
virtual void initializeFromParameters();
//Implemented for convenience. Since we overrode createParameters()
//to create a DtSpaceEntityParameters object (a derived kind of
//DtSimObjectParameters), we provide an accessor casting it to the
//dervied type.
//Accessor/mutator for our new parameter, myMaxHullTemperature.
//Set/get maximum hull temperature this entity can sustain (degrees C).
virtual void setMaxHullTemperature(DtReal temp);
virtual DtReal maxHullTemperature() const;
//Returns a newly created instance of this class. To be registered
//with the state repository factory.
DtVrfObject* vrfObject,const DtObjectType& objectType,
//Returns a the pointer the repository, if the repository passed
//in is of type DtSpaceEntityStateRepository, 0 if not. Implmementation
//is optional - may be useful for safe type checking.
const DtVrfObjectStateRepository* repository);
protected:
//Maximum hull temperature (in degrees Celsius).
};
#endif

Implementation:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: spaceSR.cxx,v $ $Revision: 1.12 $ $State: Exp $
*******************************************************************************/
#include "spaceSR.h"
#include "spacePar.h"
#include <matrix/vlVector.h>
#include "spaceTypes.h"
//constructor with parameters to set up read/writability correctly
DtVrfObject* vrfObject, const DtObjectType& objectType,
DtVrfObjectParameters* parameters, const DtString& name,
DtReaderWriterRegistry* parentRegistry) :
DtVrfMovingObjectStateRepository(vrfObject, objectType, parameters, name,
parentRegistry),
myMaxHullTemperature("max-hull-temperature", 1260.0, &myRegistry)
{
}
//copy constructor
myMaxHullTemperature(orig.myMaxHullTemperature, &myRegistry)
{
}
//assignment operator
{
if (this == &orig)
{
return *this;
}
return *this;
}
//destructor
{
}
{
}
{
{
delete myParameters;
myParameters = NULL;
}
if (myParameters == NULL)
{
return false;
}
return true;
}
{
//Set the value specified to false to insure that it will be written to the
//order of battle file as "USE-DEFAULT" unless its value gets changed
//somewhere else.
}
{
//Use the parameters() accessor instead of myParameters member directly.
//(myParameters will be created on demand in the parameters() accessor.)
}
const DtVrfObjectStateRepository* repository)
{
if (repository->type() == DtSpaceVehicleSRType )
{
return (DtSpaceEntityStateRepository*) repository;
}
return 0;
}
{
}
const DtString& name, DtVrfObject* vrfObject,
const DtObjectType& objectType, DtVrfObjectParameters* parameters,
DtReaderWriterRegistry* parentRegistry)
{
return new DtSpaceEntityStateRepository((DtVrfObject*)vrfObject, objectType,
parameters, name, parentRegistry);
}
{
}
{
}

Document ID: Generated on Sun Nov 24 19:49:21 EST 2013 from SVN revision 133924
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)