File: interfaceclass.py

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (86 lines) | stat: -rw-r--r-- 1,943 bytes parent folder | download | duplicates (4)
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
# vim: set ts=4 sws=4 sw=4:

from utils import \
        get_namespace, \
        get_ext_name, \
        _n_item, \
        _ext

from cppevent import event_dispatcher_class
from cpperror import error_dispatcher_class

_templates = {}

_templates['interface_class'] = \
"""\
template<typename Derived, typename Connection>
class interface
{
  protected:
    Connection
    connection(void) const
    {
      return static_cast<const Derived *>(this)->connection();
    }

  public:
%s\

    virtual ~interface(void) {}

    const interface<Derived, Connection> &
    %s(void)
    {
      return *this;
    }

%s\
}; // class interface
"""

_ignore_events = \
        { "XCB_PRESENT_GENERIC" }

########## INTERFACECLASS ##########

class InterfaceClass(object):
    def __init__(self):
        self.requests = []
        self.events = []
        self.errors = []

    def add(self, request):
        self.requests.append(request)

    def add_event(self, event):
        if event.opcode_name not in _ignore_events:
            self.events.append(event)

    def add_error(self, error):
        self.errors.append(error)

    def set_namespace(self, namespace):
        self.namespace = namespace

    def make_proto(self):
        ns = get_namespace(self.namespace)
        methods = ""
        for request in self.requests:
            methods += request.make_object_class_inline(True) + "\n\n"

        typedef = []
        if self.namespace.is_ext:
            typedef = [ "typedef xpp::%s::extension extension;" % ns ]

        if len(typedef) > 0:
            typedef = "".join(["    " + s for s in typedef]) + "\n\n"
        else:
            typedef = ""


        return (_templates['interface_class'] \
            % (typedef, ns, methods)) + \
              '\n' + event_dispatcher_class(self.namespace, self.events) + \
              '\n' + error_dispatcher_class(self.namespace, self.errors)

########## INTERFACECLASS ##########