Re: DragNDropOutlineView Example Define Syntax
Re: DragNDropOutlineView Example Define Syntax
- Subject: Re: DragNDropOutlineView Example Define Syntax
- From: Corbin Dunn <email@hidden>
- Date: Fri, 24 Jun 2005 09:28:36 -0700
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