📄 class.cpp
字号:
size_t offsElem = nElems*sizeElem;
offs += offsElem;
if (srcElem != NULL) {
if (fd->attr & dbFieldDescriptor::OneToOneMapping) {
memcpy(dstElem, srcElem, offsElem);
} else {
dbFieldDescriptor* component = fd->components;
while (--nElems >= 0) {
offsElem =
component->storeRecordFields(dstElem, srcElem, offsElem, mode);
offsElem -= sizeElem;
dstElem += sizeElem;
srcElem += component->appSize;
}
offs += offsElem;
}
}
}
break;
case dbField::tpReference:
*(oid_t*)(dst+fd->dbsOffs) =
((dbAnyReference*)(src+fd->appOffs))->oid;
break;
case dbField::tpRectangle:
*(rectangle*)(dst+fd->dbsOffs) = *(rectangle*)(src+fd->appOffs);
break;
case dbField::tpStructure:
offs = fd->components->storeRecordFields(dst, src+fd->appOffs, offs, mode);
break;
default:
return offs;
}
} while ((fd = fd->next) != this);
return offs;
}
void dbFieldDescriptor::markUpdatedFields(byte* dst, byte* src)
{
dbFieldDescriptor* fd = this;
do {
if (fd->indexType & (HASHED|INDEXED)) {
switch (fd->appType) {
case dbField::tpBool:
if (*(bool*)(dst+fd->dbsOffs) != *(bool*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpInt1:
if (*(int1*)(dst+fd->dbsOffs) != *(int1*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpInt2:
if (*(int2*)(dst+fd->dbsOffs) != *(int2*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpInt4:
if (*(int4*)(dst+fd->dbsOffs) != *(int4*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpInt8:
if (*(db_int8*)(dst+fd->dbsOffs) != *(db_int8*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpReference:
if (*(oid_t*)(dst+fd->dbsOffs) != *(oid_t*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpRectangle:
if (*(rectangle*)(dst+fd->dbsOffs) != *(rectangle*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpReal4:
if (*(real4*)(dst+fd->dbsOffs) != *(real4*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpReal8:
if (*(real8*)(dst+fd->dbsOffs) != *(real8*)(src+fd->appOffs)) {
fd->attr |= Updated;
}
break;
case dbField::tpRawBinary:
if (memcmp(dst+fd->dbsOffs, src+fd->appOffs, fd->dbsSize) != 0) {
fd->attr |= Updated;
}
break;
case dbField::tpString:
if (strcmp((char*)dst + ((dbVarying*)(dst+fd->dbsOffs))->offs,
*(char**)(src + fd->appOffs)) != 0)
{
fd->attr |= Updated;
}
break;
#ifdef USE_STD_STRING
case dbField::tpStdString:
if (*(std::string*)(src + fd->appOffs) != (char*)(dst + ((dbVarying*)(dst+fd->dbsOffs))->offs)) {
fd->attr |= Updated;
}
break;
#endif
case dbField::tpStructure:
fd->components->markUpdatedFields(dst, src+fd->appOffs);
break;
case dbField::tpArray:
break;
default:
return;
}
}
} while ((fd = fd->next) != this);
}
size_t dbFieldDescriptor::convertRecord(byte* dst, byte* src, size_t offs)
{
dbFieldDescriptor* fd = this;
int1 i1;
int2 i2;
int4 i4;
db_int8 i8;
real4 f4;
real8 f8;
bool b;
do {
switch (fd->type) {
case dbField::tpBool:
switch (fd->oldDbsType) {
case dbField::tpBool:
b = *(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
b = *(int1*)(src + fd->oldDbsOffs) != 0;
break;
case dbField::tpInt2:
b = *(int2*)(src + fd->oldDbsOffs) != 0;
break;
case dbField::tpInt4:
b = *(int4*)(src + fd->oldDbsOffs) != 0;
break;
case dbField::tpInt8:
b = *(db_int8*)(src + fd->oldDbsOffs) != 0;
break;
case dbField::tpReal4:
b = *(real4*)(src + fd->oldDbsOffs) != 0;
break;
case dbField::tpReal8:
b = *(real8*)(src + fd->oldDbsOffs) != 0;
break;
default:
b = false;
}
*(bool*)(dst + fd->dbsOffs) = b;
break;
case dbField::tpInt1:
switch (fd->oldDbsType) {
case dbField::tpBool:
i1 = *(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
i1 = *(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
i1 = (int1)*(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
i1 = (int1)*(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
i1 = (int1)*(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
i1 = (int1)*(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
i1 = (int1)*(real8*)(src + fd->oldDbsOffs);
break;
default:
i1 = 0;
}
*(int1*)(dst + fd->dbsOffs) = i1;
break;
case dbField::tpInt2:
switch (fd->oldDbsType) {
case dbField::tpBool:
i2 = *(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
i2 = *(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
i2 = *(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
i2 = (int2)*(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
i2 = (int2)*(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
i2 = (int2)*(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
i2 = (int2)*(real8*)(src + fd->oldDbsOffs);
break;
default:
i2 = 0;
}
*(int2*)(dst + fd->dbsOffs) = i2;
break;
case dbField::tpInt4:
switch (fd->oldDbsType) {
case dbField::tpBool:
i4 = *(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
i4 = *(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
i4 = *(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
i4 = *(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
i4 = (int4)*(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
i4 = (int4)*(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
i4 = (int4)*(real8*)(src + fd->oldDbsOffs);
break;
default:
i4 = 0;
}
*(int4*)(dst + fd->dbsOffs) = i4;
break;
case dbField::tpInt8:
switch (fd->oldDbsType) {
case dbField::tpBool:
i8 = *(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
i8 = *(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
i8 = *(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
i8 = *(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
i8 = *(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
i8 = (db_int8)*(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
i8 = (db_int8)*(real8*)(src + fd->oldDbsOffs);
break;
default:
i8 = 0;
}
*(db_int8*)(dst + fd->dbsOffs) = i8;
break;
case dbField::tpReal4:
switch (fd->oldDbsType) {
case dbField::tpBool:
f4 = (real4)*(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
f4 = (real4)*(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
f4 = (real4)*(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
f4 = (real4)*(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
f4 = (real4)*(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
f4 = *(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
f4 = (real4)*(real8*)(src + fd->oldDbsOffs);
break;
default:
f4 = 0;
}
*(real4*)(dst + fd->dbsOffs) = f4;
break;
case dbField::tpReal8:
switch (fd->oldDbsType) {
case dbField::tpBool:
f8 = (real8)*(bool*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt1:
f8 = (real8)*(int1*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt2:
f8 = (real8)*(int2*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt4:
f8 = (real8)*(int4*)(src + fd->oldDbsOffs);
break;
case dbField::tpInt8:
f8 = (real8)*(db_int8*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal4:
f8 = *(real4*)(src + fd->oldDbsOffs);
break;
case dbField::tpReal8:
f8 = *(real8*)(src + fd->oldDbsOffs);
break;
default:
f8 = 0;
}
*(real8*)(dst + fd->dbsOffs) = f8;
break;
case dbField::tpRawBinary:
if (fd->oldDbsType == dbField::tpRawBinary) {
memcpy(dst + fd->dbsOffs, src + fd->oldDbsOffs,
size_t(fd->oldDbsSize) < fd->dbsSize
? size_t(fd->oldDbsSize) : fd->dbsSize);
}
break;
case dbField::tpString:
if (fd->oldDbsType == dbField::tpUnknown) {
((dbVarying*)(dst + fd->dbsOffs))->size = 1;
((dbVarying*)(dst + fd->dbsOffs))->offs = offs;
*(char*)(dst + offs++) = '\0';
} else {
size_t len =
((dbVarying*)(src + fd->oldDbsOffs))->size;
((dbVarying*)(dst + fd->dbsOffs))->size = len;
((dbVarying*)(dst + fd->dbsOffs))->offs = offs;
memcpy(dst + offs,
src + ((dbVarying*)(src+fd->oldDbsOffs))->offs, len);
offs += len;
}
break;
case dbField::tpArray:
if (fd->oldDbsType == dbField::tpUnknown) {
((dbVarying*)(dst + fd->dbsOffs))->size = 0;
((dbVarying*)(dst + fd->dbsOffs))->offs = 0;
} else {
int len = ((dbVarying*)(src+fd->oldDbsOffs))->size;
byte* srcElem = src + ((dbVarying*)(src+fd->oldDbsOffs))->offs;
((dbVarying*)(dst + fd->dbsOffs))->size = len;
offs = DOALIGN(offs, fd->components->alignment);
byte* dstElem = dst+offs;
((dbVarying*)(dst+fd->dbsOffs))->offs = offs;
size_t offsElem = len*fd->components->dbsSize;
offs += offsElem;
while (--len >= 0) {
offsElem = fd->components->convertRecord(dstElem, srcElem,
offsElem);
offsElem -= fd->components->dbsSize;
dstElem += fd->components->dbsSize;
srcElem += fd->components->oldDbsSize;
}
offs += offsElem;
}
break;
case dbField::tpStructure:
offs = fd->components->convertRecord(dst, src, offs);
break;
case dbField::tpReference:
if (fd->oldDbsType == dbField::tpUnknown) {
*(oid_t*)(dst + fd->dbsOffs) = 0;
} else {
*(oid_t*)(dst + fd->dbsOffs) = *(oid_t*)(src + fd->oldDbsOffs);
}
break;
case dbField::tpRectangle:
if (fd->oldDbsType == dbField::tpUnknown) {
memset(dst + fd->dbsOffs, 0, sizeof(rectangle));
} else {
*(rectangle*)(dst + fd->dbsOffs) = *(rectangle*)(src + fd->oldDbsOffs);
}
break;
default:
return offs;
}
} while ((fd = fd->next) != this);
return offs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -