Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / solenv / gdb / libreoffice / svl.py
blobf82b02a7b4a3a43faf75f06df4191238fca699fe
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 gdb
11 import six
13 from libreoffice.util import printing
15 class ItemSetPrinter(object):
16 '''Prints SfxItemSets'''
18 def __init__(self, typename, value):
19 self.typename = typename
20 self.value = value
22 def to_string(self):
23 whichranges = self.which_ranges()
24 return "SfxItemSet of pool %s with parent %s and Which ranges: %s" \
25 % (self.value['m_pPool'], self.value['m_pParent'], whichranges)
27 def which_ranges(self):
28 whichranges = self.value['m_pWhichRanges']['m_pairs']
29 whichranges_cnt = self.value['m_pWhichRanges']['m_size']
30 whiches = []
31 for index in range(whichranges_cnt):
32 whiches.append((int(whichranges[index]['first']), int(whichranges[index]['second'])))
33 return whiches
35 def children(self):
36 whichranges = self.which_ranges()
37 size = 0
38 whichids = []
39 for (whichfrom, whichto) in whichranges:
40 size += whichto - whichfrom + 1
41 whichids += [which for which in range(whichfrom, whichto+1)]
42 return self._iterator(self.value['m_ppItems'], size, whichids)
44 class _iterator(six.Iterator):
46 def __init__(self, data, count, whichids):
47 self.data = data
48 self.whichids = whichids
49 self.count = count
50 self.pos = 0
51 self._check_invariant()
53 def __iter__(self):
54 return self
56 def __next__(self):
57 if self.pos == self.count:
58 raise StopIteration()
60 which = self.whichids[self.pos]
61 elem = self.data[self.pos]
62 self.pos = self.pos + 1
64 self._check_invariant()
65 if (elem == -1):
66 elem = "(Invalid)"
67 elif (elem != 0):
68 # let's try how well that works...
69 elem = elem.cast(elem.dynamic_type).dereference()
70 return (str(which), elem)
72 def _check_invariant(self):
73 assert self.count >= 0
74 assert self.data
75 assert self.pos >= 0
76 assert self.pos <= self.count
77 assert len(self.whichids) == self.count
79 printer = None
81 def build_pretty_printers():
82 global printer
84 printer = printing.Printer("libreoffice/svl")
86 printer.add('SfxItemSet', ItemSetPrinter)
88 def register_pretty_printers(obj):
89 printing.register_pretty_printer(printer, obj)
91 build_pretty_printers()
93 # vim:set shiftwidth=4 softtabstop=4 expandtab: