summaryrefslogtreecommitdiff
path: root/docs/index.rst
blob: 02120950e90794e825164a5542127855c7704e4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
=====
QFace
=====

QFace is a flexible API generator inspired by the Qt API idioms. It uses a common IDL format (called QFace interface document) to define an API. QFace is optimized to write a custom generator based on the common IDL format.

Several code generators for common use cases have already been implemented. These can be used as is or can be used as a base for a custom generator.

.. toctree::
   :maxdepth: 1

   motivation
   usage
   builtin
   grammar
   annotations
   yaml
   json
   domain
   extending
   api


Features
========

The list fo features is plit between features which are based on the chosen IDL and features which are provided by the generator itself.

.. rubric:: IDL Features

- Common modern IDL
- Scalable through modules
- Structure through structs, enums, flags
- Interface API with properties, operations and signals
- Annotations using YAML syntax
- Documentable IDL

.. rubric:: Generator Features

- Easy to install using python package manager
- Designed to be extended
- Well defined domain objects
- Template based code generator
- Simple rule based code builder
- Well documented

Quick Start
===========

QFace is a generator framework and is bundled with several reference code generators.

To install qface you need to have python3 installed and typically also pip3

.. code-block:: sh

    pip3 install qface

This installs the python qface library onto your system.

You can verify that you have qface installed with

.. code-block:: sh

    python3

and then

.. code-block:: python3

    import qface


Custom Generator
----------------

For your own generator you need several ingredients. A QFace interface file (here called "sample.qface"), a small script which loads and parses the document (generator.py) and one or more template files, used by the script to generate the resulting code.

The QFace document could look like this

.. code-block:: thrift

    // sample.qface
    module org.example 1.0

    interface Echo {
        string echo(string msg);
    }


Your generator can now parse the documents and call the templates

.. code-block:: python3

    // generator.py
    from qface.generator import FileSystem, Generator

    system = FileSystem.parse('sample.qface')
    generator = Generator('./templates')
    for module in system.modules:
        ctx = { 'module' : module }
        generator.write('{{module}}.txt', 'module.tpl', ctx)

The final piece is the template to parameterize the output in this case called "module.tpl"

.. code-block:: jinja

    // templates/module.tpl
    {% for interface in module.interfaces %}
    {{module.name}}
    {% endfor %}

Now you can simple call your script

.. code-block:: bash

    python3 generator.py

And a "org.example.txt" file named after the module should be generated.

.. rubric:: See Also

* :doc:`extending`
* :doc:`grammar`
* :doc:`domain`
* :doc:`api`

Bundled Generators
------------------

QFace has some generators which are bundled with the QFace library. They live in their own repositories. These generators are documented in their respective repositories.

.. rubric:: See Also

* :doc:`qtcpp`
* :doc:`qtqml`