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):
16 def __init__(self
, typename
, value
):
18 self
.typename
= typename
.replace('com::sun::star::', '')
22 return ('%s %s' % (self
.typename
, self
._make
_string
()))
24 return "empty %s" % self
.typename
27 return self
.value
['pType'].dereference()['eTypeClass'] != TypeClass
.VOID
29 def _make_string(self
):
30 ptr
= self
.value
['pData']
32 type_desc
= self
.value
['pType']
34 type = make_uno_type(type_desc
.dereference())
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
):
43 self
.typename
= typename
.replace('com::sun::star::', '')
46 iface
= self
.value
['_pInterface']
49 return '%s to (%s) %s' % (self
.typename
, str(iface
.dynamic_type
), str(iface
))
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
))
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
):
73 if self
.count
== self
.size
:
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
):
84 self
.typename
= typename
.replace('com::sun::star::', '')
87 pimpl
= self
.value
['_pSequence']
89 impl
= pimpl
.dereference()
90 elems
= impl
['nElements']
92 return "empty %s" % self
.typename
94 return "%s of length %d" % (self
.typename
, elems
)
96 return "uninitialized %s" % self
.typename
99 pimpl
= self
.value
['_pSequence']
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']))
106 # TODO is that the best thing to do here?
109 def display_hint(self
):
110 if self
.value
['_pSequence']:
115 class UnoTypePrinter(object):
116 '''Prints UNO Type'''
118 def __init__(self
, typename
, value
):
120 self
.typename
= typename
.replace('com::sun::star::', '')
123 uno
= make_uno_type(self
.value
)
125 return "%s %s" % (self
.typename
, uno
.tag
)
126 # return "%s %s" % (self.typename, uno.typename)
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
138 return '%s@%s' % (self
.typename
, self
.value
.address
)
142 def build_pretty_printers():
145 printer
= printing
.Printer("libreoffice/cppu")
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: