From e77fd05f85f69e312e5d9e46fe4547caf474bd4b Mon Sep 17 00:00:00 2001 From: Jan Gaspar Date: Tue, 14 Nov 2006 23:54:51 +0000 Subject: [PATCH] added srcdoc + tests [SVN r3397] --- doc/circular_buffer.html | 162 ++++++++++++++++++++++--- include/boost/circular_buffer/base.hpp | 64 ++++++++-- test/common.ipp | 74 ++++++++--- 3 files changed, 256 insertions(+), 44 deletions(-) diff --git a/doc/circular_buffer.html b/doc/circular_buffer.html index 3ce7105..cbfe62b 100644 --- a/doc/circular_buffer.html +++ b/doc/circular_buffer.html @@ -1099,7 +1099,9 @@ template <class T, class Alloc> Returns:
- The random access iterator pointing to the beginning of the circular_buffer. + A random access iterator pointing to the first element of the circular_buffer. If the + circular_buffer is empty it returns an iterator equal to the one returned by end().
@@ -1148,7 +1150,10 @@ template <class T, class Alloc> Returns:
- The random access iterator pointing to the end of the circular_buffer. + A random access iterator pointing to the element "one behind" the last element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal + to the one returned by begin().
@@ -1198,7 +1203,9 @@ template <class T, class Alloc> Returns:
- The const random access iterator pointing to the beginning of the circular_buffer. + A const random access iterator pointing to the first element of the circular_buffer. If + the circular_buffer is empty it returns an iterator equal to the one returned by end() const.
@@ -1248,7 +1255,10 @@ template <class T, class Alloc> Returns:
- The const random access iterator pointing to the end of the circular_buffer. + A const random access iterator pointing to the element "one behind" the last element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal + to the one returned by begin() const.
@@ -1298,10 +1308,9 @@ template <class T, class Alloc> Returns:
- The reverse random access iterator pointing to the last element of the circular_buffer. If - the circular_buffer is empty it returns iterator equal to one returned be rend(). TODO what about if the - buffer is empty? + A reverse random access iterator pointing to the last element of the circular_buffer. If + the circular_buffer is empty it returns an iterator equal to the one returned by rend().
@@ -1345,8 +1354,50 @@ template <class T, class Alloc> "#classboost_1_1circular__buffer_1e5dbaec472f4b6ab6a8d4d0d6b15cbdb">reverse_iterator rend();

- Return a reverse iterator pointing to the end of the reversed circular buffer.
-
+ Get the iterator pointing to the end of the "reversed" circular_buffer. +
+
+ Returns: +
+
+ A reverse random access iterator pointing to the element "one before" the first element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal + to the one returned by rbegin(). +
+
+
+
+ Throws: +
+
+ Nothing. +
+
+
+
+ Complexity: +
+
+ Constant. +
+
+
+
+ Exception Safety: +
+
+ No-throw. +
+
+
+
+ Iterator Invalidation: +
+
+ Does not invalidate any iterator. +
+
@@ -1356,8 +1407,49 @@ template <class T, class Alloc> "#classboost_1_1circular__buffer_1ca423a848964c7915629c90fa7c58598">const_reverse_iterator rbegin() const;

- Return a const reverse iterator pointing to the beginning of the reversed circular buffer.
-
+ Get the const iterator pointing to the beginning of the "reversed" circular_buffer. +
+
+ Returns: +
+
+ A const reverse random access iterator pointing to the last element of the circular_buffer + . If the circular_buffer is empty it returns an iterator equal to the one returned by + rend() const. +
+
+
+
+ Throws: +
+
+ Nothing. +
+
+
+
+ Complexity: +
+
+ Constant. +
+
+
+
+ Exception Safety: +
+
+ No-throw. +
+
+
+
+ Iterator Invalidation: +
+
+ Does not invalidate any iterator. +
+
@@ -1367,8 +1459,50 @@ template <class T, class Alloc> "#classboost_1_1circular__buffer_1ca423a848964c7915629c90fa7c58598">const_reverse_iterator rend() const;

