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 14 CfaRuleSet::CfaRuleSet() 15 : 16 fRegisterRules(NULL), 17 fRegisterCount(0) 18 { 19 } 20 21 22 CfaRuleSet::~CfaRuleSet() 23 { 24 delete[] fRegisterRules; 25 } 26 27 28 status_t 29 CfaRuleSet::Init(uint32 registerCount) 30 { 31 fRegisterRules = new(std::nothrow) CfaRule[registerCount]; 32 if (fRegisterRules == NULL) 33 return B_NO_MEMORY; 34 35 fRegisterCount = registerCount; 36 37 return B_OK; 38 } 39 40 41 CfaRuleSet* 42 CfaRuleSet::Clone() const 43 { 44 CfaRuleSet* other = new(std::nothrow) CfaRuleSet; 45 if (other == NULL) 46 return NULL; 47 48 if (other->Init(fRegisterCount) != B_OK) { 49 delete other; 50 return NULL; 51 } 52 53 other->fCfaCfaRule = fCfaCfaRule; 54 memcpy(other->fRegisterRules, fRegisterRules, 55 sizeof(CfaRule) * fRegisterCount); 56 57 return other; 58 } 59 60 61 CfaRule* 62 CfaRuleSet::RegisterRule(uint32 index) const 63 { 64 return index < fRegisterCount ? fRegisterRules + index : NULL; 65 } 66