blob: 56b1aa497ce962799b398d79fe8833938842616a [file] [log] [blame]
Jeff Thompson47eecfc2013-07-07 22:56:46 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
Jeff Thompson571f3522013-07-07 22:39:31 -07004 */
5
6#ifndef NDN_COMMON_HPP
7#define NDN_COMMON_HPP
8
Jeff Thompson51dd5fd2013-07-10 19:27:18 -07009#include <vector>
Jeff Thompson571f3522013-07-07 22:39:31 -070010#include "../config.h"
11
12// Depending on where ./configure found shared_ptr, define the ptr_lib namespace.
Jeff Thompsonf7d49942013-08-01 16:47:40 -070013// We always use ndn::ptr_lib.
Jeff Thompson571f3522013-07-07 22:39:31 -070014#if HAVE_STD_SHARED_PTR
15#include <memory>
16namespace ndn { namespace ptr_lib = std; }
17#elif HAVE_BOOST_SHARED_PTR
18#include <boost/shared_ptr.hpp>
19#include <boost/make_shared.hpp>
20namespace ndn { namespace ptr_lib = boost; }
21#else
Jeff Thompsonf7d49942013-08-01 16:47:40 -070022// Use the boost header files in this distribution that were extracted with:
Jeff Thompsona28eed82013-08-22 16:21:10 -070023// cd <INCLUDE DIRECTORY WITH boost SUBDIRECTORY>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070024// dist/bin/bcp --namespace=ndnboost shared_ptr make_shared weak_ptr function bind <NDN-CPP ROOT>
Jeff Thompsona28eed82013-08-22 16:21:10 -070025// cd <NDN-CPP ROOT>
26// mv boost ndnboost
27// cd ndnboost
28// (unset LANG; find . -type f -exec sed -i '' 's/\<boost\//\<ndnboost\//g' {} +)
29// (unset LANG; find . -type f -exec sed -i '' 's/\"boost\//\"ndnboost\//g' {} +)
Jeff Thompson2277ce52013-08-01 17:34:11 -070030#include <ndnboost/shared_ptr.hpp>
31#include <ndnboost/make_shared.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070032namespace ndn { namespace ptr_lib = ndnboost; }
Jeff Thompson571f3522013-07-07 22:39:31 -070033#endif
34
Jeff Thompsona28eed82013-08-22 16:21:10 -070035// Depending on where ./configure found function, define the func_lib namespace.
36// We always use ndn::func_lib.
37#if HAVE_STD_FUNCTION
38#include <functional>
39namespace ndn { namespace func_lib = std; }
40#elif HAVE_BOOST_FUNCTION
41#include <boost/function.hpp>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070042#include <boost/bind.hpp>
Jeff Thompsona28eed82013-08-22 16:21:10 -070043namespace ndn { namespace func_lib = boost; }
44#else
45// Use the boost header files in this distribution that were extracted as above:
46#include <ndnboost/function.hpp>
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070047#include <ndnboost/bind.hpp>
Jeff Thompsona28eed82013-08-22 16:21:10 -070048namespace ndn { namespace func_lib = ndnboost; }
49#endif
50
Jeff Thompson51dd5fd2013-07-10 19:27:18 -070051namespace ndn {
52
53/**
54 * Clear the vector and copy valueLength bytes from value.
55 * @param v the vector to copy to
56 * @param value the array of bytes, or 0 to not copy
57 * @param valueLength the length of value
58 */
59static inline void setVector(std::vector<unsigned char> &vec, const unsigned char *value, unsigned int valueLength)
60{
Jeff Thompsona0d18c92013-08-06 13:55:32 -070061 vec.clear();
Jeff Thompson51dd5fd2013-07-10 19:27:18 -070062 if (value)
63 vec.insert(vec.begin(), value, value + valueLength);
64}
Jeff Thompsona8d7b062013-08-08 15:56:35 -070065
66/**
67 * Return the hex representation of the bytes in array.
68 * @param array The array of bytes.
69 * @return Hex string.
70 */
71std::string toHex(const std::vector<unsigned char> &array);
72
Jeff Thompson51dd5fd2013-07-10 19:27:18 -070073}
74
Jeff Thompson571f3522013-07-07 22:39:31 -070075#endif