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