VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Facing North Conditional

The MyConditionalExpression is a subclass of DtSimCondExpr that stores the information about what the user wants to test to see if they are facing north.

Used in conjunction with the MyEvaluator class.


Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: conditionalExpression.h,v $ $Revision: 1.6 $ $State: Exp $
*******************************************************************************/
#ifndef DtMyConditionalExpression_H_
#define DtMyConditionalExpression_H_
namespace vrfAddConditionalExample
{
//This is the integer type which represents MyConditionalExpression on
//the network. By starting conditional expression types from
//MIN_USER_CONDITIONAL_EXPRESSION_TYPE, defined in condExprTypes.h, conflicts
//with existing VR-Forces types can be avoided.
//This is the string type which represents MyConditionalExpression in
//plan files. It must not contain any spaces.
const char DtCeFacingNorthTypeName[] = "FacingNorth";
//This struct is the fixed portion of the network representation of a
//facing north conditional expression.
struct DtNetCeFacingNorth
{
DtNetU8 myEntityNameStringLength; //1 byte
DtNetU8 myModifierStringLength; //1 byte
//padding to insure the structure is aligned on an 8 byte boundary
DtNetU8 myPadding; //1 byte
DtNetU8 myPadding1; //1 byte
DtNetU8 myPadding2; //1 byte
DtNetU8 myPadding3; //1 byte
DtNetU8 myPadding4; //1 byte
DtNetU8 myPadding5; //1 byte
};
class MyConditionalExpression : public DtSimCondExpr
{
public:
//default constructor
//real constructor
//copy constructor
DtReaderWriterRegistry* parentRegistry = NULL);
//destructor
//assignment operator
//clone operator
virtual DtSimCondExpr* clone(DtReaderWriterRegistry* parentRegistry = NULL);
//Returns DtNetCeFacingNorthType (defined above).
virtual int type() const;
//Set the entity name
virtual void setEntityName(const DtString& name);
//Returns the entity name
virtual const DtString& entityName() const;
//Set the test modifier.
// If it is an empty string, checks only the specified entity.
// If it is the string "ANY", checks all subordinate entities to see if
// any of them match the test,
// If it is neither of the above, it requires that all specified entities
// match.
virtual void setModifier(const DtString& arg);
//Returns the modifier
virtual const DtString& modifier() const;
//Get a readable string representation of this level of this expression.
//
//The subExprIndex argument indicates which stringRep to get if this
//expression can have sub-expressions. Since the facing north test has
//no sub-expressions, it only returns a string representation if passed an
//index of DtSimCondExpr::DtSR_EXPR.
//
//See the documentation for DtSimCondExpr::stringRep for more
//information.
virtual DtString stringRep(int subExprIndex = DtSR_EXPR) const;
//returns the size of the full network representation
//padded to an 8-byte boundary.
virtual int netRepSize() const;
//Fills in the expression from the network buffer
virtual bool setFromNet(const char* contentBuffer,
unsigned contentSize);
//Fills in the network buffer (created by base class conditional
//expression) with the conditional expression contents.
virtual bool setToNet();
//Returns a new MyConditionalExpression
static DtSimCondExpr * creator();
protected:
//The name of the entity to evaluate
//The modifier (set via the "Any" checkbox in the GUI)
};
#endif
}

