Enrico Granata | 979e20d | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 1 | class StdVectorSynthProvider: |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 2 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 3 | def __init__(self, valobj, dict): |
| 4 | self.valobj = valobj; |
| 5 | self.update() |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 6 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 7 | def num_children(self): |
| 8 | start_val = self.start.GetValueAsUnsigned(0) |
| 9 | finish_val = self.finish.GetValueAsUnsigned(0) |
| 10 | end_val = self.end.GetValueAsUnsigned(0) |
| 11 | # Before a vector has been constructed, it will contain bad values |
| 12 | # so we really need to be careful about the length we return since |
| 13 | # unitialized data can cause us to return a huge number. We need |
| 14 | # to also check for any of the start, finish or end of storage values |
| 15 | # being zero (NULL). If any are, then this vector has not been |
| 16 | # initialized yet and we should return zero |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 17 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 18 | # Make sure nothing is NULL |
| 19 | if start_val == 0 or finish_val == 0 or end_val == 0: |
| 20 | return 0 |
| 21 | # Make sure start is less than finish |
| 22 | if start_val >= finish_val: |
| 23 | return 0 |
| 24 | # Make sure finish is less than or equal to end of storage |
| 25 | if finish_val > end_val: |
| 26 | return 0 |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 27 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 28 | num_children = (finish_val-start_val)/self.data_size |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 29 | return num_children |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 30 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 31 | def get_child_index(self,name): |
| 32 | return int(name.lstrip('[').rstrip(']')) |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 33 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 34 | def get_child_at_index(self,index): |
| 35 | if index >= self.num_children(): |
| 36 | return None; |
| 37 | offset = index * self.data_size |
| 38 | return self.start.CreateChildAtOffset('['+str(index)+']',offset,self.data_type) |
Enrico Granata | c92eb40 | 2011-08-04 01:41:02 +0000 | [diff] [blame] | 39 | |
Enrico Granata | 7718f3f | 2011-08-04 02:35:14 +0000 | [diff] [blame] | 40 | def update(self): |
| 41 | impl = self.valobj.GetChildMemberWithName('_M_impl') |
| 42 | self.start = impl.GetChildMemberWithName('_M_start') |
| 43 | self.finish = impl.GetChildMemberWithName('_M_finish') |
| 44 | self.end = impl.GetChildMemberWithName('_M_end_of_storage') |
| 45 | self.data_type = self.start.GetType().GetPointeeType() |
| 46 | self.data_size = self.data_type.GetByteSize() |
| 47 | |