4 Copyright (C) 1996 Free Software Foundation, Inc.
6 Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
7 Helge Hess <helge.hess@mdlink.de>
11 This file is part of the GNUstep Database Library.
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Library General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Library General Public License for more details.
23 You should have received a copy of the GNU Library General Public
24 License along with this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 // $Id: EOQualifierScanner.m 1 2004-08-20 10:38:46Z znek $
31 #include "EOQualifierScanner.h"
32 #include "EOFExceptions.h"
34 #include "EOSQLQualifier.h"
35 #include <EOControl/EONull.h>
37 #if LIB_FOUNDATION_LIBRARY
38 # import <extensions/DefaultScannerHandler.h>
39 # import <extensions/PrintfFormatScanner.h>
41 # import "DefaultScannerHandler.h"
42 # import "PrintfFormatScanner.h"
45 @implementation EOQualifierScannerHandler
50 specHandler['d'] = [self methodForSelector:@selector(convertInt:scanner:)];
52 = [self methodForSelector:@selector(convertFloat:scanner:)];
54 = [self methodForSelector:@selector(convertCString:scanner:)];
56 = [self methodForSelector:@selector(convertProperty:scanner:)];
58 = [self methodForSelector:@selector(convertObject:scanner:)];
62 - (void)setEntity:(EOEntity *)_entity
64 ASSIGN(self->entity, _entity);
68 RELEASE(self->entity);
74 - (NSString *)convertInt:(va_list *)pInt scanner:(FormatScanner*)scanner {
76 sprintf(buffer, [scanner currentSpecifier], va_arg(*pInt, int));
77 return [NSString stringWithCString:buffer];
80 - (NSString*)convertFloat:(va_list *)pFloat scanner:(FormatScanner*)scanner {
82 sprintf(buffer, [scanner currentSpecifier], va_arg(*pFloat, double));
83 return [NSString stringWithCString:buffer];
86 - (NSString*)convertCString:(va_list *)pString scanner:(FormatScanner*)scanner {
88 string = va_arg(*pString, char*);
89 return string ? [NSString stringWithCString:string] : @"";
92 - (NSString*)convertProperty:(va_list*)pString scanner:(FormatScanner*)scanner {
93 NSString *propertyName;
96 propertyName = va_arg(*pString, id);
97 property = [entity propertyNamed:propertyName];
100 [[[InvalidPropertyException alloc]
101 initWithName:propertyName entity:entity] raise];
106 - (NSString *)convertObject:(va_list *)pId scanner:scanner {
107 id object = va_arg(*pId, id);
108 if (object == nil) object = [NSNull null];
109 return [object expressionValueForContext:nil];
112 @end /* EOQualifierScannerHandler */
114 @implementation EOQualifierEnumScannerHandler
119 specHandler['d'] = [self methodForSelector:@selector(convertInt:scanner:)];
121 = [self methodForSelector:@selector(convertFloat:scanner:)];
123 = [self methodForSelector:@selector(convertCString:scanner:)];
125 = [self methodForSelector:@selector(convertProperty:scanner:)];
127 = [self methodForSelector:@selector(convertObject:scanner:)];
131 - (void)setEntity:(EOEntity *)_entity {
132 ASSIGN(self->entity, _entity);
136 RELEASE(self->entity);
140 - (NSString *)convertInt:(NSEnumerator **)pInt scanner:(FormatScanner*)scanner {
142 sprintf(buffer, [scanner currentSpecifier], [[*pInt nextObject] intValue]);
143 return [NSString stringWithCString:buffer];
146 - (NSString *)convertFloat:(NSEnumerator **)pFloat
147 scanner:(FormatScanner *)scanner
150 sprintf(buffer, [scanner currentSpecifier],
151 [[*pFloat nextObject] doubleValue]);
152 return [NSString stringWithCString:buffer];
155 - (NSString *)convertCString:(NSEnumerator **)pString
156 scanner:(FormatScanner *)scanner
160 if ((str = [*pString nextObject]) == nil)
162 else if ([str isKindOfClass:[NSString class]])
164 else if ([str respondsToSelector:@selector(stringValue)])
165 str = [str stringValue];
167 str = [str description];
169 return (str == nil) ? @"" : str;
172 - (NSString *)convertProperty:(NSEnumerator **)pString
173 scanner:(FormatScanner *)scanner
175 NSString *propertyName;
178 propertyName = [*pString nextObject];
179 property = [entity propertyNamed:propertyName];
181 if(property == nil) {
182 [[[InvalidPropertyException alloc]
183 initWithName:propertyName entity:entity] raise];
188 - (NSString *)convertObject:(NSEnumerator **)pId scanner:(id)scanner {
190 object = [*pId nextObject];
191 return [object expressionValueForContext:nil];
194 @end /* EOQualifierEnumScannerHandler */