bool Db_Base::Replicate_Fields (Db_Base *file, bool notes_flag, bool nest_flag, bool drop_flag) { int i, offset, nfield; bool convert, binary; Nest_Type nest; Field_Ptr fld; if (file == 0) return (false); if (Dbase_Format () == DEFAULT_FORMAT) { Dbase_Format (DEFAULT_FORMAT); } convert = (file->Dbase_Format () != Dbase_Format () || Num_Fields () > 0); binary = (file->Record_Format () == BINARY); offset = END_OF_RECORD; nfield = file->Num_Fields (); for (i=0; i < nfield; i++) { fld = file->Field (i); if (fld == 0) continue; if (!convert) { offset = fld->Offset (); } if (notes_flag == false) { if (fld->Name ().Equals ("NOTES")) continue; } if (drop_flag && fld->Nested ()) continue; nest = (nest_flag) ? fld->Nest () : NO_NEST; Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary, nest, offset); } return (Write_Fields ()); }
bool Db_Base::Copy_Fields (Db_Base &input, bool nest_flag) { Field_Ptr in_fld, out_fld; bool nested = input.Nested (); int lvalue; double dvalue; string svalue; Dtime tvalue; if (Dbase_Format () == DEFAULT_FORMAT) { Dbase_Format (DEFAULT_FORMAT); } int num = input.Num_Fields (); for (int i=0; i < num; i++) { in_fld = input.Field (i); if (in_fld != 0) { if (nest_flag && input.Nest_Flag ()) { if (input.Nested ()) { if (in_fld->Nest () != input.Nest ()) continue; } else { if (in_fld->Nest () == input.Nest ()) continue; } } out_fld = Field (in_fld->Name ()); if (out_fld != 0) { switch (in_fld->Type ()) { case DB_INTEGER: case DB_UNSIGNED: input.Read_Field (in_fld, (void *) &lvalue, DB_INTEGER); if (!Write_Field (out_fld, (void *) &lvalue, DB_INTEGER)) return (false); break; case DB_DOUBLE: case DB_FIXED: input.Read_Field (in_fld, (void *) &dvalue, DB_DOUBLE); if (!Write_Field (out_fld, (void *) &dvalue, DB_DOUBLE)) return (false); break; case DB_STRING: case DB_CHAR: input.Read_Field (in_fld, (void *) &svalue, DB_STRING); if (!Write_Field (out_fld, (void *) &svalue, DB_STRING)) return (false); break; case DB_TIME: input.Read_Field (in_fld, (void *) &tvalue, DB_TIME); if (!Write_Field (out_fld, (void *) &tvalue, DB_TIME)) return (false); break; } } } } input.Nested (nested); return (true); }
bool Veh_Type_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("VEHTYPE", INTEGER, 2); Add_Field ("VSUBTYPE", INTEGER, 2); Add_Field ("MAXVEL", DOUBLE, 6, 2); Add_Field ("MAXACCEL", DOUBLE, 6, 2); Add_Field ("LENGTH", DOUBLE, 6, 1); Add_Field ("CAPACITY", INTEGER, 4); } else { Add_Field ("TYPE", INTEGER, 2); Add_Field ("SUBTYPE", INTEGER, 2); Add_Field ("LENGTH", DOUBLE, 6, 1); Add_Field ("MAX_SPEED", DOUBLE, 6, 1); Add_Field ("MAX_ACCEL", DOUBLE, 6, 2); Add_Field ("MAX_DECEL", DOUBLE, 6, 2); Add_Field ("USE", STRING, 20); Add_Field ("CAPACITY", INTEGER, 4); Add_Field ("LOADING", DOUBLE, 6, 2); Add_Field ("UNLOADING", DOUBLE, 6, 2); Add_Field ("METHOD", STRING, 20); Add_Field ("MIN_DWELL", INTEGER, 4); Add_Field ("MAX_DWELL", INTEGER, 4); } return (Set_Field_Numbers ()); }
bool Parking_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("ID", INTEGER, 10); Add_Field ("NODE", INTEGER, 10); Add_Field ("LINK", INTEGER, 10); Add_Field ("OFFSET", DOUBLE, 10, 2); Add_Field ("STYLE", STRING, 16); Add_Field ("CAPACITY", INTEGER, 6); Add_Field ("GENERIC", CHAR, 1); Add_Field ("VEHICLE", STRING, FIELD_BUFFER); Add_Field ("STARTTIME", STRING, TIME_BUFFER); Add_Field ("ENDTIME", STRING, TIME_BUFFER); Add_Field ("NOTES", STRING, FIELD_BUFFER); } else { Add_Field ("PARKING", INTEGER, 10); Add_Field ("LINK", INTEGER, 10); Add_Field ("NODE", INTEGER, 10); Add_Field ("OFFSET", DOUBLE, 10, 2); Add_Field ("TYPE", STRING, 16); Add_Field ("USE", STRING, FIELD_BUFFER); Add_Field ("SPACE", INTEGER, 6); Add_Field ("START", STRING, TIME_BUFFER); Add_Field ("END", STRING, TIME_BUFFER); Add_Field ("HOURLY", INTEGER, 8); Add_Field ("DAILY", INTEGER, 8); if (Notes_Flag ()) { Add_Field ("NOTES", STRING, FIELD_BUFFER); } } return (Set_Field_Numbers ()); }
bool Location_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("ID", INTEGER, 10); Add_Field ("NODE", INTEGER, 10); Add_Field ("LINK", INTEGER, 10); Add_Field ("OFFSET", DOUBLE, 10, 2); Add_Field ("LAYER", STRING, 16); Add_Field ("EASTING", DOUBLE, 14, 2); Add_Field ("NORTHING", DOUBLE, 14, 2); Add_Field ("ELEVATION", DOUBLE, 14, 2); Add_Field ("TAZ", INTEGER, 10); Add_Field ("NOTES", STRING, FIELD_BUFFER); } else { Add_Field ("LOCATION", INTEGER, 10); Add_Field ("LINK", INTEGER, 10); Add_Field ("NODE", INTEGER, 10); Add_Field ("OFFSET", DOUBLE, 10, 1); Add_Field ("X_COORD", DOUBLE, 14, 1); Add_Field ("Y_COORD", DOUBLE, 14, 1); Add_Field ("ZONE", INTEGER, 10); if (Notes_Flag ()) { Add_Field ("NOTES", STRING, FIELD_BUFFER); } } return (Set_Field_Numbers ()); }
bool Timing_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("PLAN", INTEGER, 10); Add_Field ("PHASE", INTEGER, 2); Add_Field ("NEXTPHASES", STRING, 16); Add_Field ("GREENMIN", INTEGER, 3); Add_Field ("GREENMAX", INTEGER, 3); Add_Field ("GREENEXT", INTEGER, 3); Add_Field ("YELLOW", INTEGER, 2); Add_Field ("REDCLEAR", INTEGER, 2); Add_Field ("GROUPFIRST", INTEGER, 2); Add_Field ("NOTES", STRING, FIELD_BUFFER); //Add_Field ("GROUP", INTEGER, 2); Add_Field ("BARRIER", INTEGER, 2); } else { Add_Field ("TIMING", INTEGER, 10); Add_Field ("PHASE", INTEGER, 2); Add_Field ("NEXT_PHASE", STRING, 16); Add_Field ("MIN_GREEN", INTEGER, 3); Add_Field ("MAX_GREEN", INTEGER, 3); Add_Field ("EXT_GREEN", INTEGER, 3); Add_Field ("YELLOW", INTEGER, 2); Add_Field ("RED_CLEAR", INTEGER, 2); Add_Field ("RING", INTEGER, 2); //Add_Field ("GROUP", INTEGER, 2); Add_Field ("BARRIER", INTEGER, 2); if (Notes_Flag ()) { Add_Field ("NOTES", STRING, FIELD_BUFFER); } } return (Set_Field_Numbers ()); }
Db_Base::Db_Base (string filename, Access_Type access, Format_Type format) : Db_File (access, format) { Time_Format (NO_UNITS); Dbase_Format (format); Open (filename); }
void Location_File::Add_User_Fields (Location_File *file) { int i, offset, nfield; bool convert, binary; Field_Ptr fld; if (file == 0) return; if (Dbase_Format () == DEFAULT_FORMAT) { Dbase_Format (DEFAULT_FORMAT); } convert = (file->Dbase_Format () != Dbase_Format () || Num_Fields () > 0); binary = (file->Record_Format () == BINARY); offset = END_OF_RECORD; nfield = file->Num_Fields (); for (i=0; i < nfield; i++) { fld = file->Field (i); if (fld == 0) continue; //---- skip standard fields ---- if (fld->Name ().Equals ("LOCATION") || fld->Name ().Equals ("ID") || fld->Name ().Equals ("LINK") || fld->Name ().Equals ("OFFSET") || fld->Name ().Equals ("SETBACK") || fld->Name ().Equals ("ZONE") || fld->Name ().Equals ("TAZ") || fld->Name ().Equals ("DIR") || fld->Name ().Equals ("NODE") || fld->Name ().Equals ("X_COORD") || fld->Name ().Equals ("EASTING") || fld->Name ().Equals ("X") || fld->Name ().Equals ("Y_COORD") || fld->Name ().Equals ("NORTHING") || fld->Name ().Equals ("Y") || fld->Name ().Equals ("NOTES")) continue; if (!convert) { offset = fld->Offset (); } Add_Field (fld->Name (), fld->Type (), fld->Size (), fld->Units (), binary, NO_NEST, offset); } Write_Fields (); Write_Header (); }
bool Coordinator_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("ID", INTEGER, 10); Add_Field ("TYPE", STRING, 10); Add_Field ("ALGORITHM", STRING, 10); Add_Field ("NOTES", STRING, FIELD_BUFFER); } else { Add_Field ("ID", INTEGER, 10); if (Notes_Flag ()) { Add_Field ("NOTES", STRING, FIELD_BUFFER); } } return (Set_Field_Numbers ()); }
bool Skim_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Header_Lines (0); Add_Field ("ORG", INTEGER, 5); Add_Field ("DES", INTEGER, 5); Add_Field ("MODE", INTEGER, 2); Add_Field ("INTERVAL", INTEGER, 3); Add_Field ("TIME", DOUBLE, 16, 6); Add_Field ("COUNT", INTEGER, 10); Add_Field ("VARIANCE", DOUBLE, 16, 6); } else { Add_Field ("ORG", INTEGER, 5); Add_Field ("DES", INTEGER, 5); Add_Field ("PERIOD", INTEGER, 3); if (total_flag) { Add_Field ("TIME", INTEGER, 6); if (length_flag) { Add_Field ("LENGTH", INTEGER, 8); } } else { Add_Field ("COUNT", INTEGER, 5); Add_Field ("WALK", INTEGER, 5); if (transit_flag) { Add_Field ("WAIT", INTEGER, 5); Add_Field ("TRANSIT", INTEGER, 5); } if (drive_flag) { Add_Field ("DRIVE", INTEGER, 5); } if (other_flag) { Add_Field ("OTHER", INTEGER, 5); } if (length_flag) { Add_Field ("LENGTH", INTEGER, 8); } if (transit_flag || drive_flag) { Add_Field ("COST", INTEGER, 5); } } } return (Set_Field_Numbers ()); }
bool Fare_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("FROMZONE", STRING, 8); Add_Field ("TOZONE", STRING, 8); Add_Field ("MODE", STRING, 20); Add_Field ("COST", INTEGER, 6); } else { Add_Field ("FROM_ZONE", STRING, FIELD_BUFFER); Add_Field ("TO_ZONE", STRING, FIELD_BUFFER); Add_Field ("FROM_MODE", STRING, FIELD_BUFFER); Add_Field ("TO_MODE", STRING, FIELD_BUFFER); Add_Field ("PERIOD", STRING, FIELD_BUFFER); Add_Field ("CLASS", STRING, FIELD_BUFFER); Add_Field ("FARE", INTEGER, 6); if (Notes_Flag ()) { Add_Field ("NOTES", STRING, FIELD_BUFFER); } } return (Set_Field_Numbers ()); }
bool System_Event_File::Create_Fields (void) { if (Dbase_Format () == VERSION3) { Add_Field ("TIME", STRING, TIME_BUFFER); Add_Field ("EVENT", INTEGER, 5); Add_Field ("NODE", INTEGER, 10); Add_Field ("PLAN", INTEGER, 10); Add_Field ("PHASE", INTEGER, 10); Add_Field ("RING", INTEGER, 2); Add_Field ("GROUP", INTEGER, 2); Add_Field ("STATUS", STRING, 16); } else { Add_Field ("TIME", STRING, TIME_BUFFER); Add_Field ("EVENT", INTEGER, 5); Add_Field ("NODE", INTEGER, 10); Add_Field ("PLAN", INTEGER, 10); Add_Field ("PHASE", INTEGER, 5); Add_Field ("RING", INTEGER, 2); Add_Field ("GROUP", INTEGER, 2); Add_Field ("STATUS", STRING, 16); } return (Set_Field_Numbers ()); }
int Db_Base::Add_Field (const char *name, Field_Type type, double size, Units_Type units, bool binary, Nest_Type nest, int offset) { if (Dbase_Format () == DEFAULT_FORMAT) { Dbase_Format (DEFAULT_FORMAT); } if (field.capacity () == 0) { field.reserve (10); } if (time_format == NO_UNITS) { time_format = Static_Service::Time_Format (); if (type == DB_TIME && units == NO_UNITS) { units = time_format; } } int length, num; Field_Itr itr; switch (Dbase_Format ()) { case COMMA_DELIMITED: case SPACE_DELIMITED: case TAB_DELIMITED: case CSV_DELIMITED: case VERSION3: num = 1; length = 0; for (itr = field.begin (); itr != field.end (); itr++) { if ((nest != NESTED && !itr->Nested ()) || itr->Nest () == nest) { length += itr->Width () + 1; num++; } } if (binary) { Binary_Text_Size (type, &size); } length += (int) size; if (offset <= 0) offset = num; break; case UNFORMATED: case BINARY: case FIXED_COLUMN: case DBASE: case ARCVIEW: case SQLITE3: case TPPLUS: case TRANSCAD: default: if (offset < 0) { offset = (Dbase_Format () == DBASE || Dbase_Format () == ARCVIEW) ? 1 : 0; for (itr = field.begin (); itr != field.end (); itr++) { if ((nest != NESTED && !itr->Nested ()) || itr->Nest () == nest) { length = itr->Offset () + itr->Width (); if (offset < length) offset = length; } } } if (binary) { if (Record_Format () != BINARY) { Binary_Text_Size (type, &size); } } else if (Record_Format () == BINARY) { Text_Binary_Size (type, &size); } if (type == DB_TIME && Record_Format () == BINARY) { units = SECONDS; } length = offset + (int) size; break; } //---- convert to internal units ---- if (File_Access () == CREATE) Internal_Units (1.0, &units); Db_Field fld (name, type, offset, size, units, nest); num = (int) field.size (); field.push_back (fld); Nested (nest); if (!Record_Size (length)) return (-1); return (num); }
void Db_Base::Initialize (Access_Type access, Format_Type format) { Dbase_Format (format); Db_File::Initialize (access, format); }
Db_Base::Db_Base (Access_Type access, Format_Type format) : Db_File (access, format) { Time_Format (NO_UNITS); Dbase_Format (format); }
bool TPPlus_Matrix::Db_Open (string filename) { int i, type; char *license = 0; if (!Load_DLL ()) return (Status (NO_TPPLUS)); Set_Field_Numbers (); if (File_Access () == CREATE) { int len; unsigned char *header; Db_Field *fld_ptr; if (Num_Des () == 0 || Tables () == 0) return (false); if (Dbase_Format () == TRANPLAN) { type = TPLAN; } else { type = TPP; } TppMatMatSet (&fh, type, (char *) filename.c_str (), Num_Des (), Tables ()); header = fh->Mnames; for (i=0; i < Tables (); i++) { fld_ptr = Table_Field (i); if (fld_ptr->Decimal () == 0) { fh->Mspecs [i] = 'D'; } else { fh->Mspecs [i] = (unsigned char) fld_ptr->Decimal (); } len = (int) fld_ptr->Name ().length () + 1; memcpy (header, fld_ptr->Name ().c_str (), len); header += len; } if ((i = TppMatOpenOP (fh, (char *) File_ID ().c_str (), (char *) exe->Program (), 0, license, CUBE)) <= 0) { if (i < -1) { return (Status (TPPLUS_LICENSE)); } else { return (false); } } TppMatMatResize (&fh); } else { if (FileInquire ((char *) filename.c_str (), &fh) <= 0) return (false); if ((i = TppMatOpenIP (fh, license, CUBE)) <= 0) { if (i < -1) { return (Status (TPPLUS_LICENSE)); } else { return (false); } } Num_Org (fh->zones); Num_Des (fh->zones); Tables (fh->mats); } for (i=1; i <= Num_Des (); i++) { Add_Org (i); Add_Des (i); } fh->buffer = (void *) new char [fh->bufReq]; return (true); }