2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-22 05:22:45 +00:00

Optional flags parameter to visitor allows container features to be suppressed

[SVN r20874]
This commit is contained in:
Raoul Gough
2003-11-19 23:07:01 +00:00
parent bdde13d1bc
commit 0bc4ee884f
14 changed files with 261 additions and 70 deletions

View File

@@ -60,6 +60,7 @@ bpl-test test_deque_ref : test_deque_ref.py test_deque_ext.cpp ;
bpl-test test_deque_plain : test_deque_plain.py test_deque_ext.cpp ;
bpl-test test_indexing_const ;
bpl-test test_vector_shared ;
bpl-test test_vector_disable ;
bpl-test test_array : test_array.py test_array_ext.cpp ;
bpl-test test_array_ref : test_array_ref.py test_array_ext.cpp ;
bpl-test test_list_plain : test_list_plain.py test_list_ext.cpp ;

42
test/test_vector_disable.cpp Executable file
View File

@@ -0,0 +1,42 @@
// Module test_vector_disable.cpp
//
// Copyright (c) 2003 Raoul M. Gough
//
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
// at http://www.boost.org/LICENSE_1_0.txt)
//
// History
// =======
// 2003/11/19 rmg File creation
//
// $Id$
//
#include <boost/python/suite/indexing/container_suite.hpp>
#include <boost/python/suite/indexing/vector.hpp>
#include <vector>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
BOOST_PYTHON_MODULE(test_vector_disable_ext)
{
namespace indexing = boost::python::indexing;
typedef std::vector<int> Container1;
// Generate a vector suite with all optional support disabled
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
// Normal case (automatic algorithm and traits selection)
typedef indexing::container_suite<Container1, indexing::minimum_support>
Suite1;
#else
// For broken compilers - explicit selection of algorithms/traits
typedef indexing::vector_suite<Container1, indexing::minimum_support>
Suite1;
#endif
boost::python::class_<Container1>("Vector_disable").def (Suite1());
}

View File

@@ -0,0 +1,71 @@
# Python module test_vector_disable.py
#
# Copyright (c) 2003 Raoul M. Gough
#
# Use, modification and distribution is subject to the Boost Software
# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
# at http://www.boost.org/LICENSE_1_0.txt)
#
# History
# =======
# 2003/11/19 rmg File creation
#
# $Id$
#
'''>>> from test_vector_disable_ext import *
>>> v = Vector_disable()
>>> v.append (1)
>>> v.append (2)
>>> v.append (3)
>>> v.append (4)
>>> del v[0]
>>> print [ x for x in v ]
[2, 3, 4]
>>> v[0] = 5
>>> print [ x for x in v ]
[5, 3, 4]
>>> assert getattr (v, "len", None) == None
>>> assert getattr (v, "sort", None) == None
>>> assert getattr (v, "reverse", None) == None
>>> assert getattr (v, "index", None) == None
>>> assert getattr (v, "count", None) == None
>>> assert getattr (v, "insert", None) == None
>>> assert getattr (v, "extend", None) == None
>>> try:
... s = v[:]
... print "__getitem__ supports slices (should be disabled)"
... except TypeError, e:
... print "Got expected exception"
...
Got expected exception
>>> try:
... v[:1] = [1]
... print "__setitem__ supports slices (should be disabled)"
... except TypeError, e:
... print "Got expected exception"
...
Got expected exception
>>> try:
... del v[:]
... print "__delitem__ supports slices (should be disabled)"
... except TypeError, e:
... print "Got expected exception"
...
Got expected exception
'''
def run(args = None):
import sys
import doctest
if args is not None:
sys.argv = args
return doctest.testmod(sys.modules.get(__name__))
if __name__ == '__main__':
print 'running...'
import sys
status = run()[0]
if (status == 0): print "Done."
sys.exit(status)

View File

@@ -70,7 +70,7 @@ BOOST_PYTHON_MODULE(test_vector_shared_ext)
typedef indexing::default_sequence_traits<Container1, value_traits_>
container_traits_;
typedef indexing::default_algorithms<container_traits_> algorithms_;
typedef indexing::container_suite<Container1, algorithms_> Suite1;
typedef indexing::container_suite<Container1, 0, algorithms_> Suite1;
boost::python::class_<Container1>("Vector_shared")
.def (Suite1())