MCPcopy Create free account
hub / github.com/apache/arrow / StdVector

Class StdVector

cpp/gdb_arrow.py:501–551  ·  view source on GitHub ↗

A `std::vector ` value.

Source from the content-addressed store, hash-verified

499
500
501class StdVector(Sequence):
502 """
503 A `std::vector<T>` value.
504 """
505
506 def __init__(self, val):
507 self.val = val
508 try:
509 # libstdc++ internals
510 impl = self.val['_M_impl']
511 self._data = impl['_M_start']
512 self._size = int(impl['_M_finish'] - self._data)
513 except gdb.error:
514 # fallback for other C++ standard libraries
515 self._data = int(gdb.parse_and_eval(
516 f"{for_evaluation(self.val)}.data()"))
517 self._size = int(gdb.parse_and_eval(
518 f"{for_evaluation(self.val)}.size()"))
519
520 def _check_index(self, index):
521 if index < 0 or index >= self._size:
522 raise IndexError(
523 f"Index {index} out of bounds (should be in [0, {self._size - 1}])")
524
525 def __len__(self):
526 return self._size
527
528 def __getitem__(self, index):
529 self._check_index(index)
530 return self._data[index]
531
532 def eval_at(self, index, eval_format):
533 """
534 Run `eval_format` with the value at `index`.
535
536 For example, if `eval_format` is "{}.get()", this will evaluate
537 "{self[index]}.get()".
538 """
539 self._check_index(index)
540 return gdb.parse_and_eval(
541 eval_format.format(for_evaluation(self._data[index])))
542
543 def iter_eval(self, eval_format):
544 data_eval = for_evaluation(self._data)
545 for i in range(self._size):
546 yield gdb.parse_and_eval(
547 eval_format.format(f"{data_eval}[{i}]"))
548
549 @property
550 def size(self):
551 return self._size
552
553
554class StdPtrVector(StdVector):

Callers 6

__init__Method · 0.85
to_stringMethod · 0.85
childrenMethod · 0.85
to_stringMethod · 0.85
_bufferMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected