Containers

Daabli has built-in support for loading the following generic containers: List, Dictionary, Queue, Stack, LinkedList. All the containers are described by elements enclosed within curly brackets and separated by commas.

Let's look at an example:
using System;
using System.Collections.Generic;
using Daabli;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Reader and load data from file
            var r = new DefaultReader();
            if (!r.FromFile("input.txt"))
                return;

            var names = new Queue<string>();
            var matrix = new List<List<float>>();

            // Read the data
            if (!r.Read("names", ref names) ||
                !r.Read("transform", ref matrix))
                return;

            // Display the name queue
            foreach (var name in names)
                Console.Write("{0} ", name);

            Console.WriteLine();

            // Display the transform matrix
            foreach (var row in matrix)
            {
                foreach (var element in row)
                    Console.Write("{0} ", element);

                Console.WriteLine();
            }
        }
    }
}

Given the description in input.txt:
names = { "Jimmy", "Zuko", "Ludo" };

transform =
{
    { 1, 0, 0 },
    { 0, 1, 0 },
    { 0, 0, 1 }
};

The output generated would be:
Jimmy Zuko Ludo
1 0 0
0 1 0
0 0 1

Note how nested containers (like the matrix in the above example) are also supported.

Next: Custom Types

Last edited Apr 20, 2012 at 4:52 PM by francisxavier, version 4

Comments

No comments yet.