1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <string.h>
8
9#include <new>
10
11#include "CfaRuleSet.h"
12
13
14CfaRuleSet::CfaRuleSet()
15	:
16	fRegisterRules(NULL),
17	fRegisterCount(0)
18{
19}
20
21
22status_t
23CfaRuleSet::Init(uint32 registerCount)
24{
25	fRegisterRules = new(std::nothrow) CfaRule[registerCount];
26	if (fRegisterRules == NULL)
27		return B_NO_MEMORY;
28
29	fRegisterCount = registerCount;
30
31	return B_OK;
32}
33
34
35CfaRuleSet*
36CfaRuleSet::Clone() const
37{
38	CfaRuleSet* other = new(std::nothrow) CfaRuleSet;
39	if (other == NULL)
40		return NULL;
41
42	if (other->Init(fRegisterCount) != B_OK) {
43		delete other;
44		return NULL;
45	}
46
47	other->fCfaCfaRule = fCfaCfaRule;
48	memcpy(other->fRegisterRules, fRegisterRules,
49		sizeof(CfaRule) * fRegisterCount);
50
51	return other;
52}
53
54
55CfaRule*
56CfaRuleSet::RegisterRule(uint32 index) const
57{
58	return index < fRegisterCount ? fRegisterRules + index : NULL;
59}
60