Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "dynamic-uint8-vector.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame^] | 13 | DynamicUInt8Vector::DynamicUInt8Vector(size_t initialLength) |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 14 | : vector_(new vector<uint8_t>(initialLength)) |
| 15 | { |
| 16 | ndn_DynamicUInt8Array_initialize(this, &vector_->front(), initialLength, DynamicUInt8Vector::realloc); |
| 17 | } |
| 18 | |
| 19 | uint8_t* |
Jeff Thompson | 97223af | 2013-09-24 17:01:27 -0700 | [diff] [blame^] | 20 | DynamicUInt8Vector::realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length) |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 21 | { |
| 22 | // Because this method is private, assume there is not a problem with upcasting. |
| 23 | DynamicUInt8Vector *thisObject = (DynamicUInt8Vector *)self; |
| 24 | |
| 25 | if (array != &thisObject->vector_->front()) |
| 26 | // We don't expect this to ever happen. The caller didn't pass the array from this object. |
| 27 | return 0; |
| 28 | |
| 29 | thisObject->vector_->resize(length); |
| 30 | return &thisObject->vector_->front(); |
| 31 | } |
| 32 | |
| 33 | } |