Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

NVList.h

Go to the documentation of this file.
00001 #ifndef _NVList_h_
00002 #define _NVList_h_
00003 
00004 #include"NVlist.h"
00005 
00006 /* NVContainer Class Library */
00007 class NVList;
00008 class NVListIter;
00009 
00015 class NVList:public NVlist {
00016         friend class NVListIter;
00017 
00018       public:
00019          NVList():NVlist() {
00020         } NVList(const char *dbname, int flags = 0):NVlist(dbname, flags) {
00021         }
00022 
00023         int is_empty(void);
00024         void prepend(const char *data, size_t szdata);
00025         void append(const char *data, size_t szdata);
00026         void remove(void);
00027         void clear(void);
00028 
00029         void print(std::ostream & os);
00030 };
00031 
00037 class NVListIter {
00038         NVList *l;
00039          NVList::Record * pos;
00040          NVList::Record * tail;
00041       public:
00042          NVListIter() {
00043                 l = NULL;
00044                 pos = NULL;
00045         } NVListIter(NVList & nvl) {
00046                 l = &nvl;
00047                 l->lock(NVList::ShrdLock);
00048                 pos = NULL;
00049         }
00050         ~NVListIter() {
00051                 detach();
00052         }
00053 
00054         void attach(NVList & nvl) {
00055                 detach();
00056                 l = &nvl;
00057                 l->lock(NVList::ShrdLock);
00058                 pos = NULL;
00059                 tail = l->o2r(l->getdata());
00060         }
00061         void detach() {
00062                 if (l) {
00063                         l->lock(NVList::UnLock);
00064                 }
00065                 l = NULL;
00066         }
00067 
00068         void first() {
00069                 if (l)
00070                         pos = l->o2r(tail->next);
00071         }
00072         int valid() {
00073                 return pos != NULL;
00074         }
00075         void next() {
00076                 if (pos) {
00077                         if (pos == tail)
00078                                 pos = 0;
00079                         else
00080                                 pos = l->o2r(pos->next);
00081                 }
00082         }
00083 
00084         void data(const char **data, unsigned int *szdata) {
00085                 (*data) = l->mem_p + l->r2o(pos) + sizeof(NVList::Record);
00086                 (*szdata) = pos->szdata;
00087         }
00088 };
00089 
00090 #endif

Generated on Sun Oct 24 21:08:19 2004 for NewsCache by doxygen 1.3.6-20040222