blob: da26a634f83ee462f632076173d8689d1869356a [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompson10ad12a2013-09-24 16:19:11 -07002/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_DYNAMIC_UCHAR_VECTOR_HPP
9#define NDN_DYNAMIC_UCHAR_VECTOR_HPP
10
11#include <vector>
Jeff Thompson25b4e612013-10-10 16:03:24 -070012#include <ndn-cpp/common.hpp>
Jeff Thompson10ad12a2013-09-24 16:19:11 -070013#include "../c/util/dynamic-uint8-array.h"
14
15namespace ndn {
16
17/**
18 * A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr<vector<uint8_t> > for use with
19 * C functions which need an ndn_DynamicUInt8Array.
20 */
21class DynamicUInt8Vector : public ndn_DynamicUInt8Array {
22public:
23 /**
24 * Create a new DynamicUInt8Vector with an initial length.
25 * @param initialLength The initial size of the allocated vector.
26 */
Jeff Thompson97223af2013-09-24 17:01:27 -070027 DynamicUInt8Vector(size_t initialLength);
Jeff Thompson10ad12a2013-09-24 16:19:11 -070028
29 /**
30 * Get the shared_ptr to the allocated vector.
31 * @return The shared_ptr to the allocated vector.
32 */
Jeff Thompsonc38ee7f2013-12-11 15:24:03 -080033 ptr_lib::shared_ptr<std::vector<uint8_t> >&
Jeff Thompson10ad12a2013-09-24 16:19:11 -070034 get() { return vector_; }
35
36private:
37 /**
38 * Implement the static realloc function using vector resize.
39 * @param self A pointer to this object.
40 * @param array Should be the front of the vector.
41 * @param length The new length for the vector.
42 * @return The front of the allocated vector.
43 */
44 static uint8_t*
Jeff Thompson97223af2013-09-24 17:01:27 -070045 realloc(struct ndn_DynamicUInt8Array *self, uint8_t *array, size_t length);
Jeff Thompson10ad12a2013-09-24 16:19:11 -070046
47 ptr_lib::shared_ptr<std::vector<uint8_t> > vector_;
48};
49
50}
51
52#endif