update credits
[LibreOffice.git] / solenv / gdb / libreoffice / cppu.py
blobbc265aee7521d39902e182227b2f87a615bb4ef5
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 from libreoffice.util import printing
11 from libreoffice.util.uno import TypeClass, make_uno_type, uno_cast
13 class UnoAnyPrinter(object):
14 '''Prints UNO any'''
16 def __init__(self, typename, value):
17 self.value = value
18 self.typename = typename.replace('com::sun::star::', '')
20 def to_string(self):
21 if self._is_set():
22 return ('%s %s' % (self.typename, self._make_string()))
23 else:
24 return "empty %s" % self.typename
26 def _is_set(self):
27 return self.value['pType'].dereference()['eTypeClass'] != TypeClass.VOID
29 def _make_string(self):
30 ptr = self.value['pData']
31 assert ptr
32 type_desc = self.value['pType']
33 assert type_desc
34 type = make_uno_type(type_desc.dereference())
35 assert type
36 return str(uno_cast(type, ptr).dereference())
38 class UnoReferencePrinter(object):
39 '''Prints reference to a UNO interface'''
41 def __init__(self, typename, value):
42 self.value = value
43 self.typename = typename.replace('com::sun::star::', '')
45 def to_string(self):
46 iface = self.value['_pInterface']
47 if iface:
48 try:
49 return '%s to (%s) %s' % (self.typename, str(iface.dynamic_type), str(iface))
50 except:
51 # fallback for potential problem:
52 # base class 'com::sun::star::uno::XInterface' is ambiguous
53 return '%s to (XInterface) %s' % (self.typename, str(iface))
55 else:
56 return "empty %s" % self.typename
58 class UnoSequencePrinter(object):
59 '''Prints UNO Sequence'''
61 class iterator(object):
62 '''Sequence iterator'''
64 def __init__(self, first, size):
65 self.item = first
66 self.size = size
67 self.count = 0
69 def __iter__(self):
70 return self
72 def next(self):
73 if self.count == self.size:
74 raise StopIteration
75 count = self.count
76 self.count = self.count + 1
77 elem = self.item.dereference()
78 self.item = self.item + 1
79 return ('[%d]' % count, elem)
82 def __init__(self, typename, value):
83 self.value = value
84 self.typename = typename.replace('com::sun::star::', '')
86 def to_string(self):
87 pimpl = self.value['_pSequence']
88 if pimpl:
89 impl = pimpl.dereference()
90 elems = impl['nElements']
91 if elems == 0:
92 return "empty %s" % self.typename
93 else:
94 return "%s of length %d" % (self.typename, elems)
95 else:
96 return "uninitialized %s" % self.typename
98 def children(self):
99 pimpl = self.value['_pSequence']
100 if pimpl:
101 impl = pimpl.dereference()
102 elemtype = self.value.type.template_argument(0)
103 elements = impl['elements'].cast(elemtype.pointer())
104 return self.iterator(elements, int(impl['nElements']))
105 else:
106 # TODO is that the best thing to do here?
107 return None
109 def display_hint(self):
110 if self.value['_pSequence']:
111 return 'array'
112 else:
113 return None
115 class UnoTypePrinter(object):
116 '''Prints UNO Type'''
118 def __init__(self, typename, value):
119 self.value = value
120 self.typename = typename.replace('com::sun::star::', '')
122 def to_string(self):
123 uno = make_uno_type(self.value)
124 if uno:
125 return "%s %s" % (self.typename, uno.tag)
126 # return "%s %s" % (self.typename, uno.typename)
127 else:
128 return "invalid %s" % self.typename
130 class CppuThreadpoolThreadPoolPrinter(object):
131 '''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)'''
133 def __init__(self, typename, value):
134 self.typename = typename
135 self.value = value
137 def to_string(self):
138 return '%s@%s' % (self.typename, self.value.address)
140 printer = None
142 def build_pretty_printers():
143 global printer
145 printer = printing.Printer("libreoffice/cppu")
147 # basic UNO stuff
148 printer.add('_uno_Any', UnoAnyPrinter)
149 printer.add('com::sun::star::uno::Any', UnoAnyPrinter)
150 printer.add('com::sun::star::uno::Reference', UnoReferencePrinter)
151 printer.add('com::sun::star::uno::Sequence', UnoSequencePrinter)
152 printer.add('com::sun::star::uno::Type', UnoTypePrinter)
153 printer.add('cppu_threadpool::ThreadPool', CppuThreadpoolThreadPoolPrinter)
155 def register_pretty_printers(obj):
156 printing.register_pretty_printer(printer, obj)
158 build_pretty_printers()
160 # vim:set shiftwidth=4 softtabstop=4 expandtab: