Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include "dynamic-uchar-vector.hpp" |
| 7 | |
| 8 | using namespace std; |
| 9 | |
| 10 | namespace ndn { |
| 11 | |
| 12 | DynamicUCharVector::DynamicUCharVector(unsigned int initialLength) |
| 13 | : vector_(new vector<unsigned char>(initialLength)) |
| 14 | { |
| 15 | ndn_DynamicUCharArray_init(this, &vector_->front(), initialLength, DynamicUCharVector::realloc); |
| 16 | } |
| 17 | |
| 18 | unsigned char *DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length) |
| 19 | { |
| 20 | // Because this method is private, assume there is not a problem with upcasting. |
| 21 | DynamicUCharVector *thisObject = (DynamicUCharVector *)self; |
| 22 | |
| 23 | if (array != &thisObject->vector_->front()) |
| 24 | // We don't expect this to ever happen. The caller didn't pass the array from this object. |
| 25 | return 0; |
| 26 | |
| 27 | thisObject->vector_->reserve(length); |
| 28 | return &thisObject->vector_->front(); |
| 29 | } |
| 30 | |
| 31 | } |