Chris@16: // Chris@16: // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: #ifndef BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED Chris@16: #define BOOST_LOCALE_BOUNDARY_BOUNDARY_POINT_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace locale { Chris@16: namespace boundary { Chris@16: Chris@16: /// Chris@16: /// \addtogroup boundary Chris@16: /// @{ Chris@16: Chris@16: /// Chris@16: /// \brief This class represents a boundary point in the text. Chris@16: /// Chris@16: /// It represents a pair - an iterator and a rule that defines this Chris@16: /// point. Chris@16: /// Chris@16: /// This type of object is dereference by the iterators of boundary_point_index. Using a rule() Chris@16: /// member function you can get the reason why this specific boundary point was selected. Chris@16: /// Chris@16: /// For example, When you use a sentence boundary analysis, the (rule() & \ref sentence_term) != 0 means Chris@16: /// that this boundary point was selected because a sentence terminator (like .?!) was spotted Chris@16: /// and the (rule() & \ref sentence_sep)!=0 means that a separator like line feed or carriage Chris@16: /// return was observed. Chris@16: /// Chris@16: /// \note Chris@16: /// Chris@16: /// - The beginning of analyzed range is always considered a boundary point and its rule is always 0. Chris@16: /// - when using a word boundary analysis the returned rule relates to a chunk of text preceding Chris@16: /// this point. Chris@16: /// Chris@16: /// \see Chris@16: /// Chris@16: /// - \ref boundary_point_index Chris@16: /// - \ref segment Chris@16: /// - \ref segment_index Chris@16: /// Chris@16: template Chris@16: class boundary_point { Chris@16: public: Chris@16: /// Chris@16: /// The type of the base iterator that iterates the original text Chris@16: /// Chris@16: typedef IteratorType iterator_type; Chris@16: Chris@16: /// Chris@16: /// Empty default constructor Chris@16: /// Chris@16: boundary_point() : rule_(0) {} Chris@16: Chris@16: /// Chris@16: /// Create a new boundary_point using iterator \p and a rule \a r Chris@16: /// Chris@16: boundary_point(iterator_type p,rule_type r) : Chris@16: iterator_(p), Chris@16: rule_(r) Chris@16: { Chris@16: } Chris@16: /// Chris@16: /// Set an new iterator value \a i Chris@16: /// Chris@16: void iterator(iterator_type i) Chris@16: { Chris@16: iterator_ = i; Chris@16: } Chris@16: /// Chris@16: /// Set an new rule value \a r Chris@16: /// Chris@16: void rule(rule_type r) Chris@16: { Chris@16: rule_ = r; Chris@16: } Chris@16: /// Chris@16: /// Fetch an iterator Chris@16: /// Chris@16: iterator_type iterator() const Chris@16: { Chris@16: return iterator_; Chris@16: } Chris@16: /// Chris@16: /// Fetch a rule Chris@16: /// Chris@16: rule_type rule() const Chris@16: { Chris@16: return rule_; Chris@16: } Chris@16: /// Chris@16: /// Check if two boundary points are the same Chris@16: /// Chris@16: bool operator==(boundary_point const &other) const Chris@16: { Chris@16: return iterator_ == other.iterator_ && rule_ = other.rule_; Chris@16: } Chris@16: /// Chris@16: /// Check if two boundary points are different Chris@16: /// Chris@16: bool operator!=(boundary_point const &other) const Chris@16: { Chris@16: return !(*this==other); Chris@16: } Chris@16: /// Chris@16: /// Check if the boundary point points to same location as an iterator \a other Chris@16: /// Chris@16: bool operator==(iterator_type const &other) const Chris@16: { Chris@16: return iterator_ == other; Chris@16: } Chris@16: /// Chris@16: /// Check if the boundary point points to different location from an iterator \a other Chris@16: /// Chris@16: bool operator!=(iterator_type const &other) const Chris@16: { Chris@16: return iterator_ != other; Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Automatic cast to the iterator it represents Chris@16: /// Chris@16: operator iterator_type ()const Chris@16: { Chris@16: return iterator_; Chris@16: } Chris@16: Chris@16: private: Chris@16: iterator_type iterator_; Chris@16: rule_type rule_; Chris@16: Chris@16: }; Chris@16: /// Chris@16: /// Check if the boundary point \a r points to same location as an iterator \a l Chris@16: /// Chris@16: template Chris@16: bool operator==(BaseIterator const &l,boundary_point const &r) Chris@16: { Chris@16: return r==l; Chris@16: } Chris@16: /// Chris@16: /// Check if the boundary point \a r points to different location from an iterator \a l Chris@16: /// Chris@16: template Chris@16: bool operator!=(BaseIterator const &l,boundary_point const &r) Chris@16: { Chris@16: return r!=l; Chris@16: } Chris@16: Chris@16: /// @} Chris@16: Chris@16: typedef boundary_point sboundary_point; ///< convenience typedef Chris@16: typedef boundary_point wsboundary_point; ///< convenience typedef Chris@16: #ifdef BOOST_HAS_CHAR16_T Chris@16: typedef boundary_point u16sboundary_point;///< convenience typedef Chris@16: #endif Chris@16: #ifdef BOOST_HAS_CHAR32_T Chris@16: typedef boundary_point u32sboundary_point;///< convenience typedef Chris@16: #endif Chris@16: Chris@16: typedef boundary_point cboundary_point; ///< convenience typedef Chris@16: typedef boundary_point wcboundary_point; ///< convenience typedef Chris@16: #ifdef BOOST_HAS_CHAR16_T Chris@16: typedef boundary_point u16cboundary_point; ///< convenience typedef Chris@16: #endif Chris@16: #ifdef BOOST_HAS_CHAR32_T Chris@16: typedef boundary_point u32cboundary_point; ///< convenience typedef Chris@16: #endif Chris@16: Chris@16: Chris@16: } // boundary Chris@16: } // locale Chris@16: } // boost Chris@16: Chris@16: Chris@16: #endif Chris@16: Chris@16: // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4