/******************************************************************************/ /* File : GXops.cc */ /* Schema : bdeschema.sch */ /* GENCPP Version : Chgen V 12 - Sathya */ /******************************************************************************/ #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 *GXtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *GXtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int GXtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator GXtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ GX *GXtable::getLastRow() { GX *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 GXtable::Terminator() { return row.end(); } bool GXtable::isFirstRow(GX* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool GXtable::isLastRow(GX* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void GXtable::insertRow(GX *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 GXtable::removeRow(list::iterator i) { GX *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ GXtable::GXtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ GXtable::~GXtable() { GX *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 GX::set_CGid (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "CGid", decode_retstr(&value) ); } CGid = value ; GXid = RC::get_pkid(); decode(temp_key, &GXid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s CGid %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_DAid (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if ( strlen(value) >= sizeof(DAid) ) fprintf(stderr, "Warning: field DAid in class GX 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()) ),"DAid", (value) ); } strncpy(DAid, value, sizeof(DAid)) ; GXid = RC::get_pkid(); decode(temp_key, &GXid); sprintf(log_text,"PR_SET_STR %s DAid %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_GXorigin (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"GXorigin", (value) ); } GXorigin = value ; GXid = RC::get_pkid(); decode(temp_key, &GXid); sprintf(log_text,"PR_SET_FLT %s GXorigin %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_txtfont (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if ( strlen(value) >= sizeof(txtfont) ) fprintf(stderr, "Warning: field txtfont in class GX 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)) ; GXid = RC::get_pkid(); decode(temp_key, &GXid); 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 GX::set_txtoffsetx (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"txtoffsetx", (value) ); } txtoffsetx = value ; GXid = RC::get_pkid(); decode(temp_key, &GXid); sprintf(log_text,"PR_SET_FLT %s txtoffsetx %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_txtoffsety (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"txtoffsety", (value) ); } txtoffsety = value ; GXid = RC::get_pkid(); decode(temp_key, &GXid); sprintf(log_text,"PR_SET_FLT %s txtoffsety %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_txtwidth (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"txtwidth", (value) ); } txtwidth = value ; #ifdef USE_STL GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif decode(temp_key, &GXid); sprintf(log_text,"PR_SET_INT %s txtwidth %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_txtheight (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"txtheight", (value) ); } txtheight = value ; #ifdef USE_STL GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif decode(temp_key, &GXid); sprintf(log_text,"PR_SET_INT %s txtheight %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void GX::set_grphcaption (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; logwait(); if ( strlen(value) >= sizeof(grphcaption) ) fprintf(stderr, "Warning: field grphcaption in class GX 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()) ),"grphcaption", (value) ); } strncpy(grphcaption, value, sizeof(grphcaption)) ; GXid = RC::get_pkid(); decode(temp_key, &GXid); sprintf(log_text,"PR_SET_STR %s grphcaption %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key GX::get_CGid () { return CGid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GX::get_DAid () { return DAid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GX::get_GXorigin () { return GXorigin; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GX::get_txtfont () { return txtfont; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GX::get_txtoffsetx () { return txtoffsetx; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float GX::get_txtoffsety () { return txtoffsety; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int GX::get_txtwidth () { return txtwidth; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int GX::get_txtheight () { return txtheight; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* GX::get_grphcaption () { return grphcaption; } #ifndef USE_STL GX* GX::create_row() { GX *GXtmp; GXtmp = new GX; GXtmp->set_pkid(0); GXtmp->set_CGid(0); GXtmp->set_DAid("\0"); GXtmp->set_GXorigin(0.0); GXtmp->set_txtfont("\0"); GXtmp->set_txtoffsetx(0.0); GXtmp->set_txtoffsety(0.0); GXtmp->set_txtwidth(0); GXtmp->set_txtheight(0); GXtmp->set_grphcaption("\0"); GXtmp->next_ptr = NULL; GXtmp->prev_ptr = NULL; GXtmp->CGid_pp = NULL; GXtmp->CGid_fpp = NULL; GXtmp->CGid_bpp = NULL; return GXtmp; } #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 GX::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key GXid; 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("GX")) { strncpy_null(error_table, "GX", 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 GXelt = this; #endif pr_gen_pkey(viewname,GX,GXid); #ifdef USE_STL set_pkid(GXid); #else RC::set_pkid(GXid); #endif #ifndef USE_STL pr_check_fkey(GX,GXelt,CGid,CG,CGid,CGelt); #else pr_check_fkey(GX,this,CGid,CG,CGid,CGelt); #endif pr_check_str (GX,GXelt,DAid,8); pr_check_str (GX,GXelt,txtfont,25); pr_check_str (GX,GXelt,grphcaption,120); 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 GX::link_row() { hcg_key GXid; #ifndef USE_STL insert_element(GX); #else GXtab->insertRow(this); #endif /* USE_STL */ link_parent_bp_m(GX,CG,CGid,CGid,CGid,GXid); } /******************************************************************************/ /* 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 GX::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); encode(hcg_t, &hcg_k); CGid = hcg_k; hcg_parse(buffer,hcg_t,&idx); mystrcpy(DAid,hcg_t,8,0); hcg_parse(buffer,hcg_t,&idx); set_GXorigin((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); mystrcpy(txtfont,hcg_t,25,0); hcg_parse(buffer,hcg_t,&idx); set_txtoffsetx((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_txtoffsety((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_txtwidth(atoi(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_txtheight(atoi(hcg_t)); mystrcpy(grphcaption,buffer+idx,120,1); } /******************************************************************************/ /* 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 GX::delete_row (list::iterator rowIter) #else void GX::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key GXid; char log_text[BUFSIZE]; logwait(); #ifdef USE_STL GXcurr = rowIter; #endif unlink_parent_bp_m(GX,CG,CGid,GXid); #ifdef DEBUG #ifdef USE_STL GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif decode(temp_key, &GXid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = GXtab->removeRow(rowIter); delete this; #else del_row(GX); #endif /* The following is to support logging */ #ifdef USE_STL GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif decode(temp_key, &GXid); 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 GXtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void GX::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,GX) { #ifndef USE_STL GXcurr->dump_row(viewname,file_name,new_version,modestr); #else (*GXcurr)->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 GX::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key GXid; 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 GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif hcg_update_version(&GXid,GX_idx,new_version); decode(outkey[0], &GXid); hcg_update_version(&CGid,CG_idx,new_version); decode(outkey[1], &CGid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-8s %8.4f %-25s %8.4f %8.4f %8d %8d %-120s\n" , outkey[0], outkey[1], DAid, GXorigin, txtfont, txtoffsetx, txtoffsety, txtwidth , txtheight, grphcaption)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void GX::setParent_CGid(CG *currentRow) { CGid_pp = currentRow; } CG *GX::getParent_CGid() { return CGid_pp; } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for GX. */ /********************************************************************************/ GX::GX () { set_pkid(0); /* initialize */ set_CGid(0); set_DAid("\0"); set_GXorigin(0.0); set_txtfont("\0"); set_txtoffsetx(0.0); set_txtoffsety(0.0); set_txtwidth(0); set_txtheight(0); set_grphcaption("\0"); setParent_CGid(NULL); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for GX. */ /********************************************************************************/ GX::~GX () { /* 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 GX::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key GXid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("GX"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL GXid = get_pkid(); #else GXid = RC::get_pkid(); #endif hcg_update_version(&GXid,GX_idx,0); decode(outkey[0], &GXid); hcg_update_version(&CGid,CG_idx,0); decode(outkey[1], &CGid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-8s %8.4f %-25s %8.4f %8.4f %8d %8d %-120s\n" , outkey[0], outkey[1], DAid, GXorigin, txtfont, txtoffsetx , txtoffsety, txtwidth, txtheight, grphcaption)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void GX::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); CGid = hcg_k; hcg_parse(theRest, hcg_t, &idx); mystrcpy(DAid, hcg_t, 8, 0); hcg_parse(theRest, hcg_t, &idx); GXorigin = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); mystrcpy(txtfont, hcg_t, 25, 0); hcg_parse(theRest, hcg_t, &idx); txtoffsetx = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); txtoffsety = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); txtwidth = (atoi(hcg_t)); hcg_parse(theRest, hcg_t, &idx); txtheight = (atoi(hcg_t)); mystrcpy(grphcaption, theRest+idx, 120, 1); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void GX::log_do_set_int_row (const char fieldname[NAMELENGTH+1], const int newval) { if(strcmp(fieldname,"txtwidth")==0) txtwidth = newval; else if(strcmp(fieldname,"txtheight")==0) txtheight = newval; } /********************************************************************************/ /* This routine is used to set the value of an float field. */ /********************************************************************************/ void GX::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { if (strcmp(fieldname,"GXorigin")==0) GXorigin = newval; else if (strcmp(fieldname,"txtoffsetx")==0) txtoffsetx = newval; else if (strcmp(fieldname,"txtoffsety")==0) txtoffsety = newval; } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void GX::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"GXid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif else if (strcmp(fieldname,"CGid")==0) CGid = new_key; } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void GX::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"DAid")==0) strcpy(DAid,newval); else if (strcmp(fieldname,"txtfont")==0) strcpy(txtfont,newval); }