/******************************************************************************/ /* File : HGops.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 *HGtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *HGtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int HGtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator HGtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ HG *HGtable::getLastRow() { HG *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 HGtable::Terminator() { return row.end(); } bool HGtable::isFirstRow(HG* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool HGtable::isLastRow(HG* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void HGtable::insertRow(HG *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 HGtable::removeRow(list::iterator i) { HG *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ HGtable::HGtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ HGtable::~HGtable() { HG *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 HG::set_FSid (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(FSid) ) fprintf(stderr, "Warning: field FSid in class HG 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()) ),"FSid", (value) ); } strncpy(FSid, value, sizeof(FSid)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s FSid %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HG::set_HNid (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(HNid) ) fprintf(stderr, "Warning: field HNid in class HG 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()) ),"HNid", (value) ); } strncpy(HNid, value, sizeof(HNid)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s HNid %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HG::set_HGauthor (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(HGauthor) ) fprintf(stderr, "Warning: field HGauthor in class HG 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()) ),"HGauthor", (value) ); } strncpy(HGauthor, value, sizeof(HGauthor)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s HGauthor %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HG::set_HGcreated (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(HGcreated) ) fprintf(stderr, "Warning: field HGcreated in class HG 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()) ),"HGcreated", (value) ); } strncpy(HGcreated, value, sizeof(HGcreated)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s HGcreated %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HG::set_HGlastmod (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(HGlastmod) ) fprintf(stderr, "Warning: field HGlastmod in class HG 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()) ),"HGlastmod", (value) ); } strncpy(HGlastmod, value, sizeof(HGlastmod)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s HGlastmod %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void HG::set_HGtitle (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; logwait(); if ( strlen(value) >= sizeof(HGtitle) ) fprintf(stderr, "Warning: field HGtitle in class HG 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()) ),"HGtitle", (value) ); } strncpy(HGtitle, value, sizeof(HGtitle)) ; HGid = RC::get_pkid(); decode(temp_key, &HGid); sprintf(log_text,"PR_SET_STR %s HGtitle %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_FSid () { return FSid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_HNid () { return HNid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_HGauthor () { return HGauthor; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_HGcreated () { return HGcreated; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_HGlastmod () { return HGlastmod; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* HG::get_HGtitle () { return HGtitle; } #ifndef USE_STL HG* HG::create_row() { HG *HGtmp; HGtmp = new HG; HGtmp->set_pkid(0); HGtmp->set_FSid("\0"); HGtmp->set_HNid("\0"); HGtmp->set_HGauthor("\0"); HGtmp->set_HGcreated("\0"); HGtmp->set_HGlastmod("\0"); HGtmp->set_HGtitle("\0"); HGtmp->next_ptr = NULL; HGtmp->prev_ptr = NULL; HGtmp->CGid_fcp = NULL; HGtmp->CGid_bcp = NULL; HGtmp->HNid_fcp = NULL; HGtmp->HNid_bcp = NULL; return HGtmp; } #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 HG::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key HGid; 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("HG")) { strncpy_null(error_table, "HG", 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 HGelt = this; #endif pr_gen_pkey(viewname,HG,HGid); #ifdef USE_STL set_pkid(HGid); #else RC::set_pkid(HGid); #endif pr_check_str (HG,HGelt,FSid,8); pr_check_str (HG,HGelt,HNid,8); pr_check_str (HG,HGelt,HGauthor,12); pr_check_str (HG,HGelt,HGcreated,12); pr_check_str (HG,HGelt,HGlastmod,12); pr_check_str (HG,HGelt,HGtitle,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 HG::link_row() { hcg_key HGid; #ifndef USE_STL insert_element(HG); #else HGtab->insertRow(this); #endif /* USE_STL */ link_child_bp_m(CG,HG,HGid,HGid,HGid,CGid); link_child_bp_m(HN,HG,HGid,HGid,HGid,HNid); } /******************************************************************************/ /* 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 HG::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(FSid,hcg_t,8,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(HNid,hcg_t,8,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(HGauthor,hcg_t,12,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(HGcreated,hcg_t,12,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(HGlastmod,hcg_t,12,0); mystrcpy(HGtitle,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 HG::delete_row (list::iterator rowIter) #else void HG::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key HGid; char log_text[BUFSIZE]; logwait(); unlink_child_bp_m(CG,HG,HGid,CGid); unlink_child_bp_m(HN,HG,HGid,HNid); #ifdef DEBUG #ifdef USE_STL HGid = get_pkid(); #else HGid = RC::get_pkid(); #endif decode(temp_key, &HGid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = HGtab->removeRow(rowIter); delete this; #else del_row(HG); #endif /* The following is to support logging */ #ifdef USE_STL HGid = get_pkid(); #else HGid = RC::get_pkid(); #endif decode(temp_key, &HGid); 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 HGtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void HG::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,HG) { #ifndef USE_STL HGcurr->dump_row(viewname,file_name,new_version,modestr); #else (*HGcurr)->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 HG::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key HGid; 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 HGid = get_pkid(); #else HGid = RC::get_pkid(); #endif hcg_update_version(&HGid,HG_idx,new_version); decode(outkey[0], &HGid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-8s %-12s %-12s %-12s %-60s\n" , outkey[0], FSid, HNid, HGauthor, HGcreated, HGlastmod, HGtitle)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void HG::insertChild_CGid(CG *childRow) { CGid_children.push_back(childRow); } void HG::removeChild_CGid(list::iterator rowIter) { CGid_children.remove((*rowIter)); } list::iterator HG::getFirstChild_CGid() { return CGid_children.begin(); } list::iterator HG::getLastChild_CGid() { list::iterator iter; iter = CGid_children.end(); if (!CGid_children.empty()) iter--; return iter; } list::iterator HG::CGid_Terminator() { return CGid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void HG::insertChild_HNid(HN *childRow) { HNid_children.push_back(childRow); } void HG::removeChild_HNid(list::iterator rowIter) { HNid_children.remove((*rowIter)); } list::iterator HG::getFirstChild_HNid() { return HNid_children.begin(); } list::iterator HG::getLastChild_HNid() { list::iterator iter; iter = HNid_children.end(); if (!HNid_children.empty()) iter--; return iter; } list::iterator HG::HNid_Terminator() { return HNid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for HG. */ /********************************************************************************/ HG::HG () { set_pkid(0); /* initialize */ set_FSid("\0"); set_HNid("\0"); set_HGauthor("\0"); set_HGcreated("\0"); set_HGlastmod("\0"); set_HGtitle("\0"); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for HG. */ /********************************************************************************/ HG::~HG () { /* 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 HG::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key HGid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("HG"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL HGid = get_pkid(); #else HGid = RC::get_pkid(); #endif hcg_update_version(&HGid,HG_idx,0); decode(outkey[0], &HGid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-8s %-12s %-12s %-12s %-60s\n" , outkey[0], FSid, HNid, HGauthor, HGcreated, HGlastmod , HGtitle)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void HG::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); mystrcpy(FSid, hcg_t, 8, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(HNid, hcg_t, 8, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(HGauthor, hcg_t, 12, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(HGcreated, hcg_t, 12, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(HGlastmod, hcg_t, 12, 0); mystrcpy(HGtitle, theRest+idx, 60, 1); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void HG::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 HG::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void HG::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"HGid")==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 HG::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"FSid")==0) strcpy(FSid,newval); else if (strcmp(fieldname,"HNid")==0) strcpy(HNid,newval); else if (strcmp(fieldname,"HGauthor")==0) strcpy(HGauthor,newval); else if (strcmp(fieldname,"HGcreated")==0) strcpy(HGcreated,newval); else if (strcmp(fieldname,"HGlastmod")==0) strcpy(HGlastmod,newval); }