4.9. foundations.library

library.py

Platform:
Windows, Linux, Mac Os X.
Description:
This module provides objects for C / C++ libraries binding.

Others:

4.9.1. Module Attributes

foundations.library.LOGGER

4.9.2. Classes

class foundations.library.LibraryHook(**kwargs)[source]

Bases: foundations.dataStructures.Structure

This class represents a library hook used by the Library class to bind target library functions.

Usage:

LibraryHook(name="FreeImage_GetVersion", argumentsTypes=None, returnValue=ctypes.c_char_p)
Parameters:
  • name – Name of the target library function to bind. ( String )
  • argumentsTypes – Required function arguments type (Refer to Python ctypes - 15.17.1.7 module for more informations). ( List )
  • returnValue – Function return type (Refer to Python ctypes - 15.17.1.8 module for more informations). ( Object )
class foundations.library.Library(libraryPath, functions=None, bindLibrary=True)[source]

Bases: object

This class provides methods to bind a C / C++ Library.
The class is a singleton and will bind only one time a given library. Each unique library instance is stored in Library.librariesInstances attribute and get returned if the library is requested again through a new instantiation.

Usage:

>>> path = "FreeImage.dll"
>>> functions = (LibraryHook(name="FreeImage_GetVersion", argumentsTypes=None, returnValue=ctypes.c_char_p),)
>>> library = Library(path, functions)
>>> library.FreeImage_GetVersion()
3.13.1
Parameters:
  • libraryPath – Library path. ( String )
  • functions – Binding functions list. ( Tuple )
  • bindLibrary – Library will be binded on initialization. ( Boolean )
callback

callback: Defines library callback default function. ( ctypes.CFUNCTYPE )

alias of CFunctionType

librariesInstances[source]

This method is the property for self.__librariesInstances attribute.

Returns:self.__librariesInstances. ( WeakValueDictionary )
libraryInstantiated[source]

This method is the property for self.__libraryInstantiated attribute.

Returns:self.__libraryInstantiated. ( String )
libraryPath[source]

This method is the property for self.__libraryPath attribute.

Returns:self.__libraryPath. ( String )
functions[source]

This method is the property for self.__functions attribute.

Returns:self.__functions. ( Tuple )
library[source]

This method is the property for self.__library attribute.

Returns:self.__library. ( Object )
bindFunction(function)[source]

This method binds given function to a class object attribute.

Usage:

>>> path = "FreeImage.dll"
>>> function = LibraryHook(name="FreeImage_GetVersion", argumentsTypes=None, returnValue=ctypes.c_char_p)
>>> library = Library(path, bindLibrary=False)
>>> library.bindFunction(function)
True
>>> library.FreeImage_GetVersion()
3.13.1
Parameters:function – Function to bind. ( LibraryHook )
Returns:Method success. ( Boolean )
bindLibrary()[source]

This method binds the Library using functions registered in the self.__functions attribute.

Usage:

>>> path = "FreeImage.dll"
>>> functions = (LibraryHook(name="FreeImage_GetVersion", argumentsTypes=None, returnValue=ctypes.c_char_p),)
>>> library = Library(path, functions, bindLibrary=False)
>>> library.bindLibrary()
True
>>> library.FreeImage_GetVersion()
3.13.1
Returns:Method success. ( Boolean )

Table Of Contents

Previous topic

4.8. foundations.io

Next topic

4.10. foundations.namespace

This Page