Re: DragNDropOutlineView Example Define Syntax
Re: DragNDropOutlineView Example Define Syntax
- Subject: Re: DragNDropOutlineView Example Define Syntax
- From: Ronnie O <email@hidden>
- Date: Sat, 25 Jun 2005 12:49:50 -0500
Thanks for breaking that down for me. I am can say that I ALMOST
completely get it. The following line is throwing me off though:
SimpleTreeNode* treeNodeItem = (SimpleTreeNode*)item;
Is this a way to cast the item as a SimpleTreeNode instance named
treeNodeItem? I don't recognize that syntax statement. Would another
of saying that be:
SimpleTreeNode* item = [[SimpleTreeNode alloc] initWithObject:item];
I am assuming it is a type of casting that is going on here?
Thanks again!
On 6/24/05, Corbin Dunn <email@hidden> wrote:
> > This is probably more of a C or Objective C syntax question than an
> > OutlineView question, but can anyone explain to me what is going on
> > with the following defintion statements in the DragNDropOutlineView
> > example (this is in the Developer Examples Folder):
> >
> > // Conveniences for accessing nodes, or the data in the node.
> > #define NODE(n) ((SimpleTreeNode*)n)
> > #define NODE_DATA(n) ((SimpleNodeData*)[NODE((n)) nodeData])
> > #define SAFENODE(n) ((SimpleTreeNode*)((n)?(n):(treeData)))
>
> Well, these are macros, which are expanded by the C preprocessor.
> Anytime you see NODE(n), it is replaced with ((SimpleTreeNode*)n),
> where n is the variable passed into the macro. It just saves some
> typing.
>
> For example, this line:
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
> return [SAFENODE(item) childAtIndex:index];
> }
>
> Could have been (typed in mail):
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
> return [((SimpleTreeNode*)((item)?(item):(treeData)))
> childAtIndex:index];
> }
>
> But, to understand it better, this is the same logic:
>
> - (id)outlineView:(NSOutlineView *)olv child:(int)index ofItem:(id)
> item {
> SimpleTreeNode* treeNodeItem = (SimpleTreeNode*)item;
> if (treeNodeItem == nil) {
> // Since item is nil (the top level), use the root item.
> treeNodeItem = treeData;
> }
> return [treeNodeItem childAtIndex:index];
> }
>
> It probably should be re-written to be easier to understand.
>
> --corbin
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden