Go to the documentation of this file.
10 #include <boost/circular_buffer.hpp>
11 #include <gtest/gtest.h>
45 const_pointer
address(const_reference value)
const
70 return std::numeric_limits<std::size_t>::max() /
sizeof(T);
77 std::cerr <<
typeid(T).name() <<
" allocate " << num <<
" element(s)"
78 <<
" of size " <<
sizeof(T) << std::endl;
80 std::cerr <<
" allocated at: " << (
void*)ret << std::endl;
88 new ((
void*)p) T(value);
102 std::cerr <<
typeid(T).name() <<
" deallocate " << num <<
" element(s)"
103 <<
" of size " <<
sizeof(T) <<
" at: " << (
void*)p << std::endl;
104 ::operator
delete((
void*)p);
109 template <
class T1,
class T2>
114 template <
class T1,
class T2>
128 for (
int i = 0; i < buffer.
capacity(); ++i)
133 for (
int i = 0; i < buffer.
capacity(); ++i)
136 EXPECT_EQ(i, buffer.
front());
143 typedef std::vector<int, MyAlloc<int>> MyVector;
149 MyVector v(my_alloc);
156 ASSERT_EQ(buffer.
size(), 0);
159 ROS_INFO_STREAM(
"Size of type " <<
sizeof(std::vector<int>) <<
" size of container "
160 << v.size() *
sizeof(
int));
162 for (
int i = 0; i < 10; ++i)
165 ASSERT_EQ(i + 1, buffer.
size());
169 for (
int i = 0; i < 10; ++i)
172 ASSERT_EQ(10, buffer.
size());
233 TEST(BufferTest, circularBuffer)
235 typedef std::vector<int, MyAlloc<int>> MyVector;
241 MyVector v(my_alloc);
246 boost::circular_buffer<MyVector, MyAlloc<MyVector>> buffer(10, v, my_buffer_alloc);
248 ROS_INFO_STREAM(
"Size of type " <<
sizeof(std::vector<int>) <<
" size of container "
249 << v.size() *
sizeof(
int));
251 for (
int i = 0; i < 10; ++i)
258 for (
int i = 0; i < 10; ++i)
267 for (
int i = 0; i < 10; ++i)
273 for (
int i = 0; i < 10; ++i)
282 for (
int i = 0; i < 10; ++i)
288 for (
int i = 0; i < 10; ++i)
298 buffer.resize(10, v);
301 for (
int i = 0; i < 10; ++i)
307 for (
int i = 0; i < 10; ++i)
313 for (
int i = 0; i < 10; ++i)
319 for (
int i = 0; i < 20; ++i)
329 int main(
int argc,
char** argv)
333 testing::InitGoogleTest(&argc, argv);
334 return RUN_ALL_TESTS();
bool operator!=(const MyAlloc< T1 > &, const MyAlloc< T2 > &)
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
pointer address(reference value) const
void deallocate(pointer p, size_type num)
T & push_back()
push_back Increases the buffer size (not capacity) by one, and returns a reference to the last item i...
size_type max_size() const
const typedef T & const_reference
#define ROS_WARN_STREAM(args)
bool operator==(const in6_addr a, const in6_addr b)
#define ROS_INFO_STREAM(args)
int main(int argc, char **argv)
MyAlloc(const MyAlloc< U > &)
const typedef T * const_pointer
pointer allocate(size_type num, const void *=0)
void set_capacity(size_t max_size, const T &val)
set_capacity Allocates memory for max_size copies of val
TEST(BufferTest, circularBuffer)
const_pointer address(const_reference value) const
void pop_front()
pop_front Reduces buffer size by one, advancing the begin iterator
void construct(pointer p, const T &value)
std::ptrdiff_t difference_type
CircularBuffer implementation that does not perform allocations/deallocations outside of the construc...