I bind a UUID value from a SQL SERVER colomn (via Qt Sql module) into a QUuid object.
After that I have to assign it into a in-house uuid object by using a assign function which take a char* as parameter.
QUuid expose several char* as public members, so I have to built a char * of 16 bytes with the several char * QUuid’s members.
namely, copy :
char buff0;
char buff1;
char buff2[2];
char buff3[4];
char buff4[8];
inside
char final[16];
I have used memcpy to do this task like that :
int accu = 0;
memcpy(final, &buff0, sizeof(buff0));
accu += sizeof(buff1);
memcpy(final+accu, &buff1, sizeof(buff1));
accu += sizeof(buff2);
memcpy(final+accu, buff2, sizeof(buff2));
accu += sizeof(buff3);
memcpy(final+accu, buff3, sizeof(buff3));
accu += sizeof(buff4);
memcpy(final+accu, buff4, sizeof(buff4));
but I find this manner of doing not really readable and maintanable.
I’m looking for a more elegant manner to do this task. By elegant I mean with less line of codes and/or less arithmetics.
Here’s a C++11 STL version.