5 // Created by Chaz McGarvey on 12/13/04.
6 // Copyright 2004 Chaz McGarvey. All rights reserved.
12 @implementation SearchData
17 if ( self = [super init
] ) {
18 [self setVariableType
:TCInt32
];
19 [self setIntegerSign
:TCSigned
];
20 [self setSearchOperator
:TCEqual
];
21 [self setValueUsed
:TCGivenValue
];
31 [_variableValue release
];
32 TCReleaseArray( _addresses
);
33 TCReleaseArray( _values
);
38 - (TCVariableType
)variableType
43 - (void)setVariableType
:(TCVariableType
)varType
45 // can't change the variable type when there has been a search
46 if ( ![self hasSearchedOnce
] ) {
47 _variableType
= varType
;
52 - (TCIntegerSign
)integerSign
57 - (void)setIntegerSign
:(TCIntegerSign
)sign
59 // can't change the integer sign when there has been a search
60 if ( ![self hasSearchedOnce
] ) {
66 - (TCSearchOperator
)searchOperator
71 - (void)setSearchOperator
:(TCSearchOperator
)op
77 - (TCSearchType
)valueUsed
79 if ( ![self hasSearchedOnce
] ) {
80 // if there is no search, then use search value no matter what
81 _value
= TCGivenValue
;
86 - (void)setValueUsed
:(TCSearchType
)value
92 - (Variable
*)searchValue
94 if ( !_variableValue
) {
95 // create a zero value if there is none
96 _variableValue
= [[Variable alloc
] init
];
98 return _variableValue
;
101 - (void)setSearchValue
:(Variable
*)value
104 [_variableValue release
];
105 _variableValue
= value
;
109 - (unsigned)numberOfResults
112 return TCArrayElementCount( _addresses
);
122 - (void)setAddresses
:(TCArray
)addresses
124 TCReleaseArray( _addresses
);
125 _addresses
= addresses
;
128 // clear the undoes and redoes if the search is cleared
133 // clear the stored values
134 [self setValues
:NULL
];
142 - (void)setValues
:(TCArray
)values
144 TCReleaseArray( _values
);
148 - (void)setValue
:(Variable
*)value atIndex
:(unsigned)index
151 if ( index
< TCArrayElementCount( _values
) ) {
152 TCArraySetElementAtIndex( _values
, index
, [value value
] );
159 return ( _values
!= NULL
);
162 - (Variable
*)variableAtIndex
:(unsigned)index
164 if ( [self hasSearchedOnce
] ) {
165 Variable
*var
= [[Variable alloc
] initWithType
:[self variableType
] integerSign
:[self integerSign
]];
166 [var setAddress
:*(TCAddress
*)TCArrayElementAtIndex( [self addresses
], index
)];
167 if ( [self valuesLoaded
] ) {
168 [var setValue
:TCArrayElementAtIndex( [self values
], index
) size
:TCArrayElementSize([self values
])];
170 return [var autorelease
];
175 - (NSString
*)stringForRow
:(unsigned)rowIndex
177 Variable
*var
= [self variableAtIndex
:rowIndex
];
180 if ( [self valuesLoaded
] ) {
181 if ( [var type
] == TCString
) {
182 return [NSString stringWithFormat
:@
"%@ = \"%@\"", [var addressString
], [var stringValue
]];
185 return [NSString stringWithFormat
:@
"%@ = %@", [var addressString
], [var stringValue
]];
189 return [var addressString
];
196 - (BOOL)hasSearchedOnce
198 return ( _addresses
!= NULL
);
212 - (void)didAddResults
231 - (BOOL)isTypeInteger
233 return _variableType
<= TCInt8
;
239 [self setAddresses
:NULL
];