home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ITBTRE.H
< prev
next >
Wrap
Text File
|
1993-09-22
|
13KB
|
282 lines
/*******************************************************************************
* *
* COPYRIGHT: *
* IBM C/C++ Tools Version 2.01 - Collection Class Library *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _ITBTRE_H
#define _ITBTRE_H
#include <iglobals.h>
#include <itcursor.h>
#include <iitbtre.h>
template < class Element, class ElementOps, INumber pNumberOfChildren >
class IGTabularTree
{
static ElementOps elementOps ()
{ ElementOps ops;
return ops;
}
class Node;
class Cursor;
friend class Node;
friend class Cursor;
class Node
{ friend class IGTabularTree < Element, ElementOps, pNumberOfChildren >;
friend class Cursor;
// must be layout compatible with ITabularTreeImpl::Node
// cannot derive because of unknown pNumberOfChildren in impl
Node* ivParent;
Node* ivChildren [pNumberOfChildren];
Element ivElement;
public :
Node (Element const& element)
: ivElement (element) {};
#if defined (__IBMCPP__) && defined (__DEBUG_ALLOC__)
void* operator new (size_t s, char const* fn, size_t ln)
{ return elementOps().allocate (s, fn, ln); }
void operator delete (void* p, char const* fn, size_t ln)
{ elementOps().deallocate (p, fn, ln); }
#else
void* operator new (size_t s)
{ return elementOps().allocate (s); }
void operator delete (void* p)
{ elementOps().deallocate (p); }
#endif // __IBMCPP__ && __DEBUG_ALLOC__
};
ITabularTreeImpl ivImpl;
public :
class Cursor : public ITreeCursor {
protected:
IGTabularTree < Element, ElementOps,
pNumberOfChildren > const* ivCollection;
ITabularTreeImpl::Node *ivNode;
friend class IGTabularTree < Element, ElementOps, pNumberOfChildren >;
IBoolean isFor (IGTabularTree < Element, ElementOps, pNumberOfChildren >
const& c) const
{ return ivCollection == &c; }
public:
Cursor (IGTabularTree < Element, ElementOps,
pNumberOfChildren > const& collection)
: ivCollection (&collection), ivNode (0) {};
IBoolean setToRoot ();
IBoolean setToChild (IPosition);
IBoolean setToParent ();
IBoolean setToFirstExistingChild ();
IBoolean setToNextExistingChild ();
IBoolean setToLastExistingChild ();
IBoolean setToPreviousExistingChild ();
IBoolean isValid () const;
void invalidate ();
Element const& element () const
{ return ivCollection->elementAt (*this); }
IBoolean operator== (Cursor const& cursor)
{ return ivCollection == cursor.ivCollection &&
ivNode == cursor.ivNode; }
IBoolean operator!= (Cursor const& cursor)
{ return ! operator== (cursor); }
};
IGTabularTree ();
IGTabularTree (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren > const&);
~IGTabularTree ();
IGTabularTree < Element, ElementOps, pNumberOfChildren >&
operator= (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren > const&);
void copy (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren > const&);
void copySubtree (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren > const&,
ITreeCursor const&);
void addAsRoot (Element const&);
void addAsChild (ITreeCursor const&,
IPosition,
Element const&);
void attachAsRoot (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren >&);
void attachAsChild (ITreeCursor const&,
IPosition,
IGTabularTree
< Element,
ElementOps,
pNumberOfChildren >&);
void attachSubtreeAsRoot (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren >&,
ITreeCursor const&);
void attachSubtreeAsChild (ITreeCursor const&,
IPosition,
IGTabularTree
< Element,
ElementOps,
pNumberOfChildren >&,
ITreeCursor const&);
INumber removeAll ();
INumber removeSubtree (ITreeCursor const&);
Element const& elementAt (ITreeCursor const&) const;
Element& elementAt (ITreeCursor const&);
void replaceAt (ITreeCursor const&,
Element const&);
INumber numberOfChildren () const;
INumber numberOfElements () const;
INumber numberOfSubtreeElements (ITreeCursor const&) const;
INumber numberOfLeaves () const;
INumber numberOfSubtreeLeaves (ITreeCursor const&) const;
IBoolean isEmpty () const;
ITreeCursor* newCursor () const;
IBoolean isRoot (ITreeCursor const&) const;
IBoolean isLeaf (ITreeCursor const&) const;
INumber position (ITreeCursor const&) const;
IBoolean hasChild (IPosition,
ITreeCursor const&) const;
IBoolean setToRoot (ITreeCursor&) const;
IBoolean setToChild (IPosition, ITreeCursor&) const;
IBoolean setToParent (ITreeCursor&) const;
IBoolean setToFirstExistingChild (ITreeCursor&) const;
IBoolean setToNextExistingChild (ITreeCursor&) const;
IBoolean setToLastExistingChild (ITreeCursor&) const;
IBoolean setToPreviousExistingChild (ITreeCursor&) const;
IBoolean setToFirst (ITreeCursor&,
ITreeIterationOrder) const;
IBoolean setToNext (ITreeCursor&,
ITreeIterationOrder) const;
IBoolean setToLast (ITreeCursor&,
ITreeIterationOrder) const;
IBoolean setToPrevious (ITreeCursor&,
ITreeIterationOrder) const;
IBoolean allElementsDo (IBoolean (*function)
(Element&, void*),
ITreeIterationOrder,
void* additionalArgument = 0);
IBoolean allElementsDo (IIterator <Element>&,
ITreeIterationOrder);
IBoolean allElementsDo (IBoolean (*function)
(Element const&, void*),
ITreeIterationOrder,
void* additionalArgument = 0)
const;
IBoolean allElementsDo (IConstantIterator <Element>&,
ITreeIterationOrder) const;
IBoolean allSubtreeElementsDo (ITreeCursor const&,
IBoolean (*function)
(Element&, void*),
ITreeIterationOrder,
void* additionalArgument = 0);
IBoolean allSubtreeElementsDo (ITreeCursor const&,
IIterator <Element>&,
ITreeIterationOrder);
IBoolean allSubtreeElementsDo (ITreeCursor const&,
IBoolean (*function)
(Element const&, void*),
ITreeIterationOrder,
void* additionalArgument = 0)
const;
IBoolean allSubtreeElementsDo (ITreeCursor const&,
IConstantIterator <Element>&,
ITreeIterationOrder) const;
IBoolean isConsistent () const;
private:
void copySubtree (Node* from);
void copySubtree (Node*& to, Node* from);
INumber removeSubtree (Node*);
Node* newNode (Element const&);
void checkCursorIsForThis (ITreeCursor const&) const;
void checkCursor (ITreeCursor const&) const;
void checkCursorOfTree (IGTabularTree
< Element,
ElementOps,
pNumberOfChildren > const&,
ITreeCursor const&) const;
void checkPosition (IPosition position) const;
void checkRootNotExists () const;
void checkChildNotExists (ITabularTreeImpl::Node*) const;
static
IBoolean constantFunctionIteration (void *function,
void* env,
void const* node);
static
IBoolean functionIteration (void *function,
void* env,
void* node);
static
IBoolean constantIteratorIteration (void* iterator,
void const* node);
static
IBoolean iteratorIteration (void* iterator,
void* node);
};
template < class Element, INumber pNumberOfChildren >
class ITabularTree :
public IGTabularTree < Element, IStdOps < Element >, pNumberOfChildren > {
};
#include <itbtre.if>
#ifdef __IBMCPP__
#ifndef __TEMPINC__
#include <itbtre.c>
#endif
#endif
#endif