//------------------------------- relation.h -------------------------------
#include
#include
#include "parseline.h"
#include "speclist.h"
class relation {
enum { MAXNAME = 50, MAXFILENAME = 100, MAXFIELDS = 200,
MAXRECORDS = 100000 };
struct {
char name[MAXNAME];
char datatype;
int position;
int printwidth;
} dict[MAXFIELDS];
parseline *records[MAXRECORDS];
void print (FILE *fp);
char relfilename[MAXFILENAME];
relation* istats (int whichfield);
relation* dstats (int whichfield);
int current; // current record num
// Support functions
void copydict (relation *source, relation *dest);
void copydict2 (relation *source1, relation *source2, relation *dest);
int xmatch1c (parseline *x, int pos, char *comparison, char *fieldvalueC);
int xmatch1i (parseline *x, int pos, char *comparison, char *fieldvalueC);
int xmatch1d (parseline *x, int pos, char *comparison, char *fieldvalueC);
int match1 (parseline *x, spec comparison);
int match (parseline *x, speclist comps);
void makewidthline (char *line);
public:
int numrecords, numfields;
relation () { numrecords = numfields = 0; }
relation* select (speclist specs);
void addfield (char *name, int pos, char type, int width);
void addfieldvalue (char *newfield, int recnum, char *newvalue);
void delrecord (int recnum);
void append (relation *other);
relation* difference (char *field1, relation *other, char *field2);
relation* copy ();
relation* project (char *numlist);
void addrecord (char *someline);
void addrecord ();
void print ();
void printheader (FILE *fp);
void load (char *filename);
void save (char *filename);
relation* cross (relation *other);
relation* ejoin (relation *other, char *whichf1, char *whichf2);
void sort (char *whichfield, bool ascending);
void sort ();
relation* addseqnums ();
relation* summarystats (char *whichfield);
int findfield (char *whichfield);
char getfieldtype (char *whichfield);
void showdict ();
void print1record (int recnum);
void info ();
void unique ();
void changefieldname (char *fieldname, char *newname);
void changefieldwidth (char *fieldname, int newwidth);
int getfieldwidth (char *fieldname);
// These will be useful for programs that directly deal with relations
// (as opposed to the interface program).
int whichrec () { return current; }
int findrecord (char *fieldname, char *value);
int findrecord (char *fieldname, int value);
int findrecord (char *fieldname, double value);
void setcurrent (int recnum);
void advance ();
bool atend ();
char *getvalueC (char *fieldname);
int getvalueI (char *fieldname);
double getvalueD (char *fieldname);
void setvalue (char *fieldname, char *newvalueC);
void setvalue (char *fieldname, int newvalueI);
void setvalue (char *fieldname, double newvalueD);
void formatvalue (int recnum, int fieldnum, char *result,
int resultmaxlen);
};