![]() |
VR-Forces 4.0.4 Class Documentation
|
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
/******************************************************************************* ** Copyright (c) 2004 MAK Technologies, Inc. ** All rights reserved. *******************************************************************************/ /******************************************************************************* ** $RCSfile: search.h,v $ $Revision: 1.5 $ $State: Exp $ *******************************************************************************/ #ifndef MySearch_H_ #define MySearch_H_ #include "vrfobjcore/subSearch.h" class DtVrfObject; // //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(). // class MySearch : public DtSimSubordinateSearch { public: //default constructor MySearch(); //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
/******************************************************************************* ** 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 #include "vrfutil/kinTools.h" #include "vrfobjcore/vrfObjSR.h" #include "vrfobjcore/vrfKinState.h" //default constructor MySearch::MySearch() { } //destructor MySearch::~MySearch() { } //Function to initialize the search. bool MySearch::initializeSearch(const DtVrfObject& entity) { 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. bool MySearch::inspectEntity( 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. bool MySearch::searchSubordinates( const DtVrfObject& pAggEntity) { if (myAnyFlag) { return DtSimSubordinateSearch::searchSubordinates(pAggEntity); } return false; }