epoc32/include/bamatch.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// 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
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
// Incremental matcher class
williamr@2
    15
// 
williamr@2
    16
//
williamr@2
    17
williamr@2
    18
#if !defined (__BAMATCH_H__)
williamr@2
    19
#define __BAMATCH_H__
williamr@2
    20
williamr@2
    21
#if !defined(__E32STD_H__)
williamr@2
    22
#include <e32std.h>
williamr@2
    23
#endif
williamr@2
    24
williamr@2
    25
#if !defined(__E32BASE_H__)
williamr@2
    26
#include <e32base.h>
williamr@2
    27
#endif
williamr@2
    28
williamr@2
    29
#if !defined(__BAMDESCA_H__)
williamr@2
    30
#include <bamdesca.h>
williamr@2
    31
#endif
williamr@2
    32
williamr@2
    33
williamr@2
    34
class RTextBuf
williamr@2
    35
/** A simple class that encapsulates a text string.
williamr@2
    36
williamr@2
    37
As with the descriptor classes, the class sets a maximum length for the encapsulated 
williamr@2
    38
string, which cannot be exceeded. The class might be preferred to a descriptor 
williamr@2
    39
in some circumstances as its maximum length can be increased (unlike a TBuf), 
williamr@2
    40
and it can be created on the stack (unlike an HBufC) . 
williamr@2
    41
@publishedAll
williamr@2
    42
@released
williamr@2
    43
*/
williamr@2
    44
	{
williamr@2
    45
public:
williamr@2
    46
	IMPORT_C RTextBuf();
williamr@2
    47
	IMPORT_C ~RTextBuf();
williamr@2
    48
public:
williamr@2
    49
	inline TPtr& Text();
williamr@2
    50
	inline const TPtr& Text() const;
williamr@2
    51
	inline TInt MaxLength() const;
williamr@2
    52
	inline void SetText(const TDesC &aDes);
williamr@2
    53
	IMPORT_C void SetMaxLengthL(TInt aMaxLength);
williamr@2
    54
	IMPORT_C void Close();
williamr@2
    55
private:
williamr@2
    56
	TPtr iPtr;
williamr@2
    57
	TText* iText;
williamr@2
    58
	};
williamr@2
    59
williamr@2
    60
williamr@2
    61
williamr@2
    62
class RIncrMatcherBase
williamr@2
    63
/** Base class for incremental matcher classes.
williamr@2
    64
williamr@2
    65
An incremental matcher compares two text buffers from left-to-right. For example, 
williamr@2
    66
the match between "garage" and "gander" is "ga".
williamr@2
    67
williamr@2
    68
The class provides the interface for getting and setting the text to be matched 
williamr@2
    69
against, and for performing match tests. Each type of match test is available 
williamr@2
    70
in three versions, one using binary comparison, one using locale collation 
williamr@2
    71
rules (comparison of strings to produce a dictionary-like ('lexicographic') 
williamr@2
    72
ordering, e.g. ignoring punctuation), and one using locale folding rules (e.g. 
williamr@2
    73
ignoring case). 
williamr@2
    74
williamr@2
    75
"bafl.lib" 
williamr@2
    76
@since 5.0
williamr@2
    77
@publishedAll
williamr@2
    78
@released
williamr@2
    79
*/
williamr@2
    80
	{
williamr@2
    81
public:
williamr@2
    82
    IMPORT_C virtual ~RIncrMatcherBase();
williamr@2
    83
protected:
williamr@2
    84
	/** Default constructor. */
williamr@2
    85
	inline RIncrMatcherBase() {}
williamr@2
    86
protected:
williamr@2
    87
	/** Gets the match text.
williamr@2
    88
	
williamr@2
    89
	@return Match text */
williamr@2
    90
	virtual TDes& MatchDes()=0;
williamr@2
    91
williamr@2
    92
	/** Gets the match text.
williamr@2
    93
	
williamr@2
    94
	@return Match text */
williamr@2
    95
	virtual const TDes& MatchDes() const=0; 
williamr@2
    96
public:
williamr@2
    97
	inline TInt MaxLength() const;
williamr@2
    98
	inline TInt MatchLength() const;
williamr@2
    99
	inline TPtrC MatchText() const;
williamr@2
   100
//
williamr@2
   101
	inline void Clear();
williamr@2
   102
	IMPORT_C void DeleteLastChar();
williamr@2
   103
	IMPORT_C void AppendChar(TChar aLetter);
williamr@2
   104
	inline void SetMatchText(const TDesC& aText);
williamr@2
   105
//
williamr@2
   106
	IMPORT_C void SetBestMatch(const TDesC& aBuf);
williamr@2
   107
	IMPORT_C void SetBestMatchC(const TDesC& aBuf);
williamr@2
   108
	IMPORT_C void SetBestMatchF(const TDesC& aBuf);
williamr@2
   109
	IMPORT_C TBool IsMatch(const TDesC& aBuf) const;
williamr@2
   110
	IMPORT_C TBool IsMatchC(const TDesC& aBuf) const;
williamr@2
   111
	IMPORT_C TBool IsMatchF(const TDesC& aBuf) const;
williamr@2
   112
	IMPORT_C TInt FirstMatchingIndex(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
williamr@2
   113
	IMPORT_C TInt FirstMatchingIndexC(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
williamr@2
   114
	IMPORT_C TInt FirstMatchingIndexF(TInt& aResult,const MDesCArray& aDesArray,TInt aStartIndex=0) const;
williamr@2
   115
private:
williamr@2
   116
	typedef TInt (*TCompareFunc)(const TText*,TInt,const TText*,TInt);
williamr@2
   117
	TBool DoIsMatch(const TDesC& aQuery,TCompareFunc aCompare) const;
williamr@2
   118
	TInt DoFirstMatchingIndex(TInt& aIndex,const MDesCArray& aDesArray,TCompareFunc aCompare) const;
williamr@2
   119
	void DoSetBestMatch(const TDesC& aBuf,TCompareFunc aCompare);
williamr@2
   120
	};
williamr@2
   121
williamr@2
   122
williamr@2
   123
class RIncrMatcherPtr : public RIncrMatcherBase
williamr@2
   124
/** Incrementally matches text against a descriptor, accessed via a pointer.
williamr@2
   125
williamr@2
   126
The class does not take a copy of the text to match against, but only stores 
williamr@2
   127
the pointer. 
williamr@2
   128
@publishedAll
williamr@2
   129
@released
williamr@2
   130
*/
williamr@2
   131
	{
williamr@2
   132
public:
williamr@2
   133
	IMPORT_C RIncrMatcherPtr();
williamr@2
   134
	IMPORT_C RIncrMatcherPtr(TDes& aDes);
williamr@2
   135
    IMPORT_C virtual ~RIncrMatcherPtr();
williamr@2
   136
public:
williamr@2
   137
	inline void SetMatcherPtr(TDes& aDes);
williamr@2
   138
protected:
williamr@2
   139
	IMPORT_C TDes& MatchDes();
williamr@2
   140
	IMPORT_C const TDes& MatchDes() const;
williamr@2
   141
private:
williamr@2
   142
	TDes* iDesPtr;
williamr@2
   143
	};
williamr@2
   144
williamr@2
   145
williamr@2
   146
class RIncrMatcherTextBuf : public RIncrMatcherBase
williamr@2
   147
/** Incrementally matches text against a text buffer with variable maximum 
williamr@2
   148
length. 
williamr@2
   149
@publishedAll
williamr@2
   150
@released
williamr@2
   151
*/
williamr@2
   152
	{
williamr@2
   153
public:
williamr@2
   154
    IMPORT_C RIncrMatcherTextBuf();
williamr@2
   155
    IMPORT_C virtual ~RIncrMatcherTextBuf();
williamr@2
   156
	inline void SetMatcherLengthL(TInt aMaxLength);
williamr@2
   157
protected:
williamr@2
   158
	IMPORT_C TDes& MatchDes();
williamr@2
   159
	IMPORT_C const TDes& MatchDes() const;
williamr@2
   160
private:
williamr@2
   161
	RTextBuf iTextBuf;
williamr@2
   162
	};
williamr@2
   163
williamr@2
   164
template <TInt aMaximumSize> 
williamr@2
   165
class RIncrMatcherBuf : public RIncrMatcherBase
williamr@2
   166
/**
williamr@2
   167
Incrementally matches text against a modifiable descriptor buffer.
williamr@2
   168
Set aMaximumSize to be the maximum size of this buffer. 
williamr@2
   169
@publishedAll
williamr@2
   170
@released
williamr@2
   171
*/
williamr@2
   172
	{
williamr@2
   173
public:
williamr@2
   174
	/** Default constructor. */
williamr@2
   175
	RIncrMatcherBuf() {}
williamr@2
   176
protected:
williamr@2
   177
williamr@2
   178
	/**	 Gets the match text.
williamr@2
   179
	 
williamr@2
   180
	  @return   Match text (non const) */
williamr@2
   181
	inline TDes& MatchDes() {return(iMatchBuf);}
williamr@2
   182
williamr@2
   183
	/**	 Gets the match text.
williamr@2
   184
	 
williamr@2
   185
	  @return   Match text (const)*/
williamr@2
   186
	inline const TDes& MatchDes() const {return(iMatchBuf);}
williamr@2
   187
williamr@2
   188
	/** Copy constructor.
williamr@2
   189
	
williamr@2
   190
	@param aMatcher RIncrMatcherBuf to copy */
williamr@2
   191
	inline RIncrMatcherBuf(const RIncrMatcherBuf& aMatcher) {iMatchBuf=aMatcher.iMatchBuf;}
williamr@2
   192
private:
williamr@2
   193
	TBuf<aMaximumSize> iMatchBuf;
williamr@2
   194
    };
williamr@2
   195
williamr@2
   196
inline TPtr& RTextBuf::Text()
williamr@2
   197
/** Gets the text as a descriptor. 
williamr@2
   198
williamr@2
   199
@return   Match text descriptor (non const) */
williamr@2
   200
	{return(iPtr);}
williamr@2
   201
williamr@2
   202
inline const TPtr& RTextBuf::Text() const
williamr@2
   203
/** Gets the text as a descriptor. 
williamr@2
   204
williamr@2
   205
@return   Match text descriptor (const) */
williamr@2
   206
	{return(iPtr);}
williamr@2
   207
williamr@2
   208
inline TInt RTextBuf::MaxLength() const
williamr@2
   209
/** Gets the maximum length of the text. 
williamr@2
   210
williamr@2
   211
@return The maximum length of the text.*/
williamr@2
   212
	{return(iPtr.MaxLength());}
williamr@2
   213
williamr@2
   214
inline void RTextBuf::SetText(const TDesC &aDes)
williamr@2
   215
/** Sets the text. You must have set the maximum length appropriately first with
williamr@2
   216
SetMaxLengthL(). */
williamr@2
   217
	{iPtr.Copy(aDes);}
williamr@2
   218
williamr@2
   219
inline TInt RIncrMatcherBase::MaxLength() const
williamr@2
   220
/** Gets the maximum length of the match text buffer. */
williamr@2
   221
	{return(MatchDes().MaxLength());}
williamr@2
   222
inline TInt RIncrMatcherBase::MatchLength() const
williamr@2
   223
/** Gets the current length of the match text buffer. */
williamr@2
   224
	{return(MatchDes().Length());}
williamr@2
   225
inline TPtrC RIncrMatcherBase::MatchText() const
williamr@2
   226
/** Gets the match text as a TPtrC. */
williamr@2
   227
	{return(TPtrC(MatchDes()));}
williamr@2
   228
inline void RIncrMatcherBase::SetMatchText(const TDesC& aText)
williamr@2
   229
/** Sets the match text.
williamr@2
   230
	
williamr@2
   231
@param aText String to which to set the match text. */
williamr@2
   232
	{MatchDes()=aText;}
williamr@2
   233
williamr@2
   234
inline void RIncrMatcherBase::Clear()
williamr@2
   235
/** Clears the match text. */
williamr@2
   236
	{MatchDes().Zero();}
williamr@2
   237
williamr@2
   238
inline void RIncrMatcherPtr::SetMatcherPtr(TDes& aDes)
williamr@2
   239
/** Sets the text to be matched against.
williamr@2
   240
	
williamr@2
   241
@param aDes Text to be matched against */
williamr@2
   242
	{iDesPtr=&aDes;}
williamr@2
   243
williamr@2
   244
williamr@2
   245
inline void RIncrMatcherTextBuf::SetMatcherLengthL(TInt aMaxLength)
williamr@2
   246
/** Sets the maximum length of text that can be stored through SetMatchText() 
williamr@2
   247
etc.
williamr@2
   248
	
williamr@2
   249
@param aMaxLength Maximum length of text that can be stored */
williamr@2
   250
	{iTextBuf.SetMaxLengthL(aMaxLength);}
williamr@2
   251
williamr@2
   252
williamr@2
   253
#endif