tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / solenv / gdb / libreoffice / cppu.py
blobc5b257b72b5d1bae372205b7e1f9317c953ee490
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import six
12 from libreoffice.util import printing
13 from libreoffice.util.uno import TypeClass, make_uno_type, uno_cast
15 class UnoAnyPrinter(object):
16 '''Prints UNO any'''
18 def __init__(self, typename, value):
19 self.value = value
20 self.typename = typename.replace('com::sun::star::', '')
22 def to_string(self):
23 type_desc = self.value['pType']
24 assert type_desc
25 type = make_uno_type(type_desc.dereference())
26 assert type
27 if type_desc.dereference()['eTypeClass'] == TypeClass.VOID:
28 return ('%s(%s)' % (self.typename, type.tag))
29 else:
30 ptr = self.value['pData']
31 assert ptr
32 return ('%s(%s: %s)' % (self.typename, type.tag, str(uno_cast(type, ptr).dereference())))
34 class UnoReferencePrinter(object):
35 '''Prints reference to a UNO interface'''
37 def __init__(self, typename, value):
38 self.value = value
39 self.typename = typename.replace('com::sun::star::', '')
41 def to_string(self):
42 iface = self.value['_pInterface']
43 if iface:
44 try:
45 return '%s to (%s) %s' % (self.typename, str(iface.dynamic_type), str(iface))
46 except Exception:
47 # fallback for potential problem:
48 # base class 'com::sun::star::uno::XInterface' is ambiguous
49 return '%s to (XInterface) %s' % (self.typename, str(iface))
51 else:
52 return "empty %s" % self.typename
54 class UnoSequencePrinter(object):
55 '''Prints UNO Sequence'''
57 class iterator(six.Iterator):
58 '''Sequence iterator'''
60 def __init__(self, first, size):
61 self.item = first
62 self.size = size
63 self.count = 0
65 def __iter__(self):
66 return self
68 def __next__(self):
69 if self.count == self.size:
70 raise StopIteration
71 count = self.count
72 self.count = self.count + 1
73 elem = self.item.dereference()
74 self.item = self.item + 1
75 return ('[%d]' % count, elem)
78 def __init__(self, typename, value):
79 self.value = value
80 self.typename = typename.replace('com::sun::star::', '')
82 def to_string(self):
83 pimpl = self.value['_pSequence']
84 if pimpl:
85 impl = pimpl.dereference()
86 elems = impl['nElements']
87 if elems == 0:
88 return "empty %s" % self.typename
89 else:
90 return "%s of length %d" % (self.typename, elems)
91 else:
92 return "uninitialized %s" % self.typename
94 def children(self):
95 pimpl = self.value['_pSequence']
96 if pimpl:
97 impl = pimpl.dereference()
98 elemtype = self.value.type.template_argument(0)
99 elements = impl['elements'].cast(elemtype.pointer())
100 return self.iterator(elements, int(impl['nElements']))
101 else:
102 # TODO is that the best thing to do here?
103 return None
105 def display_hint(self):
106 if self.value['_pSequence']:
107 return 'array'
108 else:
109 return None
111 class UnoTypePrinter(object):
112 '''Prints UNO Type'''
114 def __init__(self, typename, value):
115 self.value = value
116 self.typename = typename.replace('com::sun::star::', '')
118 def to_string(self):
119 uno = make_uno_type(self.value)
120 if uno:
121 return "%s %s" % (self.typename, uno.tag)
122 # return "%s %s" % (self.typename, uno.typename)
123 else:
124 return "invalid %s" % self.typename
126 class CppuThreadpoolThreadPoolPrinter(object):
127 '''Prints cppu_threadpool::ThreadPool objects (a hack to avoid infinite recursion through sal.RtlReferencePrinter when printing an rtl::Reference<cppu_threadpool::ThreadPool> whose std::list<cppu_threadpool::WaitingThread*> m_lstThreads member, via rtl::Reference<cppu_threadpool::ORequestThread> thread member, via rtl::Reference<cppu_threadpool::ThreadPool> m_aThreadPool member, has a circular reference back)'''
129 def __init__(self, typename, value):
130 self.typename = typename
131 self.value = value
133 def to_string(self):
134 return '%s@%s' % (self.typename, self.value.address)
136 printer = None
138 def build_pretty_printers():
139 global printer
141 printer = printing.Printer("libreoffice/cppu")
143 # basic UNO stuff
144 printer.add('_uno_Any', UnoAnyPrinter)
145 printer.add('com::sun::star::uno::Any', UnoAnyPrinter)
146 printer.add('com::sun::star::uno::Reference', UnoReferencePrinter)
147 printer.add('com::sun::star::uno::Sequence', UnoSequencePrinter)
148 printer.add('com::sun::star::uno::Type', UnoTypePrinter)
149 printer.add('cppu_threadpool::ThreadPool', CppuThreadpoolThreadPoolPrinter)
151 def register_pretty_printers(obj):
152 printing.register_pretty_printer(printer, obj)
154 build_pretty_printers()
156 # vim:set shiftwidth=4 softtabstop=4 expandtab: