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

NVArray Class Reference

#include <NVArray.h>

Inheritance diagram for NVArray:

NVcontainer NVNewsgroup CNewsgroup List of all members.

Public Types

enum  { force = 0x1 }

Public Member Functions

 NVArray ()
 NVArray (const char *dbname, int flags=0)
 ASSERT (nvoff_t nvalloc(size_t rsz);void nvfree(nvoff_t p);) void open(const char *dbname
void ssetsize (unsigned long fst, unsigned long lst)
int setsize (unsigned long fst, unsigned long lst, int flags=0)
void getsize (unsigned long *fst, unsigned long *lst)
void clear (void)
void set (unsigned long i, const char *data, size_t szdata)
void del (unsigned long i)
int is_empty (void)
int has_element (unsigned long i)
void get (unsigned long i, const char **data, size_t *szdata)
void print (ostream &os)

Public Attributes

int flags = 0)

Protected Member Functions

void make_current (void)
void sclear (void)
void sset (unsigned long i, const char *data, size_t szdata)
void sdel (unsigned long i)
int sis_empty (void)
int shas_element (unsigned long i)
void sget (unsigned long i, char **data, size_t *szdata)
void sprint (ostream &os)

Protected Attributes

nvoff_tarrtab
unsigned long arrfst
unsigned long arrlst

Detailed Description

Author:
Thomas Gschwind
Bug:
Documentation is missing.

Definition at line 19 of file NVArray.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
force 

Definition at line 34 of file NVArray.h.

00034              {
00035                 force = 0x1
00036         };


Constructor & Destructor Documentation

NVArray::NVArray  )  [inline]
 

Definition at line 37 of file NVArray.h.

00037                  :NVcontainer() {
00038         } NVArray(const char *dbname, int flags = 0);

NVArray::NVArray const char *  dbname,
int  flags = 0
 

Definition at line 114 of file NVArray.cc.

References NVcontainer::open().

00115 :NVcontainer()
00116 {
00117         open(dbname, flags);
00118 }


Member Function Documentation

NVArray::ASSERT nvoff_t nvalloc(size_t rsz);void nvfree(nvoff_t p);   )  const
 

Open an NVArray container

Parameters:
dbname name of the file, where the array is stored.
flags Ignored at the moment.

void NVArray::clear void   ) 
 

Definition at line 225 of file NVArray.cc.

References NVcontainer::lock(), and sclear().

Referenced by CNewsgroup::sUpdateGroupInfo().

00226 {
00227         lock(ExclLock);
00228         sclear();
00229         lock(UnLock);
00230 }

void NVArray::del unsigned long  i  ) 
 

Definition at line 239 of file NVArray.cc.

References NVcontainer::lock(), and sdel().

00240 {
00241         lock(ExclLock);
00242         sdel(i);
00243         lock(UnLock);
00244 }

void NVArray::get unsigned long  i,
const char **  data,
size_t *  szdata
 

Definition at line 264 of file NVArray.cc.

References NVcontainer::lock(), and sget().

00265 {
00266         lock(ShrdLock);
00267         sget(i, (char **) data, szdata);
00268         lock(UnLock);
00269 }

void NVArray::getsize unsigned long *  fst,
unsigned long *  lst
[inline]
 

Returns the size of NVArray.

Parameters:
fst Index of first element.
lst Index of last element.

Definition at line 69 of file NVArray.h.

References arrfst, and arrlst.

Referenced by NVNewsgroup::getarticle(), NVNewsgroup::getover(), NVNewsgroup::printarticle(), NVNewsgroup::printheaderdb(), NVNewsgroup::setarticle(), NVNewsgroup::setover(), and NVNewsgroup::sprintover().

00069                                                              {
00070                 // No lock necessary, because the user has to lock the NVArray
00071                 // himself, if he wants to have an accurate information.
00072                 *fst = arrfst;
00073                 *lst = arrlst;
00074         }

int NVArray::has_element unsigned long  i  ) 
 

Definition at line 255 of file NVArray.cc.

References NVcontainer::lock(), and shas_element().

Referenced by NVNewsgroup::hasrecord().

00256 {
00257         int r;
00258         lock(ShrdLock);
00259         r = shas_element(i);
00260         lock(UnLock);
00261         return r;
00262 }

int NVArray::is_empty void   ) 
 

Definition at line 246 of file NVArray.cc.

References NVcontainer::lock(), and sis_empty().

00247 {
00248         int r;
00249         lock(ShrdLock);
00250         r = sis_empty();
00251         lock(UnLock);
00252         return r;
00253 }

void NVArray::make_current void   )  [protected, virtual]
 

Reimplemented from NVcontainer.

Definition at line 12 of file NVArray.cc.

References arrfst, arrlst, arrtab, NVcontainer::getdata(), NVcontainer::is_current(), NVcontainer::make_current(), and nvoff_t.

