Bump version to 6.4.7.2.M8
[LibreOffice.git] / solenv / gdb / libreoffice / tl.py
blob22ca3ba57c5fbda4f1a387a54c12ccff9827df0b
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
12 from libreoffice.util import printing
14 class BigIntPrinter(object):
15 '''Prints big integer'''
17 def __init__(self, typename, val):
18 self.val = val
20 def to_string(self):
21 if self.val['bIsSet']:
22 if self.val['bIsBig']:
23 return self._value()
24 else:
25 return self.val['nVal']
26 else:
27 return "unset %s" % self.typename
29 def _value(self):
30 len = self.val['nLen']
31 digits = self.val['nNum']
32 dsize = digits.dereference().type.sizeof * 8
33 num = 0
34 # The least significant byte is on index 0
35 for i in reversed(range(0, len)):
36 num <<= dsize
37 num += digits[i]
38 return num
40 class ColorPrinter(object):
41 '''Prints color as rgb(r, g, b) or rgba(r, g, b, a)'''
43 def __init__(self, typename, val):
44 self.val = val
46 def to_string(self):
47 r = self.val['R']
48 g = self.val['G']
49 b = self.val['B']
50 a = self.val['A']
51 if a:
52 return "rgba(%d, %d, %d, %d)" % (r, g, b, a)
53 else:
54 return "rgb(%d, %d, %d)" % (r, g, b)
56 class DateTimeImpl(object):
58 def __init__(self, date, time):
59 self.date = date
60 self.time = time
62 def __str__(self):
63 result = ''
64 if self.date:
65 result += str(self.date)
66 if self.time:
67 result += ' '
68 if self.time:
69 result += str(self.time)
70 return result
72 @staticmethod
73 def parse(val):
74 return DateTimeImpl(DateImpl.parse(val), TimeImpl.parse(val))
76 class DateTimePrinter(object):
77 '''Prints date and time'''
79 def __init__(self, typename, val):
80 self.val = val
82 def to_string(self):
83 return str(DateTimeImpl.parse(self.val))
85 class DateImpl(DateTimeImpl):
87 def __init__(self, year, month, day):
88 super(DateImpl, self).__init__(self, None)
89 self.year = year
90 self.month = month
91 self.day = day
93 def __str__(self):
94 return "%d-%d-%d" % (self.year, self.month, self.day)
96 @staticmethod
97 def parse(val):
98 date = val['mnDate']
99 y = date / 10000
100 if date < 0:
101 date = -date
102 m = (date / 100) % 100
103 d = date % 100
104 return DateImpl(y, m, d)
106 class DatePrinter(object):
107 '''Prints date'''
109 def __init__(self, typename, val):
110 self.val = val
112 def to_string(self):
113 return str(DateImpl.parse(self.val))
115 class TimeImpl(DateTimeImpl):
117 def __init__(self, hour, minute, second, nanosecond = 0):
118 super(TimeImpl, self).__init__(None, self)
119 self.hour = hour
120 self.minute = minute
121 self.second = second
122 self.nanosecond = nanosecond
124 def __str__(self):
125 decimal = ''
126 if self.nanosecond != 0:
127 decimal = '.%09d' % self.nanosecond
128 return "%02d:%02d:%02d%s" % (self.hour, self.minute, self.second, decimal)
130 @staticmethod
131 def parse(val):
132 time = val['nTime']
133 h = time / 10000000000000
134 m = (time / 100000000000) % 100
135 s = (time / 1000000000) % 100
136 ns = time % 1000000000
137 return TimeImpl(h, m, s, ns)
139 class TimePrinter(object):
140 '''Prints time'''
142 def __init__(self, typename, val):
143 self.val = val
145 def to_string(self):
146 return str(TimeImpl.parse(self.val))
148 class PointPrinter(object):
149 '''Prints a Point.'''
151 def __init__(self, typename, value):
152 self.typename = typename
153 self.value = value
155 def to_string(self):
156 return "%s" % (self.typename)
158 def children(self):
159 x = self.value['nA']
160 y = self.value['nB']
161 children = [('x', x), ('y', y)]
162 return children.__iter__()
164 class SizePrinter(object):
165 '''Prints a Size.'''
167 def __init__(self, typename, value):
168 self.typename = typename
169 self.value = value
171 def to_string(self):
172 return "%s" % (self.typename)
174 def children(self):
175 width = self.value['nA']
176 height = self.value['nB']
177 children = [('width', width), ('height', height)]
178 return children.__iter__()
180 class RectanglePrinter(object):
181 '''Prints a Rectangle.'''
183 def __init__(self, typename, value):
184 self.typename = typename
185 self.value = value
187 def to_string(self):
188 return "%s" % (self.typename)
190 def children(self):
191 left = self.value['nLeft']
192 top = self.value['nTop']
193 right = self.value['nRight']
194 bottom = self.value['nBottom']
195 children = [('left', left), ('top', top), ('right', right), ('bottom', bottom)]
196 return children.__iter__()
198 printer = None
200 def build_pretty_printers():
201 global printer
203 printer = printing.Printer('libreoffice/tl')
205 # various types
206 printer.add('BigInt', BigIntPrinter)
207 printer.add('Color', ColorPrinter)
208 printer.add('DateTime', DateTimePrinter)
209 printer.add('Date', DatePrinter)
210 printer.add('Time', TimePrinter)
211 printer.add('Point', PointPrinter)
212 printer.add('Size', SizePrinter)
213 printer.add('Rectangle', RectanglePrinter)
215 def register_pretty_printers(obj):
216 printing.register_pretty_printer(printer, obj)
218 build_pretty_printers()
220 # vim:set shiftwidth=4 softtabstop=4 expandtab: