All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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/weak_ptr.hpp>
40 #include <boost/make_shared.hpp>
41 #include <boost/enable_shared_from_this.hpp>
42 namespace ndn { namespace ptr_lib = boost; }
43 #else
44 /* Use the boost header files in this distribution that were extracted with:
45 cd <BOOST DEVELOPMENT DIRECTORY WITH boost SUBDIRECTORY>
46 dist/bin/bcp --namespace=ndnboost shared_ptr make_shared enable_shared_from_this weak_ptr function bind atomic <NDN-CPP ROOT>/include
47 cd <NDN-CPP ROOT>/include
48 rm -rf boost.css boost.png jamroot libs
49 mv boost ndnboost
50 cd ndnboost
51 # Replace when including files.
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 (unset LANG; find . -type f -exec sed -i '' 's/(boost\//(ndnboost\//g' {} +)
56 # Replace macro definitions.
57 (unset LANG; find . -type f -exec sed -i '' 's/BOOST_/NDNBOOST_/g' {} +)
58 # Replace header include guards which don't start with BOOST_ . This may result in some with NDNBOOST twice, but that is OK.
59 (unset LANG; find . -type f -exec sed -i '' 's/_DWA/_NDNBOOST_DWA/g' {} +)
60 (unset LANG; find . -type f -exec sed -i '' 's/ UUID_/ NDNBOOST_UUID_/g' {} +)
61 (unset LANG; find . -type f -exec sed -i '' 's/ FILE_boost/ FILE_ndnboost/g' {} +)
62 # Replace the mpl_ barrier namespace. This should only change file adl_barrier.hpp.
63 (unset LANG; find . -type f -exec sed -i '' 's/ mpl_/ ndnboost_mpl_/g' {} +)
64  */
65 #include <ndnboost/shared_ptr.hpp>
66 #include <ndnboost/weak_ptr.hpp>
67 #include <ndnboost/make_shared.hpp>
68 #include <ndnboost/enable_shared_from_this.hpp>
69 namespace ndn { namespace ptr_lib = ndnboost; }
70 #endif
71 
72 // Depending on where ./configure found function and the options --with-std-function
73 // and --with-boost-function, define the func_lib namespace.
74 // We always use ndn::func_lib.
75 #if NDN_CPP_HAVE_STD_FUNCTION && NDN_CPP_WITH_STD_FUNCTION
76 #include <functional>
77 // Define the func_lib namespace explicitly to pull in _1, _2, etc.
78 namespace ndn { namespace func_lib {
79  using std::function;
80  using std::mem_fn;
81  using std::bind;
82  using std::ref;
83 
84  using std::placeholders::_1;
85  using std::placeholders::_2;
86  using std::placeholders::_3;
87  using std::placeholders::_4;
88  using std::placeholders::_5;
89  using std::placeholders::_6;
90  using std::placeholders::_7;
91  using std::placeholders::_8;
92  using std::placeholders::_9;
93 
94  // Define this namespace for backwards compatibility with code that pulls in _1, etc. with:
95  // using namespace ndn::func_lib::placeholders;
96  namespace placeholders {}
97 } }
98 #elif NDN_CPP_HAVE_BOOST_FUNCTION && NDN_CPP_WITH_BOOST_FUNCTION
99 #include <boost/function.hpp>
100 #include <boost/bind.hpp>
101 namespace ndn { namespace func_lib = boost; }
102 #else
103 // Use the boost header files in this distribution that were extracted as above:
104 #include <ndnboost/function.hpp>
105 #include <ndnboost/bind.hpp>
106 namespace ndn { namespace func_lib = ndnboost; }
107 #endif
108 
109 namespace ndn {
110 
114 typedef double Milliseconds;
115 
119 typedef double MillisecondsSince1970;
120 
127 void
128 toHex(const uint8_t* array, size_t arrayLength, std::ostringstream& result);
129 
135 static __inline void
136 toHex(const std::vector<uint8_t>& array, std::ostringstream& result)
137 {
138  return toHex(&array[0], array.size(), result);
139 }
140 
147 std::string
148 toHex(const uint8_t* array, size_t arrayLength);
149 
155 static __inline std::string
156 toHex(const std::vector<uint8_t>& array)
157 {
158  return toHex(&array[0], array.size());
159 }
160 
165 void
166 ndn_trim(std::string& str);
167 
174 bool
175 equalsIgnoreCase(const std::string& s1, const std::string& s2);
176 
177 }
178 
179 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
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:119
bool equalsIgnoreCase(const std::string &s1, const std::string &s2)
Compare the strings for equality, ignoring case.
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:32