Macros to Create InfoTables for Data Shapes
InfoTables are commonly used in the ThingWorx Edge C SDK. However, they are not simple to create and are often misunderstood. The macros for the Edge Extensions of the C SDK simplify the process of creating InfoTables while helping you understand the data structure that is being created. An InfoTable is a set of rows and columns, like a spreadsheet but governed by a Data Shape that describes what type of information must be in each column. Here are the commands used to create an InfoTable using macros:
• TW_MAKE_IT(dataShape,…) where dataShape is a twDataShape* structure as described in the preceding section, followed by n number of TW_IT_ROWS() as described next.
Using these commands, you can construct an twInfoTable as shown here:
twExt_InfoTable* it = TW_MAKE_IT(
TW_MAKE_DATASHAPE(NO_SHAPE_NAME,
TW_DS_ENTRY("a", TW_NO_DESCRIPTION ,TW_NUMBER),
TW_DS_ENTRY("b", TW_NO_DESCRIPTION ,TW_STRING),
TW_DS_ENTRY("c", TW_NO_DESCRIPTION ,TW_BOOLEAN)
),
TW_IT_ROW(TW_MAKE_NUMBER(1),TW_MAKE_BOOL(TRUE),
TW_MAKE_STRING("Hello World")),
TW_IT_ROW(TW_MAKE_NUMBER(2),TW_MAKE_BOOL(FALSE),
TW_MAKE_STRING("Hello Again, World")),
TW_IT_ROW(TW_MAKE_NUMBER(3),TW_MAKE_BOOL(TRUE),
TW_MAKE_STRING("Hello Also, World"))
);
TW_MAKE_IT() and TW_IT_ROW() use new C SDK functions, as shown below:
• For TW_MAKE_IT():
twExt_InfoTable* twExt_InfoTable_CreateInfoTableFromRows(
twDataShape * dataShape, ...);
• For TW_IT_ROW()
twExt_InfoTableRow* twExt_InfoTable_CreateRowFromEntries(
twPrimitive * firstEntry, ...);
In both cases, using the macro makes it unnecessary to provide NULL as the last argument in the list.