/******************************************************************************/ /* File : FOops.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 *FOtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *FOtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int FOtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator FOtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ FO *FOtable::getLastRow() { FO *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 FOtable::Terminator() { return row.end(); } bool FOtable::isFirstRow(FO* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool FOtable::isLastRow(FO* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void FOtable::insertRow(FO *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 FOtable::removeRow(list::iterator i) { FO *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ FOtable::FOtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ FOtable::~FOtable() { FO *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 FO::set_xfont (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key FOid; logwait(); if ( strlen(value) >= sizeof(xfont) ) fprintf(stderr, "Warning: field xfont in class FO 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()) ),"xfont", (value) ); } strncpy(xfont, value, sizeof(xfont)) ; FOid = RC::get_pkid(); decode(temp_key, &FOid); sprintf(log_text,"PR_SET_STR %s xfont %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void FO::set_psfontname (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key FOid; logwait(); if ( strlen(value) >= sizeof(psfontname) ) fprintf(stderr, "Warning: field psfontname in class FO 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()) ),"psfontname", (value) ); } strncpy(psfontname, value, sizeof(psfontname)) ; FOid = RC::get_pkid(); decode(temp_key, &FOid); sprintf(log_text,"PR_SET_STR %s psfontname %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void FO::set_psfontsize (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key FOid; logwait(); if ( strlen(value) >= sizeof(psfontsize) ) fprintf(stderr, "Warning: field psfontsize in class FO 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()) ),"psfontsize", (value) ); } strncpy(psfontsize, value, sizeof(psfontsize)) ; FOid = RC::get_pkid(); decode(temp_key, &FOid); sprintf(log_text,"PR_SET_STR %s psfontsize %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void FO::set_bdefont (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key FOid; logwait(); if ( strlen(value) >= sizeof(bdefont) ) fprintf(stderr, "Warning: field bdefont in class FO 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()) ),"bdefont", (value) ); } strncpy(bdefont, value, sizeof(bdefont)) ; FOid = RC::get_pkid(); decode(temp_key, &FOid); sprintf(log_text,"PR_SET_STR %s bdefont %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* FO::get_xfont () { return xfont; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* FO::get_psfontname () { return psfontname; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* FO::get_psfontsize () { return psfontsize; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* FO::get_bdefont () { return bdefont; } #ifndef USE_STL FO* FO::create_row() { FO *FOtmp; FOtmp = new FO; FOtmp->set_pkid(0); FOtmp->set_xfont("\0"); FOtmp->set_psfontname("\0"); FOtmp->set_psfontsize("\0"); FOtmp->set_bdefont("\0"); FOtmp->next_ptr = NULL; FOtmp->prev_ptr = NULL; return FOtmp; } #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 FO::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key FOid; 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("FO")) { strncpy_null(error_table, "FO", 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 FOelt = this; #endif pr_gen_pkey(viewname,FO,FOid); #ifdef USE_STL set_pkid(FOid); #else RC::set_pkid(FOid); #endif pr_check_str (FO,FOelt,xfont,50); pr_check_str (FO,FOelt,psfontname,50); pr_check_str (FO,FOelt,psfontsize,2); pr_check_str (FO,FOelt,bdefont,15); 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 FO::link_row() { hcg_key FOid; #ifndef USE_STL insert_element(FO); #else FOtab->insertRow(this); #endif /* USE_STL */ } /******************************************************************************/ /* This routine is used to parse a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void FO::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(xfont,hcg_t,50,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(psfontname,hcg_t,50,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(psfontsize,hcg_t,2,0); mystrcpy(bdefont,buffer+idx,15,0); } /******************************************************************************/ /* 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 FO::delete_row (list::iterator rowIter) #else void FO::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key FOid; char log_text[BUFSIZE]; logwait(); #ifdef DEBUG #ifdef USE_STL FOid = get_pkid(); #else FOid = RC::get_pkid(); #endif decode(temp_key, &FOid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = FOtab->removeRow(rowIter); delete this; #else del_row(FO); #endif /* The following is to support logging */ #ifdef USE_STL FOid = get_pkid(); #else FOid = RC::get_pkid(); #endif decode(temp_key, &FOid); 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 FOtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void FO::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,FO) { #ifndef USE_STL FOcurr->dump_row(viewname,file_name,new_version,modestr); #else (*FOcurr)->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 FO::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key FOid; 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 FOid = get_pkid(); #else FOid = RC::get_pkid(); #endif hcg_update_version(&FOid,FO_idx,new_version); decode(outkey[0], &FOid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-50s %-50s %-2s %-15s\n" , outkey[0], xfont, psfontname, psfontsize, bdefont)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL /********************************************************************************/ /* Default constructor for FO. */ /********************************************************************************/ FO::FO () { set_pkid(0); /* initialize */ set_xfont("\0"); set_psfontname("\0"); set_psfontsize("\0"); set_bdefont("\0"); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for FO. */ /********************************************************************************/ FO::~FO () { /* 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 FO::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key FOid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("FO"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL FOid = get_pkid(); #else FOid = RC::get_pkid(); #endif hcg_update_version(&FOid,FO_idx,0); decode(outkey[0], &FOid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-50s %-50s %-2s %-15s\n" , outkey[0], xfont, psfontname, psfontsize, bdefont)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void FO::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); mystrcpy(xfont, hcg_t, 50, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(psfontname, hcg_t, 50, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(psfontsize, hcg_t, 2, 0); mystrcpy(bdefont, theRest+idx, 15, 0); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void FO::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 FO::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 FO::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"FOid")==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 FO::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"xfont")==0) strcpy(xfont,newval); else if (strcmp(fieldname,"psfontname")==0) strcpy(psfontname,newval); else if (strcmp(fieldname,"psfontsize")==0) strcpy(psfontsize,newval); else if (strcmp(fieldname,"bdefont")==0) strcpy(bdefont,newval); }