Skip to content

Commit 20550fb

Browse files
committed
VectorData : Add method to compare data sources
1 parent c90c392 commit 20550fb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/IECorePython/VectorTypedDataBinding.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ class VectorTypedDataFunctions
541541
);
542542
}
543543

544+
static bool dataSourceEqual( ThisClass &x, ThisClass &y )
545+
{
546+
return &x.readable() == &y.readable();
547+
}
548+
544549

545550
protected:
546551
/*
@@ -725,6 +730,7 @@ std::string str<IECore::TypedData<std::vector<TYPE> > >( IECore::TypedData<std::
725730
.def("resize", &ThisBinder::resize, "s.resize( size )\nAdjusts the size of s.") \
726731
.def("resize", &ThisBinder::resizeWithValue, "s.resize( size, value )\nAdjusts the size of s, inserting elements of value as necessary.") \
727732
.def("hasBase", &ThisClass::hasBase ).staticmethod( "hasBase" ) \
733+
.def("_dataSourceEqual", &ThisBinder::dataSourceEqual, "Returns true if the given object points to the same source data as this object.") \
728734
.def("__str__", &str<ThisClass> ) \
729735
.def("__repr__", &repr<ThisClass> ) \
730736

test/IECore/VectorData.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,31 @@ def test( self ) :
13411341

13421342
self.assertEqual( d2, d )
13431343

1344+
class TestSourceDataEquality( unittest.TestCase ) :
1345+
1346+
def test( self ) :
1347+
1348+
a = IECore.FloatVectorData( [ 1, 2, 3 ] )
1349+
b = IECore.FloatVectorData( [ 4, 5, 6 ] )
1350+
1351+
self.assertTrue( a._dataSourceEqual( a ) )
1352+
self.assertFalse( a._dataSourceEqual( b ) )
1353+
1354+
ca = a.copy()
1355+
self.assertTrue( a._dataSourceEqual( ca ) )
1356+
1357+
ca[0] = 42
1358+
self.assertFalse( a._dataSourceEqual( ca ) )
1359+
1360+
ca2 = a.copy()
1361+
ca3 = ca2.copy()
1362+
self.assertTrue( a._dataSourceEqual( ca2 ) )
1363+
self.assertTrue( a._dataSourceEqual( ca3 ) )
1364+
1365+
a[0] = 99
1366+
self.assertFalse( a._dataSourceEqual( ca2 ) )
1367+
self.assertTrue(ca2._dataSourceEqual( ca3 ) )
1368+
13441369
if __name__ == "__main__":
13451370
unittest.main()
13461371

0 commit comments

Comments
 (0)