Before we can use tables, we need to make them. Tables are constructed using two classes:
Table
classField
classThe Table
class represents the data table at large.
Tables consists of columns or fields.
This is what the Field
class represents.
DOP-C is designed for us to declare tables and fields separately,
so that we may reference fields directly (as opposed to calling a std::map
for example).
In principle, tables and fields can be declared anywhere. In practice however, the author advises the pattern shown in the following example.
class Data
{
public:
class Proto
{
public:
dopc::Table table;
dopc::Field<int> a;
dopc::Field<float> b;
Proto()
{
a.init(&table);
b.init(&table);
}
};
inline static Proto main;
};
Here we define a prototype data table Data::Proto
.
The master class, Data::Proto::table
holds the fields Data::Proto::a
and Data::Proto::b
.
The relationship between the table and the field is conveyed in the field constructor.
A single instance of the prototype is declared at Data::main
.
Although this is maybe a bit clunky, this pattern seems to be the one which works best will all the features of DOP-C. The prototype class is useful when creating multiverses or sorting according to row-based rules. The main table isi the one we actually use to store our data.
Once you learn the ins and outs of DOP-C, you might be comfortable using other patterns. But for now I advise you stick to the one given above.