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

GroupInfo.h

Go to the documentation of this file.
00001 #ifndef _GroupInfo_h_
00002 #define _GroupInfo_h_
00003 
00004 #include <iostream>
00005 
00006 #include "NSError.h"
00007 #include "NVcontainer.h"
00008 
00015 class GroupInfo {
00016         nvtime_t _ctime;
00017         nvtime_t _mtime;
00018         unsigned int _fst, _lst, _n;
00019         char _flag;
00020         char _name[512];
00021 
00022       public:
00023          GroupInfo() {
00024                 init();
00025         } GroupInfo(const char *gd) {
00026                 _name[sizeof(_name) - 1] = '\0';
00027                 set(gd);
00028         }
00029 
00030         void init() {
00031                 _ctime = _mtime = 0;
00032                 _name[0] = _name[sizeof(_name) - 1] = '\0';
00033                 _flag = 'y';
00034         }
00035 
00036         // All data-types stored in NVcontainers must have a set- and getraw
00037         // method
00038         void setraw(const char *buf, unsigned int bufsz) {
00039                 if (bufsz > sizeof(_ctime) + sizeof(_mtime) +
00040                     sizeof(_fst) + sizeof(_lst) + sizeof(_n) +
00041                     sizeof(_flag) + sizeof(_name))
00042                         throw Error("GroupInfo(24230): setraw buf too big",
00043                                     ERROR_LOCATION);
00044                 memcpy(this, buf, bufsz);
00045         }
00046 
00047         void getraw(const char **buf, unsigned int *bufsz) {
00048                 *buf = (const char *) this;
00049                 *bufsz = sizeof(_ctime) + sizeof(_mtime) +
00050                     sizeof(_fst) + sizeof(_lst) + sizeof(_n) +
00051                     sizeof(_flag) + strlen(_name) + 1;
00052         }
00053 
00054         void set(const char *gd) {
00055                 const char *p = gd, *e;
00056                 char *q = _name;
00057                 unsigned int i = 0;
00058 
00059                 while (i < sizeof(_name) && !isspace(*p)) {
00060                         *q++ = *p++;
00061                         ++i;
00062                 }
00063                 if (i == sizeof(_name))
00064                         throw Error("Name of newsgroup too long",
00065                                     ERROR_LOCATION);
00066                 *q = '\0';
00067 
00068                 _lst = strtol(p, (char **) &e, 10);
00069                 _fst = strtol(e, (char **) &p, 10);
00070                 if (e == p)
00071                         throw NSError("gd not in form name int int flag",
00072                                       ERROR_LOCATION);
00073 
00074                 if (_fst > _lst)
00075                         _n = 0;
00076                 else
00077                         _n = _lst - _fst + 1;
00078 
00079                 while (isspace(*p))
00080                         p++;
00081                 if (*p)
00082                         _flag = *p;
00083                 else
00084                         _flag = 'y';
00085 
00086                 nvtime(&_mtime);
00087         }
00088 
00089         void set(const char *group, int fst, int lst, int n, char fl = 'y') {
00090                 strncpy(_name, group, sizeof(_name));
00091                 if (_name[sizeof(_name) - 1] != '\0')
00092                         throw Error("Name of newsgroup too long",
00093                                     ERROR_LOCATION);
00094                 setfln(fst, lst, n, fl);
00095         }
00096 
00097         void setfln(int first, int last, int n, char fl = 'y') {
00098                 nvtime_t tm;
00099                 _fst = first;
00100                 _lst = last;
00101                 _n = n;
00102                 if (fl)
00103                         _flag = fl;
00104                 nvtime(&tm);
00105                 _mtime = tm;
00106         }
00107         void setflag(char fl) {
00108                 _flag = fl;
00109         }
00110 
00111         void setctime(nvtime_t ctime) {
00112                 _ctime = ctime;
00113         }
00114 
00115         nvtime_t ctime() const {
00116                 return _ctime;
00117         } nvtime_t mtime() const {
00118                 return _mtime;
00119         } const char *name() const {
00120                 return _name;
00121         } unsigned int first() const {
00122                 return _fst;
00123         } unsigned int last() const {
00124                 return _lst;
00125         } unsigned int n() const {
00126                 return _n;
00127         } char flags() const {
00128                 return _flag;
00129         } friend std::ostream & operator <<(std::ostream & os,
00130                                             const GroupInfo & gd) {
00131                 os << gd._name << ' ' << gd._lst << ' ' << gd.
00132                     _fst << ' ' << gd._flag;
00133                 return os;
00134         }
00135 };
00136 
00137 #endif

Generated on Fri Aug 20 10:58:06 2004 for NewsCache by doxygen 1.3.6-20040222