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/.
12 from libreoffice
.util
import printing
13 from libreoffice
.util
.uno
import TypeClass
, make_uno_type
, uno_cast
15 class UnoAnyPrinter(object):
18 def __init__(self
, typename
, value
):
20 self
.typename
= typename
.replace('com::sun::star::', '')
24 return ('%s %s' % (self
.typename
, self
._make
_string
()))
26 return "empty %s" % self
.typename
29 return self
.value
['pType'].dereference()['eTypeClass'] != TypeClass
.VOID
31 def _make_string(self
):
32 ptr
= self
.value
['pData']
34 type_desc
= self
.value
['pType']
36 type = make_uno_type(type_desc
.dereference())
38 return str(uno_cast(type, ptr
).dereference())
40 class UnoReferencePrinter(object):
41 '''Prints reference to a UNO interface'''
43 def __init__(self
, typename
, value
):
45 self
.typename
= typename
.replace('com::sun::star::', '')
48 iface
= self
.value
['_pInterface']
51 return '%s to (%s) %s' % (self
.typename
, str(iface
.dynamic_type
), str(iface
))
53 # fallback for potential problem:
54 # base class 'com::sun::star::uno::XInterface' is ambiguous
55 return '%s to (XInterface) %s' % (self
.typename
, str(iface
))
58 return "empty %s" % self
.typename
60 class UnoSequencePrinter(object):
61 '''Prints UNO Sequence'''
63 class iterator(six
.Iterator
):
64 '''Sequence iterator'''
66 def __init__(self
, first
, size
):
75 if self
.count
== self
.size
:
78 self
.count
= self
.count
+ 1
79 elem
= self
.item
.dereference()
80 self
.item
= self
.item
+ 1
81 return ('[%d]' % count
, elem
)
84 def __init__(self
, typename
, value
):
86 self
.typename
= typename
.replace('com::sun::star::', '')
89 pimpl
= self
.value
['_pSequence']
91 impl
= pimpl
.dereference()
92 elems
= impl
['nElements']
94 return "empty %s" % self
.typename
96 return "%s of length %d" % (self
.typename
, elems
)
98 return "uninitialized %s" % self
.typename
101 pimpl
= self
.value
['_pSequence']
103 impl
= pimpl
.dereference()
104 elemtype
= self
.value
.type.template_argument(0)
105 elements
= impl
['elements'].cast(elemtype
.pointer())
106 return self
.iterator(elements
, int(impl
['nElements']))
108 # TODO is that the best thing to do here?
111 def display_hint(self
):
112 if self
.value
['_pSequence']:
117 class UnoTypePrinter(object):
118 '''Prints UNO Type'''
120 def __init__(self
, typename
, value
):
122 self
.typename
= typename
.replace('com::sun::star::', '')
125 uno
= make_uno_type(self
.value
)
127 return "%s %s" % (self
.typename
, uno
.tag
)
128 # return "%s %s" % (self.typename, uno.typename)
130 return "invalid %s" % self
.typename
132 class CppuThreadpoolThreadPoolPrinter(object):
133 '''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)'''
135 def __init__(self
, typename
, value
):
136 self
.typename
= typename
140 return '%s@%s' % (self
.typename
, self
.value
.address
)
144 def build_pretty_printers():
147 printer
= printing
.Printer("libreoffice/cppu")
150 printer
.add('_uno_Any', UnoAnyPrinter
)
151 printer
.add('com::sun::star::uno::Any', UnoAnyPrinter
)
152 printer
.add('com::sun::star::uno::Reference', UnoReferencePrinter
)
153 printer
.add('com::sun::star::uno::Sequence', UnoSequencePrinter
)
154 printer
.add('com::sun::star::uno::Type', UnoTypePrinter
)
155 printer
.add('cppu_threadpool::ThreadPool', CppuThreadpoolThreadPoolPrinter
)
157 def register_pretty_printers(obj
):
158 printing
.register_pretty_printer(printer
, obj
)
160 build_pretty_printers()
162 # vim:set shiftwidth=4 softtabstop=4 expandtab: