Commit Graph

191 Commits

Author SHA1 Message Date
Jason Rhinelander
5fffe200e3 Allow arbitrary class_ template option ordering
The current pybind11::class_<Type, Holder, Trampoline> fixed template
ordering results in a requirement to repeat the Holder with its default
value (std::unique_ptr<Type>) argument, which is a little bit annoying:
it needs to be specified not because we want to override the default,
but rather because we need to specify the third argument.

This commit removes this limitation by making the class_ template take
the type name plus a parameter pack of options.  It then extracts the
first valid holder type and the first subclass type for holder_type and
trampoline type_alias, respectively.  (If unfound, both fall back to
their current defaults, `std::unique_ptr<type>` and `type`,
respectively).  If any unmatched template arguments are provided, a
static assertion fails.

What this means is that you can specify or omit the arguments in any
order:

    py::class_<A, PyA> c1(m, "A");
    py::class_<B, PyB, std::shared_ptr<B>> c2(m, "B");
    py::class_<C, std::shared_ptr<C>, PyB> c3(m, "C");

It also allows future class attributes (such as base types in the next
commit) to be passed as class template types rather than needing to use
a py::base<> wrapper.
2016-09-06 12:22:13 -04:00
Dean Moldovan
625bd48a91 Document calling function with keyword arguments from C++ 2016-09-06 16:41:50 +02:00
Wenzel Jakob
6f017cf658 basics.rst: minor table update for Eigen types 2016-09-06 14:13:35 +09:00
Wenzel Jakob
48ce0727e4 added docs for custom type casters (fixes #298) 2016-09-06 14:13:22 +09:00
Wenzel Jakob
fe34241e50 minor doc & style fixes 2016-09-06 13:02:29 +09:00
Sergey Lyskov
7520418e26 Adding bind_map 2016-09-05 17:11:16 -04:00
Wenzel Jakob
70f5a4dc8b minor: added error message to faq 2016-09-05 17:19:18 +09:00
Jason Rhinelander
64830e3333 Doc fix for OVERLOAD*_NAME macros
The documentation says the string-valued python function name goes
after the C++ function, but it actually goes before it.
2016-08-29 16:58:59 -04:00
Wenzel Jakob
5e4e477b8b minor fixes to PR #368 2016-08-28 02:03:15 +02:00
Nickolai Belakovski
6333825350 Added support for exposing classes with private destructors and corresponding documentation 2016-08-27 15:09:15 -07:00
Ivan Smirnov
606160ed68 Update the changelog re: generalized iterators 2016-08-24 23:32:13 +01:00
Wenzel Jakob
faec30c4db Merge pull request #321 from dean0x7d/pytest
Port test suite to pytest
2016-08-22 13:02:27 +02:00
Wenzel Jakob
bf099587cd documentation clarifications (fixes #346) 2016-08-22 12:52:02 +02:00
Dean Moldovan
ec0d38ef25 Update the docs to reflect the new test structure
Test compilation instructions for Windows were changed to use the
`cmake --build` command line invocation which should be easier than
manually setting up using the CMake GUI and Visual Studio.
2016-08-19 13:32:01 +02:00
Wenzel Jakob
192eb88475 ..mention in benchmark docs as well 2016-08-19 09:38:14 +02:00
Wenzel Jakob
68b193e3f2 mention pyrosetta stats 2016-08-19 09:32:58 +02:00
Wenzel Jakob
0b63231bae minor doc touchups 2016-08-18 10:58:21 +02:00
Glen Walker
f45bb585c3 Support keep_alive where nurse may be None
For example keep_alive<0,1>() should work where the return value may sometimes be None. At present a "Could not allocate weak reference!" exception is thrown.
Update documentation to clarify behaviour of keep_alive when nurse is None or does not support weak references.
2016-08-18 09:09:41 +12:00
Dean Moldovan
aebca12bb9 Fix sphinx doc missing code blocks and warnings
The missing empty line after `.. code-block::` resulted in incorrectly
parsed restructuredtext (sphinx warnings) and the code blocks were not
generated in the html output.

The `exclude_patterns` change just silences the orphaned file warning.

[ci skip]
2016-08-16 01:30:58 +02:00
Ivan Smirnov
6715736936 Add handle::repr() method 2016-08-14 13:43:31 +01:00
Ivan Smirnov
bccbc10a65 Update changelog and authors 2016-08-13 21:17:26 +01:00
Ivan Smirnov
b65185906d Update the docs to use the new array ctor 2016-08-13 13:28:56 +01:00
Ivan Smirnov
5412a05cf0 Rename PYBIND11_DTYPE to PYBIND11_NUMPY_DTYPE 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5afe9df30a Minor fix in the docs 2016-08-13 12:43:16 +01:00
Ivan Smirnov
223afe37fa Add documentation re: PYBIND11_DTYPE macro 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5e71e17bdf Make changes to format_descriptor backwards-compat
The format strings that are known at compile time are now accessible
via both ::value and ::format(), and format strings for everything
else is accessible via ::format(). This makes it backwards compatible.
2016-08-13 12:43:16 +01:00
Ivan Smirnov
42ad328481 Change format_descriptor::value to a static func 2016-08-13 12:43:16 +01:00
Jason Rhinelander
5aa85be26e Added pybind11::make_key_iterator for map iteration
This allows exposing a dict-like interface to python code, allowing
iteration over keys via:

    for k in custommapping:
        ...

while still allowing iteration over pairs, so that you can also
implement 'dict.items()' functionality which returns a pair iterator,
allowing:

    for k, v in custommapping.items():
        ...

example-sequences-and-iterators is updated with a custom class providing
both types of iteration.
2016-08-11 21:22:05 -04:00
Jason Rhinelander
f2ecd8927e Implement reference_internal with a keep_alive
reference_internal requires an `instance` field to track the returned
reference's parent, but that's just a duplication of what
keep_alive<0,1> does, so use a keep alive to do this to eliminate the
duplication.
2016-08-10 12:08:04 -04:00
Jason Rhinelander
efc2aa7ee7 Removed obsolete documentation about duplicate address problems
It no longer applies since instances are now identified by both address
and type.
2016-08-10 11:38:33 -04:00
Jason Rhinelander
d6c365bcfa virtual + inheritance example: remove multiple inheritance approach
It was already pretty badly intrusive, but it also appears to make MSVC
segfault.  Rather than investigating and fixing it, it's easier to just
remove it.
2016-08-05 18:03:06 -04:00
Jason Rhinelander
0ca96e2915 Added advanced doc section on virtual methods + inheritance
As discussed in #320.

The adds a documentation block that mentions that the trampoline classes
must provide overrides for both the classes' own virtual methods *and*
any inherited virtual methods.  It also provides a templated solution to
avoiding method duplication.

The example includes a third method (only mentioned in the "see also"
section of the documentation addition), using multiple inheritance.
While this approach works, and avoids code generation in deep
hierarchies, it is intrusive by requiring that the wrapped classes use
virtual inheritance, which itself is more instrusive if any of the
virtual base classes need anything other than default constructors.  As
per the discussion in #320, it is kept as an example, but not suggested
in the documentation.
2016-08-05 18:02:37 -04:00
Jason Rhinelander
b68d8fc2c5 *Really* fix enumeration indices 2016-08-04 16:39:30 -04:00
Jason Rhinelander
38d5b4565c Fixed enumeration indices 2016-08-04 16:36:16 -04:00
Jason Rhinelander
9ffb3dda5f Eigen support for special matrix objects
Functions returning specialized Eigen matrices like Eigen::DiagonalMatrix and
Eigen::SelfAdjointView--which inherit from EigenBase but not
DenseBase--isn't currently allowed; such classes are explicitly copyable
into a Matrix (by definition), and so we can support functions that
return them by copying the value into a Matrix then casting that
resulting dense Matrix into a numpy.ndarray.  This commit does exactly
that.
2016-08-04 15:24:41 -04:00
Wenzel Jakob
3764e28475 added note about args/kwargs limitation 2016-08-01 23:34:48 +02:00
Wenzel Jakob
f38f359f96 documentation fix (fixes #290) 2016-07-19 17:48:42 +02:00
Jason Rhinelander
3e2e44f53f Updated advanced.rst example references 2016-07-18 17:03:37 -04:00
Wenzel Jakob
fb6aed2157 return value policy clarifications 2016-07-18 20:29:53 +02:00
Wenzel Jakob
a720a6046e updated changelog with v1.8.1, updated release instructions 2016-07-12 18:03:17 +02:00
Wenzel Jakob
c47d498c35 fix rare GC issue during type creation (fixes #277) 2016-07-11 23:41:15 +02:00
Wenzel Jakob
58ec1caa9b updated README and changelog 2016-07-11 23:39:39 +02:00
Wenzel Jakob
3c6ada3a48 Merge pull request #273 from lsst-dm/master
Add support for user defined exception translators
2016-07-11 23:38:21 +02:00
Pim Schellart
5a7d17ff16 Add support for user defined exception translators 2016-07-11 17:33:04 -04:00
Wenzel Jakob
e6b2f75949 updated changelog 2016-07-10 10:54:46 +02:00
Wenzel Jakob
954b7932fe avoid C++ -> Python -> C++ overheads when passing around function objects 2016-07-10 10:44:44 +02:00
Wenzel Jakob
0d3fc3566a complete rewrite of eval/exec patch 2016-07-08 10:52:10 +02:00
Klemens Morgenstern
c6ad2c4993 added exec functions 2016-07-08 10:05:24 +02:00
Wenzel Jakob
3eeea6fa61 docs: point out limitations of implicit conversions 2016-06-30 18:10:28 +02:00
Wenzel Jakob
f53e300fbd doc updates 2016-06-30 14:59:23 +02:00