aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken/conversions.h
Commit message (Collapse)AuthorAgeFilesLines
...
* Sequence conversion are made ONLY for python sequences.Hugo Lima2010-03-181-3/+7
| | | | | | Not for binded types implementing sequence protocol, otherwise this will cause a mess like QBitArray being accepted by someone expecting a QStringList.
* Just try to reduce a bit the noise in source code caused by the use of ↵Hugo Lima2010-03-181-4/+2
| | | | templates.
* Add a default implementation for SbkType, so not binded types will return a ↵Hugo Lima2010-03-181-1/+4
| | | | | | | null pointer. Pro: Will be possible to write template functions to handle sequence conversions. Cons: We will not have an unresolved symbol when an error occur on generator.
* Renamed templates used for conversions of containers.Hugo Lima2010-03-181-5/+5
|
* Changed the semantic of Converter<T>::isConvertible method.Hugo Lima2010-03-181-21/+70
| | | | | | | | | The new semantic is: Returns true when the type can be converted to T OR the type is T. The old semantic was: Returns true when the type can be converted to T and false if the type is T, however int and float converters did not follow this rule, because they used PyNumber_Check on their isConvertible implementation.
* Do not incref and decref the python dict reference on python to c++ conversions.Hugo Lima2010-03-181-5/+0
|
* Fix reference leak in StdPair converter.Hugo Lima2010-03-181-2/+2
|
* Merge branch 'master' into extensibleconversionsMarcelo Lira2010-03-041-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: cppgenerator.cpp libshiboken/basewrapper.cpp Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Lauro Moura <lauro.neto@openbossa.org>
| * Merge remote branch 'hugopl/typediscovery2'Hugo Lima2010-03-031-1/+1
| |\ | | | | | | | | | | | | Conflicts: libshiboken/conversions.h
| | * Use polymorphic-id-expression to discover the correct type of a C++ object.Hugo Lima2010-03-021-1/+1
| | |
* | | Adds support for extensible converters for value type classes.Marcelo Lira2010-03-021-4/+24
|/ / | | | | | | | | | | | | | | | | | | Value type classes without implicit conversions use the default implementation provided by ValueTypeConverter. This commit updates ValueTypeConverter to check for extended conversions, since even a class without implicit conversions in one module could get some conversion operators in another. CppGenerator now writes 'isConvertible' calls to all object and value types checks leaving the door open to extended conversions.
* / Refactored and documented base Converters.Marcelo Lira2010-03-021-59/+68
|/ | | | | | | | | | | | To improve legibility and understanding ConverterBase<T> was renamed to ValueTypeConverter<T>, and ConverterBase<T*> specialization is now an independent base converter ObjectTypeConverter<T>. Converter_CppEnum was renamed to EnumConverter. The HeaderGenerator and custom converters for the test bindings were updated accordingly. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Lauro Moura <lauro.neto@openbossa.org>
* Rename SbkCreateWrapper to createWrapper, to follow our fuction naming ↵Hugo Lima2010-02-261-4/+4
| | | | | | conventions. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Fix bug #142 by eliminating the CppCopier::copy function and adding it to a ↵Hugo Lima2010-02-261-7/+28
| | | | field in SbkBaseWrapper_Type.
* Remove warnings related to comparison between signed and unsigned integer ↵Hugo Lima2010-02-221-21/+41
| | | | expressions.
* The C string converter now transforms a Python None in a C null pointer.Marcelo Lira2010-02-201-1/+5
| | | | | The conversion of '[const] char*' to C++ now accepts an None object and gives back a NULL pointer.
* Some optimizations and code cleanup on conversion code for std containers.Hugo Lima2010-02-181-11/+7
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Converter<T> doesn't inherits ConverterBase, to avoid uneeded template ↵Hugo Lima2010-02-181-1/+1
| | | | instanciations.
* char converter return string instead of intLauro Neto2010-02-021-1/+7
| | | | | | Only if not specified signed/unsigned Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
* Adds support for void pointer conversions.Marcelo Lira2010-01-281-0/+24
| | | | | | | | | A new converter specialization was added to deal with 'void*' conversions. In the case of C++ generating a unknown void pointer a BaseWrapper is used to hold the said pointer. There is a new test for this situation. Reviewed by Renato Araújo <renato.filho@openbossa.org>
* Add overflow check to unsigned int, because we need it on 64bit platforms.Hugo Lima2010-01-221-21/+10
|
* Fix bug on overflow check routines under 32 bits platforms.Hugo Lima2010-01-221-33/+50
|
* Add special conversion rules to the char type.Hugo Lima2010-01-201-3/+28
| | | | | | A type is convertible to char if it is a number or a 1-sized char. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Converter<PyInt> now follows the Converter interface.Hugo Lima2010-01-201-2/+2
| | | | | - Converter<PyInt>::isConvertible should return bool instead of int and - Converter<PyInt>::toPython must receive "const PyInt&" instead of just "PyInt".
* Added template specialization SbkType<signed char>(), needed by someone.Hugo Lima2010-01-141-0/+1
|
* Implemented type discovery feature.Hugo Lima2010-01-141-3/+5
| | | | | | | | | | | | | | | The problem: - There are two class, A and B, B inherits from A. - You are inside a virtual method reimplemented in python with just one parameter of type A*. - But the object referenced by a variable of type A* is an instance of B and it was created by C++, not Python! - Shiboken needs to create a PyObject of type B, not A! This does not makes sense for C++, but does for Python, because python variables does not store type information, just values. To achieve this we use RTTI to get the real type name of a variable, then we create the PyObject using the TypeResolver infrastructure initially developed to help with signal slot problems. In other words, the TypeResolver class has been moved from libpyside to libshiboken.
* Fix transfer ownership on return values.Hugo Lima2010-01-131-0/+1
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Replaces SbkCopyCppObject template function with the CppObjectCopier ↵Marcelo Lira2009-12-221-113/+46
| | | | | | | | | | | | | | | template struct In addition to the mere use of SbkCopyCppObject to copy C++ objects, it is needed to know if a C++ type has a C++ wrapped produced by the generator. To solve this SbkCopyCppObject was transformed in the template struct CppObjectCopier with the methods copy and the constant member isCppWrapper. The Converter[Base]<>::createWrapper methods were replaced by template function SbkCreateWrapper. Also some refactoring was made on the Converters code to improve legibility. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
* Improvements and refactor on libshiboken's converters.Marcelo Lira2009-12-211-41/+87
| | | | | | | Short methods in Converter and ConverterBase variations received the "inline" keyword. A convenience "toPython" signature receiving "void*" as parameter was also added to the converter classes.
* Refactored SbkType specializations and replaced "long long" by "PY_LONG_LONG".Marcelo Lira2009-12-211-78/+13
|
* Added template specializations for SbkType<T> when T is a primitive type.Hugo Lima2009-12-161-5/+81
|
* Tests for numerical implicit conversions and fixesLauro Neto2009-12-161-9/+36
| | | | | | | | | | | | Added a test for simple implicit numerical conversions involving doubles, signed and unsigned ints and longs. Some fixes to the converters were also made, mostly related to adding manual checks for boundaries with doubles for negative values Also put the overflow check in a single template Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
* All wrapped classes now inherit from the SbkBaseWrapper of the metatype ↵Marcelo Lira2009-12-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | SbkBaseWrapperType. The wrapped classes are described with a SbkBaseWrapperType structure which extends the PyTypeObject with information about multiple inheritance and parenting ownership. This works well for the classes produced by the generator but inheriting classes written in Python continues using the PyTypeObject to describe themselves. To fix this the SbkBaseWrapperType is now a metatype for all the wrapped classes and anyone inheriting from them. In addition all the wrapped classes now inherit from SbkBaseWrapper, since Python's PyType_Ready method need that multiple inheriting classes have a common base class with the same size of the classes involved in the multiple inheritance, which disqualifies Python's base "object" class. The metatype and the base wrapper type are initialized by calling the new Shiboken::init_shiboken() function. This is done by all the imported binding modules, but it is really run only in the first call. Another noteworthy change is the replacement of PyTypeObject as a basis for SbkBaseWrapperType by the PyHeapTypeObject, since the latter is the proper choice for types created on the heap, e.g. user defined classes extending the generated wrapper classes. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Renamed ShiboTypeObject to SbkBaseWrapperType to clearify its relationship ↵Marcelo Lira2009-12-111-2/+2
| | | | with SbkBaseWrapper.
* Converter<T>::copyCppObject method was replaced by a template function.Marcelo Lira2009-12-101-8/+25
| | | | | | | | | | | | | | | | | Added the template function T* SbkCopyCppObject(const T& cppobj); whose task is simply to copy a C++ object. If the binding has a C++ class wrapper for it, the function is specialized to use the copy constructor of the C++ wrapper class. This replaces the Converter<T>::copyCppObject method. Also moved implementation of Converter<T>::toPython from the generator to ConverterBase<T> in the conversions header, for it makes use of the SbkCopyCppObject. Reviewed by Lauro Neto <lauro.neto@openbossa.org>
* Renamed a lot of Shiboken things with "Py" prefix to use "Sbk" prefix.Marcelo Lira2009-12-081-7/+7
| | | | | | | | | | | | | | To avoid confusion of Python stuff with Shiboken generated stuff. For example: a C++ class called "String" would have the PyString_Type wrapper generated for it, mixing with the proper Python PyString_Type; now the generate code will have things like SbkString_Type, SbkString_New, SbkString_someMethod, and so on. PyBaseWrapper and its variants were renamed to SbkBaseWrapper. PyType<T>() is now SbkType<T>() PyEnumObject was renamed to SbkEnumObject.
* Moved container converters from test library to libshiboken's converter header.Marcelo Lira2009-12-071-0/+117
| | | | | | | The implementation of converters for pair, list and map containers was moved from libsample test binding to libshiboken/conversions.h. The implementation must be used with types similar to the C++ STL containers of the same name.
* Added Shiboken_TypeCheck macro that makes use of PyType<T>().Marcelo Lira2009-12-071-3/+3
| | | | | | | | | | | The Shiboken_TypeCheck calls Python's PyObject_TypeCheck using the type pointer stored in PyType<T> for the type being checked. Conversion<T*>::toCpp(pyobj) converter tries first to convert pyobj to the Python wrapper for type T and only second to any of the convertible types. If pyobj is neither of those, 0 is returned as the C++ object. This works fine for Py_None and invalid values are not expected to be passed because the generated code checked the types first.
* Do not generate the method Converter<T>::createWrapper, it'll beHugo Lima2009-12-071-17/+22
| | | | | | | auto generated by the compiler using the function PyType<T> to get PyTypeObject of a type T. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Adds Overflow check to integer types conversions.Marcelo Lira2009-12-071-3/+9
| | | | | | Unit tests were added also. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Multiple inheritance works as desired for 99.9% of all known use cases!Hugo Lima2009-12-051-0/+15
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Converter's basic isConvertible and toCpp methods consider None as C++ NULL ↵Marcelo Lira2009-12-011-2/+6
| | | | pointer.
* Added the invalidateWrapper method to BindingManager.Marcelo Lira2009-11-251-3/+3
| | | | | | | | | | | | It sets the wrapper as invalid and removes the relation of C++ objects to the Python wrapper from the mappings. Moved BindingManager::releaseWrapper(void*) to BindingManagerPrivate, since it should only be used by releaseWrapper(PyObject*). Modified includes on conversions.h to use quotes instead of < and >. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Added an PyObject* specialization to the Conversion template toMarcelo Lira2009-11-241-0/+8
| | | | | | | avoid problems when converting PyObjects to C++. Tests where also added for this. Reviewed by Lauro Neto <lauro.neto@openbossa.org>
* When the user adds a function with an argument unknown for the typesystem,Hugo Lima2009-11-191-0/+4
| | | | | | | the generator writes type checks as TYPENAME_Check, so this macro allows users to add PyObject arguments to their added functions. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Fixed C string toPython converter to return Py_None when a NULL pointerMarcelo Lira2009-11-181-2/+4
| | | | | is received. Fixed and improved the test for functions returning NULL pointer values.
* Fixed Converter<>::toPython(cppobj) method to return Py_None when cppobj is ↵Marcelo Lira2009-11-181-0/+4
| | | | NULL.
* Adding signed int/long/char to primitiveType dictLauro Neto2009-11-101-0/+1
| | | | Reviewed by Hugo Lima (hugo.lima@openbossa.org)
* improved and organized the workings of conversion templates: addedMarcelo Lira2009-11-031-22/+40
| | | | | | | | | | | | | | | | | | | | | ConverterBase from which the generic Converter<T> and the specific Converters inherit; two methods were added: * createWrapper: returns a new PyObject wrapper with the Python type information produced by the HeaderGenerator; this method is called by toPython when a not yet wrapped C++ object needs to be converted. * copyCppObject: copies a instance of a C++ class, usually created by a implicit conversion that needs to be passed to a C++ methods; could be more than one method with variants of the converted type (value, reference, pointer) that makes no difference to the Python wrapped class. The C++ arguments converted from Python arguments by the Python method wrapper are dealt with as pointers if they are object or value types. Abstract classes and object-types, whose copy constructor and operator= should be private, are declared as Converter<T*> instead of Converter<T> and inherit from ConverterBase<T*>, this avoids impossible tries to copy such objects.
* added "PyObject* createWrapper(const T* cppobj)" to the Converter structureMarcelo Lira2009-11-011-28/+55
| | | | | | | | | | | | | | | | | from libshiboken, other changes followed this improvement: * added a Converter<T*> specialization that inherits from Converter<T>; its toPython(const T* cppobj) method returns a existing Python wrapper and increments its refcount, or else it creates a new wrapper using the createWrapper method. Now createWrapper is the only method generated for Object Type conversions. * added a Converter<T&> specialization that inherits from Converter<T*> and just calls its parent's methods adapting them to C++ references. * added a base template class for C++ enums and flags conversions called Converter_CppEnum, it inherits from the base Conversion class. Now the HeaderGenerator need only to generate the Converter<ENUM>::createWrapper method. * all generated conversions now uses only the type name and no qualifiers (i.e. Object Type converters are declared Converter<TYPE> instead of Converter<TYPE*>