common.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_COMMON_HPP
23 #define NDN_COMMON_HPP
24 
25 #include <vector>
26 #include <string>
27 // common.h includes ndn-cpp-config.h.
28 #include "c/common.h"
29 
30 // Depending on where ./configure found shared_ptr and the options --with-std-shared-ptr
31 // and --with-boost-shared-ptr, define the ptr_lib namespace.
32 // We always use ndn::ptr_lib.
33 #if NDN_CPP_HAVE_STD_SHARED_PTR && NDN_CPP_WITH_STD_SHARED_PTR
34 #include <memory>
35 namespace ndn { namespace ptr_lib = std; }
36 #elif NDN_CPP_HAVE_BOOST_SHARED_PTR && NDN_CPP_WITH_BOOST_SHARED_PTR
37 #include <boost/shared_ptr.hpp>
38 #include <boost/make_shared.hpp>
39 #include <boost/enable_shared_from_this.hpp>
40 namespace ndn { namespace ptr_lib = boost; }
41 #else
42 /* Use the boost header files in this distribution that were extracted with:
43 cd <BOOST DEVELOPMENT DIRECTORY WITH boost SUBDIRECTORY>
44 dist/bin/bcp --namespace=ndnboost shared_ptr make_shared enable_shared_from_this weak_ptr function bind atomic <NDN-CPP ROOT>/include
45 cd <NDN-CPP ROOT>/include
46 rm -rf boost.css boost.png jamroot libs
47 mv boost ndnboost
48 cd ndnboost
49 # Replace when including files.
50 (unset LANG; find . -type f -exec sed -i '' 's/<boost\//<ndnboost\//g' {} +)
51 (unset LANG; find . -type f -exec sed -i '' 's/\"boost\//\"ndnboost\//g' {} +)
52 (unset LANG; find . -type f -exec sed -i '' 's/ boost\// ndnboost\//g' {} +)
53 (unset LANG; find . -type f -exec sed -i '' 's/(boost\//(ndnboost\//g' {} +)
54 # Replace macro definitions.
55 (unset LANG; find . -type f -exec sed -i '' 's/BOOST_/NDNBOOST_/g' {} +)
56 # Replace header include guards which don't start with BOOST_ . This may result in some with NDNBOOST twice, but that is OK.
57 (unset LANG; find . -type f -exec sed -i '' 's/_DWA/_NDNBOOST_DWA/g' {} +)
58 (unset LANG; find . -type f -exec sed -i '' 's/ UUID_/ NDNBOOST_UUID_/g' {} +)
59 (unset LANG; find . -type f -exec sed -i '' 's/ FILE_boost/ FILE_ndnboost/g' {} +)
60 # Replace the mpl_ barrier namespace. This should only change file adl_barrier.hpp.
61 (unset LANG; find . -type f -exec sed -i '' 's/ mpl_/ ndnboost_mpl_/g' {} +)
62  */
63 #include <ndnboost/shared_ptr.hpp>
64 #include <ndnboost/make_shared.hpp>
65 #include <ndnboost/enable_shared_from_this.hpp>
66 namespace ndn { namespace ptr_lib = ndnboost; }
67 #endif
68 
69 // Depending on where ./configure found function and the options --with-std-function
70 // and --with-boost-function, define the func_lib namespace.
71 // We always use ndn::func_lib.
72 #if NDN_CPP_HAVE_STD_FUNCTION && NDN_CPP_WITH_STD_FUNCTION
73 #include <functional>
74 // Define the func_lib namespace explicitly to pull in _1, _2, etc.
75 namespace ndn { namespace func_lib {
76  using std::function;
77  using std::mem_fn;
78  using std::bind;
79  using std::ref;
80 
81  using std::placeholders::_1;
82  using std::placeholders::_2;
83  using std::placeholders::_3;
84  using std::placeholders::_4;
85  using std::placeholders::_5;
86  using std::placeholders::_6;
87  using std::placeholders::_7;
88  using std::placeholders::_8;
89  using std::placeholders::_9;
90 
91  // Define this namespace for backwards compatibility with code that pulls in _1, etc. with:
92  // using namespace ndn::func_lib::placeholders;
93  namespace placeholders {}
94 } }
95 #elif NDN_CPP_HAVE_BOOST_FUNCTION && NDN_CPP_WITH_BOOST_FUNCTION
96 #include <boost/function.hpp>
97 #include <boost/bind.hpp>
98 namespace ndn { namespace func_lib = boost; }
99 #else
100 // Use the boost header files in this distribution that were extracted as above:
101 #include <ndnboost/function.hpp>
102 #include <ndnboost/bind.hpp>
103 namespace ndn { namespace func_lib = ndnboost; }
104 #endif
105 
106 namespace ndn {
107 
111 typedef double Milliseconds;
112 
116 typedef double MillisecondsSince1970;
117 
124 std::string
125 toHex(const uint8_t* array, size_t arrayLength);
126 
132 static __inline std::string
133 toHex(const std::vector<uint8_t>& array)
134 {
135  return toHex(&array[0], array.size());
136 }
137 
142 void
143 ndn_trim(std::string& str);
144 
145 }
146 
147 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Copyright (C) 2015-2016 Regents of the University of California.
Definition: threadsafe-face.hpp:27
Copyright (C) 2015-2016 Regents of the University of California.
void ndn_trim(std::string &str)
Modify str in place to erase whitespace on the left and right.
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
std::string toHex(const uint8_t *array, size_t arrayLength)
Return the hex representation of the bytes in array.
Definition: common.cpp:30