1// 2// RuleMapElement.m 3// ANTLR 4// 5// Created by Alan Condit on 6/16/10. 6// [The "BSD licence"] 7// Copyright (c) 2010 Alan Condit 8// All rights reserved. 9// 10// Redistribution and use in source and binary forms, with or without 11// modification, are permitted provided that the following conditions 12// are met: 13// 1. Redistributions of source code must retain the above copyright 14// notice, this list of conditions and the following disclaimer. 15// 2. Redistributions in binary form must reproduce the above copyright 16// notice, this list of conditions and the following disclaimer in the 17// documentation and/or other materials provided with the distribution. 18// 3. The name of the author may not be used to endorse or promote products 19// derived from this software without specific prior written permission. 20// 21// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32#import "ACNumber.h" 33#import "RuleMapElement.h" 34 35 36@implementation RuleMapElement 37 38@synthesize ruleNum; 39 40+ (RuleMapElement *)newRuleMapElement 41{ 42 return [[RuleMapElement alloc] init]; 43} 44 45+ (RuleMapElement *)newRuleMapElementWithIndex:(ACNumber *)aNumber 46{ 47 return [[RuleMapElement alloc] initWithAnIndex:(ACNumber *)aNumber]; 48} 49 50+ (RuleMapElement *)newRuleMapElementWithIndex:(ACNumber *)aNumber RuleNum:(ACNumber *)aRuleNum 51{ 52 return [[RuleMapElement alloc] initWithAnIndex:aNumber RuleNum:aRuleNum]; 53} 54 55- (id) init 56{ 57 if ((self = [super init]) != nil ) { 58 index = nil; 59 ruleNum = nil; 60 } 61 return (self); 62} 63 64- (id) initWithAnIndex:(ACNumber *)aNumber 65{ 66 if ((self = [super initWithAnIndex:aNumber]) != nil ) { 67 ruleNum = nil; 68 } 69 return (self); 70} 71 72- (id) initWithAnIndex:(ACNumber *)aNumber RuleNum:(ACNumber *)aRuleNum 73{ 74 if ((self = [super initWithAnIndex:aNumber]) != nil ) { 75 [aRuleNum retain]; 76 ruleNum = aRuleNum; 77 } 78 return (self); 79} 80 81- (id) copyWithZone:(NSZone *)aZone 82{ 83 RuleMapElement *copy; 84 85 copy = [super copyWithZone:aZone]; 86 copy.ruleNum = ruleNum; 87 return( copy ); 88} 89 90- (id)getRuleNum 91{ 92 return ruleNum; 93} 94 95- (void)setRuleNum:(id)aRuleNum 96{ 97 if ( aRuleNum != ruleNum ) { 98 if ( ruleNum ) [ruleNum release]; 99 [aRuleNum retain]; 100 } 101 ruleNum = aRuleNum; 102} 103 104- (NSInteger)size 105{ 106 NSInteger aSize = 0; 107 if (ruleNum != nil) aSize++; 108 if (index != nil) aSize++; 109 return( aSize ); 110} 111 112@end 113