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/>.
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
39 return "empty " + self
.typename
41 return "%s with %s elements" % (self
.typename
, len(self
.impl
))
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
):
54 class _iterator(six
.Iterator
):
56 def __init__(self
, impl
):
66 self
.value
= six
.advance_iterator(self
.impl
)
70 self
.step
= not self
.step
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
):
81 class _iterator(six
.Iterator
):
83 def __init__(self
, impl
):
90 return ("", six
.advance_iterator(self
.impl
)[1])
94 def build_pretty_printers():
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: