blob: 3007eee63120f935b1d2c1efb0a85a7936fca6c4 [file] [log] [blame]
Alexander Afanasyev452645b2013-02-24 15:41:29 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012-2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
20 */
21
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070022#ifndef NDNX_NDNX_CHARBUF_H
23#define NDNX_NDNX_CHARBUF_H
Alexander Afanasyev452645b2013-02-24 15:41:29 -080024
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070025#include "ndnx-common.h"
Alexander Afanasyev452645b2013-02-24 15:41:29 -080026#include <boost/shared_ptr.hpp>
27
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070028namespace Ndnx {
Alexander Afanasyev452645b2013-02-24 15:41:29 -080029
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070030class NdnxCharbuf;
31typedef boost::shared_ptr<NdnxCharbuf> NdnxCharbufPtr;
Alexander Afanasyev452645b2013-02-24 15:41:29 -080032
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070033// This class is mostly used in NdnxWrapper; users should not be directly using this class
Alexander Afanasyev452645b2013-02-24 15:41:29 -080034// The main purpose of this class to is avoid manually create and destroy charbuf everytime
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070035class NdnxCharbuf
Alexander Afanasyev452645b2013-02-24 15:41:29 -080036{
37public:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070038 NdnxCharbuf();
39 NdnxCharbuf(ndn_charbuf *buf);
40 NdnxCharbuf(const NdnxCharbuf &other);
41 NdnxCharbuf(const void *buf, size_t length);
42 ~NdnxCharbuf();
Alexander Afanasyev452645b2013-02-24 15:41:29 -080043
44 // expose internal data structure, use with caution!!
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070045 ndn_charbuf *
Alexander Afanasyev452645b2013-02-24 15:41:29 -080046 getBuf() { return m_buf; }
47
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070048 const ndn_charbuf *
Alexander Afanasyev452645b2013-02-24 15:41:29 -080049 getBuf() const { return m_buf; }
50
51 const unsigned char *
52 buf () const
53 { return m_buf->buf; }
54
55 size_t
56 length () const
57 { return m_buf->length; }
58
59private:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070060 void init(ndn_charbuf *buf);
Alexander Afanasyev452645b2013-02-24 15:41:29 -080061
62protected:
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070063 ndn_charbuf *m_buf;
Alexander Afanasyev452645b2013-02-24 15:41:29 -080064};
65
66}
67
Alexander Afanasyev1dd37ed2013-08-14 18:08:09 -070068#endif // NDNX_NDNX_CHARBUF_H