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

en_tree.h

Go to the documentation of this file.
00001 /* dutree  -- Graphical display of disk useage
00002    Copyright (C) 2002 Aaron Bentley
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software Foundation,
00016    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00017 
00018 #ifndef _EN_TREE_H_
00019 #define _EN_TREE_H_ //make idempotent
00020 
00021 #include <inttypes.h>
00022 #include <stdlib.h>
00023 #include <sys/stat.h>
00024 #define xmalloc malloc
00025 
00029 class EnTree
00030 {
00031 public:
00033    char *name;
00035    uintmax_t size;
00037    EnTree *parent;
00039    EnTree *child;
00041    EnTree *next;
00043    EnTree *prev;
00044    int r, g, b;
00045 
00047    uid_t uid;
00048 
00050    gid_t gid;
00051 
00053    time_t mtime;
00054 
00056    time_t atime;
00057 
00058    EnTree()
00059       :
00060    uid(0), gid(0), mtime(0), atime(0)
00061    {
00062       init();
00063    }
00064 
00065    
00069    void init()
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    }
00087    ~EnTree()
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    }
00099 
00103    EnTree *seek_end();
00104    
00105    /* Add a child to a node */
00106    int add_child(EnTree *child);
00107 
00108    void remove();
00109 
00110    void set(uintmax_t n_blocks, const char *name);
00111 
00112    void add(uintmax_t n_blocks, const char *name);
00113 
00114    void incr_up(uintmax_t n_blocks);
00115    void set_attribs(struct stat const &stat_buf)
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    }
00122    gid_t getGid() const
00123    {
00124       return gid;
00125    }
00126    time_t getMTime() const
00127    {
00128       return mtime;
00129    }
00130    time_t getATime() const
00131    {
00132       return atime;
00133    }
00134    uintmax_t my_size() const
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    }
00143 };
00144 
00145 #endif //_EN_TREE_H_

Generated on Mon Apr 7 19:41:45 2003 for DuTree by doxygen1.2.18