Utilities

Module for extracting cython headers from the Spinnaker headers. For example:

header = r'E:\FLIR\Spinnaker\include\spinc\FSpinnakerC'
content = parse_header('{}.h'.format(header))
dump_cython(content, '{}.h'.format(header), '{}.pxi'.format(header))

Or to get the class nodes:

content = parse_class_vars(f)
dump_genapi_var_type_prop_cython(content, f'{name}.px')

Classes:

VariableSpec

Represents a variable declaration in e.g.

FunctionSpec

Represents a c function prototype.

StructSpec

Represents a c struct definition.

EnumSpec

Represents a c enum definition.

EnumMemberSpec

Represents a c enum member.

TypeDef

Represents a c typedef.

GenAPIVarSpec

Represnts a Node that is a class variable in the header.

Functions:

strip_comments

Returns the headers with comments removed.

parse_prototype

Returns a FunctionSpec instance from the input.

parse_struct

Returns a StructSpec instance from the input.

parse_enum

Returns a EnumSpec instance from the input.

parse_header

Returns a list of VariableSpec, FunctionSpec, StructSpec, EnumSpec, EnumMemberSpec, and TypeDef instances representing the c header file.

format_typedef

Generates a cython typedef from a TypeDef instance.

format_enum

Returns a cython enum from a EnumSpec instance.

format_variable

Returns a cython variable from a VariableSpec instance.

format_function

Returns a cython function from a FunctionSpec instance.

format_struct

Returns a cython struct from a StructSpec instance.

dump_cython

Generates a cython pxi file from the output of parse_header().

parse_class_vars

Parses the variable nodes from a header.

dump_genapi_prop_cython

Dumps all the nodes as @property methods of a cython class.

dump_genapi_import_prop_cython

Dumps all the C++ class nodes in the format to be included in a pxi file representing the header import.

dump_genapi_var_type_prop_cython

Dumps all the names of the nodes of a cython class and groups them into the type of node, e.g.

class VariableSpec(type, pointer, name, count)

Bases: tuple

Represents a variable declaration in e.g. the definition of a function or its return value.

Attributes:

count

Alias for field number 3

name

Alias for field number 2

pointer

Alias for field number 1

type

Alias for field number 0

count

Alias for field number 3

name

Alias for field number 2

pointer

Alias for field number 1

type

Alias for field number 0

class FunctionSpec(dec, type, pointer, name, args)

Bases: tuple

Represents a c function prototype.

Attributes:

args

Alias for field number 4

dec

Alias for field number 0

name

Alias for field number 3

pointer

Alias for field number 2

type

Alias for field number 1

args

Alias for field number 4

dec

Alias for field number 0

name

Alias for field number 3

pointer

Alias for field number 2

type

Alias for field number 1

class StructSpec(tp_name, names, members)

Bases: tuple

Represents a c struct definition.

Attributes:

members

Alias for field number 2

names

Alias for field number 1

tp_name

Alias for field number 0

members

Alias for field number 2

names

Alias for field number 1

tp_name

Alias for field number 0

class EnumSpec(tp_name, names, values)

Bases: tuple

Represents a c enum definition.

Attributes:

names

Alias for field number 1

tp_name

Alias for field number 0

values

Alias for field number 2

names

Alias for field number 1

tp_name

Alias for field number 0

values

Alias for field number 2

class EnumMemberSpec(name, value)

Bases: tuple

Represents a c enum member.

Attributes:

name

Alias for field number 0

value

Alias for field number 1

name

Alias for field number 0

value

Alias for field number 1

class TypeDef(body)

Bases: tuple

Represents a c typedef.

Attributes:

body

Alias for field number 0

body

Alias for field number 0

class GenAPIVarSpec(visibility, type_name, type_template, name, description)

Bases: tuple

Represnts a Node that is a class variable in the header.

Attributes:

description

Alias for field number 4

name

Alias for field number 3

type_name

Alias for field number 1

type_template

Alias for field number 2

visibility

Alias for field number 0

description

Alias for field number 4

name

Alias for field number 3

type_name

Alias for field number 1

type_template

Alias for field number 2

visibility

Alias for field number 0

strip_comments(code)[source]

Returns the headers with comments removed.

parse_prototype(prototype)[source]

Returns a FunctionSpec instance from the input.

parse_struct(type_name, body, name)[source]

Returns a StructSpec instance from the input.

parse_enum(type_name, body: str, name)[source]

Returns a EnumSpec instance from the input.

parse_header(filename)[source]

Returns a list of VariableSpec, FunctionSpec, StructSpec, EnumSpec, EnumMemberSpec, and TypeDef instances representing the c header file.

format_typedef(typedef)[source]

Generates a cython typedef from a TypeDef instance.

format_enum(enum_def)[source]

Returns a cython enum from a EnumSpec instance.

format_variable(variable)[source]

Returns a cython variable from a VariableSpec instance.

format_function(function)[source]

Returns a cython function from a FunctionSpec instance.

format_struct(struct_def)[source]

Returns a cython struct from a StructSpec instance.

dump_cython(content, name, ofile)[source]

Generates a cython pxi file from the output of parse_header().

parse_class_vars(filename)[source]

Parses the variable nodes from a header.

dump_genapi_prop_cython(items: List[GenAPIVarSpec], ofile, prop_storage_name='_nodes', cam_name='_camera', handle_name='_camera', prop_prefix='', name_mod='.camera', enum_suffix='Enum')[source]

Dumps all the nodes as @property methods of a cython class.

dump_genapi_import_prop_cython(items: List[GenAPIVarSpec], ofile)[source]

Dumps all the C++ class nodes in the format to be included in a pxi file representing the header import.

dump_genapi_var_type_prop_cython(items: List[GenAPIVarSpec], ofile)[source]

Dumps all the names of the nodes of a cython class and groups them into the type of node, e.g. string, float, enum etc.