python-efl/efl/eolian/__init__.pyx

891 lines
24 KiB
Cython
Raw Normal View History

2014-06-05 16:57:14 -07:00
from libc.stdint cimport uintptr_t
from cpython cimport PyUnicode_AsUTF8String
from efl.eina cimport eina_inlist_count, EINA_LOG_DOM_DBG, \
EINA_LOG_DOM_INFO, EINA_LOG_DOM_WARN, EINA_LOG_DOM_ERR, EINA_LOG_DOM_CRIT
2014-06-05 16:57:14 -07:00
from efl.utils.conversions cimport _ctouni, eina_list_strings_to_python_list
from efl.utils.logger cimport add_logger
cdef int EOLIAN_DOM = add_logger("efl.eolian").eina_log_domain
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
from efl.utils.enum import IntEnum
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
class FunctionType(IntEnum):
"""Function Type"""
2014-06-10 14:28:08 -07:00
UNRESOLVED = EOLIAN_UNRESOLVED
PROPERTY = EOLIAN_PROPERTY
PROP_SET = EOLIAN_PROP_SET
PROP_GET = EOLIAN_PROP_GET
METHOD = EOLIAN_METHOD
CTOR = EOLIAN_CTOR
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
class ParameterDir(IntEnum):
"""Parameter Direction"""
2014-06-12 13:46:36 -07:00
IN = EOLIAN_IN_PARAM
OUT = EOLIAN_OUT_PARAM
INOUT = EOLIAN_INOUT_PARAM
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
class ClassType(IntEnum):
"""Class Type"""
2014-06-10 14:28:08 -07:00
UNKNOWN = EOLIAN_CLASS_UNKNOWN_TYPE
REGULAR = EOLIAN_CLASS_REGULAR
ABSTRACT = EOLIAN_CLASS_ABSTRACT
MIXIN = EOLIAN_CLASS_MIXIN
INTERFACE = EOLIAN_CLASS_INTERFACE
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
class FunctionScope(IntEnum):
"""Function Scope"""
2014-06-10 14:28:08 -07:00
PUBLIC = EOLIAN_SCOPE_PUBLIC
PROTECTED = EOLIAN_SCOPE_PROTECTED
2014-06-05 16:57:14 -07:00
cdef list eina_list_obj_to_python_list(const Eina_List *lst, type cls):
2014-06-05 16:57:14 -07:00
cdef:
list ret = list()
while lst:
if lst.data == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eina lists data pointer is NULL", NULL
)
lst = lst.next
if cls is Class:
o = eolian_class_to_python_obj(<Eolian_Class>lst.data)
elif cls is Function:
o = eolian_func_to_python_obj(<Eolian_Function>lst.data)
elif cls is FunctionParameter:
o = eolian_func_param_to_python_obj(<Eolian_Function_Parameter>lst.data)
elif cls is Type:
o = eolian_type_to_python_obj(<Eolian_Type>lst.data)
elif cls is Implement:
o = eolian_implement_to_python_obj(<Eolian_Implement>lst.data)
elif cls is Event:
o = eolian_event_to_python_obj(<Eolian_Event>lst.data)
else:
EINA_LOG_DOM_WARN(
EOLIAN_DOM, "Unknown type for conversion", NULL
)
return
2014-06-05 16:57:14 -07:00
ret.append(o)
lst = lst.next
return ret
cdef Class eolian_class_to_python_obj(Eolian_Class o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Class is NULL", NULL
)
return None
cdef Class ret = Class.__new__(Class)
ret._set_obj(o)
return ret
cdef Function eolian_func_to_python_obj(Eolian_Function o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Function is NULL", NULL
)
return None
cdef Function ret = Function.__new__(Function)
ret._set_obj(o)
return ret
cdef FunctionParameter eolian_func_param_to_python_obj(
Eolian_Function_Parameter o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Function_Parameter is NULL", NULL
)
return None
cdef FunctionParameter ret = FunctionParameter.__new__(FunctionParameter)
ret._set_obj(o)
return ret
cdef Type eolian_type_to_python_obj(Eolian_Type o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Type is NULL", NULL
)
return None
cdef Type ret = Type.__new__(Type)
ret._set_obj(o)
return ret
cdef Implement eolian_implement_to_python_obj(Eolian_Implement o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Implement is NULL", NULL
)
return None
cdef Implement ret = Implement.__new__(Implement)
ret._set_obj(o)
return ret
cdef Event eolian_event_to_python_obj(Eolian_Event o):
if o == NULL:
EINA_LOG_DOM_DBG(
EOLIAN_DOM, "Eolian_Event is NULL", NULL
)
return None
cdef Event ret = Event.__new__(Event)
ret._set_obj(o)
2014-06-05 16:57:14 -07:00
return ret
def eo_file_parse(filename):
"""Parse a given .eo file and fill the database.
During parsing, the class described into the .eo file is created with
all the information related to this class.
:param filename: Name of the file to parse.
"""
if isinstance(filename, unicode): filename = PyUnicode_AsUTF8String(filename)
cdef bint ret = eolian_eo_file_parse(filename)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in directory_scan()", NULL)
return ret
2014-06-05 16:57:14 -07:00
def init():
"""Init Eolian.
:rtype: int
"""
EINA_LOG_DOM_INFO(EOLIAN_DOM, "Initializing efl.eolian", NULL)
2014-06-05 16:57:14 -07:00
return eolian_init()
def shutdown():
"""Shutdown Eolian.
:rtype: int
"""
EINA_LOG_DOM_INFO(EOLIAN_DOM, "Shutting down efl.eolian", NULL)
2014-06-05 16:57:14 -07:00
return eolian_shutdown()
def directory_scan(directory):
"""Scan the given directory and search for .eo files.
The found files are just open to extract the class name.
2014-06-07 08:17:40 -07:00
:param dir: the directory to scan
:return: True on success, False otherwise.
2014-06-05 16:57:14 -07:00
"""
if isinstance(directory, unicode): directory = PyUnicode_AsUTF8String(directory)
cdef bint ret = eolian_directory_scan(directory)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in directory_scan()", NULL)
return ret
2014-06-05 16:57:14 -07:00
def all_eo_files_parse():
"""Force parsing of all the files located in the directories
given in eolian_directory_scan..
2014-06-07 08:17:40 -07:00
:return: True on success, False otherwise.
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
:see: :py:func:`directory_scan`
2014-06-05 16:57:14 -07:00
"""
cdef bint ret = eolian_all_eo_files_parse()
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in all_eo_files_parse()", NULL)
return ret
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def show(Class klass=None):
2014-06-05 16:57:14 -07:00
"""Show information about a given class.
2014-06-07 08:17:40 -07:00
If klass is None, this function will print information of
2014-06-05 16:57:14 -07:00
all the classes stored into the database.
2014-06-07 08:17:40 -07:00
:param klass: the class to show
2014-06-05 16:57:14 -07:00
"""
cdef bint ret = eolian_show(
2014-06-07 08:17:40 -07:00
klass.klass if klass is not None else NULL
)
if not ret:
EINA_LOG_DOM_WARN(EOLIAN_DOM, "Failure in show()", NULL)
return ret
2014-06-05 16:57:14 -07:00
def class_find_by_name(class_name):
"""Finds a class by its name
2014-06-07 08:17:40 -07:00
:param class_name: name of the class to find.
:return: the class
2014-06-05 16:57:14 -07:00
"""
if isinstance(class_name, unicode): class_name = PyUnicode_AsUTF8String(class_name)
cdef Eolian_Class klass = eolian_class_find_by_name(class_name)
if klass is NULL:
return None
else:
return eolian_class_to_python_obj(klass)
2014-06-05 16:57:14 -07:00
def class_find_by_file(file_name):
"""Finds a class by its location (.eo file)
2014-06-07 08:17:40 -07:00
:param file_name: filename where the class is stored.
:return: the class stored in the file
2014-06-05 16:57:14 -07:00
"""
if isinstance(file_name, unicode): file_name = PyUnicode_AsUTF8String(file_name)
return eolian_class_to_python_obj(
eolian_class_find_by_file(file_name)
2014-06-05 16:57:14 -07:00
)
cdef class Class(object):
cdef Eolian_Class klass
cdef _set_obj(self, Eolian_Class obj):
self.klass = obj
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def __init__(self):
pass
2014-06-10 14:28:08 -07:00
def __repr__(self):
return (
2014-06-11 05:50:15 -07:00
"<%s (full_name=%s, filename=%s, type=%s, inherits=%r, "
"description=%s)>" % (
2014-06-10 14:28:08 -07:00
self.name, self.full_name, self.filename,
2014-06-11 05:50:15 -07:00
self.type, self.inherits_list,
self.description.replace('\n', ' ') if self.description else \
None
2014-06-10 14:28:08 -07:00
))
2014-06-05 16:57:14 -07:00
property filename:
"""Returns the name of the file containing the given class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_file_get(self.klass))
property full_name:
"""Returns the full name of the given class.
:type: string
The full name and the name of a class will be different if namespaces
are used.
"""
def __get__(self):
return _ctouni(eolian_class_full_name_get(self.klass))
property name:
"""Returns the name of the given class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_name_get(self.klass))
property namespaces_list:
"""Returns the namespaces list of the given class.
2014-06-07 08:17:40 -07:00
:type: list of strings
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
2014-06-07 08:17:40 -07:00
return eina_list_strings_to_python_list(
eolian_class_namespaces_list_get(self.klass)
)
2014-06-05 16:57:14 -07:00
property type:
"""Returns the class type of the given class
:type: :class:`ClassType`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
2014-06-10 14:28:08 -07:00
return ClassType(eolian_class_type_get(self.klass))
2014-06-05 16:57:14 -07:00
property description:
"""Returns the description of a class.
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_description_get(self.klass))
property legacy_prefix:
"""Returns the legacy prefix of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_legacy_prefix_get(self.klass))
property eo_prefix:
"""Returns the eo prefix of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_eo_prefix_get(self.klass))
property data_type:
"""Returns the data type of a class
:type: string
"""
def __get__(self):
return _ctouni(eolian_class_data_type_get(self.klass))
property inherits_list:
"""Returns the names list of the inherit classes of a class
2014-06-07 08:17:40 -07:00
:type: list of strings
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
2014-06-07 08:17:40 -07:00
return eina_list_strings_to_python_list(
eolian_class_inherits_list_get(self.klass)
)
2014-06-05 16:57:14 -07:00
def functions_list_get(self, Eolian_Function_Type func_type):
"""Returns a list of functions of a class.
2014-06-07 08:17:40 -07:00
:param func_type: type of the functions to insert into the list.
:return: the list of Eolian_Function
2014-06-05 16:57:14 -07:00
"""
return eina_list_obj_to_python_list(
eolian_class_functions_list_get(
self.klass, func_type
),
Function
)
property implements:
"""Get the list of overriding functions defined in a class.
2014-06-07 08:17:40 -07:00
:type: list of :py:class:`Implement`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eina_list_obj_to_python_list(
eolian_class_implements_list_get(self.klass), Implement
)
property events:
"""Get the list of events defined in a class.
2014-06-07 08:17:40 -07:00
:type: list of :py:class:`Event`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eina_list_obj_to_python_list(
eolian_class_events_list_get(self.klass), Event
)
property constructor_enabled:
"""Indicates if the class constructor has to invoke
a non-generated class constructor function.
2014-06-07 08:17:40 -07:00
:type: bool
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return bool(eolian_class_ctor_enable_get(self.klass))
property destructor_enabled:
"""Indicates if the class destructor has to invoke
a non-generated class destructor function.
2014-06-07 08:17:40 -07:00
:type: bool
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return bool(eolian_class_dtor_enable_get(self.klass))
def function_find_by_name(self, func_name, Eolian_Function_Type f_type):
"""Find a function in a class by its name and type
2014-06-07 08:17:40 -07:00
:param func_name: name of the function
:param f_type: type of the function
:return: the function id if found, None otherwise.
2014-06-05 16:57:14 -07:00
"""
2014-06-07 08:17:40 -07:00
if isinstance(func_name, unicode):
func_name = PyUnicode_AsUTF8String(func_name)
return eolian_func_to_python_obj(
eolian_class_function_find_by_name(
2014-06-05 16:57:14 -07:00
self.klass, func_name, f_type
)
2014-06-05 16:57:14 -07:00
)
def class_names_list_get():
"""Returns the names list of all the classes stored into the database.
2014-06-07 08:17:40 -07:00
:return: the list
2014-06-05 16:57:14 -07:00
Returns the list of class names of the database
"""
return eina_list_strings_to_python_list(eolian_class_names_list_get())
cdef class Function(object):
cdef Eolian_Function function_id
cdef _set_obj(self, Eolian_Function obj):
self.function_id = obj
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def __init__(self):
pass
2014-06-10 14:28:08 -07:00
def __repr__(self):
return (
"<%s (type=%s, scope=%s, is_const=%r)>" % (
self.name, self.type, self.scope, self.object_is_const,
))
2014-06-05 16:57:14 -07:00
property type:
"""Returns the type of a function
:type: :class:`FunctionType`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
2014-06-10 14:28:08 -07:00
return FunctionType(eolian_function_type_get(self.function_id))
2014-06-05 16:57:14 -07:00
property scope:
"""Returns the scope of a function
:type: :class:`FunctionScope`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
2014-06-10 14:28:08 -07:00
return FunctionScope(eolian_function_scope_get(self.function_id))
2014-06-05 16:57:14 -07:00
property name:
"""Returns the name of a function
2014-06-07 08:17:40 -07:00
:type: string
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return _ctouni(eolian_function_name_get(self.function_id))
def data_get(self, key):
"""Returns a specific data for a function.
2014-06-07 08:17:40 -07:00
:param key: key to access the data
:return: the data.
2014-06-05 16:57:14 -07:00
"""
if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
return _ctouni(eolian_function_data_get(self.function_id, key))
def is_virtual_pure_get(self, Eolian_Function_Type f_type):
"""Indicates if a function is virtual pure.
2014-06-07 08:17:40 -07:00
:return: True if virtual pure, False otherwise..
2014-06-05 16:57:14 -07:00
"""
return bool(eolian_function_is_virtual_pure(self.function_id, f_type))
def description_get(self, key):
"""Returns a specific description for a function.
2014-06-07 08:17:40 -07:00
:param key: key to access the description
:return: the description.
2014-06-05 16:57:14 -07:00
"""
if isinstance(key, unicode): key = PyUnicode_AsUTF8String(key)
return _ctouni(eolian_function_data_get(self.function_id, key))
def parameter_get(self, param_name):
"""Returns a parameter of a function pointed by its id.
2014-06-07 08:17:40 -07:00
:param param_name: Name of the parameter
:return: a handle to this parameter.
2014-06-05 16:57:14 -07:00
"""
2014-06-07 08:17:40 -07:00
if isinstance(param_name, unicode):
param_name = PyUnicode_AsUTF8String(param_name)
return eolian_func_param_to_python_obj(
eolian_function_parameter_get(
2014-06-05 16:57:14 -07:00
self.function_id, param_name
)
2014-06-05 16:57:14 -07:00
)
property property_keys_list:
"""Returns a list of keys params of a given function.
2014-06-07 08:17:40 -07:00
:type: list of :py:class:`FunctionParameter`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eina_list_obj_to_python_list(
eolian_property_keys_list_get(self.function_id), FunctionParameter
)
property property_values_list:
"""Returns a list of values params of a given function.
2014-06-07 08:17:40 -07:00
:type: list of :py:class:`FunctionParameter`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eina_list_obj_to_python_list(
2014-06-07 08:17:40 -07:00
eolian_property_values_list_get(self.function_id),
FunctionParameter
2014-06-05 16:57:14 -07:00
)
property parameters_list:
"""Returns a list of parameter handles for a method/ctor/dtor.
2014-06-07 08:17:40 -07:00
:type: list of :py:class:`FunctionParameter`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eina_list_obj_to_python_list(
eolian_parameters_list_get(self.function_id), FunctionParameter
)
def return_type_get(self, Eolian_Function_Type ftype):
"""Get the return type of a function.
2014-06-07 08:17:40 -07:00
:param ftype: type of the function
:return: the return type of the function
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
The type of the function is needed because a given function can
represent a property, that can be set and get functions.
2014-06-05 16:57:14 -07:00
"""
return _ctouni(eolian_function_return_type_get(
self.function_id, ftype
))
def return_types_list_get(self, Eolian_Function_Type ftype):
"""Get a list of all the types of a function return
2014-06-07 08:17:40 -07:00
:param ftype: Function Type
:return: the types of the function return
2014-06-05 16:57:14 -07:00
"""
return eolian_type_to_python_obj(
eolian_function_return_types_list_get(
2014-06-05 16:57:14 -07:00
self.function_id, ftype
)
2014-06-05 16:57:14 -07:00
)
def return_dflt_value_get(self, Eolian_Function_Type ftype):
"""Get the return default value of a function.
2014-06-07 08:17:40 -07:00
:param ftype: type of the function
:return: the return default value of the function
2014-06-05 16:57:14 -07:00
The return default value is needed to return an appropriate
value if an error occurs (eo_do failure...).
2014-06-07 08:17:40 -07:00
The default value is not mandatory, so None can be returned.
2014-06-05 16:57:14 -07:00
"""
return _ctouni(eolian_function_return_dflt_value_get(
self.function_id, ftype
))
def return_comment_get(self, Eolian_Function_Type ftype):
"""Get the return comment of a function.
2014-06-07 08:17:40 -07:00
:param ftype: type of the function
:return: the return comment of the function
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
The type of the function is needed because a given function can
represent a property, that can be set and get functions.
2014-06-05 16:57:14 -07:00
"""
return _ctouni(eolian_function_return_comment_get(
self.function_id, ftype
))
def return_is_warn_unused_get(self, Eolian_Function_Type ftype):
"""Indicates if a function return is warn-unused.
2014-06-07 08:17:40 -07:00
:param ftype: type of the function
:return: True is warn-unused, False otherwise.
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
The type of the function is needed because a given function can
represent a property, that can be set and get functions.
2014-06-05 16:57:14 -07:00
"""
return bool(eolian_function_return_is_warn_unused(
self.function_id, ftype
))
property object_is_const:
"""Indicates if a function object is const.
2014-06-07 08:17:40 -07:00
:return: True if the object is const, False otherwise
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return bool(eolian_function_object_is_const(self.function_id))
cdef class FunctionParameter(object):
cdef Eolian_Function_Parameter param
cdef _set_obj(self, Eolian_Function_Parameter obj):
self.param = obj
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def __init__(self):
pass
2014-06-10 14:28:08 -07:00
def __repr__(self):
info = self.information
return (
2014-06-11 05:50:15 -07:00
"<%s (type=%s, direction=%s, is_nonull=%r, description=%s)>" % (
2014-06-10 14:28:08 -07:00
info[2], info[1], info[0], self.is_nonull,
2014-06-11 05:50:15 -07:00
info[3].replace('\n', ' ') if info[3] else None
2014-06-10 14:28:08 -07:00
))
2014-06-05 16:57:14 -07:00
property information:
"""Get information about a function parameter
:type: :class:`ParameterDir` direction, string type, string name,
2014-06-07 08:17:40 -07:00
string description
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
cdef:
Eolian_Parameter_Dir param_dir
const char *type
const char *name
const char *description
eolian_parameter_information_get(
self.param, &param_dir, &type, &name, &description
)
2014-06-07 08:17:40 -07:00
return (
2014-06-10 14:28:08 -07:00
ParameterDir(param_dir), _ctouni(type), _ctouni(name),
_ctouni(description)
2014-06-07 08:17:40 -07:00
)
2014-06-05 16:57:14 -07:00
property type:
"""Get type of a parameter
2014-06-07 08:17:40 -07:00
:type: string
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return _ctouni(eolian_parameter_type_get(self.param))
property types_list:
"""Get a list of all the types of a parameter
2014-06-07 08:17:40 -07:00
:type: :py:class:`Type`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return eolian_type_to_python_obj(
eolian_parameter_types_list_get(self.param)
2014-06-05 16:57:14 -07:00
)
property name:
"""Get name of a parameter
2014-06-07 08:17:40 -07:00
:type: string
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return _ctouni(eolian_parameter_name_get(self.param))
def const_attribute_get(self, bint is_get):
"""Indicates if a parameter has a const attribute.
This function is relevant for properties, to know if a parameter is a
const parameter in the get operation.
2014-06-07 08:17:40 -07:00
:param bool is_get: indicates if the information needed is for get or
set.
:return: True if const in get, False otherwise
2014-06-05 16:57:14 -07:00
"""
return bool(eolian_parameter_const_attribute_get(self.param, is_get))
property is_nonull:
"""Indicates if a parameter cannot be NULL.
2014-06-07 08:17:40 -07:00
:type: bool
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return bool(eolian_parameter_is_nonull(self.param))
cdef class Type(object):
2014-06-12 13:46:58 -07:00
"""A type iterator
An Eolian type is an inlist of basic C types. For example:
``Eina_List * <Eo *>`` contains two basic types.
The first Eolian type of the list stores ``Eina_List *``, the next one
``Eo *``.
:return: C type, ownership
(indicates if the ownership has to pass to the caller/callee.)
:rtype: (string, bool)
"""
2014-06-05 16:57:14 -07:00
cdef Eolian_Type etype
cdef _set_obj(self, Eolian_Type obj):
self.etype = obj
2014-06-05 16:57:14 -07:00
2014-06-12 13:46:58 -07:00
def __iter__(self):
return self
2014-06-07 08:17:40 -07:00
2014-06-05 16:57:14 -07:00
def __next__(self):
cdef:
const char *type
Eina_Bool own
Eolian_Type etype
2014-06-12 13:46:58 -07:00
if self.etype == NULL:
raise StopIteration
2014-06-05 16:57:14 -07:00
etype = eolian_type_information_get(
self.etype, &type, &own
)
self.etype = etype
return _ctouni(type), bool(own)
2014-06-12 13:46:58 -07:00
def __len__(self):
return eina_inlist_count(self.etype)
2014-06-05 16:57:14 -07:00
cdef class Implement(object):
cdef Eolian_Implement impl
cdef _set_obj(self, Eolian_Implement obj):
self.impl = obj
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def __init__(self):
pass
2014-06-10 14:28:08 -07:00
def __repr__(self):
info = self.information
if not info:
info = (None, None, None)
return (
"<%s (class=%r, function=%r, type=%r)>" % (
self.full_name, info[0], info[1], info[2],
))
2014-06-05 16:57:14 -07:00
property full_name:
"""Get full string of an overriding function (implement).
2014-06-07 08:17:40 -07:00
:type: string
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
return _ctouni(eolian_implement_full_name_get(self.impl))
property information:
"""Get information about an overriding function (implement).
:type: overridden :py:class:`Class`, overridden :py:class:`Function`,
overridden :class:`FunctionType`
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
cdef:
Eolian_Class klass
Eolian_Function function
Eolian_Function_Type type
if not eolian_implement_information_get(self.impl,
&klass,
&function,
&type
):
EINA_LOG_DOM_WARN(
EOLIAN_DOM, "Fetching info for %s failed",
eolian_implement_full_name_get(self.impl)
)
2014-06-10 14:28:08 -07:00
return None
2014-06-05 16:57:14 -07:00
return (
eolian_class_to_python_obj(klass),
eolian_func_to_python_obj(function),
2014-06-10 14:28:08 -07:00
FunctionType(type)
2014-06-05 16:57:14 -07:00
)
cdef class Event(object):
cdef Eolian_Event event
cdef _set_obj(self, Eolian_Event obj):
self.event = obj
2014-06-05 16:57:14 -07:00
2014-06-07 08:17:40 -07:00
def __init__(self):
pass
2014-06-10 14:28:08 -07:00
def __repr__(self):
info = self.information
if info:
return (
"<%s (type=%s, description=%s)>" % (
info[0], info[1], info[2]
))
else:
return "<Event>"
2014-06-05 16:57:14 -07:00
property information:
"""Get information about an event.
2014-06-07 08:17:40 -07:00
:type: name of the event (string), type of the event (string),
description of the event (string)
2014-06-05 16:57:14 -07:00
"""
def __get__(self):
cdef:
const char *event_name
const char *event_type
const char *event_desc
if not eolian_class_event_information_get(
self.event, &event_name, &event_type, &event_desc
):
EINA_LOG_DOM_WARN(
EOLIAN_DOM, "Fetching info for an event failed", NULL
)
2014-06-10 14:28:08 -07:00
return None
2014-06-05 16:57:14 -07:00
2014-06-10 14:28:08 -07:00
return (
_ctouni(event_name), _ctouni(event_type), _ctouni(event_desc)
)
2014-06-05 16:57:14 -07:00
def type_find_by_alias(alias):
"""Find the type for a certain alias
2014-06-07 08:17:40 -07:00
:param alias: alias of the type definition
:return: real type of the type definition
2014-06-05 16:57:14 -07:00
"""
if isinstance(alias, unicode): alias = PyUnicode_AsUTF8String(alias)
return eolian_type_to_python_obj(
eolian_type_find_by_alias(alias)
2014-06-05 16:57:14 -07:00
)