1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0028103: Foundation Classes - extend NCollection_Map to check whether two given maps are intersected

Mehtod HasIntersection added in NCollection_Map to check whether two given maps contain at least one same item.
'Draw' command and test to check the method were created.
This commit is contained in:
abk 2016-11-14 18:08:44 +03:00 committed by apn
parent f411f94fac
commit d673da182b
6 changed files with 91 additions and 39 deletions

View File

@ -383,6 +383,28 @@ class NCollection_Map : public NCollection_BaseMap
return anOldExtent != Extent(); return anOldExtent != Extent();
} }
//! Returns true if this and theMap have common elements.
Standard_Boolean HasIntersection (const NCollection_Map& theMap) const
{
const NCollection_Map* aMap1 = this;
const NCollection_Map* aMap2 = &theMap;
if (theMap.Size() < Size())
{
aMap1 = &theMap;
aMap2 = this;
}
for (NCollection_Map::Iterator aIt(*aMap1); aIt.More(); aIt.Next())
{
if (aMap2->Contains(aIt.Value()))
{
return Standard_True;
}
}
return Standard_False;
}
//! Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps. //! Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps.
//! The new Map contains only the values that are contained in both map operands. //! The new Map contains only the values that are contained in both map operands.
//! All previous content of this Map is cleared. //! All previous content of this Map is cleared.

View File

@ -299,7 +299,8 @@ static void TestSequence (QANCollection_SequenceFunc& theS)
// ===================== Test methods of Map type ============================= // ===================== Test methods of Map type =============================
////////////////////////////////void TestMap (QANCollection_Map& theM) ////////////////////////////////void TestMap (QANCollection_Map& theM)
static void TestMap (QANCollection_MapFunc& theM) static void TestMap(QANCollection_MapFunc& theM, Draw_Interpretor& theDI)
{
{ {
// Extent // Extent
Standard_Integer iExt=theM.Extent(); Standard_Integer iExt=theM.Extent();
@ -324,13 +325,12 @@ static void TestMap (QANCollection_MapFunc& theM)
// Contains, Remove // Contains, Remove
if (!aM.Contains(aKey)) if (!aM.Contains(aKey))
{ {
printf("Error : map says that it does not contain its key "); theDI << "Error: map says that it does not contain its key " << aKey;
PrintItem(aKey);
} }
else else
{ {
aM.Remove(aKey); aM.Remove(aKey);
printf(" successfully removed item, l=%d\n", aM.Size()); cout << " successfully removed item, l=%d\n" << aM.Size() << "\n";
} }
// Copy constructor (including operator=) // Copy constructor (including operator=)
////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM); ////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM);
@ -342,6 +342,30 @@ static void TestMap (QANCollection_MapFunc& theM)
aM.Clear(); aM.Clear();
} }
// Check method 'HasIntersection'.
{
QANCollection_MapFunc aM1, aM2, aM3;
aM1.Add(6);
aM1.Add(8);
aM1.Add(10);
aM2.Add(4);
aM2.Add(8);
aM2.Add(16);
aM3.Add(1);
aM3.Add(2);
aM3.Add(3);
if (!aM1.HasIntersection(aM2) || !aM2.HasIntersection(aM1) ||
aM1.HasIntersection(aM3) || aM3.HasIntersection(aM1))
{
theDI << "Error: method 'HasIntersection' failed.";
}
}
}
// ===================== Test methods of DataMap type ========================= // ===================== Test methods of DataMap type =========================
////////////////////////////////void TestDataMap (QANCollection_DataMap& theM) ////////////////////////////////void TestDataMap (QANCollection_DataMap& theM)
static void TestDataMap (QANCollection_DataMapFunc& theM) static void TestDataMap (QANCollection_DataMapFunc& theM)
@ -671,7 +695,7 @@ static Standard_Integer QANColTestMap(Draw_Interpretor& di, Standard_Integer arg
return 1; return 1;
} }
QANCollection_MapFunc aMap; QANCollection_MapFunc aMap;
TestMap(aMap); TestMap(aMap, di);
return 0; return 0;
} }

1
tests/collections/grids.list Executable file
View File

@ -0,0 +1 @@
001 n

View File

@ -0,0 +1 @@
pload QAcommands

1
tests/collections/n/end Normal file
View File

@ -0,0 +1 @@
puts "TEST COMPLETED"

3
tests/collections/n/map Normal file
View File

@ -0,0 +1,3 @@
puts "Check NCollection_Map functionality"
QANColTestMap