blob: 12425f630aea0e4f1ab28f5e6fa67fdf76823e95 [file] [log] [blame]
Jeff Thompsonfa306642013-06-17 15:06:57 -07001/* -*- 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
15using namespace std;
16
17namespace ndn {
18
19void
20Charbuf::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
31Charbuf::Charbuf()
32 : m_buf(NULL)
33{
34 m_buf = ccn_charbuf_create();
35}
36
37Charbuf::Charbuf(ccn_charbuf *buf)
38 : m_buf(NULL)
39{
40 init(buf);
41}
42
43Charbuf::Charbuf(const Charbuf &other)
44 : m_buf (NULL)
45{
46 init(other.m_buf);
47}
48
49Charbuf::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
57Charbuf::~Charbuf()
58{
59 ccn_charbuf_destroy (&m_buf);
60}
61
62namespace iostreams
63{
64
65charbuf_append_device::charbuf_append_device (Charbuf& cnt)
66 : container (cnt)
67{
68}
69
70std::streamsize
71charbuf_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