/******************************************************************************/ /* File : GDops.cc */ /* Schema : bdeschema.sch */ /* GENCPP Version : Chgen V 12 - Sathya */ /******************************************************************************/ /* RJL: See comments below re: risks of parsing empty string fields - RJL 021109*/ /*(default values for key int float string fields should be "XX000000, 0, 0.0 and "?")*/ #include #include #include #include "bdeschema.h" #include "SVschema.h" #include "TTschema.h" #include "TAschema.h" #include "VVschema.h" #include "TSschema.h" #include "FOschema.h" #include "GDschema.h" #include "HGschema.h" #include "HNschema.h" #include "HAschema.h" #include "HLschema.h" #include "HPschema.h" #include "HIschema.h" #include "CGschema.h" #include "GXschema.h" #ifdef USE_STL /******************************************************************************/ /* This routine returns table abbreviation. */ /******************************************************************************/ char *GDtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *GDtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int GDtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator GDtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ GD *GDtable::getLastRow() { GD *retval; list::iterator iter; if (row.empty()) { retval = NULL; } else { iter = row.end(); iter--; retval = *iter; } return retval; } /******************************************************************************/ /* This routine returns the terminator after last row in the table. */ /******************************************************************************/ list::iterator GDtable::Terminator() { return row.end(); } bool GDtable::isFirstRow(GD* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool GDtable::isLastRow(GD* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void GDtable::insertRow(GD *newRow) { list::iterator iter; iter = row.begin(); while (iter != row.end() && (*iter)->get_pkid() < newRow->get_pkid()) iter++; row.insert(iter, newRow); } #endif /* USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine returns removes the specified row from the table. */ /******************************************************************************/ list::iterator GDtable::removeRow(list::iterator i) { GD *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ GDtable::GDtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ GDtable::~GDtable() { GD *currRow; list::iterator iterator; iterator = row.begin(); while (iterator != row.end()) { currRow = *iterator; iterator = currRow->delete_row(iterator); } delete [] name; } #endif /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_shape (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if ( strlen(value) >= sizeof(shape) ) fprintf(stderr, "Warning: field shape in class GD is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"shape", (value) ); } strncpy(shape, value, sizeof(shape)) ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_STR %s shape %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_width (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"width", (value) ); } width = value ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_FLT %s width %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_height (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"height", (value) ); } height = value ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_FLT %s height %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_hsegpattern (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if ( strlen(value) >= sizeof(hsegpattern) ) fprintf(stderr, "Warning: field hsegpattern in class GD is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"hsegpattern", (value) ); } strncpy(hsegpattern, value, sizeof(hsegpattern)) ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_STR %s hsegpattern %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_txtfont (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if ( strlen(value) >= sizeof(txtfont) ) fprintf(stderr, "Warning: field txtfont in class GD is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"txtfont", (value) ); } strncpy(txtfont, value, sizeof(txtfont)) ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_STR %s txtfont %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_location (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if ( strlen(value) >= sizeof(location) ) fprintf(stderr, "Warning: field location in class GD is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"location", (value) ); } strncpy(location, value, sizeof(location)) ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_STR %s location %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_justify (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if ( strlen(value) >= sizeof(justify) ) fprintf(stderr, "Warning: field justify in class GD is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"justify", (value) ); } strncpy(justify, value, sizeof(justify)) ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_STR %s justify %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_gcwidth (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"gcwidth", (value) ); } gcwidth = value ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_FLT %s gcwidth %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GD::set_gcheight (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"gcheight", (value) ); } gcheight = value ; GDid = RC::get_pkid(); decode(temp_key, &GDid); sprintf(log_text,"PR_SET_FLT %s gcheight %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GD::get_shape () { return shape; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GD::get_width () { return width; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GD::get_height () { return height; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GD::get_hsegpattern () { return hsegpattern; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GD::get_txtfont () { return txtfont; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GD::get_location () { return location; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GD::get_justify () { return justify; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GD::get_gcwidth () { return gcwidth; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GD::get_gcheight () { return gcheight; } #ifndef USE_STL GD* GD::create_row() { GD *GDtmp; GDtmp = new GD; GDtmp->set_pkid(0); GDtmp->set_shape("\0"); GDtmp->set_width(0.0); GDtmp->set_height(0.0); GDtmp->set_hsegpattern("\0"); GDtmp->set_txtfont("\0"); GDtmp->set_location("\0"); GDtmp->set_justify("\0"); GDtmp->set_gcwidth(0.0); GDtmp->set_gcheight(0.0); GDtmp->next_ptr = NULL; GDtmp->prev_ptr = NULL; return GDtmp; } #endif /******************************************************************************/ /* This routine is used to add a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void GD::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key GDid; char VNstring[NAMELENGTH] = "VN "; if (hcg_log == 1) { logwait(); if (strcmp(viewname, hcg_viewname)) { logstr(strcat (strcat (VNstring, viewname), "\n")); strcpy (hcg_viewname, viewname); } } if (!hcg_initialized) { printf("Error: pr_add() called when database is not yet initialized.\n"); add_row_log (viewname); return; } if (!find_view_idx(viewname)) { printf("Error: view %s passed to pr_load is not defined.\n",viewname); add_row_log (viewname); return; } if (!find_tbl_idx("GD")) { strncpy_null(error_table, "GD", HCG_ABBR_SIZE); printf("Warning: unknown table (%s) passed to pr_add, ignored.\n",error_table); add_row_log (viewname); return; } hcg_version = hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx]; hcg_table_seq_list[hcg_tbl_idx].rcount++; hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].rcount++; #ifndef USE_STL GDelt = this; #endif pr_gen_pkey(viewname,GD,GDid); #ifdef USE_STL set_pkid(GDid); #else RC::set_pkid(GDid); #endif pr_check_str (GD,GDelt,shape,10); pr_check_str (GD,GDelt,hsegpattern,4); pr_check_str (GD,GDelt,txtfont,25); pr_check_str (GD,GDelt,location,10); pr_check_str (GD,GDelt,justify,10); add_row_log (viewname); link_row(); hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].maxrow++; } /******************************************************************************/ /* This routine is used to link a single row to a virtual database table. */ /******************************************************************************/ void GD::link_row() { hcg_key GDid; #ifndef USE_STL insert_element(GD); #else GDtab->insertRow(this); #endif /* USE_STL */ } /******************************************************************************/ /* This routine is used to parse a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void GD::parse_row (char *buffer, int idx, hcg_key hcg_k) { #ifdef USE_STL set_pkid(hcg_k); #else RC::set_pkid(hcg_k); #endif hcg_parse(buffer,hcg_t,&idx); mystrcpy(shape,hcg_t,10,0); hcg_parse(buffer,hcg_t,&idx); set_width((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_height((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); mystrcpy(hsegpattern,hcg_t,4,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(txtfont,hcg_t,25,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(location,hcg_t,10,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(justify,hcg_t,10,0); hcg_parse(buffer,hcg_t,&idx); set_gcwidth((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_gcheight((float) atof(hcg_t)); } /******************************************************************************/ /* This routine will delete a single row from the database. The row is the */ /* one pointed to by the XXcurr variable. */ /******************************************************************************/ #ifdef USE_STL list::iterator GD::delete_row (list::iterator rowIter) #else void GD::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key GDid; char log_text[BUFSIZE]; logwait(); #ifdef DEBUG #ifdef USE_STL GDid = get_pkid(); #else GDid = RC::get_pkid(); #endif decode(temp_key, &GDid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = GDtab->removeRow(rowIter); delete this; #else del_row(GD); #endif /* The following is to support logging */ #ifdef USE_STL GDid = get_pkid(); #else GDid = RC::get_pkid(); #endif decode(temp_key, &GDid); sprintf(log_text,"DL %s\n",temp_key); logstr(log_text); #ifdef USE_STL return rowIter; #endif } /******************************************************************************/ /* This routine will write-out (dump) all rows that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ #ifdef USE_STL void GDtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void GD::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,GD) { #ifndef USE_STL GDcurr->dump_row(viewname,file_name,new_version,modestr); #else (*GDcurr)->dump_row(viewname,file_name,new_version,modestr); #endif /* USE_STL */ } } /******************************************************************************/ /* This routine will write-out (dump) a single row that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ void GD::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key GDid; if (open_file==1) { if ((hcg_dump_fp=fopen(file_name,modestr)) == NULL) { printf("Error: dump_row() cannot open %s using file mode %s\n", file_name,modestr); exit(1); } } #ifdef USE_STL GDid = get_pkid(); #else GDid = RC::get_pkid(); #endif hcg_update_version(&GDid,GD_idx,new_version); decode(outkey[0], &GDid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-10s %8.4f %8.4f %-4s %-25s %-10s %-10s %8.4f %8.4f\n" , outkey[0], shape, width, height, hsegpattern, txtfont, location, justify , gcwidth, gcheight)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL /********************************************************************************/ /* Default constructor for GD. */ /********************************************************************************/ /* WARNING (RJL 021109): Null string values wil be pr_dumped; pr_load will not */ /* recover; make sure PrintCheck gets non-null string values. */ GD::GD () { set_pkid(0); /* initialize */ set_shape("\0"); set_width(0.0); set_height(0.0); set_hsegpattern("\0"); set_txtfont("\0"); set_location("\0"); set_justify("\0"); set_gcwidth(0.0); set_gcheight(0.0); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for GD. */ /********************************************************************************/ GD::~GD () { /* Empty */ } #endif /********************************************************************************/ /* This routine is used to log a call to pr_add to hcg_logfile */ /* The tbl indicates which table is having a row added. */ /* tbl_ptr points to the record to be added. */ /********************************************************************************/ void GD::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key GDid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("GD"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL GDid = get_pkid(); #else GDid = RC::get_pkid(); #endif hcg_update_version(&GDid,GD_idx,0); decode(outkey[0], &GDid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-10s %8.4f %8.4f %-4s %-25s %-10s %-10s %8.4f %8.4f\n" , outkey[0], shape, width, height, hsegpattern, txtfont , location, justify, gcwidth, gcheight)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ /* RJL: theRest starts AFTER the pkey, and hcg_parse shortens it on each call */ /* the result can never be a null string, until end-of-line is reached, */ /* (after consuming words with space separators in last field, if type is tnn). */ /* SUch words introduce garbage into preceding fields ; */ void GD::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); mystrcpy(shape, hcg_t, 10, 0); hcg_parse(theRest, hcg_t, &idx); width = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); height = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); mystrcpy(hsegpattern, hcg_t, 4, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(txtfont, hcg_t, 25, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(location, hcg_t, 10, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(justify, hcg_t, 10, 0); hcg_parse(theRest, hcg_t, &idx); gcwidth = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); gcheight = ((float) atof(hcg_t)); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ /* RJL: empty because GD has no int fields? */ void GD::log_do_set_int_row (const char fieldname[NAMELENGTH+1], const int newval) { } /********************************************************************************/ /* This routine is used to set the value of an float field. */ /********************************************************************************/ void GD::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { if (strcmp(fieldname,"width")==0) width = newval; else if (strcmp(fieldname,"height")==0) height = newval; else if (strcmp(fieldname,"gcwidth")==0) gcwidth = newval; else if (strcmp(fieldname,"gcheight")==0) gcheight = newval; } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ /* WARNING (RJL): pkey should NEVER be updated after creation - this is illegal */ /* fkey changes are high-risk UNLESS export/re-import or alt. relinks list pointers*/ void GD::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"GDid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void GD::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"shape")==0) strcpy(shape,newval); else if (strcmp(fieldname,"hsegpattern")==0) strcpy(hsegpattern,newval); else if (strcmp(fieldname,"txtfont")==0) strcpy(txtfont,newval); else if (strcmp(fieldname,"location")==0) strcpy(location,newval); else if (strcmp(fieldname,"justify")==0) strcpy(justify,newval); }