VR-Forces 5.0.2 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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) 2014 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#pragma once
#include "vrfutil/rwUUID.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";
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) const;
//Returns DtNetCeFacingNorthType (defined above).
virtual int type() const;
//Set the entity
virtual void setEntity(const DtUUID& name);
//Returns the entity
virtual const DtUUID& entity() 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)
};
}

Implementation:

/*******************************************************************************
** Copyright (c) 2015 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
#include <malloc.h>
#include <vlutil/vlString.h>
#include "vrfplan/plan.h"
#include "../addConditionalSim/conditionalExpression.h"
namespace vrfAddConditionalExample
{
myEntity("Entity", &myRegistry),
myModifier("Modifier", &myRegistry)
{
myModifier.setValueSpecified(false);
}
MyConditionalExpression::MyConditionalExpression(
DtReaderWriterRegistry* parentRegistry) :
myEntity("Entity", &myRegistry),
myModifier("Modifier", &myRegistry)
{
myModifier.setValueSpecified(false);
}
MyConditionalExpression::MyConditionalExpression(
const MyConditionalExpression& orig,
DtReaderWriterRegistry* parentRegistry) :
DtSimCondExpr(orig, parentRegistry),
myEntity("Entity", orig.myEntity, &myRegistry),
myModifier("Modifier", orig.myModifier, &myRegistry)
{
}
MyConditionalExpression::~MyConditionalExpression()
{
}
MyConditionalExpression& MyConditionalExpression::operator=(
const MyConditionalExpression& orig)
{
if (this == &orig)
{
return *this;
}
myEntity = orig.myEntity;
myModifier = orig.myModifier;
return *this;
}
DtSimCondExpr* MyConditionalExpression::clone(
DtReaderWriterRegistry* parentRegistry) const
{
return new MyConditionalExpression(*this, parentRegistry);
}
int MyConditionalExpression::type() const
{
}
void MyConditionalExpression::setEntity(const DtUUID& name)
{
myEntity = name;
if (myNetRep)
{
free(myNetRep);
myNetRep = NULL;
}
}
const DtUUID& MyConditionalExpression::entity() const
{
return myEntity;
}
//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.
DtString MyConditionalExpression::stringRep(int subExprIndex) const
{
if (subExprIndex == DtSR_EXPR)
{
DtString str;
DtString ms(modifierStringRep(myModifier));
if (ms.length())
{
str = ms;
}
else
{
str = "\"" + myEntity.markingText() + "\"";
}
str += " ";
str += trUtf8(" facing north", "MyConditionalExpression");
return str;
}
return "";
}
DtSimCondExpr * MyConditionalExpression::creator()
{
return new MyConditionalExpression();
}
int MyConditionalExpression::netRepSize() const
{
size += DtBufferSerialize::getSize(myModifier);
return size;
}
bool MyConditionalExpression::setFromNet(const char* contentBuffer,
unsigned contentSize)
{
contentBuffer = DtBufferSerialize::decode(myEntity, contentBuffer);
contentBuffer = DtBufferSerialize::decode(myModifier, contentBuffer);
return true;
}
bool MyConditionalExpression::setToNet()
{
if (!netRep())
{
return false;
}
char* buffer = DtBufferSerialize::encode(myEntity, myNetRep);
buffer = DtBufferSerialize::encode(myModifier, buffer);
return true;
}
}

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)