00013 {
00014         nvoff_t adata;
00015 
00016         if (!mem_p || !is_current())
00017                 NVcontainer::make_current();
00018         if ((adata = getdata()) == 0) {
00019                 arrtab = NULL;
00020                 arrfst = 1;
00021                 arrlst = 0;
00022         } else {
00023                 arrtab =
00024                     (nvoff_t *) (mem_p + adata +
00025                                  2 * sizeof(unsigned long));
00026                 arrfst = *(unsigned long *) (mem_p + adata);
00027                 arrlst = *((unsigned long *) (mem_p + adata) + 1);
00028         }
00029 }

void NVArray::print ostream &  os  ) 
 

Definition at line 271 of file NVArray.cc.

References NVcontainer::lock(), and sprint().

00272 {
00273         lock(ShrdLock);
00274         sprint(os);
00275         lock(UnLock);
00276 }

void NVArray::sclear void   )  [protected]
 

Definition at line 31 of file NVArray.cc.

References arrfst, arrlst, arrtab, and NVcontainer::nvfree().

Referenced by clear().

00032 {
00033         unsigned long i, n;
00034 
00035         if (arrfst > arrlst)
00036                 return;
00037         n = arrlst - arrfst + 1;
00038         for (i = 0; i < n; i++)
00039                 if (arrtab[i])
00040                         nvfree(arrtab[i]);
00041 }

void NVArray::sdel unsigned long  i  )  [protected]
 

Definition at line 55 of file NVArray.cc.

References arrtab, and NVcontainer::nvfree().

Referenced by del().

00056 {
00057         if (arrtab[i]) {
00058                 nvfree(arrtab[i]);
00059                 arrtab[i] = 0;
00060         }
00061 }

void NVArray::set unsigned long  i,
const char *  data,
size_t  szdata
 

Definition at line 232 of file NVArray.cc.

References NVcontainer::lock(), and sset().

00233 {
00234         lock(ExclLock);
00235         sset(i, data, szdata);
00236         lock(UnLock);
00237 }

int NVArray::setsize unsigned long  fst,
unsigned long  lst,
int  flags = 0
 

Sets a new size for the NVArray.

Parameters:
fst index of first element.
lst index of last element.
flags indicates, whether the new size must be set even if some elements will not be accessible any more. Those elements will be removed.
Returns:

Definition at line 179 of file NVArray.cc.

References arrlst, force, NVcontainer::lock(), NVcontainer::nvfree(), and ssetsize().

00180 {
00181         // Usually, the user should have already set an excludive lock
00182         // Otherwise, it cannot be guaranteed that no other process
00183         // changes the arraysize again
00184         // This is just to ensure that the NVArray cannot get inconsistent
00185         // even in the case where the user uses this database incorrectly.
00186         lock(ExclLock);
00187         int ok = 1;
00188         unsigned long i, n;
00189 
00190         if (arrfst <= arrlst) {
00191                 // Clean up existing array or return an error
00192                 if (fst > arrfst) {
00193                         n = fst - arrfst + 1;
00194                         for (i = 0; i < n; i++) {
00195                                 if (arrtab[i]) {
00196                                         if (flags & force)
00197                                                 nvfree(arrtab[i]);
00198                                         else
00199                                                 ok = 0;
00200                                 }
00201                         }
00202                 }
00203                 if (lst < arrlst) {
00204                         n = arrlst - arrfst + 1;
00205                         for (i = lst - arrfst + 1; i < n; i++) {
00206                                 if (arrtab[i]) {
00207                                         if (flags & force) {
00208                                                 nvfree(arrtab[i]);
00209                                                 arrtab[i] = 0;
00210                                         } else
00211                                                 ok = 0;
00212                                 }
00213                         }
00214                 }
00215         }
00216         if (ok)
00217                 ssetsize(fst, lst);
00218         lock(UnLock);
00219         if (ok)
00220                 return 0;
00221         else
00222                 return -1;
00223 }

void NVArray::sget unsigned long  i,
char **  data,
size_t *  szdata
[protected]
 

Definition at line 83 of file NVArray.cc.

References arrfst, arrlst, and arrtab.

Referenced by get(), NVNewsgroup::getarticle(), NVNewsgroup::getover(), CNewsgroup::prefetchGroup(), NVNewsgroup::printarticle(), NVNewsgroup::printheaderdb(), NVNewsgroup::setarticle(), NVNewsgroup::setover(), and NVNewsgroup::sprintover().

00084 {
00085         if (arrfst <= i && i <= arrlst && arrtab[i = i - arrfst]) {
00086                 *szdata = *(unsigned long *) (mem_p + arrtab[i]);
00087                 *data = mem_p + arrtab[i] + sizeof(unsigned long);
00088         } else {
00089                 *szdata = 0;
00090                 *data = NULL;
00091         }
00092 }

