Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * Zhenkai Zhu |
| 6 | * |
| 7 | * BSD license, See the LICENSE file for more information |
| 8 | * |
| 9 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 10 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 11 | */ |
| 12 | |
| 13 | #ifndef NDN_BLOB_H |
| 14 | #define NDN_BLOB_H |
| 15 | |
| 16 | #include <vector> |
| 17 | #include <cstddef> |
Jeff Thompson | 4454bf7 | 2013-06-18 13:33:12 -0700 | [diff] [blame^] | 18 | #include <boost/shared_ptr.hpp> |
Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 19 | |
| 20 | namespace ndn { |
| 21 | |
Jeff Thompson | 4454bf7 | 2013-06-18 13:33:12 -0700 | [diff] [blame^] | 22 | class Blob; |
| 23 | typedef boost::shared_ptr<Blob> BlobPtr; |
| 24 | typedef boost::shared_ptr<const Blob> ConstBlobPtr; |
| 25 | |
Jeff Thompson | fa30664 | 2013-06-17 15:06:57 -0700 | [diff] [blame] | 26 | /** |
| 27 | * @brief Class representing a general-use binary blob |
| 28 | */ |
| 29 | class Blob : public std::vector<char> |
| 30 | { |
| 31 | public: |
| 32 | /** |
| 33 | * @brief Creates an empty blob |
| 34 | */ |
| 35 | Blob () |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | Blob (const void *buf, size_t length) |
| 40 | : std::vector<char> (reinterpret_cast<const char*> (buf), reinterpret_cast<const char*> (buf) + length) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @brief Get pointer to the first byte of the binary blob |
| 46 | */ |
| 47 | inline char* |
| 48 | buf () |
| 49 | { |
| 50 | return &front (); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @brief Get const pointer to the first byte of the binary blob |
| 55 | */ |
| 56 | inline const char* |
| 57 | buf () const |
| 58 | { |
| 59 | return &front (); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | } // ndn |
| 64 | |
| 65 | #endif // NDN_BLOB_H |