pkg://ofc-0.7.1.tbz:514040/
include/
ofc/DTree.h
downloads
#ifndef _DTREE_H
#define _DTREE_H
// This file was automatically generated by objch.
//==============================================================================
//
// DTree - the tree collection in ofc-library
//
// Copyright (C) 2003 Dick van Oudheusden
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
//
// $Date: 2006/07/22 13:28:57 $ $Revision: 1.12 $
//
//==============================================================================
#include "ofc/config.h"
typedef struct _DTreeNode
{
id _object; // the stored object
struct _DTreeNode *_parent; // the parent node
struct _DTreeNode *_children; // the (first) child node
struct _DTreeNode *_next; // the next node
struct _DTreeNode *_prev; // the previous ode
int _path; // the path during iterating
} DTreeNode;
// The tree class implements a n-tree collection. It stores objects in a
// tree of nodes. Because there is no key or index available to store and
// remove the objects, the objects can only be stored, inserted and removed
// by the tree iterator: @class(DTreeIterator).
@interface DTree : Object
{
@private
DTreeNode *_root; // the root of the tree
long _length; // the number of nodes in the tree
}
//// Constructors
//
// Initialise an empty tree
//
// @return the object
//
- (DTree *) init ;
//// Copy related methods
//
// Do a shallow copy of the tree object
//
// @return the object
//
- shallowCopy;
//
// Deepen a copied tree object
//
// @return the object
//
- deepen;
//// Deconstructor
//
// Free the object (without the stored objects)
//
// @return the object
//
- shallowFree;
//
// (Deep) free the object (including the stored objects)
//
// @return the object
//
- free;
//// Member methods
//
// Return the number of objects in the tree
//
// @return the number of objects
//
- (long) length;
//
// Check if the tree is empty
//
// @return is it
//
- (BOOL) isEmpty;
//// Collection methods
//
// Check if the collection has a certain object
//
// @param obj the object to be found
//
// @return has it ?
//
- (BOOL) has :(id) obj;
//
// Count the number of occurences of an object
//
// @param obj the object to be counted
//
// @return the number of occurences
//
- (long) count :(id) obj;
//
// Perform a method for each object in the tree
//
// @param sel the selector
//
// @return the object
//
- (DTree *) each :(SEL) sel;
@end
// The tree iterator class implements an iterator on a n-tree collection.
// Because there is no key or index available to store and remove the objects,
// the objects can only be stored and removed by this iterator.
@interface DTreeIterator : Object
{
@private
DTree *_tree; // the tree
DTreeNode *_node; // the current node
}
//// Constructors
//
// Initialise an empty iterator
//
// @return the object
//
- (DTreeIterator *) init ;
//
// Initialise the iterator with a tree (iterator is moved to the root)
//
// @param tree the tree for the iterator (<> nil)
//
// @return the object
//
- (DTreeIterator *) init :(DTree *) tree;
//// Movement methods
//
// Move to the first child (in the list of childs)
//
// @return the object of the first child (or nil)
//
- (id) first;
//
// Move to the next child (in the list of childs)
//
// @return the object of the next child (or nil)
//
- (id) next;
//
// Move to the previous child (in the list of childs)
//
// @return the object of the previous child (or nil)
//
- (id) prev;
//
// Move to the last child (in the list of childs)
//
// @return the object in the last node (or nil)
//
- (id) last;
//
// Move the iterator to a certain object. The object is searched
// from the root. If the object is not found, the iterator
// remains on the same location as before calling this method.
// If the object is found, the iterator is moved to this object.
//
// @param obj the object to be found
//
// @return is it found ?
//
- (BOOL) move :(id) obj;
//
// Move to the root
//
// @return the object in the root (or nil)
//
- (id) root;
//
// Move to the parent (for the current child)
//
// @return the object in the parent (or nil)
//
- (id) parent;
//
// Move to the first child (for the current parent)
//
// @return the object in the first child (or nil)
//
- (id) child;
//// Test methods
//
// Test if the iterator is on the first child (in the list of childs)
//
// @return is it ?
//
- (BOOL) isFirst;
//
// Test if the iterator is on the last child (in the list of childs)
//
// @return is it ?
//
- (BOOL) isLast;
//
// Test if the iterator is on the root
//
// @return is it ?
//
- (BOOL) isRoot;
//
// Test if the iterator is on a parent with children
//
// @return has it ?
//
- (BOOL) hasChildren;
//// Stored object methods
//
// Set the object in the current node
//
// @param obj the object to be set
//
// @return the previous object in the node
//
- (id) object :(id) obj;
//
// Get the object in the current node
//
// @return the object in the node (or nil)
//
- (id) object;
//// Add/Insert/Remove methods
//
// Prepend a child to the current (parent) node (iterator is moved to this new child)
//
// @param obj the object to be added as child
//
// @return the object
//
- (DTreeIterator *) prepend :(id) obj;
//
// Append a child to current (parent) node (iterator is moved to new child)
//
// @param obj the object to be added as child
//
// @return the object
//
- (DTreeIterator *) append :(id) obj;
//
// Insert a new child before current (child) node (iterator is moved to new child)
//
// @param obj the object to be added as child
//
// @return the object
//
- (DTreeIterator *) before :(id) obj;
//
// Insert a new child after current (child) node (iterator is moved to new child)
//
// @param obj the object to be added as child
//
// @return the object
//
- (DTreeIterator *) after :(id) obj;
//
// Remove the current node
// Note: only if current node has no children
// Note: iterator moves to 1. the next child or 2. the previous child or 3. the parent
//
// @return the object from the current node (or nil)
//
//
- (id) remove;
@end
#endif