We've seen already a simple example of how to use Eet Data Descriptors to handle our structures, but it didn't show how this works when you have structures inside other structures.
Now, there's a very simple case of this, for when you have inline structs to keep your big structure more organized, you don't need anything else besides what this simple example does. Just use something like some_struct.sub_struct.member
when adding the member to the descriptor and it will work.
For example:
But this is not what we are here for today. When we talk about nested structures, what we really want are things like lists and hashes to be taken into consideration automatically, and all their contents saved and loaded just like ordinary integers and strings are.
And of course, Eet can do that, and considering the work it saves you as a programmer, we could say it's even easier to do than handling just integers.
Let's begin with our example then, which is not all too different from the simple one introduced earlier.
We won't ignore the headers this time to show how easy it is to use Eina data types with Eet, but we'll still skip most of the code that is not pertinent to what we want to show now, but as usual, you can get it full by following this link.
Extremely similar to our previous example. Just a new struct in there, and a pointer to a list in the one we already had. Handling a list of subtypes is easy on our program, but now we'll see what Eet needs to work with them (Hint: it's easy too).
Since we have two structures now, it's only natural that we'll need two descriptors. One for each, which will be defined exactly as before.
We create our descriptors, each for one type, and as before, we are going to use a simple macro to set their contents, to save on typing.
So far, nothing new. We have our descriptors and we know already how to save them separately. But what we want is to link them together, and even more so, we want our main type to hold a list of more than one of the new sub type. So how do we do that?
Simple enough, we tell Eet that our main descriptor will hold a list, of which each node will point to some type described by our new descriptor.
And that's all. We are closing the function now so as to not leave dangling curly braces, but there's nothing more to show in this example. Only other additions are the necessary code to free our new data, but you can see it in the full code listing.