void DBObjTableField::Swap() { DBByteOrderSwapHalfWord(&StartByteVAR); DBByteOrderSwapHalfWord(&LengthVAR); switch (TypeVAR) { case DBTableFieldInt: switch (LengthVAR) { case 2: ShortPROP.Swap(); break; case 4: IntPROP.Swap(); break; } break; case DBTableFieldFloat: switch (LengthVAR) { case 4: Float4PROP.Swap(); break; case 8: FloatPROP.Swap(); break; } break; case DBTableFieldDate: DatePROP.Swap(); break; case DBTableFieldTableRec: case DBTableFieldDataRec: DBByteOrderSwapWord(&RecordPROP); break; } }
void DBDataHeader::Swap() { DBByteOrderSwapHalfWord(&ByteOrderVAR); DBByteOrderSwapHalfWord(&TypeVAR); DBByteOrderSwapHalfWord(&MajorVAR); DBByteOrderSwapHalfWord(&MinorVAR); DBByteOrderSwapHalfWord(&ProjectionVAR); DBByteOrderSwapHalfWord(&PrecisionVAR); DBByteOrderSwapHalfWord(&SpatialUnitVAR); DBByteOrderSwapHalfWord(&ValueUnitVAR); DBByteOrderSwapHalfWord(&MaxScaleVAR); DBByteOrderSwapHalfWord(&MinScaleVAR); DBByteOrderSwapWord(&DummyVAR); ExtentVAR.Swap(); LastModVAR.Swap(); }
int DBObjTable::Read(FILE *file, int swap) { DBInt id; DBDate date; DBCoordinate coord; DBRegion region; DBPosition pos; DBUShort row, col; DBObjRecord *record; DBObjTableField *field; if (DBObjectLIST<DBObjRecord>::Read(file, swap) != DBSuccess) return (DBFault); if (FieldPTR->Read(file, swap) != DBSuccess) return (DBFault); for (id = 0; id < FieldPTR->ItemNum(); ++id) if (FieldPTR->ReadItem(file, id, swap) == DBFault) return (DBFault); RecordLengthVAR = 0; for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next()) RecordLengthVAR = RecordLengthVAR > field->StartByte() + field->Length() ? RecordLengthVAR : field->StartByte() + field->Length(); for (id = 0; id < ItemNum(); ++id) { if (ReadItem(file, id, swap) == DBFault) return (DBFault); record = Item(id); if (swap == false) continue; for (field = FieldPTR->First(); field != (DBObjTableField *) NULL; field = FieldPTR->Next()) switch (field->Type()) { case DBTableFieldInt: case DBTableFieldFloat: case DBTableFieldTableRec: case DBTableFieldDataRec: switch (field->Length()) { case 2: DBByteOrderSwapHalfWord((char *) record->Data() + field->StartByte()); break; case 4: DBByteOrderSwapWord((char *) record->Data() + field->StartByte()); break; case 8: DBByteOrderSwapLongWord((char *) record->Data() + field->StartByte()); break; } break; case DBTableFieldDate: date = field->Date(record); date.Swap(); field->Date(record, date); break; case DBTableFieldCoord: coord = field->Coordinate(record); coord.Swap(); field->Coordinate(record, coord); break; case DBTableFieldRegion: region = field->Region(record); region.Swap(); field->Region(record, region); break; case DBTableFieldPosition: pos = field->Position(record); switch (field->Length()) { case sizeof(DBPosition): pos.Swap(); break; default: row = pos.Row; col = pos.Col; DBByteOrderSwapHalfWord(&row); DBByteOrderSwapHalfWord(&col); pos.Row = row; pos.Col = col; break; } field->Position(record, pos); break; default: break; } } if (MethodPTR->Read(file, swap) != DBSuccess) return (DBFault); for (id = 0; id < MethodPTR->ItemNum(); ++id) if (MethodPTR->ReadItem(file, id, swap) == DBFault) return (DBFault); return (DBSuccess); }