- Return a const reverse iterator pointing to the end of the reversed circular buffer.
-
+ Get the const iterator pointing to the end of the "reversed" circular_buffer. +
+
+ Returns: +
+
+ A const reverse random access iterator pointing to the element "one before" the first element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal + to the one returned by rbegin() const. +
+
+
+
+ Throws: +
+
+ Nothing. +
+
+
+
+ Complexity: +
+
+ Constant. +
+
+
+
+ Exception Safety: +
+
+ No-throw. +
+
+
+
+ Iterator Invalidation: +
+
+ Does not invalidate any iterator. +
+
diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 47289e0..b282c6b 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -206,7 +206,8 @@ public: //! Get the iterator pointing to the beginning of the circular_buffer. /*! - \return The random access iterator pointing to the beginning of the circular_buffer. + \return A random access iterator pointing to the first element of the circular_buffer. If the + circular_buffer is empty it returns an iterator equal to the one returned by end(). \throws Nothing. \par Complexity Constant. @@ -219,8 +220,9 @@ public: //! Get the iterator pointing to the end of the circular_buffer. /*! - \return The random access iterator pointing to "one behind" the last element of the circular_buffer - . + \return A random access iterator pointing to the element "one behind" the last element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal to + the one returned by begin(). \throws Nothing. \par Complexity Constant. @@ -233,7 +235,9 @@ public: //! Get the const iterator pointing to the beginning of the circular_buffer. /*! - \return The const random access iterator pointing to the beginning of the circular_buffer. + \return A const random access iterator pointing to the first element of the circular_buffer. If + the circular_buffer is empty it returns an iterator equal to the one returned by + end() const. \throws Nothing. \par Complexity Constant. @@ -246,7 +250,9 @@ public: //! Get the const iterator pointing to the end of the circular_buffer. /*! - \return The const random access iterator pointing to the end of the circular_buffer. + \return A const random access iterator pointing to the element "one behind" the last element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal to + the one returned by begin() const. \throws Nothing. \par Complexity Constant. @@ -259,9 +265,9 @@ public: //! Get the iterator pointing to the beginning of the "reversed" circular_buffer. /*! - \return The reverse random access iterator pointing to the last element of the circular_buffer. - If the circular_buffer is empty it returns iterator equal to one returned by rend(). - TODO what about if the buffer is empty? + \return A reverse random access iterator pointing to the last element of the circular_buffer. + If the circular_buffer is empty it returns an iterator equal to the one returned by + rend(). \throws Nothing. \par Complexity Constant. @@ -272,13 +278,49 @@ public: */ reverse_iterator rbegin() { return reverse_iterator(end()); } - //! Return a reverse iterator pointing to the end of the reversed circular buffer. + //! Get the iterator pointing to the end of the "reversed" circular_buffer. + /*! + \return A reverse random access iterator pointing to the element "one before" the first element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal to the + one returned by rbegin(). + \throws Nothing. + \par Complexity + Constant. + \par Exception Safety + No-throw. + \par Iterator Invalidation + Does not invalidate any iterator. + */ reverse_iterator rend() { return reverse_iterator(begin()); } - //! Return a const reverse iterator pointing to the beginning of the reversed circular buffer. + //! Get the const iterator pointing to the beginning of the "reversed" circular_buffer. + /*! + \return A const reverse random access iterator pointing to the last element of the circular_buffer + . If the circular_buffer is empty it returns an iterator equal to the one returned + by rend() const. + \throws Nothing. + \par Complexity + Constant. + \par Exception Safety + No-throw. + \par Iterator Invalidation + Does not invalidate any iterator. + */ const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - //! Return a const reverse iterator pointing to the end of the reversed circular buffer. + //! Get the const iterator pointing to the end of the "reversed" circular_buffer. + /*! + \return A const reverse random access iterator pointing to the element "one before" the first element of the + circular_buffer. If the circular_buffer is empty it returns an iterator equal + to the one returned by rbegin() const. + \throws Nothing. + \par Complexity + Constant. + \par Exception Safety + No-throw. + \par Iterator Invalidation + Does not invalidate any iterator. + */ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } //! Return the element at the index position. diff --git a/test/common.ipp b/test/common.ipp index 4f14a38..9f02c1c 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -156,45 +156,80 @@ void boundary_capacity_test() { generic_test(cb); } +void allocator_test() { + + CB_CONTAINER cb(10, 0); + CB_CONTAINER::allocator_type alloc = cb.get_allocator(); + CB_CONTAINER::allocator_type& alloc_ref = cb.get_allocator(); + + generic_test(cb); +} + void begin_and_end_test() { - CB_CONTAINER cb1(10); - cb1.push_back(1); - cb1.push_back(2); - cb1.insert(cb1.begin(), 3); + vector v; + v.push_back(11); + v.push_back(12); + v.push_back(13); + + CB_CONTAINER cb1(10, v.begin(), v.end()); + const CB_CONTAINER cb2(10, v.begin(), v.end()); + + CB_CONTAINER cb3(10); + cb3.push_back(1); + cb3.push_back(2); + cb3.insert(cb3.begin(), 3); int i = 0; - CB_CONTAINER::const_iterator it = cb1.begin(); - for (; it != cb1.end(); it++) { + CB_CONTAINER::const_iterator it = cb3.begin(); + for (; it != cb3.end(); it++) { i += *it; } - CB_CONTAINER cb2(20); + CB_CONTAINER cb4(20); + const CB_CONTAINER cb5(20); + BOOST_CHECK(*cb1.begin() == 11); + BOOST_CHECK(*cb2.begin() == 11); BOOST_CHECK(i == 6); - BOOST_CHECK(cb2.begin() == cb2.end()); + BOOST_CHECK(cb4.begin() == cb4.end()); + BOOST_CHECK(cb5.begin() == cb5.end()); generic_test(cb1); - generic_test(cb2); + generic_test(cb3); + generic_test(cb4); } void rbegin_and_rend_test() { - CB_CONTAINER cb1(3); - cb1.push_back(1); - cb1.push_back(2); - cb1.insert(cb1.begin(), 3); - cb1.push_back(1); + vector v; + v.push_back(11); + v.push_back(12); + v.push_back(13); + + CB_CONTAINER cb1(10, v.begin(), v.end()); + const CB_CONTAINER cb2(10, v.begin(), v.end()); + + CB_CONTAINER cb3(3); + cb3.push_back(1); + cb3.push_back(2); + cb3.insert(cb3.begin(), 3); + cb3.push_back(1); int i = 0; - CB_CONTAINER::reverse_iterator it = cb1.rbegin(); - for (; it != cb1.rend(); it++) { + CB_CONTAINER::reverse_iterator it = cb3.rbegin(); + for (; it != cb3.rend(); it++) { i += *it; } - CB_CONTAINER cb2(20); + CB_CONTAINER cb4(20); + const CB_CONTAINER cb5(20); + BOOST_CHECK(*cb1.rbegin() == 13); + BOOST_CHECK(*cb2.rbegin() == 13); BOOST_CHECK(i == 4); - BOOST_CHECK(cb2.rbegin() == cb2.rend()); + BOOST_CHECK(cb4.rbegin() == cb4.rend()); + BOOST_CHECK(cb5.rbegin() == cb5.rend()); generic_test(cb1); - generic_test(cb2); + generic_test(cb3); + generic_test(cb4); } void element_access_and_insert_test() { @@ -1521,6 +1556,7 @@ void add_common_tests(test_suite* tests) { tests->add(BOOST_TEST_CASE(&constructor_and_element_access_test)); tests->add(BOOST_TEST_CASE(&size_test)); tests->add(BOOST_TEST_CASE(&boundary_capacity_test)); + tests->add(BOOST_TEST_CASE(&allocator_test)); tests->add(BOOST_TEST_CASE(&begin_and_end_test)); tests->add(BOOST_TEST_CASE(&rbegin_and_rend_test)); tests->add(BOOST_TEST_CASE(&element_access_and_insert_test));