void FCNEqv( void ) { //================ // Logical .NEQV. F-Code processor. Equivalent( O_NE ); }
void FCEqv( void ) { //=============== // Logical .EQV. F-Code processor. Equivalent( O_EQ ); }
void DependencyValidation::OnChange() { ++_validationIndex; ResourceDependenciesLock.lock(); auto range = std::equal_range( ResourceDependencies.begin(), ResourceDependencies.end(), this, CompareFirst<const OnChangeCallback*, std::weak_ptr<DependencyValidation>>()); unsigned changeIdStart = ResourceDepsChangeId; bool foundExpired = false; for (auto i=range.first; i!=range.second; ++i) { auto l = i->second.lock(); if (l) { l->OnChange(); if (ResourceDepsChangeId != changeIdStart) { // another object may have changed the list of objects // during the OnChange() call. If this happens, // we need to search through and find the range again. // then we need to set 'i' to the position of the // same element in the new range (it's guaranteed to // be there, because we have a lock on it! // Oh, it's a wierd hack... But it should work well. range = std::equal_range( ResourceDependencies.begin(), ResourceDependencies.end(), this, CompareFirst<const OnChangeCallback*, std::weak_ptr<DependencyValidation>>()); for (i=range.first;; ++i) { assert(i!=range.second); if (Equivalent(i->second, l)) break; } changeIdStart = ResourceDepsChangeId; } } else foundExpired = true; } if (foundExpired) { // Remove any pointers that have expired // (note that we only check matching pointers. Non-matching pointers // that have expired are untouched) ResourceDependencies.erase( std::remove_if(range.first, range.second, [](std::pair<const OnChangeCallback*, std::weak_ptr<DependencyValidation>>& i) { return i.second.expired(); }), range.second); ++ResourceDepsChangeId; // signal to callers that this has changed } ResourceDependenciesLock.unlock(); }
ForwardIterator BinarySearch(ForwardIterator first, ForwardIterator last, const T& value) { // Note: std::lower_bound() has O(log n) on random access iterators ForwardIterator result = std::lower_bound(first, last, value); // std::lower_bound() returns iterator to first element >= value, which can be inequal to value if (result == last || !Equivalent(*result, value)) return last; else return result; }
void Unite(size_t firstAgent, size_t secondAgent) { if (Equivalent(firstAgent, secondAgent)) { return; } TDSUElement* firstRoot = Root(&nodes[firstAgent]); TDSUElement* secondRoot = Root(&nodes[secondAgent]); if (firstRoot->rank < secondRoot->rank) { firstRoot->pFather = secondRoot; ++secondRoot->rank; } else { secondRoot->pFather = firstRoot; ++firstRoot->rank; } --numberOfClasses; }
int operatorTest(void) { gpstk::TestUtil testFramework("TimeSystem", "== Operator", __FILE__, __LINE__); std::string testMesg; gpstk::TimeSystem Compare(4); gpstk::TimeSystem Equivalent(4); gpstk::TimeSystem LessThan(3); gpstk::TimeSystem GreaterThan(5); //--------------------------------------------------------------------------- //Does the == operator function correctly? //--------------------------------------------------------------------------- testMesg = "Equivalent objects were not marked equivalent by =="; testFramework.assert(Compare == Equivalent, testMesg, __LINE__); testMesg = "Equivalent objects were marked not equivalent by =="; testFramework.assert(!(Compare == LessThan), testMesg, __LINE__); testFramework.changeSourceMethod("!= Operator"); //--------------------------------------------------------------------------- //Does the != operator function correctly? //--------------------------------------------------------------------------- testMesg = "Non-equivalent objects were marked equivalent by !="; testFramework.assert(Compare != LessThan, testMesg, __LINE__); testMesg = "Equivalent objects were marked equivalent by !="; testFramework.assert(!(Compare != Equivalent), testMesg, __LINE__); testFramework.changeSourceMethod("> Operator"); //--------------------------------------------------------------------------- //Does the > operator function correctly? //--------------------------------------------------------------------------- testMesg = "Less-than object was not marked as lesser by the > operator"; testFramework.assert(Compare > LessThan, testMesg, __LINE__); testMesg = "Less-than object was marked as greater by the > operator"; testFramework.assert(!(LessThan > Compare), testMesg, __LINE__); testMesg = "Equivalent objects were marked as non-equivalent by the > operator"; testFramework.assert(!(Compare > Equivalent), testMesg, __LINE__); testFramework.changeSourceMethod("< Operator"); //--------------------------------------------------------------------------- //Does the < operator function correctly? //--------------------------------------------------------------------------- testMesg = "Greater-than object was not marked as greater by the < operator"; testFramework.assert(Compare < GreaterThan, testMesg, __LINE__); testMesg = "Greater-than object was marked as lesser by the < operator"; testFramework.assert(!(GreaterThan < Compare), testMesg, __LINE__); testMesg = "Equivalent objects were marked as non-equivalent by the < operator"; testFramework.assert(!(Compare < Equivalent), testMesg, __LINE__); testFramework.changeSourceMethod(">= Operator"); //--------------------------------------------------------------------------- //Does the >= operator function correctly? //--------------------------------------------------------------------------- testMesg = "Less-than object was not marked as lesser by the >= operator"; testFramework.assert(Compare >= LessThan, testMesg, __LINE__); testMesg = "Less-than object was marked as greater by the >= operator"; testFramework.assert(!(LessThan >= Compare), testMesg, __LINE__); testMesg = "Equivalent objects were marked as non-equivalent by the >= operator"; testFramework.assert(Compare >= Equivalent, testMesg, __LINE__); testFramework.changeSourceMethod("<= Operator"); //--------------------------------------------------------------------------- //Does the <= operator function correctly? //--------------------------------------------------------------------------- testMesg = "Greater-than object was not marked as greater by the < operator"; testFramework.assert(Compare <= GreaterThan, testMesg, __LINE__); testMesg = "Greater-than object was marked as lesser by the < operator"; testFramework.assert(!(GreaterThan <= Compare), testMesg, __LINE__); testMesg = "Equivalent objects were marked as non-equivalent by the < operator"; testFramework.assert(Compare <= Equivalent, testMesg, __LINE__); testFramework.changeSourceMethod("<< Operator"); //--------------------------------------------------------------------------- //Does the << operator function correctly? //--------------------------------------------------------------------------- std::string outputString, compareString; std::stringstream outputStream; outputStream << Compare; outputString = outputStream.str(); compareString = "GAL"; testMesg = "The << operator did not function correctly"; testFramework.assert(compareString == outputString, testMesg, __LINE__); return testFramework.countFails(); }
//========================================================================================================================== // operatorTest verifies the various operators of the SatID class //========================================================================================================================== int operatorTest(void) { gpstk::TestUtil testFramework( "SatID", "OperatorEquivalence", __FILE__, __LINE__); gpstk::SatID Compare (5, gpstk::SatID::SatelliteSystem(2) ); gpstk::SatID Equivalent (5, gpstk::SatID::SatelliteSystem(2) ); gpstk::SatID LessThanID (2, gpstk::SatID::SatelliteSystem(2) ); gpstk::SatID DiffSatSys (5, gpstk::SatID::SatelliteSystem(5) ); gpstk::SatID DiffEvery (2, gpstk::SatID::SatelliteSystem(5) ); gpstk::SatID DiffEvery2 (7, gpstk::SatID::SatelliteSystem(1) ); gpstk::SatID Redirected (6, gpstk::SatID::SatelliteSystem(1) ); //--------------------------------------------------------------------- //Does the == Operator function? //--------------------------------------------------------------------- testFramework.assert( Compare == Equivalent , "Equivalence Operator found equivalent objects to not be equal" , __LINE__); testFramework.assert(!(Compare == LessThanID), "Equivalence Operator found differing IDs to be equal" , __LINE__); testFramework.assert(!(Compare == DiffSatSys), "Equivalence Operator found differing SatteliteSystems to be equal", __LINE__); testFramework.changeSourceMethod("OperatorNotEquals"); //--------------------------------------------------------------------- //Does the != Operator function? //--------------------------------------------------------------------- testFramework.assert(!(Compare != Equivalent), "Not Equals Operator found equivalent objects to be not equal" , __LINE__); testFramework.assert( Compare != LessThanID , "Not Equals Operator found differing IDs to be equal" , __LINE__); testFramework.assert( Compare != DiffSatSys , "Not Equals Operator found differing SatteliteSystems to be equal", __LINE__); testFramework.changeSourceMethod("OperatorLessThan"); //--------------------------------------------------------------------- //Does the < Operator function? //--------------------------------------------------------------------- //ID only comparisons testFramework.assert(!(Compare < LessThanID), "Less-than Operator found object with greater IDs and same SatSys to be less-than" , __LINE__); testFramework.assert( LessThanID < Compare , "Less-than Operator found object with lesser IDs and same SatSys to not be less-than", __LINE__); testFramework.assert(!(Compare < Equivalent), "Less-than Operator found equivalent object to be less-than" , __LINE__); //SatelliteSystem only comparisons testFramework.assert( Compare < DiffSatSys , "Less-than Operator found object with lesser SatSys and same IDs to not be less-than", __LINE__); testFramework.assert(!(DiffSatSys < Compare), "Less-than Operator found object with greater SatSys and same IDs to be less-than" , __LINE__); //Completely different comparisons testFramework.assert( Compare < DiffEvery , "Less-than Operator found object with lesser SatSys and greater ID to not be less-than", __LINE__); testFramework.assert(!(DiffEvery < Compare) , "Less-than Operator found object with greater SatSys and lesser ID to be less-than" , __LINE__); testFramework.assert(!(Compare < DiffEvery2), "Less-than Operator found object with greater SatSys and lesser ID to be less-than" , __LINE__); testFramework.assert( DiffEvery2 < Compare , "Less-than Operator found object with lesser SatSys and greater ID to not be less-than", __LINE__); testFramework.changeSourceMethod("OperatorGreaterThan"); //--------------------------------------------------------------------- //Does the > Operator function? //--------------------------------------------------------------------- //ID only comparisons testFramework.assert( (Compare > LessThanID), "Greater-than Operator found object with greater IDs and same SatSys to not be greater-than", __LINE__); testFramework.assert(!(LessThanID > Compare), "Greater-than Operator found object with lesser IDs and same SatSys to be greater-than" , __LINE__); testFramework.assert(!(Compare > Equivalent), "Greater-than Operator found equivalent object to be greater-than" , __LINE__); //SatelliteSystem only comparisons testFramework.assert(!(Compare > DiffSatSys), "Greater-than Operator found object with lesser SatSys and same IDs to be greater-than" , __LINE__); testFramework.assert( (DiffSatSys > Compare), "Greater-than Operator found object with greater SatSys and same IDs to not be greater-than", __LINE__); //Completely different comparisons testFramework.assert(!(Compare > DiffEvery) , "Greater-than Operator found object with lesser SatSys and greater ID to be greater-than" , __LINE__); testFramework.assert( (DiffEvery > Compare) , "Greater-than Operator found object with greater SatSys and lesser ID to not be greater-than", __LINE__); testFramework.assert( (Compare > DiffEvery2), "Greater-than Operator found object with greater SatSys and lesser ID to not be greater-than", __LINE__); testFramework.assert(!(DiffEvery2 > Compare), "Greater-than Operator found object with lesser SatSys and greater ID to be greater-than" , __LINE__); testFramework.changeSourceMethod("OperatorLessThanOrEqualTo"); //--------------------------------------------------------------------- //Does the <= Operator function? //--------------------------------------------------------------------- //ID only comparisons testFramework.assert(!(Compare <= LessThanID), "Less-than-or-equal-to Operator found object with greater IDs and same SatSys to be less-than-or-equal-to" , __LINE__); testFramework.assert( LessThanID <= Compare , "Less-than-or-equal-to Operator found object with lesser IDs and same SatSys to not be less-than-or-equal-to", __LINE__); testFramework.assert( (Compare <= Equivalent), "Less-than-or-equal-to Operator found equivalent object to not be less-than-or-equal-to" , __LINE__); //SatelliteSystem only comparisons testFramework.assert( Compare <= DiffSatSys , "Less-than-or-equal-to Operator found object with lesser SatSys and same IDs to not be less-than-or-equal-to", __LINE__); testFramework.assert(!(DiffSatSys <= Compare), "Less-than-or-equal-to Operator found object with greater SatSys and same IDs to be less-than-or-equal-to" , __LINE__); //Completely different comparisons testFramework.assert( Compare <= DiffEvery , "Less-than-or-equal-to Operator found object with lesser SatSys and greater ID to not be less-than-or-equal-to", __LINE__); testFramework.assert(!(DiffEvery <= Compare) , "Less-than-or-equal-to Operator found object with greater SatSys and lesser ID to be less-than-or-equal-to" , __LINE__); testFramework.assert(!(Compare <= DiffEvery2), "Less-than-or-equal-to Operator found object with greater SatSys and lesser ID to be less-than-or-equal-to" , __LINE__); testFramework.assert( DiffEvery2 <= Compare , "Less-than-or-equal-to Operator found object with lesser SatSys and greater ID to not be less-than-or-equal-to", __LINE__); testFramework.changeSourceMethod("OperatorGreaterThanOrEqualTo"); //--------------------------------------------------------------------- //Does the >= Operator function? //--------------------------------------------------------------------- //ID only comparisons testFramework.assert( (Compare >= LessThanID), "Greater-than-or-equal-to Operator found object with greater IDs and same SatSys to not be greater-than-or-equal-to", __LINE__); testFramework.assert(!(LessThanID >= Compare), "Greater-than-or-equal-to Operator found object with lesser IDs and same SatSys to be greater-than-or-equal-to" , __LINE__); testFramework.assert( (Compare >= Equivalent), "Greater-than-or-equal-to Operator found equivalent object to not be greater-than-or-equal-to" , __LINE__); //SatelliteSystem only comparisons testFramework.assert(!(Compare >= DiffSatSys), "Greater-than-or-equal-to Operator found object with lesser SatSys and same IDs to be greater-than-or-equal-to" , __LINE__); testFramework.assert( (DiffSatSys >= Compare), "Greater-than-or-equal-to Operator found object with greater SatSys and same IDs to not be greater-than-or-equal-to", __LINE__); //Completely different comparisons testFramework.assert(!(Compare >= DiffEvery) , "Greater-than-or-equal-to Operator found object with lesser SatSys and greater ID to be greater-than-or-equal-to" , __LINE__); testFramework.assert( (DiffEvery >= Compare) , "Greater-than-or-equal-to Operator found object with greater SatSys and lesser ID to not be greater-than-or-equal-to", __LINE__); testFramework.assert( (Compare >= DiffEvery2), "Greater-than-or-equal-to Operator found object with greater SatSys and lesser ID to not be greater-than-or-equal-to", __LINE__); testFramework.assert(!(DiffEvery2 >= Compare), "Greater-than-or-equal-to Operator found object with lesser SatSys and greater ID to be greater-than-or-equal-to" , __LINE__); testFramework.changeSourceMethod("OperatorRedirect"); //--------------------------------------------------------------------- //Does the << Operator function? //--------------------------------------------------------------------- std::string outputString, compareString; std::stringstream outputStream; outputStream << Redirected; outputString = outputStream.str(); compareString = "GPS 6"; testFramework.assert(outputString == compareString, "Redirect operator did not function properly", __LINE__); return testFramework.countFails(); }