/******************************************************************************/ /* File : CGops.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 *CGtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *CGtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int CGtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator CGtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ CG *CGtable::getLastRow() { CG *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 CGtable::Terminator() { return row.end(); } bool CGtable::isFirstRow(CG* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool CGtable::isLastRow(CG* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void CGtable::insertRow(CG *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 CGtable::removeRow(list::iterator i) { CG *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ CGtable::CGtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ CGtable::~CGtable() { CG *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 CG::set_HGid (hcg_key value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; char temp_fkey[HCG_KEY_SIZE+1]; hcg_key CGid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_KEY %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ), "HGid", decode_retstr(&value) ); } HGid = value ; CGid = RC::get_pkid(); decode(temp_key, &CGid); decode(temp_fkey, &value); sprintf(log_text,"PR_SET_KEY %s HGid %s\n",temp_key, temp_fkey); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void CG::set_CGcenterx (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key CGid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"CGcenterx", (value) ); } CGcenterx = value ; CGid = RC::get_pkid(); decode(temp_key, &CGid); sprintf(log_text,"PR_SET_FLT %s CGcenterx %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void CG::set_CGcentery (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key CGid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"CGcentery", (value) ); } CGcentery = value ; CGid = RC::get_pkid(); decode(temp_key, &CGid); sprintf(log_text,"PR_SET_FLT %s CGcentery %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void CG::set_CGwidth (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key CGid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"CGwidth", (value) ); } CGwidth = value ; CGid = RC::get_pkid(); decode(temp_key, &CGid); sprintf(log_text,"PR_SET_FLT %s CGwidth %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void CG::set_CGheight (float value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key CGid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_FLT %s %s %f\n", decode_retstr( (hcg_key*)(get_pkid()) ),"CGheight", (value) ); } CGheight = value ; CGid = RC::get_pkid(); decode(temp_key, &CGid); sprintf(log_text,"PR_SET_FLT %s CGheight %f\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ hcg_key CG::get_HGid () { return HGid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float CG::get_CGcenterx () { return CGcenterx; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float CG::get_CGcentery () { return CGcentery; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float CG::get_CGwidth () { return CGwidth; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ float CG::get_CGheight () { return CGheight; } #ifndef USE_STL CG* CG::create_row() { CG *CGtmp; CGtmp = new CG; CGtmp->set_pkid(0); CGtmp->set_HGid(0); CGtmp->set_CGcenterx(0.0); CGtmp->set_CGcentery(0.0); CGtmp->set_CGwidth(0.0); CGtmp->set_CGheight(0.0); CGtmp->next_ptr = NULL; CGtmp->prev_ptr = NULL; CGtmp->HGid_pp = NULL; CGtmp->HGid_fpp = NULL; CGtmp->HGid_bpp = NULL; CGtmp->GXid_fcp = NULL; CGtmp->GXid_bcp = NULL; return CGtmp; } #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 CG::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key CGid; 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("CG")) { strncpy_null(error_table, "CG", 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 CGelt = this; #endif pr_gen_pkey(viewname,CG,CGid); #ifdef USE_STL set_pkid(CGid); #else RC::set_pkid(CGid); #endif #ifndef USE_STL pr_check_fkey(CG,CGelt,HGid,HG,HGid,HGelt); #else pr_check_fkey(CG,this,HGid,HG,HGid,HGelt); #endif 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 CG::link_row() { hcg_key CGid; #ifndef USE_STL insert_element(CG); #else CGtab->insertRow(this); #endif /* USE_STL */ link_child_bp_m(GX,CG,CGid,CGid,CGid,GXid); link_parent_bp_m(CG,HG,HGid,HGid,HGid,CGid); } /******************************************************************************/ /* 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 CG::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); HGid = hcg_k; hcg_parse(buffer,hcg_t,&idx); set_CGcenterx((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_CGcentery((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_CGwidth((float) atof(hcg_t)); hcg_parse(buffer,hcg_t,&idx); set_CGheight((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 CG::delete_row (list::iterator rowIter) #else void CG::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key CGid; char log_text[BUFSIZE]; logwait(); unlink_child_bp_m(GX,CG,CGid,GXid); #ifdef USE_STL CGcurr = rowIter; #endif unlink_parent_bp_m(CG,HG,HGid,CGid); #ifdef DEBUG #ifdef USE_STL CGid = get_pkid(); #else CGid = RC::get_pkid(); #endif decode(temp_key, &CGid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = CGtab->removeRow(rowIter); delete this; #else del_row(CG); #endif /* The following is to support logging */ #ifdef USE_STL CGid = get_pkid(); #else CGid = RC::get_pkid(); #endif decode(temp_key, &CGid); 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 CGtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void CG::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,CG) { #ifndef USE_STL CGcurr->dump_row(viewname,file_name,new_version,modestr); #else (*CGcurr)->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 CG::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key CGid; 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 CGid = get_pkid(); #else CGid = RC::get_pkid(); #endif hcg_update_version(&CGid,CG_idx,new_version); decode(outkey[0], &CGid); hcg_update_version(&HGid,HG_idx,new_version); decode(outkey[1], &HGid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %8.4f %8.4f %8.4f %8.4f\n" , outkey[0], outkey[1], CGcenterx, CGcentery, CGwidth, CGheight)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void CG::insertChild_GXid(GX *childRow) { GXid_children.push_back(childRow); } void CG::removeChild_GXid(list::iterator rowIter) { GXid_children.remove((*rowIter)); } list::iterator CG::getFirstChild_GXid() { return GXid_children.begin(); } list::iterator CG::getLastChild_GXid() { list::iterator iter; iter = GXid_children.end(); if (!GXid_children.empty()) iter--; return iter; } list::iterator CG::GXid_Terminator() { return GXid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void CG::setParent_HGid(HG *currentRow) { HGid_pp = currentRow; } HG *CG::getParent_HGid() { return HGid_pp; } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for CG. */ /********************************************************************************/ CG::CG () { set_pkid(0); /* initialize */ set_HGid(0); set_CGcenterx(0.0); set_CGcentery(0.0); set_CGwidth(0.0); set_CGheight(0.0); setParent_HGid(NULL); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for CG. */ /********************************************************************************/ CG::~CG () { /* 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 CG::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key CGid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("CG"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL CGid = get_pkid(); #else CGid = RC::get_pkid(); #endif hcg_update_version(&CGid,CG_idx,0); decode(outkey[0], &CGid); hcg_update_version(&HGid,HG_idx,0); decode(outkey[1], &HGid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %8.4f %8.4f %8.4f %8.4f\n" , outkey[0], outkey[1], CGcenterx, CGcentery, CGwidth, CGheight)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void CG::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); encode(hcg_t, &hcg_k); HGid = hcg_k; hcg_parse(theRest, hcg_t, &idx); CGcenterx = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); CGcentery = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); CGwidth = ((float) atof(hcg_t)); hcg_parse(theRest, hcg_t, &idx); CGheight = ((float) atof(hcg_t)); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void CG::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 CG::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { if (strcmp(fieldname,"CGcenterx")==0) CGcenterx = newval; else if (strcmp(fieldname,"CGcentery")==0) CGcentery = newval; else if (strcmp(fieldname,"CGwidth")==0) CGwidth = newval; else if (strcmp(fieldname,"CGheight")==0) CGheight = newval; } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void CG::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"CGid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif else if (strcmp(fieldname,"HGid")==0) HGid = new_key; } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void CG::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { }