/******************************************************************************/ /* File : HAops.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 *HAtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *HAtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int HAtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator HAtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ HA *HAtable::getLastRow() { HA *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 HAtable::Terminator() { return row.end(); } bool HAtable::isFirstRow(HA* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool HAtable::isLastRow(HA* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void HAtable::insertRow(HA *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 HAtable::removeRow(list::iterator i) { HA *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ HAtable::HAtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ HAtable::~HAtable() { HA *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 HA::set_HNid (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key HAid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "HNid", decode_retstr(&value) ); } HNid = value ; HAid = RC::get_pkid(); decode(temp_key, &HAid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s HNid %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HA::set_DAid (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; logwait(); if ( strlen(value) >= sizeof(DAid) ) fprintf(stderr, "Warning: field DAid in class HA 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)) ; HAid = RC::get_pkid(); decode(temp_key, &HAid); 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 HA::set_txtoffsetx (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; 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 ; HAid = RC::get_pkid(); decode(temp_key, &HAid); 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 HA::set_txtoffsety (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; 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 ; HAid = RC::get_pkid(); decode(temp_key, &HAid); 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 HA::set_HAorigin (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"HAorigin", (value) ); } HAorigin = value ; HAid = RC::get_pkid(); decode(temp_key, &HAid); sprintf(log_text,"PR_SET_FLT %s HAorigin %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HA::set_txtwidth (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; 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 HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif decode(temp_key, &HAid); 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 HA::set_txtheight (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; 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 HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif decode(temp_key, &HAid); 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 HA::set_txtfont (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; logwait(); if ( strlen(value) >= sizeof(txtfont) ) fprintf(stderr, "Warning: field txtfont in class HA 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)) ; HAid = RC::get_pkid(); decode(temp_key, &HAid); 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 HA::set_hlabel (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; logwait(); if ( strlen(value) >= sizeof(hlabel) ) fprintf(stderr, "Warning: field hlabel in class HA 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()) ),"hlabel", (value) ); } strncpy(hlabel, value, sizeof(hlabel)) ; HAid = RC::get_pkid(); decode(temp_key, &HAid); sprintf(log_text,"PR_SET_STR %s hlabel %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key HA::get_HNid () { return HNid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HA::get_DAid () { return DAid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float HA::get_txtoffsetx () { return txtoffsetx; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float HA::get_txtoffsety () { return txtoffsety; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float HA::get_HAorigin () { return HAorigin; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int HA::get_txtwidth () { return txtwidth; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int HA::get_txtheight () { return txtheight; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HA::get_txtfont () { return txtfont; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HA::get_hlabel () { return hlabel; } #ifndef USE_STL HA* HA::create_row() { HA *HAtmp; HAtmp = new HA; HAtmp->set_pkid(0); HAtmp->set_HNid(0); HAtmp->set_DAid("\0"); HAtmp->set_txtoffsetx(0.0); HAtmp->set_txtoffsety(0.0); HAtmp->set_HAorigin(0.0); HAtmp->set_txtwidth(0); HAtmp->set_txtheight(0); HAtmp->set_txtfont("\0"); HAtmp->set_hlabel("\0"); HAtmp->next_ptr = NULL; HAtmp->prev_ptr = NULL; HAtmp->HNid_pp = NULL; HAtmp->HNid_fpp = NULL; HAtmp->HNid_bpp = NULL; return HAtmp; } #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 HA::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key HAid; 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("HA")) { strncpy_null(error_table, "HA", 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 HAelt = this; #endif pr_gen_pkey(viewname,HA,HAid); #ifdef USE_STL set_pkid(HAid); #else RC::set_pkid(HAid); #endif #ifndef USE_STL pr_check_fkey(HA,HAelt,HNid,HN,HNid,HNelt); #else pr_check_fkey(HA,this,HNid,HN,HNid,HNelt); #endif pr_check_str (HA,HAelt,DAid,8); pr_check_str (HA,HAelt,txtfont,25); pr_check_str (HA,HAelt,hlabel,60); 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 HA::link_row() { hcg_key HAid; #ifndef USE_STL insert_element(HA); #else HAtab->insertRow(this); #endif /* USE_STL */ link_parent_bp_m(HA,HN,HNid,HNid,HNid,HAid); } /******************************************************************************/ /* 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 HA::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); HNid = hcg_k; hcg_parse(buffer,hcg_t,&idx); mystrcpy(DAid,hcg_t,8,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_HAorigin((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)); hcg_parse(buffer,hcg_t,&idx); mystrcpy(txtfont,hcg_t,25,0); mystrcpy(hlabel,buffer+idx,60,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 HA::delete_row (list::iterator rowIter) #else void HA::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key HAid; char log_text[BUFSIZE]; logwait(); #ifdef USE_STL HAcurr = rowIter; #endif unlink_parent_bp_m(HA,HN,HNid,HAid); #ifdef DEBUG #ifdef USE_STL HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif decode(temp_key, &HAid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = HAtab->removeRow(rowIter); delete this; #else del_row(HA); #endif /* The following is to support logging */ #ifdef USE_STL HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif decode(temp_key, &HAid); 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 HAtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void HA::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,HA) { #ifndef USE_STL HAcurr->dump_row(viewname,file_name,new_version,modestr); #else (*HAcurr)->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 HA::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key HAid; 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 HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif hcg_update_version(&HAid,HA_idx,new_version); decode(outkey[0], &HAid); hcg_update_version(&HNid,HN_idx,new_version); decode(outkey[1], &HNid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-8s %8.4f %8.4f %8.4f %8d %8d %-25s %-60s\n" , outkey[0], outkey[1], DAid, txtoffsetx, txtoffsety, HAorigin, txtwidth, txtheight , txtfont, hlabel)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void HA::setParent_HNid(HN *currentRow) { HNid_pp = currentRow; } HN *HA::getParent_HNid() { return HNid_pp; } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for HA. */ /********************************************************************************/ HA::HA () { set_pkid(0); /* initialize */ set_HNid(0); set_DAid("\0"); set_txtoffsetx(0.0); set_txtoffsety(0.0); set_HAorigin(0.0); set_txtwidth(0); set_txtheight(0); set_txtfont("\0"); set_hlabel("\0"); setParent_HNid(NULL); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for HA. */ /********************************************************************************/ HA::~HA () { /* 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 HA::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key HAid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("HA"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL HAid = get_pkid(); #else HAid = RC::get_pkid(); #endif hcg_update_version(&HAid,HA_idx,0); decode(outkey[0], &HAid); hcg_update_version(&HNid,HN_idx,0); decode(outkey[1], &HNid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-8s %8.4f %8.4f %8.4f %8d %8d %-25s %-60s\n" , outkey[0], outkey[1], DAid, txtoffsetx, txtoffsety, HAorigin , txtwidth, txtheight, txtfont, hlabel)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void HA::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); HNid = hcg_k; hcg_parse(theRest, hcg_t, &idx); mystrcpy(DAid, hcg_t, 8, 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); HAorigin = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); txtwidth = (atoi(hcg_t)); hcg_parse(theRest, hcg_t, &idx); txtheight = (atoi(hcg_t)); hcg_parse(theRest, hcg_t, &idx); mystrcpy(txtfont, hcg_t, 25, 0); mystrcpy(hlabel, theRest+idx, 60, 1); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void HA::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 HA::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { if (strcmp(fieldname,"txtoffsetx")==0) txtoffsetx = newval; else if (strcmp(fieldname,"txtoffsety")==0) txtoffsety = newval; else if (strcmp(fieldname,"HAorigin")==0) HAorigin = newval; } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void HA::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"HAid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif else if (strcmp(fieldname,"HNid")==0) HNid = new_key; } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void HA::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); }