Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add operator = for std::vector #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/py/statiskit/stl/_stl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
__stl.std._Set_6436891c9b6854f494789a812891cbe5.KeyType = __stl.std._BasicString_448c20257e485acda59dc59305fceb58
__stl.std._Set_6436891c9b6854f494789a812891cbe5.ValueType = __stl.std._BasicString_448c20257e485acda59dc59305fceb58
__stl.std._UnorderedSet_d48105936d4f5d09a78d2aa9f878fdb8.KeyEqual = __stl.std._EqualTo_d0ba0922f2505f7b8e291326cad79af5
__stl.statiskit.stl.SetLessDoubleGenerator = __stl.statiskit.stl._Generator_74bc331707c1505eb2f807cae7c32bbb
__stl.statiskit.stl.SetLessString = __stl.std._Set_6436891c9b6854f494789a812891cbe5
__stl.statiskit.stl.SetLessStringGenerator = __stl.statiskit.stl._Generator_745e4933f5b250d9bc5232fe864d0cf7
__stl.statiskit.stl.VectorInt = __stl.std._Vector_6b9ae5eac40858c9a0f5e6e21c15d1d3
__stl.statiskit.stl.SetLessIntGenerator = __stl.statiskit.stl._Generator_e76a1308464d5a9a837d9a61f942fae7
__stl.statiskit.stl.SetLessIndexGenerator = __stl.statiskit.stl._Generator_10b14312eeb655268489cd34090870cf
__stl.statiskit.stl.SetIndex = __stl.std._UnorderedSet_d48105936d4f5d09a78d2aa9f878fdb8
__stl.statiskit.stl.SetLessIndex = __stl.std._Set_476c1c1f206251dba7af53c48f3f6e42
__stl.statiskit.stl.SetLessIntGenerator = __stl.statiskit.stl._Generator_e76a1308464d5a9a837d9a61f942fae7
__stl.statiskit.stl.SetIndexGenerator = __stl.statiskit.stl._Generator_3b59a0980c80518c808634f7a84dc3cd
__stl.statiskit.stl.SetLessStringGenerator = __stl.statiskit.stl._Generator_745e4933f5b250d9bc5232fe864d0cf7
__stl.statiskit.stl.SetIndex = __stl.std._UnorderedSet_d48105936d4f5d09a78d2aa9f878fdb8
__stl.statiskit.stl.SetLessString = __stl.std._Set_6436891c9b6854f494789a812891cbe5
__stl.statiskit.stl.VectorString = __stl.std._Vector_c047f2c3135554ceb57f166fd404cfc8
__stl.statiskit.stl.SetLessInt = __stl.std._Set_882a8dd1e64a51b4a9da29ab852a852e
__stl.statiskit.stl.SetLessDouble = __stl.std._Set_858bbf0613575e2ebe4b0e5902107ad6
__stl.statiskit.stl.VectorDouble = __stl.std._Vector_107131f9768c56e794a9b0de728d1738
__stl.statiskit.stl.VectorIndex = __stl.std._Vector_dc5522842bc75d8b9ac7b46020c60854
__stl.statiskit.stl.SetLessInt = __stl.std._Set_882a8dd1e64a51b4a9da29ab852a852e
__stl.statiskit.stl.SetLessDoubleGenerator = __stl.statiskit.stl._Generator_74bc331707c1505eb2f807cae7c32bbb
__stl.statiskit.stl.VectorDouble = __stl.std._Vector_107131f9768c56e794a9b0de728d1738
__stl.statiskit.stl.String = __stl.std._BasicString_448c20257e485acda59dc59305fceb58
__stl.statiskit.stl.VectorInt = __stl.std._Vector_6b9ae5eac40858c9a0f5e6e21c15d1d3
__stl.statiskit.stl.SetIndexGenerator = __stl.statiskit.stl._Generator_3b59a0980c80518c808634f7a84dc3cd
__stl.statiskit.Indices = __stl.std._Set_476c1c1f206251dba7af53c48f3f6e42
__stl.std._Vector_c047f2c3135554ceb57f166fd404cfc8.ValueType = __stl.std._BasicString_448c20257e485acda59dc59305fceb58
9 changes: 9 additions & 0 deletions src/py/statiskit/stl/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def __init__(self, arg=None):

cls.__init__ = wrapper__init__(cls.__init__)

# def __eq__(self, other):
# if isinstance(other, self.__class__):
# return all(self[index] == other[index] for index in range(len(self)))
# else:
# return False

# cls.__eq__ = __eq__
# del __eq__

def __str__(self):
return "{" + ", ".join(str(value) for value in self) + "}"

Expand Down
9 changes: 9 additions & 0 deletions src/py/statiskit/stl/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def __setitem__(self, index, value):

return __getitem__, __setitem__

def __eq__(self, other):
if isinstance(other, self.__class__):
return all(self[index] == other[index] for index in range(len(self)))
else:
return False

cls.__eq__ = __eq__
del __eq__

cls.__getitem__, cls.__setitem__ = wrapper_at(cls.at)
del cls.at

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void wrapper_8f249c2863945cb59771b97c53bdafec()
boost::python::scope().attr("std") = module_a5e4e9231d6351ccb0e06756b389f0af;
boost::python::scope scope_a5e4e9231d6351ccb0e06756b389f0af = module_a5e4e9231d6351ccb0e06756b389f0af;
boost::python::class_< struct ::std::binary_function< unsigned long int, unsigned long int, bool >, autowig::Held< struct ::std::binary_function< unsigned long int, unsigned long int, bool > >::Type > class_8f249c2863945cb59771b97c53bdafec("_BinaryFunction_8f249c2863945cb59771b97c53bdafec", "", boost::python::no_init);
class_8f249c2863945cb59771b97c53bdafec.def(boost::python::init< struct ::std::binary_function< unsigned long int, unsigned long int, bool > const & >(""));
class_8f249c2863945cb59771b97c53bdafec.def(boost::python::init< >(""));
class_8f249c2863945cb59771b97c53bdafec.def(boost::python::init< struct ::std::binary_function< unsigned long int, unsigned long int, bool > const & >(""));

}
38 changes: 38 additions & 0 deletions test/test_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from statiskit import stl

import unittest
from nose.plugins.attrib import attr

@attr(linux=True,
osx=True,
win=True,
level=1)
class TestVector(unittest.TestCase):

def test___initialization(self):
"""Test vector initialization"""

v = stl.VectorIndex()
self.assertEqual(len(v), 0)

def test__equal(self):
"""Test vectors equality"""

v1 = stl.VectorIndex()
v1.push_back(3)
v1.push_back(1)
v1.push_back(2)
v2 = stl.VectorIndex()
v2.push_back(3)
v2.push_back(1)
v2.push_back(2)
self.assertEqual(v1, v2)
v3 = stl.VectorString()
v3.push_back('A')
v3.push_back('B')
v3.push_back('C')
v4 = stl.VectorString()
v4.push_back('A')
v4.push_back('B')
v4.push_back('C')
self.assertEqual(v3, v4)