Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "dynamic-uchar-vector.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | DynamicUCharVector::DynamicUCharVector(unsigned int initialLength) |
| 14 | : vector_(new vector<unsigned char>(initialLength)) |
| 15 | { |
Jeff Thompson | d1427fb | 2013-08-29 17:20:32 -0700 | [diff] [blame] | 16 | ndn_DynamicUCharArray_initialize(this, &vector_->front(), initialLength, DynamicUCharVector::realloc); |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame^] | 19 | unsigned char* |
| 20 | DynamicUCharVector::realloc(struct ndn_DynamicUCharArray *self, unsigned char *array, unsigned int length) |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 21 | { |
| 22 | // Because this method is private, assume there is not a problem with upcasting. |
| 23 | DynamicUCharVector *thisObject = (DynamicUCharVector *)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 | |
Jeff Thompson | 1e2180f | 2013-08-12 13:32:50 -0700 | [diff] [blame] | 29 | thisObject->vector_->resize(length); |
Jeff Thompson | 529779a | 2013-08-12 13:15:55 -0700 | [diff] [blame] | 30 | return &thisObject->vector_->front(); |
| 31 | } |
| 32 | |
| 33 | } |