Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

HList.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 **  $Header: /SkyOS.root/HFramework/HList.h 4     4/17/05 12:29p Lee Neuse $
00004 **
00005 ****************************************************************************/
00013 #ifndef HLIST_H
00014     #define HLIST_H
00015 
00023 template <class T>
00024 class HList :   public HObjNoCopy,
00025                 public std::list<T>
00026     {
00027     typedef HObjNoCopy  base_class;
00028     static StringPtr    ClassName(void) { return "HList<T>"; }
00029 public:
00030     typedef typename std::list<T>::iterator     HListIterator;
00031 /*  -----------------------------------------------------------------------
00032     VARIABLES
00033     ----------------------------------------------------------------------- */
00034 
00035 /*  -----------------------------------------------------------------------
00036     CTOR / DTOR
00037     ----------------------------------------------------------------------- */
00038 public:
00039     HList(void)
00040         { /* EMPTY CTOR */ }
00041 
00042     ~HList(void)
00043         { 
00044         if (!IsNotEmpty())
00045             {
00046             DEBUG_LOG("~HList() => %u elements still in list\n", this->size());
00047             this->clear(); 
00048             }
00049         }
00050 /*  -----------------------------------------------------------------------
00051     METHODS
00052     ----------------------------------------------------------------------- */
00053 public:
00060     ErrCode             
00061     AddHead(const T & tData)
00062         {
00063         (void) this->push_front(tData);
00064         return HError::NoError();
00065         }
00072     ErrCode             
00073     AddTail(const T & tData)
00074         {
00075         (void) this->push_back(tData);
00076         return HError::NoError();
00077         }
00085     ErrCode
00086     InsertAfter(const T & tAfter, const T & tData)
00087         {
00088         ErrCode         ec = HError::NoError();
00089         HListIterator   it = this->find(this->begin(), this->end(), tAfter);
00090         
00091         if (it != this->end())
00092             this->insert(it, tData);
00093         else
00094             ec = HError::Set(ERR_NOT_FOUND, __FILE__, __LINE__);
00095             
00096         return ec;
00097         }
00104     ErrCode
00105     Remove(const T & tData)
00106         {
00107         ErrCode     ec = HError::NoError();
00108         
00109         if (IsNotEmpty())
00110             this->remove(tData);
00111         else
00112             ec = HError::Set(ERR_NOT_FOUND, __FILE__, __LINE__);
00113             
00114         return ec;
00115         }
00120     ErrCode
00121     RemoveAll(void)
00122         {
00123         (void) this->clear();
00124         return HError::NoError();
00125         }
00130     ErrCode
00131     RemoveDuplicates(void)
00132         {
00133         if (IsNotEmpty())
00134             (void) this->unique();
00135         return HError::NoError();
00136         }
00142     ErrCode
00143     RemoveHead(void)
00144         { 
00145         ErrCode     ec = HError::NoError();
00146         
00147         if (IsNotEmpty())
00148             (void) this->pop_front();
00149         else
00150             ec = HError::Set(ERR_NOT_FOUND, __FILE__, __LINE__);
00151 
00152         return ec;
00153         }
00159     ErrCode
00160     RemoveTail(void)
00161         { 
00162         ErrCode     ec = HError::NoError();
00163         
00164         if (IsNotEmpty())
00165             (void) this->pop_back();
00166         else
00167             ec = HError::Set(ERR_NOT_FOUND, __FILE__, __LINE__);
00168             
00169         return ec;
00170         }
00175     ErrCode
00176     Sort(void)
00177         { 
00178         if (GetSize() > 1)
00179             (void) this->sort();
00180             
00181         return HError::NoError();
00182         }
00183 /*  -----------------------------------------------------------------------
00184     GETTERS & SETTERS
00185     ----------------------------------------------------------------------- */
00186 public:
00191     inline const T &    GetHead(void) const throw()
00192                             {
00193                             if (this->empty())
00194                                 HError::Throw(ERR_NOT_FOUND, __FILE__, __LINE__);
00195                             
00196                             return this->front();
00197                             }
00202     inline uint32       GetSize(void) const
00203                             { return this->size(); }
00208     inline const T &    GetTail(void) const throw()
00209                             {
00210                             if (this->empty())
00211                                 HError::Throw(ERR_NOT_FOUND, __FILE__, __LINE__);
00212                             
00213                             return this->back();
00214                             }
00215 /*  -----------------------------------------------------------------------
00216     INLINES
00217     ----------------------------------------------------------------------- */
00218 public:
00224     inline bool     Contains(const T & tData) const throw ()
00225                             { return (std::find(this->begin(), this->end(), tData) != this->end()); }
00230     inline bool     IsEmpty(void) const
00231                             { return this->empty(); }
00236     inline bool     IsNotEmpty(void) const
00237                             { return !this->empty(); }
00238     };
00239 
00240 #endif  // HLIST_H
00241 /****************************************************************************
00242 **
00243 **  $History: HList.h $
00244  * 
00245  * *****************  Version 4  *****************
00246  * User: Lee Neuse    Date: 4/17/05    Time: 12:29p
00247  * Updated in $/SkyOS.root/HFramework
00248  * Development snapshot 050417
00249  * 
00250  * *****************  Version 3  *****************
00251  * User: Neusel       Date: 12/10/04   Time: 3:57p
00252  * Updated in $/SkyOS.root/pig/Humble
00253  * 20041210
00254  * 
00255  * *****************  Version 2  *****************
00256  * User: Neusel       Date: 11/30/04   Time: 1:01p
00257  * Updated in $/SkyOS.root/pig/Humble
00258  * Released as HUMBLE_VER 20041130.
00259  * 
00260  * *****************  Version 1  *****************
00261  * User: Neusel       Date: 11/23/04   Time: 8:24a
00262  * Created in $/SkyOS.root/pig/Humble
00263 **
00264 **  -------------------------------------------------------------------------
00265 **
00266 **  End of HList.h
00267 **
00268 ****************************************************************************/