Bump version to 6.4.7.2.M8
[LibreOffice.git] / solenv / gdb / boost / unordered.py
blob2c56721857b8229f76d033d2403db1878a6c7525
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
2 # GDB pretty printers for Boost.Unordered.
4 # Copyright (C) 2012 Red Hat, Inc., David Tardon <dtardon@redhat.com>
6 # This file is part of boost-gdb-printers.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import gdb
23 import six
25 from boost.lib.unordered import Map, Set
27 import boost.util.printing as printing
29 class PrinterBase(object):
30 '''Contains common functionality for printing Boost.Unordered types'''
32 def __init__(self, typename, value, container, iterator):
33 self.typename = typename
34 self.impl = container(value)
35 self.iterator = iterator
37 def to_string(self):
38 if self.impl.empty():
39 return "empty " + self.typename
40 else:
41 return "%s with %s elements" % (self.typename, len(self.impl))
43 def children(self):
44 return self.iterator(iter(self.impl))
46 class UnorderedMapPrinter(PrinterBase):
48 def __init__(self, typename, value):
49 super(UnorderedMapPrinter, self).__init__(typename, value, Map, self._iterator)
51 def display_hint(self):
52 return 'map'
54 class _iterator(six.Iterator):
56 def __init__(self, impl):
57 self.impl = impl
58 self.value = None
59 self.step = True
61 def __iter__(self):
62 return self
64 def __next__(self):
65 if self.step:
66 self.value = six.advance_iterator(self.impl)
67 value = self.value[0]
68 else:
69 value = self.value[1]
70 self.step = not self.step
71 return ("", value)
73 class UnorderedSetPrinter(PrinterBase):
75 def __init__(self, typename, value):
76 super(UnorderedSetPrinter, self).__init__(typename, value, Set, self._iterator)
78 def display_hint(self):
79 return 'array'
81 class _iterator(six.Iterator):
83 def __init__(self, impl):
84 self.impl = impl
86 def __iter__(self):
87 return self
89 def __next__(self):
90 return ("", six.advance_iterator(self.impl)[1])
92 printer = None
94 def build_pretty_printers():
95 global printer
97 if printer != None:
98 return
100 printer = printing.Printer("boost.unordered")
102 printer.add('boost::unordered_map', UnorderedMapPrinter)
103 printer.add('boost::unordered_multimap', UnorderedMapPrinter)
104 printer.add('boost::unordered_multiset', UnorderedSetPrinter)
105 printer.add('boost::unordered_set', UnorderedSetPrinter)
107 def register_pretty_printers(obj):
108 printing.register_pretty_printer(printer, obj)
110 build_pretty_printers()
112 # vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: