004
26.08.2003, 19:13 Uhr
virtual
Sexiest Bit alive (Operator)
|
Der Header:
C++: |
/****************************************************************************** ******************************************************************************
jolutil
Abbreviator.h, created Mon Jul 28 12:04:52 2003
$Source: /joesoft/rep/jolutil/jolutil/source/libs/base/Abbreviator.h,v $
$Revision: 1.1 $
$Name: $
$Date: 2003/07/29 23:04:43 $
------------------------------------------------------------------------
$Log: Abbreviator.h,v $ Revision 1.1 2003/07/29 23:04:43 joe Initial added
****************************************************************************** *****************************************************************************/
#ifndef ABBREVIATOR_H_INCLUDED_ #define ABBREVIATOR_H_INCLUDED_ 1
/****************************************************************************** * * INCLUDES * *****************************************************************************/
#include <set> #include <string>
/****************************************************************************** * * CLASS Abbreviator * *****************************************************************************/
/** String set with abbreviation lookup. * This class is a set of strings (named keywords in the following). It * provides an interface to look up these keywords with abbreviation. An * abbreviation is the shortest substring of a keyword (starting with the * first letter) that exactly matches only this keyword an nothing else. */ class Abbreviator { // === TYPES ================================================================= private: /** Type the represents a keyword. * This is the type that represents a keyword, a simple string. */ typedef std::string keyword_type;
/** Type for a set of keywords. * This represents a set of keywords. */ typedef std::set<keyword_type> keyword_set;
public: /** Type for counting items. * This represents a counter type. */ typedef std::set<keyword_type>::size_type size_type;
/** Iterator for keywords. * THis allows iterating through the keywords. */ typedef std::set<keyword_type>::const_iterator iterator;
// === ATTRIBUTES ============================================================ private: /** Set of keywords. * This set contains all keywords known to the abbreviator. */ keyword_set m_setKeywords;
// === PUBLIC INTERFACE ====================================================== public: //! \name Construction, destruction //@{ /** Default constructor. * Creates a new Abbreviator with no keywords attached. */ Abbreviator();
/** Construction using a sequence of keywords. * This constructor expects two input iterators; all keywords of this * sequence are added to the keyword list. * * \param p_iterBegin 1. input iterator * \param p_iterEnd 2. input iterator */ template<class I> Abbreviator( I p_iterBegin, I p_iterEnd); //@}
//! \name Add and remove keywords- //@{ /** Add a single keyword. * This adds the keyword \a p_strKeyword to the list of keywords. * * \param p_strKeyword */ void insertKeyword( const std::string& p_strKeyword);
/** Add a sequence of keywords. * This adds a sequence of keywords to the list of keywords. * * \param p_iterBegin 1. input iterator * \param p_iterEnd 2. input iterator */ template<class I> void insertKeywords( I p_iterBegin, I p_iterEnd);
/** Erases a single keyword. * Removes the keyword \a p_strKeyword. * * \param p_strKeyword Keyword to be removed. */ void eraseKeyword( const std::string& p_strKeyword);
/** Erases all keywords. * Removes all keywords */ void clearKeywords();
/** Get the count of keywords. * Returns the number of keywords known by this instance. * * \return Keyword count. */ size_type countKeywords() const;
/** Begin iterator. * Returns iterator to first keyword. * * \return Iterator. */ iterator beginKeywords() const;
/** End iterator. * Returns iterator to last keyword. * * \return Iterator. */ iterator endKeywords() const; //@}
//! \name Abbreviations //@{ /** Get matches of an abbreviation. * This method returns all matches of the abbreviation \a p_strAbbreviation * and returns according iterators to the first and last match. * * \param p_strAbbreviation Abbreviation to be checked. * \param p_riterBegin Returns iterator to first match, or * end iterator if no match. * \param p_riterEnd Returns iterator to last match. * * \return \c true, if at least one match. */ bool getMatches( const std::string& p_strAbbreviation, iterator& p_riterBegin, iterator& p_riterEnd) const;
/** Checks for unique match. * This method checks, whether the abbreviation matches exactly one * keyword. If the match is unique, the matched keyword is returned. * * \param p_strAbbreviation Abbreviation to be checked. * \param p_rstrKeyword Returns the matched keyword, if any. * * \returm \c true, if unique match */ bool isUniqueMatch( const std::string& p_strAbbreviation, std::string& p_rstrKeyword) const;
/** Find abbreviation for a keyword. * This method tries to find the shortest abbreviation for the keyword * \a p_strKeyword, to that it uniquely matches the keyword. * * \param p_strKeyword Keyword that is abbreviated. * * \return Shortest unique abbreviation, or "" if \a p_strKeyword is * not a known keyword. */ std::string findAbbreviation( const std::string& p_strKeyword) const; //@} };
/****************************************************************************** * * TEMPLATE FUNCTIONS * *****************************************************************************/
template<class I> Abbreviator::Abbreviator( I p_iterBegin, I p_iterEnd) :m_setKeywords(p_iterBegin, p_iterEnd) { }
/ ----------------------------------------------------------------------------
template<class I> void Abbreviator::insertKeywords( I p_iterBegin, I p_iterEnd) { m_setKeywords.insert(p_iterBegin, p_iterEnd); }
#endif
|
-- Gruß, virtual Quote of the Month Ich eß' nur was ein Gesicht hat (Creme 21) |