VR-Forces 4.0.4 Class Documentation
Condition Evaluator

The MyEvaluator is a new class that will use the MySearch class to evaluate whether or not the entity in question is facing north


Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: northEvaluator.h,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/

#ifndef MyEvaluator_H_
#define MyEvaluator_H_

#include "vrfutil/evaluator.h"

//class MyEvaluator:
//
//Instances of MyEvaluator are used to perform the evaluation for a
//MyConditionalExpression using a MySearch.

namespace vrfAddConditionalExample
{
   class MyEvaluator : public DtEvaluator
   {
   public:

      //constructor
   MyEvaluator();

      //destructor
   virtual ~MyEvaluator();

      //copy constructor
   MyEvaluator(const MyEvaluator& orig);

      //assignment operator
   MyEvaluator& operator=(const MyEvaluator& orig);

      //clone operator
   virtual DtEvaluator* clone();

      //Evaluate this conditional expression for the entity with the given
      //entity name, in the context of the given DtSimManager,
      //and return the current result. The condExpr passed in must be of type 
      //MyConditionalExpression.
      //Checks to see if the entity in the MyConditionalExpression is 
      //facing north using a MySearch. If so, it returns true. The the modifier 
      //flag in MyConditionalExpression is passed to the search which optionally 
      //expands the test to return true if the entity and/or any of its 
      //subordinates are facing north.
   virtual bool evaluate(DtSimCondExpr* condExpr, 
      const DtString& echelonId, DtSimManager* simManager) const;

   public:

      //Returns a newly created MyEvaluator.
   static DtEvaluator * creator();

   };

#endif
}

Implementation:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: northEvaluator.cxx,v $ $Revision: 1.4 $ $State: Exp $
*******************************************************************************/

//Example includes
#include "northEvaluator.h"
#include "search.h"
#include "conditionalExpression.h"

//VR-Forces includes
#include "vrfutil/condExprTypes.h"
#include "vrfplan/plan.h"
#include "vrfcore/simMgr.h"
#include "vrfobjcore/vrfObjMgr.h"

//VR-Link includes
#include <vlutil/vlPrint.h>


namespace vrfAddConditionalExample
{
   MyEvaluator::MyEvaluator()
   {
   }

   MyEvaluator::~MyEvaluator()
   {
   }

   MyEvaluator::MyEvaluator(const MyEvaluator& orig) :
   DtEvaluator(orig)
   {
   }

   MyEvaluator& MyEvaluator::operator=(
   const MyEvaluator& orig)
   {
   if (this == &orig)
   {
      return *this;
   }

   DtEvaluator::operator=(orig);

   return *this;
   }

   DtEvaluator* MyEvaluator::clone()
   {
   return new MyEvaluator(*this);
   }

   bool MyEvaluator::evaluate(DtSimCondExpr* condExpr, 
                                       const DtString& echelonId, 
                                       DtSimManager* simManager) const
   {
   MyConditionalExpression* conditional = 
      dynamic_cast<MyConditionalExpression*>(condExpr);

   if (!conditional)
   {
      DtWarn("DtAndEvaluator::evaluate() : invalid conditional expression\n");
      DtWarn("The expression must be of type MyConditionalExpression\n");

      return false;
   }

   if (simManager == NULL)
   {
      DtWarn("MyEvaluator::evaluate called without valid DtSimManager!");
      return false;
   }

   DtVrfObjectManager* objectManager = simManager->vrfObjectManager();
   if (objectManager == NULL)
   {
      DtWarn("MyEvaluator::evaluate cannot access DtVrfObjectManager\n");
      return false;
   }

   //Search the entity tree for a match.
   MySearch search;
   search.setModifier(conditional->modifier());
   return search.search(conditional->entityName(), echelonId, simManager);
   }

   DtEvaluator * MyEvaluator::creator()
   {
   return new MyEvaluator();
   }
}

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)