⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwzrangetest.html

📁 Delaunay三角形的网格剖分程序
💻 HTML
字号:
<TITLE>WZ 1.1: Range</TITLE><PRE>#include "<A HREF="wzrange.hxx">wzrange.hxx</A>"</PRE><H1>wzRange</H1> <P>Here we show how the class <B>wzRange</B> has to be used.  Thisclass allows to handle index ranges.  For example, we use it to handlethe node and cell indices in our grids.  A <B>wzRange</B> contains anarray manager for the template <A HREF="mainwzarraytest.html">wzArray</A>.  Thus, together with a<B>wzRange</B> we use different <B>wzArray</B>'s. <P>First, for every item we need some application-dependent data,something like this:<PRE>typedef struct{        wzIndex a;        wzFloat b;}structure,*pointer;const wzIndex marker = 0xffffffff;void main(){ wzRange range(sizeof(structure),marker);</PRE> <P>This marker will be used to mark items which are not used. Butonce the item is used, you can use the related field for otherinformation.  By coincidence, you may write the marker into thisfield. In this case, some calls may not work correctly. <P>Thus, use a value for the marker you will never write yourselfinto the related field (the first field of your structure).<PRE> wzArray&lt;structure&gt; s(range.base); wzArray&lt;wzIndex&gt; a(range.base,wzOffsetOf(structure,a)); wzArray&lt;wzFloat&gt; b(range.base,wzOffset(pointer,b));</PRE> <P>Here you see how you can access the fields which are usedinternally.  They are used only for invalid items, thus, it would be awaste of memory not to use them, but you have to be a little bitcareful: not to write the marker value into the field a[i] and not tomodify the fields a[i] and b[i] for invalid items i. <P>A possibility to detect related errors may be not to use thisdeclaration during debugging, but:<PRE> wzArray&lt;wzIndex&gt; array(range);</PRE> <P>Now, let's see how to create new items:<PRE> wzIndex i1 = range.create(), i2=range.append(), i3=range.create(50); now(i1==1);	now(i2==2); now(i3==3); s[i2].a=5;	now(a[2]==5); b[i2]=6;	now(s[i2].b==6);</PRE> <P>Let's look how to organize a loop over the whole range.The important thing is to use the macro <B>wzRangeLoop</B>instead of explicit for-statements:<PRE> now(range.first()==1); now(range.last()==52); int i=65,j=0; wzRangeLoop(range,i){ 	// i is now the loop parameter;	a[i] = 5; b[i] = 10;	j++;  now(i==j); } now(j==52); now(i==53); now(range.invalid(i)); // be careful!!!</PRE> <P>Note that the macro <B>wzRangeLoop</B> works also if some of the itemshave been destroyed.  It is not only a pure for-statement, but testsif the item is valid!<PRE> now(range.valid(i2)); now(!range.free(i2)); range.destroy(i2); now(range.invalid(i2)); now(range.free(i2)); now(a[i2]==marker); j=0; wzRangeLoop(range,i){	j++;  now(i != i2); } now(j==51);  // one item less than before.</PRE> <P>Now, let's open a block and allocate a local field:<PRE> {wzArray&lt;wzIndex&gt; field(range);  wzAddress adr1,adr2;  field[50]= 8; // initial memory is allocated because of the range  adr1 = &(field[50]); range.create(5000); adr2 = &(field[50]);  now(adr1 != adr2);    // Be careful! The field has been reallocated!  now(field[50] == 8);  // But the value hasn't changed. } i2 = range.create(); // previously destroyed item i2 will be returned now(i2==2); now(a[i2] == 0);</PRE> <P><A NAME="errors"> <hr></A><H2><A HREF="errors.html">Errors</A></H2> <P>This package does not throw specific errors.<A NAME="End"> <hr></A> <P>You can test this code with: <BR> <BR><B>&gt;cog main wzrange</B> <BR> <BR>The output should be simply: <BR> <BR><B>success</B><PRE>  fine();}</PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -