I'm just looking for someone to sanity check my thought process here...

I've been tasked with having my application read in structs out of header files 
to
create data structures in memory that can be populated by the user. Those 
structures
which then can later be written out/displayed in a variety of ways: a packed 
binary 
format whose footprint would match the packed version of that struct as if it 
were 
compiled, displayed in the UI in human-readable values, written/read to/from 
XML 
document, etc.

The struct in question contains a combination of variables, 1D arrays, and 2D 
arrays, 
all primitive data types. The types of each of those are any combination of 
signed/unsigned,
char/short. The sizes of all arrays are variable. The number of variables, 1D 
arrays, 
and 2D arrays is also variable between different header files. I've included a 
couple of 
examples below, both of which are perfectly valid for our use case.

Example 1: three 2D arrays, two 1D arrays, three variables
typedef struct _myStruct {
  // 2D arrays
  unsigned short A[16][32];               
  unsigned short B[8][12];          
  unsigned char  C[16][16];      
         
  // 1D array
  unsigned short D[10];
  signed char E[8];
  
  // variables
  signed char    F;               
  unsigned char  G;          
  unsigned short H;         
} myStruct;

Example 2: two 2D arrays, zero 1D arrays, four variables
typedef struct _ myStruct {
  // 2D arrays
  unsigned char  J[20][4];               
  unsigned short K[12][24];    

  // 1D arrays

  // variables           
  signed char L;               
  unsigned char  M;             
  unsigned char  N;             
  unsigned char  O;               
} myStruct;

So when I parse these structs in, I need to keep track whether each entry was 
signed or 
unsigned, and whether it's type is char or short. My plan at the moment is to 
create a 
container class based on QVectors of QVariants that looks roughly like the 
following:

class myStructContainer {
private:
  QVector<QVariant> mVariables;
  QVector<QVector<QVariant> > m1DArrays;
  QVector<QVector<QVector<QVariant> > > m2DArrays;
};

And then use QVariant::type() when accessing them for writing/display to know 
what 
primitive data type each of those things contain.

Am I missing a better approach to this?
Sean


This message has been scanned for malware by Forcepoint. www.forcepoint.com
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to