Revision 63

Date:
2011/06/07 19:43:37
Author:
gdshaw@RISCID.ORG
Revision Log:
Added tagset::operator& and operator&=.
Files:

Legend:

 
Added
 
Removed
 
Modified
  • trunk/parser/tagset.cc

     
    47 47 }
    48 48 }
    49 49
    50 tagset& tagset::operator&=(const tagset& rhs)
    51 {
    52 std::vector<tag> result;
    53 const_iterator i=_tags.begin();
    54 const_iterator j=rhs._tags.begin();
    55 while ((i!=_tags.end())&&(j!=rhs._tags.end()))
    56 {
    57 if (*i>*j)
    58 {
    59 ++j;
    60 }
    61 else if (*j>*i)
    62 {
    63 ++i;
    64 }
    65 else
    66 {
    67 result.push_back(*i);
    68 ++i;
    69 ++j;
    70 }
    71 }
    72 _tags.swap(result);
    73 return *this;
    74 }
    75
    50 76 std::ostream& operator<<(std::ostream& out,const tagset& tags)
    51 77 {
    52 78 tags.write(out);
  • trunk/parser/tagset.h

     
    48 48
    49 49 /** Add tag to tagset.
    50 50 * @param rhs the tag to be added
    51 * @return a reference to this
    51 52 */
    52 53 tagset& operator|=(tag rhs);
    53 54
    54 55 /** Add tags to tagset.
    55 56 * @param rhs the tags to be added
    57 * @return a reference to this
    56 58 */
    57 59 tagset& operator|=(const tagset& rhs);
    58 60
    61 /** Intersect with another tagset.
    62 * @param rhs the tagset
    63 * @return a reference to this
    64 */
    65 tagset& operator&=(const tagset& rhs);
    66
    59 67 /** Write tagset to stream.
    60 68 * @param out the stream
    61 69 */
    62 70 void write(std::ostream& out) const;
    63 71 };
    64 72
    73 /** Calculate the intersection of two tagsets.
    74 * @param lhs the left-hand side
    75 * @param rhs the right-hand side
    76 * @return the intersection of the left- and right-hand sides
    77 */
    78 inline tagset operator&(const tagset& lhs,const tagset& rhs)
    79 {
    80 tagset result=lhs;
    81 result&=rhs;
    82 return result;
    83 }
    84
    65 85 std::ostream& operator<<(std::ostream& out,const tagset& tags);
    66 86
    67 87 #endif