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 | #include "charbuf.h" |
| 14 | |
| 15 | using namespace std; |
| 16 | |
| 17 | namespace ndn { |
| 18 | |
| 19 | void |
| 20 | Charbuf::init(ccn_charbuf *buf) |
| 21 | { |
| 22 | if (buf != NULL) |
| 23 | { |
| 24 | m_buf = ccn_charbuf_create(); |
| 25 | ccn_charbuf_reserve(m_buf, buf->length); |
| 26 | memcpy(m_buf->buf, buf->buf, buf->length); |
| 27 | m_buf->length = buf->length; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | Charbuf::Charbuf() |
| 32 | : m_buf(NULL) |
| 33 | { |
| 34 | m_buf = ccn_charbuf_create(); |
| 35 | } |
| 36 | |
| 37 | Charbuf::Charbuf(ccn_charbuf *buf) |
| 38 | : m_buf(NULL) |
| 39 | { |
| 40 | init(buf); |
| 41 | } |
| 42 | |
| 43 | Charbuf::Charbuf(const Charbuf &other) |
| 44 | : m_buf (NULL) |
| 45 | { |
| 46 | init(other.m_buf); |
| 47 | } |
| 48 | |
| 49 | Charbuf::Charbuf(const void *buf, size_t length) |
| 50 | { |
| 51 | m_buf = ccn_charbuf_create (); |
| 52 | ccn_charbuf_reserve (m_buf, length); |
| 53 | memcpy (m_buf->buf, buf, length); |
| 54 | m_buf->length = length; |
| 55 | } |
| 56 | |
| 57 | Charbuf::~Charbuf() |
| 58 | { |
| 59 | ccn_charbuf_destroy (&m_buf); |
| 60 | } |
| 61 | |
| 62 | namespace iostreams |
| 63 | { |
| 64 | |
| 65 | charbuf_append_device::charbuf_append_device (Charbuf& cnt) |
| 66 | : container (cnt) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | std::streamsize |
| 71 | charbuf_append_device::write (const char_type* s, std::streamsize n) |
| 72 | { |
| 73 | ccn_charbuf_append (container.getBuf (), s, n); |
| 74 | return n; |
| 75 | } |
| 76 | |
| 77 | } // iostreams |
| 78 | |
| 79 | } // ndn |