How to use modifiable buffer descriptor — TBuf

原创 2007年10月09日 11:16:00

下面的内容摘自Symbian S60 3rd Edition SDK,先把英文原版贴在这里,等时间充足的时候我再把它翻译出来。How to use modifiable buffer descriptor — TBuf<TInt>《如何使用可修改的缓冲描述符TBuf<TInt>》

How to use modifiable buffer descriptor — TBuf<TInt>

Modifiable buffer descriptors are useful for holding strings or data and providing safe ways to access and modify that data.

  • For text data, it is usual to construct a TBuf<TInt> type and allow the appropriate variant, either a TBuf8<TInt> or a TBuf16<TInt> to be selected at build time.

  • For binary data, an explicit TBuf8<TInt> is used.

  • It is rare to use an explicit TBuf16<TInt>.

Although, the following notes refer to the build independent types; they are equally valid for the explicit 8 bit and 16 bit types.


Constructing a TBuf<TInt>

A modifiable buffer descriptor can be constructed in a number of ways:

  • as an empty buffer descriptor.

  • as an empty buffer descriptor but giving it a length.

  • by copying data from any other type of descriptor.

  • by copying data from another modifiable buffer descriptor of the same size.

The following code fragment constructs a TBuf<16> object. The buffer descriptor is uninitialised, i.e. it contains no data. The assignment operator or the Copy() function can be used to put data into the buffer descriptor after construction:

_LIT(KText,"Hello World!");
...
TBuf<16> buf1; // length of buf1 is 0
...
buf1 = KText; // data assigned

The source descriptor is a literal which is converted to descriptor type.

The following code fragment constructs a TBuf<16> object and sets it length to 12. No data is assigned into the descriptor.

...
TBuf<16> buf1(12); // length of buf1 is 12
...

The following code fragment constructs a TBuf<16> object, initialised with the 12 characters making up the English language phrase "Hello World!".

_LIT(KText,"Hello World!");
...
TBuf<16> buf1(KText);

The following code fragment constructs a TBuf<16> object from another TBuf<16> object. This is, in effect, copy construction.

_LIT(KText,"Hello World!");
...
TBuf<16> buf1(KText);
TBuf<16> buf2(buf1); // buf2 constructed from the data in buf1

In both of these cases, the resulting length of the descriptor is 12.

A non-modifiable buffer descriptor can also be constructed from 'C' style zero terminated string. However, this is rarely necessary but may make it easier to port legacy 'C' code.


Replacing data

Data within a modifiable buffer descriptor can be completely replaced through the assignment operator or by using the Copy() function.

_LIT(KText,"Hello World!");
_LIT(KNewText,"New text");
_LIT(KReplaced,"Replaced");
...
TBuf<16> buf1(KText);
TBuf<16> buf2;
...
buf2 = buf1; // buf2 now contains "Hello World!"
...
buf2 = KNewText; // buf2 now contains "New text".
                           // the literal is converted to a descriptor
                           // type.
buf2.Copy(KReplaced); // buf2 content replaced using Copy()


Accessing and changing data

Once a modifiable buffer descriptor has been constructed, the functions in the base classes, TDesC and TDes, are available to be access and change the data.

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText);
...
buf1.Length();

and

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText); // length is 12
...
buf1.Delete(6,6); // length is now 6, leaving "Hello" in
                         // the buffer


Illegal access causing an exception

The following code fragment raises a panic because of an attempt to assign too much data. The maximum length of the buffer descriptor is 16 but the length of the data to be copied is 31:

_LIT(KText,"Hello World! The sun is shining");
...
TBufC<16> buf1(KText);

The following code fragment raises a panic because of an attempt to delete data outside the boundary defined by the descriptor:

_LIT(KText,"Hello World!");
...
TBufC<16> buf1(KText);
buf1.Delete(99,1);


 

年纪轻轻记忆力就衰退得厉害,我还有救吗?

转自:http://36kr.com/p/5097688.html 如果我有一小时的时间来背诵一段材料,我会花 55 分钟搞清楚为什么要背它、它能给我带来什么价值,然后再用 5 分钟时间去记住它。 ...
  • shellching
  • shellching
  • 2017年10月18日 17:40
  • 358

Keil C51编译及连接技术(覆盖技术OVERLAY)

http://www.cnblogs.com/heiyue/p/3271421.html Keil C51编译及连接技术
  • chungle2011
  • chungle2011
  • 2014年12月20日 21:22
  • 4882

Go实战--golang中使用号称全世界最快的JSON解析器json-iterator(json-iterator/go)

生命不止,继续go go go!!!号外号外,差不一条广告,我的博客六月到十一月UV的地域分布: golang中的使用json一点也不陌生,golang为我们提供了官方的encoding/json:...
  • wangshubo1989
  • wangshubo1989
  • 2017年12月04日 14:57
  • 12830

eclipse使用技巧

eclipse使用技巧  出处:作者:永恒の_☆ 地址:http://blog.csdn.net/chenghui0317/article/details/9417949 1、如何新建java...
  • JamesLi6
  • JamesLi6
  • 2016年08月16日 21:40
  • 783

DMA描述符及映射

1.DMA通道 DMA(Direct Memory Access)通道建立在设备和RAM之间,DMAC(DMA Controler)与设备I/O控制器相互作用共同实现数据传送。 在PC中,DMA控制...
  • phunxm
  • phunxm
  • 2013年07月24日 16:40
  • 17153

Matplotlib 中文用户指南 4.7 使用 LaTeX 渲染文本

使用 LaTeX 渲染文本 原文:Text rendering With LaTeX 译者:飞龙 协议:CC BY-NC-SA 4.0 Matplotlib 可以选择使用 La...
  • wizardforcel
  • wizardforcel
  • 2017年01月30日 11:47
  • 555

Stack_Queue 一个数组实现三个栈 @CareerCup

原文: Describe how you could use a single array to implement three stacks. 译文: 你如何只用一个数组实现三个栈...
  • hellobinfeng
  • hellobinfeng
  • 2014年03月01日 11:35
  • 1744

快来看看Google出品的Protocol Buffer,别只会用Json和XML了

前言 习惯用 Json、XML 数据存储格式的你们,相信大多都没听过Protocol BufferProtocol Buffer 其实 是 Google出品的一种轻量 & 高效的结构化数据存储格...
  • aptentity
  • aptentity
  • 2017年03月29日 23:20
  • 761

关于Swing中使用Substance皮肤和界面刷新问题一角

问题一、Swing使用Substance皮肤教程 请点链接刚开始遇到的问题基本都有http://insubstantial.github.io/insubstantial/substance/doc...
  • lidelin10
  • lidelin10
  • 2017年12月30日 14:52
  • 72

在WinForms中使用MD皮肤

Material Skin for .Net WinForms TODO: 本文由 赤石俊哉 翻译整理,您可以随意用于学习交流使用,转载之前请注明出处。 参考 GitHub - Ignac...
  • Toshiya14
  • Toshiya14
  • 2016年07月23日 15:10
  • 1015
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to use modifiable buffer descriptor — TBuf
举报原因:
原因补充:

(最多只允许输入30个字)