bump product version to 5.0.4.1
[LibreOffice.git] / solenv / gdb / libreoffice / svl.py
blob05049652c434109bb4118182fd6f26bcbd1ac2b2
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']
29 index = 0
30 whiches = []
31 while (whichranges[index]):
32 whiches.append((int(whichranges[index]), int(whichranges[index+1])))
33 index = index + 2
34 return whiches
36 def children(self):
37 whichranges = self.which_ranges()
38 size = 0
39 whichids = []
40 for (whichfrom, whichto) in whichranges:
41 size += whichto - whichfrom + 1
42 whichids += [which for which in range(whichfrom, whichto+1)]
43 return self._iterator(self.value['m_pItems'], size, whichids)
45 class _iterator(six.Iterator):
47 def __init__(self, data, count, whichids):
48 self.data = data
49 self.whichids = whichids
50 self.count = count
51 self.pos = 0
52 self._check_invariant()
54 def __iter__(self):
55 return self
57 def __next__(self):
58 if self.pos == self.count:
59 raise StopIteration()
61 which = self.whichids[self.pos]
62 elem = self.data[self.pos]
63 self.pos = self.pos + 1
65 self._check_invariant()
66 if (elem == -1):
67 elem = "(Invalid)"
68 elif (elem != 0):
69 # let's try how well that works...
70 elem = elem.cast(elem.dynamic_type).dereference()
71 return (str(which), elem)
73 def _check_invariant(self):
74 assert self.count >= 0
75 assert self.data
76 assert self.pos >= 0
77 assert self.pos <= self.count
78 assert len(self.whichids) == self.count
80 printer = None
82 def build_pretty_printers():
83 global printer
85 printer = printing.Printer("libreoffice/svl")
87 printer.add('SfxItemSet', ItemSetPrinter)
89 def register_pretty_printers(obj):
90 printing.register_pretty_printer(printer, obj)
92 build_pretty_printers()
94 # vim:set shiftwidth=4 softtabstop=4 expandtab: