VR-Forces 4.3 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Condition Search

The MySearch is a subclass of DtSimSubordinateSearch that will be used to traverse either the echelon hierarchy (if the entity is an aggregate) or simply test the entity that is supplied to see if it is facing north (heading of 0 degrees).

It will also handle pattern matching if the user has supplied an entity type patter to check


Header file:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: search.h,v $ $Revision: 1.5 $ $State: Exp $
*******************************************************************************/
#ifndef MySearch_H_
#define MySearch_H_
//
//class MySearch:
//
//Instances of MySearch are used to search an entity or an entire aggregate
//structure for entities that are facing north. If any are detected the search
//is terminated. Call the searchBelow() function to do the actual
//search. Test the result by calling result().
//
{
public:
//default constructor
//destructor
virtual ~MySearch();
protected:
//Function to initialize the search. Sets myAnyFlag and myResult based on
//myModifier. If the "ANY" modifier is used, myResult is intialized to
//false (and set to true on the first success) otherwise myResult
//is set to true (and set to false on the first failure).
virtual bool initializeSearch(const DtVrfObject& entity);
//Test any and all entities to find one that is destroyed and sets
//myResult. If the test is true and the any flag is set, it returns true
//(which continues the search). Otherwise false is returned to end the
//search.
virtual bool inspectEntity(const DtVrfObject& entity);
//Controls whether subordinates of a specified pseudo-aggregate are
//searched. If the "ANY" modifier was specified, it calls the base
//class version, otherwise it just returns false.
virtual bool searchSubordinates(
const DtVrfObject& pAggEntity);
protected:
//copy constructor; not implemented
MySearch(const MySearch& orig);
//assignment operator; not implemented
MySearch& operator=(const MySearch& orig);
};
#endif

Implementation:

/*******************************************************************************
** Copyright (c) 2004 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: search.cxx,v $ $Revision: 1.5 $ $State: Exp $
*******************************************************************************/
//Example includes
#include "search.h"
//VR-Forces includes
//default constructor
{
}
//destructor
{
}
//Function to initialize the search.
{
if (myModifier.caseCompare("ANY"))
{
//If looking for any match, assume false until we find a match
myAnyFlag = true;
myResult = false;
}
else
{
//If looking for all matching, assume true until we find a failure
myAnyFlag = false;
myResult = true;
}
return true;
}
//Test any and all entities to find one that is facing north.
const DtVrfObject& entity)
{
bool facingNorth = false;
if (entity.vrfState())
{
double heading =
DtRad2Deg(entity.vrfState()->vrfKinematicState()->heading());
DtInfo("MySearch::inspectEntity entity %s has heading %g\n",
entity.objectName().string(), heading);
//See if the heading is within one degree of north
if (DtALMOST(heading, 0.0, 1.0))
{
facingNorth = true;
}
}
if (facingNorth)
{
//If looking for any match, we found it, we're done
if (myAnyFlag)
{
myResult = true;
return true;
}
}
//If looking for all to match, we have our first failure, we're done
else if (!myAnyFlag)
{
myResult = false;
return true;
}
return false;
}
//This version of searchSubordinates only searches subordinates if the
//"ANY" test modifier was given.
const DtVrfObject& pAggEntity)
{
if (myAnyFlag)
{
}
return false;
}

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)