Implementation:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: conditionalExpression.cxx,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/
#include <malloc.h>
#include <vlutil/vlString.h>
#include "vrfplan/plan.h"
#include "../addConditionalSim/conditionalExpression.h"
namespace vrfAddConditionalExample
{
myEntityName("Entity", &myRegistry),
myModifier("Modifier", &myRegistry)
{
myModifier.setValueSpecified(false);
}
MyConditionalExpression::MyConditionalExpression(
DtReaderWriterRegistry* parentRegistry) :
myEntityName("Entity", &myRegistry),
myModifier("Modifier", &myRegistry)
{
myModifier.setValueSpecified(false);
}
MyConditionalExpression::MyConditionalExpression(
const MyConditionalExpression& orig,
DtReaderWriterRegistry* parentRegistry) :
DtSimCondExpr(orig, parentRegistry),
myEntityName("Entity", orig.myEntityName, &myRegistry),
myModifier("Modifier", orig.myModifier, &myRegistry)
{
}
MyConditionalExpression::~MyConditionalExpression()
{
}
MyConditionalExpression& MyConditionalExpression::operator=(
const MyConditionalExpression& orig)
{
if (this == &orig)
{
return *this;
}
myEntityName = orig.myEntityName;
myModifier = orig.myModifier;
return *this;
}
DtReaderWriterRegistry* parentRegistry)
{
return new MyConditionalExpression(*this, parentRegistry);
}
{
}
void MyConditionalExpression::setEntityName(const DtString& name)
{
myEntityName = name;
if (myNetRep)
{
free(myNetRep);
myNetRep = NULL;
}
}
const DtString& MyConditionalExpression::entityName() const
{
return myEntityName;
}
//Set the test modifier ("ANY" = check subordinates for any matches)
void MyConditionalExpression::setModifier(const DtString& arg)
{
myModifier = arg;
if (myNetRep)
{
free(myNetRep);
myNetRep = NULL;
}
}
const DtString& MyConditionalExpression::modifier() const
{
return myModifier;
}
//Get a readable string representation of this level of this expression.
//
//The subExprIndex argument indicates which stringRep to get if this
//expression can have sub-expressions. Since a facing north test has
//no sub-expressions, it only returns a string representation if passed an
//index of DtSimCondExpr::DtSR_EXPR.
//
//See the documentation for DtSimCondExpr::stringRep for more
//information.
{
if (subExprIndex == DtSR_EXPR)
{
if (myModifier.length() > 0)
{
return "Facing-North " + myModifier + " Entity:\"" +
myEntityName + "\"";
}
else
{
return "Facing-North:\"" + myEntityName + "\"";
}
}
return "";
}
DtSimCondExpr * MyConditionalExpression::creator()
{
return new MyConditionalExpression();
}
{
int size;
size = sizeof(DtNetCeFacingNorth);
size += myEntityName.length();
size += myModifier.length();
size = (int) ceil(size / 8.) * 8;
return size;
}
bool MyConditionalExpression::setFromNet(const char* contentBuffer,
unsigned contentSize)
{
DtNetCeFacingNorth* condExprBuffer;
condExprBuffer = (DtNetCeFacingNorth*)contentBuffer;
int entityNameStringLength = condExprBuffer->myEntityNameStringLength;
int modifierStringLength = condExprBuffer->myModifierStringLength;
char stringBuffer[256];
if(entityNameStringLength > 0)
{
const char *stringPtr = contentBuffer + sizeof(DtNetCeFacingNorth);
memcpy(stringBuffer, stringPtr, entityNameStringLength);
stringBuffer[entityNameStringLength] = '\0';
myEntityName = stringBuffer;
}
if(modifierStringLength > 0)
{
const char *stringPtr = contentBuffer + sizeof(DtNetCeFacingNorth) +
entityNameStringLength;
memcpy(stringBuffer, stringPtr, modifierStringLength);
stringBuffer[modifierStringLength] = '\0';
myModifier = stringBuffer;
}
return true;
}
{
if (!netRep())
{
return false;
}
DtNetCeFacingNorth* condExprBuffer = (DtNetCeFacingNorth*)myNetRep;
condExprBuffer->myEntityNameStringLength = myEntityName.length();
condExprBuffer->myModifierStringLength = myModifier.length();
char *stringPtr = myNetRep + sizeof(DtNetCeFacingNorth);
if (myEntityName.length() > 0)
{
memcpy(stringPtr, myEntityName.string(), myEntityName.length());
}
stringPtr = myNetRep + sizeof(DtNetCeFacingNorth) +
myEntityName.length();
if (myModifier.length() > 0)
{
memcpy(stringPtr, myModifier.string(), myModifier.length());
}
return true;
}
}

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)