1.1 --- a/epoc32/include/bamatch.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/bamatch.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,253 @@
1.4 -bamatch.h
1.5 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +// Incremental matcher class
1.19 +//
1.20 +//
1.21 +
1.22 +#if !defined (__BAMATCH_H__)
1.23 +#define __BAMATCH_H__
1.24 +
1.25 +#if !defined(__E32STD_H__)
1.26 +#include <e32std.h>
1.27 +#endif
1.28 +
1.29 +#if !defined(__E32BASE_H__)
1.30 +#include <e32base.h>
1.31 +#endif
1.32 +
1.33 +#if !defined(__BAMDESCA_H__)
1.34 +#include <bamdesca.h>
1.35 +#endif
1.36 +
1.37 +
1.38 +class RTextBuf
1.39 +/** A simple class that encapsulates a text string.
1.40 +
1.41 +As with the descriptor classes, the class sets a maximum length for the encapsulated
1.42 +string, which cannot be exceeded. The class might be preferred to a descriptor
1.43 +in some circumstances as its maximum length can be increased (unlike a TBuf),
1.44 +and it can be created on the stack (unlike an HBufC) .
1.45 +@publishedAll
1.46 +@released
1.47 +*/
1.48 + {
1.49 +public:
1.50 + IMPORT_C RTextBuf();
1.51 + IMPORT_C ~RTextBuf();
1.52 +public:
1.53 + inline TPtr& Text();
1.54 + inline const TPtr& Text() const;
1.55 + inline TInt MaxLength() const;
1.56 + inline void SetText(const TDesC &aDes);
1.57 + IMPORT_C void SetMaxLengthL(TInt aMaxLength);
1.58 + IMPORT_C void Close();
1.59 +private:
1.60 + TPtr iPtr;
1.61 + TText* iText;
1.62 + };
1.63 +
1.64 +
1.65 +
1.66 +class RIncrMatcherBase
1.67 +/** Base class for incremental matcher classes.
1.68 +
1.69 +An incremental matcher compares two text buffers from left-to-right. For example,
1.70 +the match between "garage" and "gander" is "ga".
1.71 +
1.72 +The class provides the interface for getting and setting the text to be matched
1.73 +against, and for performing match tests. Each type of match test is available
1.74 +in three versions, one using binary comparison, one using locale collation
1.75 +rules (comparison of strings to produce a dictionary-like ('lexicographic')
1.76 +ordering, e.g. ignoring punctuation), and one using locale folding rules (e.g.
1.77 +ignoring case).
1.78 +
1.79 +"bafl.lib"
1.80 +@since 5.0
1.81 +@publishedAll
1.82 +@released
1.83 +*/
1.84 + {
1.85 +public:
1.86 + IMPORT_C virtual ~RIncrMatcherBase();
1.87 +protected:
1.88 + /** Default constructor. */
1.89 + inline RIncrMatcherBase() {}
1.90 +protected:
1.91 + /** Gets the match text.
1.92 +
1.93 + @return Match text */
1.94 + virtual TDes& MatchDes()=0;
1.95 +
1.96 + /** Gets the match text.
1.97 +
1.98 + @return Match text */
1.99 + virtual const TDes& MatchDes() const=0;
1.100 +public:
1.101 + inline TInt MaxLength() const;
1.102 + inline TInt MatchLength() const;
1.103 + inline TPtrC MatchText() const;
1.104 +//
1.105 + inline void Clear();
1.106 + IMPORT_C void DeleteLastChar();
1.107 + IMPORT_C void AppendChar(TChar aLetter);
1.108 + inline void SetMatchText(const TDesC& aText);
1.109 +//
1.110 + IMPORT_C void SetBestMatch(const TDesC& aBuf);
1.111 + IMPORT_C void SetBestMatchC(const TDesC& aBuf);
1.112 + IMPORT_C void SetBestMatchF(const TDesC& aBuf);
1.113 + IMPORT_C TBool IsMatch(const TDesC& aBuf) const;
1.114 + IMPORT_C TBool IsMatchC(const TDesC& aBuf) const;
1.115 + IMPORT_C TBool IsMatchF(const TDesC& aBuf) const;
1.116 + IMPORT_C TInt FirstMatchingIndex(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
1.117 + IMPORT_C TInt FirstMatchingIndexC(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
1.118 + IMPORT_C TInt FirstMatchingIndexF(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
1.119 +private:
1.120 + typedef TInt (*TCompareFunc)(const TText*,TInt,const TText*,TInt);
1.121 + TBool DoIsMatch(const TDesC& aQuery,TCompareFunc aCompare) const;
1.122 + TInt DoFirstMatchingIndex(TInt& aIndex,const MDesCArray& aDesArray,TCompareFunc aCompare) const;
1.123 + void DoSetBestMatch(const TDesC& aBuf,TCompareFunc aCompare);
1.124 + };
1.125 +
1.126 +
1.127 +class RIncrMatcherPtr : public RIncrMatcherBase
1.128 +/** Incrementally matches text against a descriptor, accessed via a pointer.
1.129 +
1.130 +The class does not take a copy of the text to match against, but only stores
1.131 +the pointer.
1.132 +@publishedAll
1.133 +@released
1.134 +*/
1.135 + {
1.136 +public:
1.137 + IMPORT_C RIncrMatcherPtr();
1.138 + IMPORT_C RIncrMatcherPtr(TDes& aDes);
1.139 + IMPORT_C virtual ~RIncrMatcherPtr();
1.140 +public:
1.141 + inline void SetMatcherPtr(TDes& aDes);
1.142 +protected:
1.143 + IMPORT_C TDes& MatchDes();
1.144 + IMPORT_C const TDes& MatchDes() const;
1.145 +private:
1.146 + TDes* iDesPtr;
1.147 + };
1.148 +
1.149 +
1.150 +class RIncrMatcherTextBuf : public RIncrMatcherBase
1.151 +/** Incrementally matches text against a text buffer with variable maximum
1.152 +length.
1.153 +@publishedAll
1.154 +@released
1.155 +*/
1.156 + {
1.157 +public:
1.158 + IMPORT_C RIncrMatcherTextBuf();
1.159 + IMPORT_C virtual ~RIncrMatcherTextBuf();
1.160 + inline void SetMatcherLengthL(TInt aMaxLength);
1.161 +protected:
1.162 + IMPORT_C TDes& MatchDes();
1.163 + IMPORT_C const TDes& MatchDes() const;
1.164 +private:
1.165 + RTextBuf iTextBuf;
1.166 + };
1.167 +
1.168 +template <TInt aMaximumSize>
1.169 +class RIncrMatcherBuf : public RIncrMatcherBase
1.170 +/**
1.171 +Incrementally matches text against a modifiable descriptor buffer.
1.172 +Set aMaximumSize to be the maximum size of this buffer.
1.173 +@publishedAll
1.174 +@released
1.175 +*/
1.176 + {
1.177 +public:
1.178 + /** Default constructor. */
1.179 + RIncrMatcherBuf() {}
1.180 +protected:
1.181 +
1.182 + /** Gets the match text.
1.183 +
1.184 + @return Match text (non const) */
1.185 + inline TDes& MatchDes() {return(iMatchBuf);}
1.186 +
1.187 + /** Gets the match text.
1.188 +
1.189 + @return Match text (const)*/
1.190 + inline const TDes& MatchDes() const {return(iMatchBuf);}
1.191 +
1.192 + /** Copy constructor.
1.193 +
1.194 + @param aMatcher RIncrMatcherBuf to copy */
1.195 + inline RIncrMatcherBuf(const RIncrMatcherBuf& aMatcher) {iMatchBuf=aMatcher.iMatchBuf;}
1.196 +private:
1.197 + TBuf<aMaximumSize> iMatchBuf;
1.198 + };
1.199 +
1.200 +inline TPtr& RTextBuf::Text()
1.201 +/** Gets the text as a descriptor.
1.202 +
1.203 +@return Match text descriptor (non const) */
1.204 + {return(iPtr);}
1.205 +
1.206 +inline const TPtr& RTextBuf::Text() const
1.207 +/** Gets the text as a descriptor.
1.208 +
1.209 +@return Match text descriptor (const) */
1.210 + {return(iPtr);}
1.211 +
1.212 +inline TInt RTextBuf::MaxLength() const
1.213 +/** Gets the maximum length of the text.
1.214 +
1.215 +@return The maximum length of the text.*/
1.216 + {return(iPtr.MaxLength());}
1.217 +
1.218 +inline void RTextBuf::SetText(const TDesC &aDes)
1.219 +/** Sets the text. You must have set the maximum length appropriately first with
1.220 +SetMaxLengthL(). */
1.221 + {iPtr.Copy(aDes);}
1.222 +
1.223 +inline TInt RIncrMatcherBase::MaxLength() const
1.224 +/** Gets the maximum length of the match text buffer. */
1.225 + {return(MatchDes().MaxLength());}
1.226 +inline TInt RIncrMatcherBase::MatchLength() const
1.227 +/** Gets the current length of the match text buffer. */
1.228 + {return(MatchDes().Length());}
1.229 +inline TPtrC RIncrMatcherBase::MatchText() const
1.230 +/** Gets the match text as a TPtrC. */
1.231 + {return(TPtrC(MatchDes()));}
1.232 +inline void RIncrMatcherBase::SetMatchText(const TDesC& aText)
1.233 +/** Sets the match text.
1.234 +
1.235 +@param aText String to which to set the match text. */
1.236 + {MatchDes()=aText;}
1.237 +
1.238 +inline void RIncrMatcherBase::Clear()
1.239 +/** Clears the match text. */
1.240 + {MatchDes().Zero();}
1.241 +
1.242 +inline void RIncrMatcherPtr::SetMatcherPtr(TDes& aDes)
1.243 +/** Sets the text to be matched against.
1.244 +
1.245 +@param aDes Text to be matched against */
1.246 + {iDesPtr=&aDes;}
1.247 +
1.248 +
1.249 +inline void RIncrMatcherTextBuf::SetMatcherLengthL(TInt aMaxLength)
1.250 +/** Sets the maximum length of text that can be stored through SetMatchText()
1.251 +etc.
1.252 +
1.253 +@param aMaxLength Maximum length of text that can be stored */
1.254 + {iTextBuf.SetMaxLengthL(aMaxLength);}
1.255 +
1.256 +
1.257 +#endif