Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55275 - in sandbox/SOC/2009/unicode: boost/iterator boost/unicode libs/unicode/doc
From: loufoque_at_[hidden]
Date: 2009-07-30 14:45:04


Author: mgaunard
Date: 2009-07-29 22:43:09 EDT (Wed, 29 Jul 2009)
New Revision: 55275
URL: http://svn.boost.org/trac/boost/changeset/55275

Log:
Preliminary concept checking, a few issues with doxygen
Text files modified:
   sandbox/SOC/2009/unicode/boost/iterator/pipe_iterator.hpp | 116 +++++++++++++++++++++++++++++++++++----
   sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp | 61 ++++++++------------
   sandbox/SOC/2009/unicode/libs/unicode/doc/Jamfile.v2 | 7 +-
   3 files changed, 134 insertions(+), 50 deletions(-)

Modified: sandbox/SOC/2009/unicode/boost/iterator/pipe_iterator.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/iterator/pipe_iterator.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/iterator/pipe_iterator.hpp 2009-07-29 22:43:09 EDT (Wed, 29 Jul 2009)
@@ -12,8 +12,64 @@
 #include <boost/mpl/has_xxx.hpp>
 #include <boost/mpl/int.hpp>
 
+#include <boost/concept_check.hpp>
+#include <boost/concept/requires.hpp>
+#include <boost/concept_archetype.hpp>
+#include <boost/range/concepts.hpp>
+
 namespace boost
 {
+
+struct any_type
+{
+ operator bool() const
+ {
+ return false;
+ }
+};
+
+template<typename X>
+struct PipeConcept : CopyConstructible<X>
+{
+ typedef typename X::output_type output_type;
+
+ BOOST_CONCEPT_USAGE(PipeConcept)
+ {
+ X pipe;
+ std::pair<in1_type, out_type> p1 = pipe.ltr(begin1, end1, out);
+ std::pair<in2_type, out_type> p2 = pipe.rtl(begin2, end2, out);
+ (void)p1;
+ (void)p2;
+ }
+
+private:
+ typedef input_iterator_archetype_no_proxy<any_type> in1_type;
+ typedef bidirectional_iterator_archetype<any_type> in2_type;
+ typedef output_iterator_archetype<output_type> out_type;
+
+ in1_type begin1;
+ in1_type end1;
+ in2_type begin2;
+ in2_type end2;
+ out_type out;
+};
+
+template<typename X>
+struct OneManyPipeConcept : CopyConstructible<X>
+{
+ typedef typename X::output_type output_type;
+
+ BOOST_CONCEPT_USAGE(OneManyPipeConcept)
+ {
+ X pipe;
+ out = pipe(any_type(), out);
+ }
+
+private:
+ typedef output_iterator_archetype<output_type> out_type;
+ out_type out;
+};
+
 namespace detail
 {
     BOOST_MPL_HAS_XXX_TRAIT_DEF(max_output)
@@ -24,6 +80,7 @@
     template<typename P>
     struct pipe_output_storage<P, typename ::boost::disable_if< has_max_output<P> >::type>
     {
+ BOOST_CONCEPT_ASSERT((PipeConcept<P>));
 private:
         typedef std::vector<typename P::output_type> Values;
 public:
@@ -56,6 +113,7 @@
     template<typename P>
     struct pipe_output_storage<P, typename boost::enable_if< has_max_output<P> >::type>
     {
+ BOOST_CONCEPT_ASSERT((PipeConcept<P>));
 private:
         typedef typename P::output_type Value;
 public:
@@ -91,6 +149,8 @@
 template<typename OneManyPipe>
 struct one_many_pipe : OneManyPipe
 {
+ BOOST_CONCEPT_ASSERT((OneManyPipeConcept<OneManyPipe>));
+
     one_many_pipe() {} // singular
     
         one_many_pipe(OneManyPipe p_) : OneManyPipe(p_)
@@ -103,7 +163,7 @@
         {
                 BOOST_ASSERT(begin != end);
                 
- out = (*this)(*begin, out);
+ out = ((OneManyPipe&)(*this))(*begin, out);
                 return std::make_pair(++begin, out);
         }
         
@@ -113,13 +173,16 @@
         {
                 BOOST_ASSERT(begin != end);
                 
- out = (*this)(*--end, out);
+ out = ((OneManyPipe&)(*this))(*--end, out);
                 return std::make_pair(end, out);
         }
 };
 
 template<typename OneManyPipe>
-one_many_pipe<OneManyPipe> make_one_many_pipe(OneManyPipe p)
+BOOST_CONCEPT_REQUIRES(
+ ((OneManyPipeConcept<OneManyPipe>)),
+ (one_many_pipe<OneManyPipe>)
+) make_one_many_pipe(OneManyPipe p)
 {
         return one_many_pipe<OneManyPipe>(p);
 }
@@ -151,6 +214,9 @@
                 const typename Pipe::output_type
>
 {
+ BOOST_CONCEPT_ASSERT((InputIterator<It>));
+ BOOST_CONCEPT_ASSERT((PipeConcept<Pipe>));
+
     pipe_iterator() {} // singular
     
         pipe_iterator(It begin_, It end_, It pos_, Pipe p_) : pos(pos_), begin(begin_), end(end_), index(0), p(p_)
@@ -166,6 +232,8 @@
         
         It base() const
         {
+ BOOST_CONCEPT_ASSERT((ForwardIterator<It>));
+
                 return pos;
         }
 
@@ -201,6 +269,8 @@
         
         void decrement()
         {
+ BOOST_CONCEPT_ASSERT((BidirectionalIterator<It>));
+
                 if(index != 0)
                 {
                         index--;
@@ -236,15 +306,22 @@
 };
 
 template<typename It, typename Pipe>
-pipe_iterator<It, Pipe> make_pipe_iterator(It begin, It end, It pos, Pipe p)
+BOOST_CONCEPT_REQUIRES(
+ ((InputIterator<It>)),
+ (pipe_iterator<It, Pipe>)
+) make_pipe_iterator(It begin, It end, It pos, Pipe p)
 {
         return pipe_iterator<It, Pipe>(begin, end, pos, p);
 }
 
 template<typename Range, typename Pipe>
-boost::iterator_range<
- pipe_iterator<typename boost::range_iterator<const Range>::type, Pipe>
-> piped(const Range& range, Pipe p)
+BOOST_CONCEPT_REQUIRES(
+ ((SinglePassRangeConcept<Range>))
+ ((PipeConcept<Pipe>)),
+ (boost::iterator_range<
+ pipe_iterator<typename boost::range_iterator<const Range>::type, Pipe>
+ >)
+) piped(const Range& range, Pipe p)
 {
         return boost::make_iterator_range(
                 make_pipe_iterator(boost::begin(range), boost::end(range), boost::begin(range), p),
@@ -253,9 +330,13 @@
 }
 
 template<typename Range, typename Pipe>
-boost::iterator_range<
- pipe_iterator<typename boost::range_iterator<Range>::type, Pipe>
-> piped(Range& range, Pipe p)
+BOOST_CONCEPT_REQUIRES(
+ ((SinglePassRangeConcept<Range>))
+ ((PipeConcept<Pipe>)),
+ (boost::iterator_range<
+ pipe_iterator<typename boost::range_iterator<Range>::type, Pipe>
+ >)
+) piped(Range& range, Pipe p)
 {
         return boost::make_iterator_range(
                 make_pipe_iterator(boost::begin(range), boost::end(range), boost::begin(range), p),
@@ -264,7 +345,12 @@
 }
 
 template<typename Range, typename Pipe, typename OutputIterator>
-OutputIterator pipe(const Range& range, Pipe pipe, OutputIterator out)
+BOOST_CONCEPT_REQUIRES(
+ ((SinglePassRangeConcept<Range>))
+ ((PipeConcept<Pipe>))
+ ((OutputIteratorConcept<OutputIterator, typename Pipe::output_type>)),
+ (OutputIterator)
+) pipe(const Range& range, Pipe pipe, OutputIterator out)
 {
     typedef typename boost::range_iterator<const Range>::type Iterator;
     
@@ -286,6 +372,8 @@
 template<typename It, typename OneManyPipe>
 struct pipe_output_iterator
 {
+ BOOST_CONCEPT_ASSERT((OneManyPipeConcept<OneManyPipe>));
+
     typedef void difference_type;
     typedef void value_type;
     typedef pipe_output_iterator<It, OneManyPipe>* pointer;
@@ -340,7 +428,11 @@
 };
 
 template<typename OutputIterator, typename OneManyPipe>
-pipe_output_iterator<OutputIterator, OneManyPipe> piped_output(OutputIterator out, OneManyPipe p)
+BOOST_CONCEPT_REQUIRES(
+ ((OneManyPipeConcept<OneManyPipe>))
+ ((OutputIteratorConcept<OutputIterator, typename OneManyPipe::output_type>)),
+ (pipe_output_iterator<OutputIterator, OneManyPipe>)
+) piped_output(OutputIterator out, OneManyPipe p)
 {
         return pipe_output_iterator<OutputIterator, OneManyPipe>(out, p);
 }

Modified: sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp
==============================================================================
--- sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp (original)
+++ sandbox/SOC/2009/unicode/boost/unicode/utf_codecs.hpp 2009-07-29 22:43:09 EDT (Wed, 29 Jul 2009)
@@ -433,21 +433,11 @@
     template<typename Iterator, typename Enable = void>
     struct decoder
     {
+ typedef one_many_pipe< cast_pipe<output_type> > type;
     };
     
     template<typename Iterator>
     struct decoder<Iterator, typename enable_if<
- detail::is_u32<
- typename std::iterator_traits<Iterator>::value_type
- >
- >::type>
- {
- typedef one_many_pipe< cast_pipe<char32> > type;
- };
-
-
- template<typename Iterator>
- struct decoder<Iterator, typename enable_if<
         detail::is_u16<
             typename std::iterator_traits<Iterator>::value_type
>
@@ -487,45 +477,46 @@
  * \c u8_boundary depending on the value type of the input range. */
 struct utf_boundary
 {
+ template<typename In>
+ bool operator()(In begin, In end, In pos)
+ {
+ return impl(begin, end, pos, 0);
+ }
+
 #ifndef BOOST_UNICODE_DOXYGEN_INVOKED
+private:
     template<typename In>
- typename enable_if<
- detail::is_u32<
- typename std::iterator_traits<In>::value_type
- >,
- bool
- >::type
- operator()(In, In, In)
+ bool impl(In, In, In, ...)
     {
         return true;
     }
     
     template<typename In>
- typename enable_if<
- detail::is_u16<
- typename std::iterator_traits<In>::value_type
- >,
- bool
- >::type
- operator()(In begin, In end, In pos)
+ bool impl(
+ In begin, In end, In pos,
+ typename enable_if<
+ detail::is_u16<
+ typename std::iterator_traits<In>::value_type
+ >
+ >::type*
+ )
     {
         return u16_boundary()(begin, end, pos);
     }
     
     template<typename In>
- typename enable_if<
- detail::is_u8<
- typename std::iterator_traits<In>::value_type
- >,
- bool
- >::type
-#else
- bool
-#endif
- operator()(In begin, In end, In pos)
+ bool impl(
+ In begin, In end, In pos,
+ typename enable_if<
+ detail::is_u8<
+ typename std::iterator_traits<In>::value_type
+ >
+ >::type*
+ )
     {
         return u8_boundary()(begin, end, pos);
     }
+#endif
 };
 
 /** Model of \c OneManyPipe that converts from UTF-32 to ISO-8859-1

Modified: sandbox/SOC/2009/unicode/libs/unicode/doc/Jamfile.v2
==============================================================================
--- sandbox/SOC/2009/unicode/libs/unicode/doc/Jamfile.v2 (original)
+++ sandbox/SOC/2009/unicode/libs/unicode/doc/Jamfile.v2 2009-07-29 22:43:09 EDT (Wed, 29 Jul 2009)
@@ -32,12 +32,13 @@
         :
         <doxygen:param>EXTRACT_ALL=YES
         <doxygen:param>"PREDEFINED=\"BOOST_UNICODE_DOXYGEN_INVOKED\" \\
- \"BOOST_UNICODE_DECL= \""
+ \"BOOST_UNICODE_DECL= \" \\
+ \"BOOST_CONCEPT_REQUIRES(a,b)=/** Requires: a */ b \""
         <doxygen:param>HIDE_UNDOC_MEMBERS=NO
         <doxygen:param>EXTRACT_PRIVATE=NO
         <doxygen:param>ENABLE_PREPROCESSING=YES
         <doxygen:param>MACRO_EXPANSION=YES
 # <doxygen:param>EXPAND_ONLY_PREDEF=YES
- <doxygen:param>SEARCH_INCLUDES=YES
- <doxygen:param>INCLUDE_PATH=$(BOOST_ROOT)
+# <doxygen:param>SEARCH_INCLUDES=YES
+# <doxygen:param>INCLUDE_PATH=$(BOOST_ROOT)
         ;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk