Using TLitC operators

Explains how to use TLitC operations.

The TLitC class offers four operators, two of which are conversion operators.

The conversion operators are invoked by the compiler when a TLitC<TInt> type is passed to a function which takes the following argument types:

  • a reference by value, i.e. a TRefByValue<class T> type

  • a const reference to a descriptor, i.e. a const TDesC& type

The other two operators return:

  • a pointer to a constant descriptor, i.e. a const TDesC* type

  • a reference to a constant descriptor, i.e. a const TDesC& type

The following code fragments show the situations where the operators are called on a TLitC. The fragments are similar for both TLitC8 and TLitC16.

Reference by value conversion operator operator const __TRefDesC()

The following code fragment shows the operator in use:

...
TBuf<256> x;
...
_LIT(KTxtFormat,"There are %d cm in a metre");
x.Format(KTxtFormat,100);
...

Const descriptor reference conversion operator operator const TDesC&

The following code fragment shows the operator in use:

...
_LIT(KSomeData,"Some data");
...
TPtrC x(KSomeData);

Address of operator operator&()

The following code fragment shows the operator in use:

class CX...
 {
 void Foo(const TDesC* aDesC);
 };

...
_LIT(KLiteral,"some text");
...
CX* anx;
...
anx->Foo(&KLiteral);
...

Reference operator operator()

The following code fragment shows the operator in use:

...
_LIT(KKeywordSelect,"select");
if (KKeywordSelect().CompareF(token)<0)
...