int NVArray::shas_element unsigned long  i  )  [protected]
 

Definition at line 76 of file NVArray.cc.

References arrfst, arrlst, and arrtab.

Referenced by has_element(), NVNewsgroup::printlistgroup(), and CNewsgroup::sUpdateOverview().

00077 {
00078         if (i < arrfst || i > arrlst)
00079                 return 0;
00080         return arrtab[i - arrfst];
00081 }

int NVArray::sis_empty void   )  [protected]
 

Definition at line 63 of file NVArray.cc.

References arrfst, arrlst, and arrtab.

Referenced by is_empty().

00064 {
00065         unsigned long i, n;
00066 
00067         if (arrfst > arrlst)
00068                 return 1;
00069         n = arrlst - arrfst + 1;
00070         for (i = 0; i < n; i++)
00071                 if (arrtab[i])
00072                         return 0;
00073         return 1;
00074 }

void NVArray::sprint ostream &  os  )  [protected]
 

Definition at line 94 of file NVArray.cc.

References arrfst, arrlst, and arrtab.

Referenced by print().

00095 {
00096         unsigned long i, n;
00097 
00098         if (arrfst > arrlst)
00099                 return;
00100         n = arrlst - arrfst + 1;
00101         for (i = 0; i < n; i++) {
00102                 if (arrtab[i]) {
00103                         os << arrfst +
00104                             i << "/" << *(unsigned long *) (mem_p +
00105                                                             arrtab[i])
00106                             << ":" << mem_p + arrtab[i] +
00107                             sizeof(unsigned long) << endl;
00108                 } else {
00109                         os << arrfst + i << "/(null):" << endl;
00110                 }
00111         }
00112 }

void NVArray::sset unsigned long  i,
const char *  data,
size_t  szdata
[protected]
 

Definition at line 43 of file NVArray.cc.

References arrtab, NVcontainer::nvalloc(), NVcontainer::nvfree(), and nvoff_t.

Referenced by set().

00044 {
00045         nvoff_t x;
00046 
00047         if (arrtab[i])
00048                 nvfree(arrtab[i]);
00049         x = nvalloc(szdata + sizeof(unsigned long));
00050         arrtab[i] = x;
00051         *((unsigned long *) (mem_p + x)) = szdata;
00052         memcpy(mem_p + x + sizeof(unsigned long), data, szdata);
00053 }

void NVArray::ssetsize unsigned long  fst,
unsigned long  lst
 

Definition at line 147 of file NVArray.cc.

References arrlst, NVcontainer::getdata(), NVcontainer::nvalloc(), NVcontainer::nvfree(), nvoff_t, and NVcontainer::setdata().

Referenced by NVNewsgroup::setsize(), and setsize().

00148 {
00149         nvoff_t *ndata;
00150         nvoff_t p, q;
00151         unsigned long i, n;
00152 
00153         p = nvalloc((lst - fst + 1 + 2) * sizeof(unsigned long));
00154         q = getdata();
00155         ndata = (nvoff_t *) (mem_p + p);
00156         ndata[0] = fst;
00157         ndata[1] = lst;
00158         n = lst - fst + 1;
00159         if (arrfst <= arrlst) {
00160                 for (i = 0; i < n; i++) {
00161                         if (arrfst <= i + fst && i + fst <= arrlst) {
00162                                 ndata[2 + i] = arrtab[i + fst - arrfst];
00163                         } else {
00164                                 ndata[2 + i] = 0;
00165                         }
00166                 }
00167         } else {
00168                 for (i = 0; i < n; i++)
00169                         ndata[2 + i] = 0;
00170         }
00171         arrfst = fst;
00172         arrlst = lst;
00173         setdata(p);
00174         arrtab = ndata + 2;
00175         if (q)
00176                 nvfree(q);
00177 }


Member Data Documentation

unsigned long NVArray::arrfst [protected]
 

Definition at line 23 of file NVArray.h.

Referenced by getsize(), make_current(), sclear(), sget(), shas_element(), sis_empty(), and sprint().

unsigned long NVArray::arrlst [protected]
 

Definition at line 23 of file NVArray.h.

Referenced by getsize(), make_current(), sclear(), setsize(), sget(), shas_element(), sis_empty(), sprint(), and ssetsize().

nvoff_t* NVArray::arrtab [protected]
 

Definition at line 22 of file NVArray.h.

Referenced by make_current(), sclear(), sdel(), sget(), shas_element(), sis_empty(), sprint(), and sset().

int NVArray::flags = 0)
 

Definition at line 47 of file NVArray.h.


The documentation for this class was generated from the following files:
Generated on Sun Oct 24 21:08:23 2004 for NewsCache by doxygen 1.3.6-20040222