Welcome to mirror list, hosted at ThFree Co, Russian Federation.

blocks.c « objects « src - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cff37d177dd1d7b265d481442a3105b99e071a07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * \file   blocks.h
 * \brief  A list of configuration blocks.
 * \author Copyright (c) 2002-2008 Jason Perkins and the Premake project
 */

#include <assert.h>
#include <stdlib.h>
#include "premake.h"
#include "blocks.h"
#include "base/array.h"


DEFINE_CLASS(Blocks)
{
	Array blocks;
};


/**
 * Create and initialize a new list of configuration blocks.
 * \returns A new configuration block list.
 */
Blocks blocks_create(void)
{
	Blocks blks = ALLOC_CLASS(Blocks);
	blks->blocks = array_create();
	return blks;
}


/**
 * Destroy a configuration block list and release the associated memory.
 * \param   blks   The configuration block list to destroy.
 */
void blocks_destroy(Blocks blks)
{
	int i, n;
	assert(blks);
	n = blocks_size(blks);
	for (i = 0; i < n; ++i)
	{
		Block blk = blocks_item(blks, i);
		block_destroy(blk);
	}
	array_destroy(blks->blocks);
	free(blks);
}


/**
 * Add a new block to a list.
 * \param   blks      The configuration block list.
 * \param   blk       The block to add to the list.
 */
void blocks_add(Blocks blks, Block blk)
{
	assert(blks);
	assert(blk);
	array_add(blks->blocks, blk);
}


/**
 * Retrieve an item from the list of blocks.
 * \param   blks      The configuration block list.
 * \param   index     The index of the item to retrieve.
 * \returns The block at the given index.
 */
Block blocks_item(Blocks blks, int index)
{
	assert(blks);
	return (Block)array_item(blks->blocks, index);
}


/**
 * Returns the number of blocks in the list.
 * \param   blks      The configuration block list.
 */
int blocks_size(Blocks blks)
{
	return array_size(blks->blocks);
}