Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

EnTree Class Reference

Represents a directory entry. More...

#include <en_tree.h>

List of all members.

Public Methods

 EnTree ()
void init ()
 Initialize a node to safe defaults.

 ~EnTree ()
 Destroys this node and all its descendants.

EnTree * seek_end ()
 Find the end of the list.

int add_child (EnTree *child)
 Add a child to this node.

void remove ()
 Removes this EnTree from its tree without deleting it.

void set (uintmax_t n_blocks, const char *name)
 Set the name and size of an EnTree node.

void add (uintmax_t n_blocks, const char *name)
 Set the name and increments the size of an EnTree node.

void incr_up (uintmax_t n_blocks)
 increases the size of all ancestors of this block

void set_attribs (struct stat const &stat_buf)
gid_t getGid () const
time_t getMTime () const
time_t getATime () const
uintmax_t my_size () const

Public Attributes

char * name
 The name of the directory entry.

uintmax_t size
 The size of the directory entry (and all children).

EnTree * parent
 The parent of the directory entry.

EnTree * child
 The first child of the directory entry.

EnTree * next
 The next sibling of this directory entry.

EnTree * prev
 The previous sibling of this direcotry entry.

int r
int g
int b
uid_t uid
 The user id of this entry.

gid_t gid
 The group id of the entry.

time_t mtime
 The modification time of the entry.

time_t atime
 The access time of the entry.


Detailed Description

Represents a directory entry.


Constructor & Destructor Documentation

EnTree::EnTree   [inline]
 

00059       :
00060    uid(0), gid(0), mtime(0), atime(0)
00061    {
00062       init();
00063    }

EnTree::~EnTree   [inline]
 

Destroys this node and all its descendants.

00088    {
00089       if (this==NULL) return;
00090 
00091       EnTree *nextcur;
00092       for (EnTree *cur=child; cur!=NULL; cur=nextcur)
00093       {
00094     nextcur=cur->next;
00095     delete cur;
00096       }
00097       free(name);
00098    }


Member Function Documentation

void EnTree::init   [inline]
 

Initialize a node to safe defaults.

00070    {
00071       //using std::random;
00072       EnTree *target=this;
00073       if (target==NULL) return;
00074       target->size=0;
00075       target->next=NULL;
00076       target->prev=NULL;
00077       target->parent=NULL;
00078       target->child=NULL;
00079       target->name=NULL;
00080       target->r=random()%65535;
00081       target->g=random()%65535;
00082       target->b=random()%65535;
00083    }

EnTree * EnTree::seek_end  
 

Find the end of the list.

Returns:
The last EnTree

00027 {
00028    EnTree *current;
00029    for (current=this; current->next!=NULL; current=current->next);
00030    return current;
00031 }

int EnTree::add_child EnTree *    child
 

Add a child to this node.

Parameters:
child  The child to add

00038 { 
00039    if (this->child==NULL) this->child=child;
00040    else
00041    {
00042       EnTree *end;
00043       end=this->child->seek_end();
00044       end->next=child;
00045       child->prev=end;
00046    }
00047    child->parent=this;
00048    return 0;
00049 }

void EnTree::remove  
 

Removes this EnTree from its tree without deleting it.

00055 {
00056    // remove reference in the previous node
00057    if (prev!=NULL) prev->next=next;
00058 
00059    // remove reference in the next node
00060    if (next!=NULL) next->prev=prev;
00061 
00062    // remove reference in the parent node
00063    if (parent!=NULL && parent->child==this) 
00064    parent->child=next;
00065 }

void EnTree::set uintmax_t    n_blocks,
const char *    name
 

Set the name and size of an EnTree node.

Parameters:
n_blocks  The size of the entry
name  The name of the entry

00073 {
00074    size=n_blocks;
00075    if (this->name!=NULL) free (this->name);
00076    if (name==NULL) this->name=NULL;
00077    else this->name=strdup(name);
00078 }

void EnTree::add uintmax_t    n_blocks,
const char *    name
 

Set the name and increments the size of an EnTree node.

Parameters:
n_blocks  The size to add
name  The name to set

00086 {
00087    this->size+=n_blocks;
00088    if (this->name!=NULL) free (this->name);
00089    if (name==NULL) this->name=NULL;
00090    else this->name=strdup(name);
00091 }

void EnTree::incr_up uintmax_t    n_blocks
 

increases the size of all ancestors of this block

Parameters:
n_blocks  The size to increase by

00098 {
00099   for (EnTree *cur=parent; cur!=NULL; cur=cur->parent)
00100   {
00101      cur->size+=n_blocks;
00102   }
00103 }

void EnTree::set_attribs struct stat const &    stat_buf [inline]
 

00116    {
00117       uid=stat_buf.st_uid;
00118       gid=stat_buf.st_gid;
00119       mtime=stat_buf.st_mtime;
00120       atime=stat_buf.st_atime;
00121    }

gid_t EnTree::getGid   const [inline]
 

00123    {
00124       return gid;
00125    }

time_t EnTree::getMTime   const [inline]
 

00127    {
00128       return mtime;
00129    }

time_t EnTree::getATime   const [inline]
 

00131    {
00132       return atime;
00133    }

uintmax_t EnTree::my_size   const [inline]
 

00135    {
00136       uintmax_t s=size;
00137       for (EnTree const *cur=child; cur!=NULL; cur=cur->next)
00138       {
00139     s-=cur->size;
00140       }
00141       return s;
00142    }


Member Data Documentation

char* EnTree::name
 

The name of the directory entry.

uintmax_t EnTree::size
 

The size of the directory entry (and all children).

EnTree* EnTree::parent
 

The parent of the directory entry.

EnTree* EnTree::child
 

The first child of the directory entry.

EnTree* EnTree::next
 

The next sibling of this directory entry.

EnTree* EnTree::prev
 

The previous sibling of this direcotry entry.

int EnTree::r
 

int EnTree::g
 

int EnTree::b
 

uid_t EnTree::uid
 

The user id of this entry.

gid_t EnTree::gid
 

The group id of the entry.

time_t EnTree::mtime
 

The modification time of the entry.

time_t EnTree::atime
 

The access time of the entry.


The documentation for this class was generated from the following files:
Generated on Mon Apr 7 19:43:09 2003 for DuTree by doxygen1.2.18