* GSWeb/GSWAssociation.h

replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
* GSWeb/GSWAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  respect GNUstep coding standard (curly brackets placement, etc.)
  implement -debugDescription
* GSWeb/GSWConstantValueAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  fix -debugDescription
* GSWeb/GSWKeyValueAssociation.m
  replace logTakeValue: by _logPullValue:inComponent:
  replace logSetValue: by logPushValue:inComponent:
  simplify -description
* GSWeb/GSWKeyValueAssociation.h
  remove unneedded declarations
* GSWeb/GSWConstantValueAssociation.m
  remove unneedded declarations



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@37903 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Manuel Guesdon 2014-05-22 16:49:59 +00:00
parent 97e527ebed
commit 37ad587ea1
7 changed files with 222 additions and 210 deletions

View file

@ -1,3 +1,24 @@
2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb/GSWAssociation.h
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
* GSWeb/GSWAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
respect GNUstep coding standard (curly brackets placement, etc.)
implement -debugDescription
* GSWeb/GSWConstantValueAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
fix -debugDescription
* GSWeb/GSWKeyValueAssociation.m
replace logTakeValue: by _logPullValue:inComponent:
replace logSetValue: by logPushValue:inComponent:
simplify -description
* GSWeb/GSWKeyValueAssociation.h
remove unneedded declarations
* GSWeb/GSWConstantValueAssociation.m
remove unneedded declarations
2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com> 2014-05-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb/GSWUtils.m * GSWeb/GSWUtils.m
fix rangeOfData:range: fix rangeOfData:range:

View file

@ -115,8 +115,11 @@ NEW FEATURE: negate. add a "!" in front of your key path and the result will be
inComponent:(GSWComponent*)component; inComponent:(GSWComponent*)component;
-(void)logSynchronizeParentToComponentForValue:(id)value -(void)logSynchronizeParentToComponentForValue:(id)value
inComponent:(GSWComponent*)component; inComponent:(GSWComponent*)component;
-(void)logTakeValue:(id)value;
-(void)logSetValue:(id)value; -(void)_logPullValue:(id)value
inComponent:(GSWComponent*) component;
-(void)_logPushValue:(id)value
inComponent:(GSWComponent*) component;
-(NSString*)debugDescription; -(NSString*)debugDescription;
-(void)setDebugEnabledForBinding:(NSString*)bindingName -(void)setDebugEnabledForBinding:(NSString*)bindingName

View file

@ -118,17 +118,6 @@ static Class NSStringClass = Nil;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// init
-(id)init
{
if ((self=[super init]))
{
}
_negate = NO;
return self;
}
-(void)dealloc -(void)dealloc
{ {
DESTROY(_bindingName); DESTROY(_bindingName);
@ -137,18 +126,20 @@ static Class NSStringClass = Nil;
[super dealloc]; [super dealloc];
} }
//--------------------------------------------------------------------
// YES if we negate the result before returnig it. // YES if we negate the result before returnig it.
-(BOOL)negate -(BOOL)negate
{ {
return _negate; return _negate;
} }
//--------------------------------------------------------------------
-(void) setNegate:(BOOL) yn -(void) setNegate:(BOOL) yn
{ {
_negate = yn; _negate = yn;
} }
//--------------------------------------------------------------------
- (BOOL)_hasBindingInParent:(GSWComponent*) parent - (BOOL)_hasBindingInParent:(GSWComponent*) parent
{ {
return YES; return YES;
@ -206,11 +197,13 @@ static Class NSStringClass = Nil;
return NO; return NO;
} }
//--------------------------------------------------------------------
- (BOOL) isValueSettableInComponent:(GSWComponent*) comp - (BOOL) isValueSettableInComponent:(GSWComponent*) comp
{ {
return [self isValueSettable]; return [self isValueSettable];
} }
//--------------------------------------------------------------------
- (BOOL) isValueConstantInComponent:(GSWComponent*) comp - (BOOL) isValueConstantInComponent:(GSWComponent*) comp
{ {
return [self isValueConstant]; return [self isValueConstant];
@ -219,7 +212,6 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// setValue:inComponent: // setValue:inComponent:
-(void)setValue:(id)value -(void)setValue:(id)value
inComponent:(GSWComponent*)component inComponent:(GSWComponent*)component
{ {
@ -233,58 +225,65 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// valueInComponent: // valueInComponent:
-(id)valueInComponent:(GSWComponent*)component; -(id)valueInComponent:(GSWComponent*)component;
{ {
return [self subclassResponsibility:_cmd]; return [self subclassResponsibility:_cmd];
} }
//--------------------------------------------------------------------
// added in WO5? // added in WO5?
// they call it booleanValueInComponent: // they call it booleanValueInComponent:
- (BOOL) boolValueInComponent:(GSWComponent*)component - (BOOL) boolValueInComponent:(GSWComponent*)component
{ {
id value = [self valueInComponent: component]; id value = [self valueInComponent: component];
int length = 0;
NSString * tmpStr = nil;
if (! value) { if (value==nil)
if (_negate) { {
if (_negate)
return YES; return YES;
} else
return NO; return NO;
} }
if ([value isKindOfClass: NSNumberClass]) { if ([value isKindOfClass: NSNumberClass])
if (_negate) { {
return (! [value boolValue]); if (_negate)
} return (![value boolValue]);
else
return [value boolValue]; return [value boolValue];
} }
if ([value isKindOfClass: NSStringClass]) { else if ([value isKindOfClass: NSStringClass])
length = [value length]; {
if ((length >= 2) && (length <= 5)) { NSString* tmpStr = nil;
int length = [value length];
if (length >= 2 && length <= 5)
{
tmpStr = [value lowercaseString]; tmpStr = [value lowercaseString];
if ([tmpStr isEqual:@"no"] || [tmpStr isEqual:@"false"] || [tmpStr isEqual:@"nil"] || [tmpStr isEqual:@"null"]) { if ([tmpStr isEqual:@"no"]
if (_negate) { || [tmpStr isEqual:@"false"]
|| [tmpStr isEqual:@"nil"]
|| [tmpStr isEqual:@"null"])
{
if (_negate)
return YES;
else
return NO;
}
}
if ([tmpStr isEqual:@"0"])
{
if (_negate)
return YES;
else
return NO;
}
if (_negate)
return NO;
else
return YES; return YES;
} }
if (_negate)
return NO; return NO;
} else
}
if ([tmpStr isEqual:@"0"]) {
if (_negate) {
return YES;
}
return NO;
}
if (_negate) {
return NO;
}
return YES;
}
if (_negate) {
return NO;
}
return YES; return YES;
} }
@ -473,31 +472,7 @@ static Class NSStringClass = Nil;
LoggedUnlock(associationsLock); LoggedUnlock(associationsLock);
} }
/*
//====================================================================
@implementation GSWAssociation (GSWAssociationOldFn)
//-------------------------------------------------------------------- //--------------------------------------------------------------------
// value
-(id)value
{
GSWContext* context=[[GSWApplication application] context];
[self valueInComponent:GSWContext_component(context)];
}
//--------------------------------------------------------------------
// setValue:inComponent:
//OldFn
-(void)setValue:(id)value
{
GSWContext* context=[[GSWApplication application] context];
[self setValue:(id)value
inComponent:GSWContext_component(context)];
}
@end
*/
//====================================================================
// returns the binding String as in the wod. // returns the binding String as in the wod.
// override in subclasses // override in subclasses
- (NSString*) bindingInComponent:(GSWComponent*) component - (NSString*) bindingInComponent:(GSWComponent*) component
@ -512,11 +487,9 @@ static Class NSStringClass = Nil;
return YES; return YES;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)keyPath -(NSString*)keyPath
{ {
//OK
[self subclassResponsibility:_cmd]; [self subclassResponsibility:_cmd];
return nil; return nil;
} }
@ -564,6 +537,28 @@ static Class NSStringClass = Nil;
} }
} }
//--------------------------------------------------------------------
-(void)_logPullValue:(id)value
inComponent:(GSWComponent*) component
{
[GSWApp logTakeValueForDeclarationNamed:_declarationName
type:_declarationType
bindingNamed:_bindingName
associationDescription:[self debugDescription]
value:value];
}
//--------------------------------------------------------------------
-(void)_logPushValue:(id)value
inComponent:(GSWComponent*) component
{
[GSWApp logSetValueForDeclarationNamed:_declarationName
type:_declarationType
bindingNamed:_bindingName
associationDescription:[self debugDescription]
value:value];
}
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(void)logTakeValue:(id)value -(void)logTakeValue:(id)value
{ {
@ -635,9 +630,7 @@ static Class NSStringClass = Nil;
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)debugDescription -(NSString*)debugDescription
{ {
//OK return NSStringFromClass([self class]);
[self subclassResponsibility:_cmd];
return nil;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -659,9 +652,7 @@ static Class NSStringClass = Nil;
static id EONullNull=nil; static id EONullNull=nil;
//TODO MultiThread Protection ? //TODO MultiThread Protection ?
if (!EONullNull) if (!EONullNull)
{
EONullNull=[NSNull null]; EONullNull=[NSNull null];
}
id retValue=nil; id retValue=nil;
if (keyPath && object && object!=EONullNull) if (keyPath && object && object!=EONullNull)
@ -697,17 +688,20 @@ static Class NSStringClass = Nil;
inComponent:(GSWComponent*)object inComponent:(GSWComponent*)object
forKeyPath:(NSString*)keyPath forKeyPath:(NSString*)keyPath
{ {
id tmpObject = nil; id tmpObject = nil;
NSString *tmpKey = nil; NSString *tmpKey = nil;
if (keyPath) { if (keyPath)
{
NSRange r = [keyPath rangeOfString: @"."]; NSRange r = [keyPath rangeOfString: @"."];
if (r.length == 0) { if (r.length == 0)
{
tmpObject = object; tmpObject = object;
tmpKey = keyPath; tmpKey = keyPath;
} else { }
else
{
NSString *key = [keyPath substringToIndex: r.location]; NSString *key = [keyPath substringToIndex: r.location];
tmpObject = [object valueForKey: key]; tmpObject = [object valueForKey: key];
tmpKey = [keyPath substringFromIndex: NSMaxRange(r)]; tmpKey = [keyPath substringFromIndex: NSMaxRange(r)];
@ -716,7 +710,9 @@ static Class NSStringClass = Nil;
{ {
NSError * outError = nil; NSError * outError = nil;
BOOL ok = [tmpObject validateValue:&value forKey:tmpKey error:&outError]; BOOL ok = [tmpObject validateValue:&value
forKey:tmpKey
error:&outError];
if (ok == NO) if (ok == NO)
{ {
NSException * exception=nil; NSException * exception=nil;
@ -728,7 +724,9 @@ static Class NSStringClass = Nil;
keyPath, @"EOValidatedPropertyUserInfoKey", keyPath, @"EOValidatedPropertyUserInfoKey",
nil]; nil];
if ((outError) && ([outError userInfo])) { if (outError
&& [outError userInfo])
{
errorStr = [[outError userInfo] valueForKey:NSLocalizedDescriptionKey]; errorStr = [[outError userInfo] valueForKey:NSLocalizedDescriptionKey];
} }
@ -739,9 +737,10 @@ static Class NSStringClass = Nil;
[object validationFailedWithException:exception [object validationFailedWithException:exception
value:value value:value
keyPath:keyPath]; keyPath:keyPath];
} else { }
else
{
// all fine, set the value // all fine, set the value
[tmpObject setValue:value [tmpObject setValue:value
forKey:tmpKey]; forKey:tmpKey];
} }

View file

@ -39,12 +39,5 @@
}; };
-(id)initWithValue:(id)aValue; -(id)initWithValue:(id)aValue;
-(NSString*)debugDescription;
-(BOOL)isValueConstant;
-(BOOL)isValueSettable;
-(id)valueInComponent:(GSWComponent*)component;
-(void)setValue:(id)aValue
inComponent:(GSWComponent*)component;
@end @end
#endif //GSWConstantValueAssociation #endif //GSWConstantValueAssociation

View file

@ -65,12 +65,7 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)debugDescription -(NSString*)debugDescription
{ {
NSString* dscr=[NSString stringWithFormat:@"<%s %p - value=%@ (class: %@)>", return NSStringFromClass([_value class]);
object_getClassName(self),
(void*)self,
_value,
[_value class]];
return dscr;
}; };
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -88,7 +83,11 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(id)valueInComponent:(GSWComponent*)object -(id)valueInComponent:(GSWComponent*)object
{ {
[self logTakeValue:_value]; if (_debugEnabled)
{
[self _logPullValue:_value
inComponent:object];
}
return _value; return _value;
}; };

View file

@ -40,15 +40,7 @@
} }
-(id)initWithKeyPath:(NSString*)aKeyPath; -(id)initWithKeyPath:(NSString*)aKeyPath;
-(id)valueInComponent:(GSWComponent*)component;
-(void)setValue:(id)aValue
inComponent:(GSWComponent*)component;
-(BOOL)isValueConstant;
-(BOOL)isValueSettable;
-(NSString*)keyPath; -(NSString*)keyPath;
-(NSString*)debugDescription;
@end @end
#endif //_GSWKeyValueAssociation_h__ #endif //_GSWKeyValueAssociation_h__

View file

@ -75,7 +75,11 @@ RCS_ID("$Id$")
// but we need: // but we need:
retValue=[GSWAssociation valueInComponent: component retValue=[GSWAssociation valueInComponent: component
forKeyPath:_keyPath]; forKeyPath:_keyPath];
if (_debugEnabled)
{
[self _logPullValue:retValue
inComponent:component];
}
return retValue; return retValue;
}; };
@ -92,24 +96,37 @@ RCS_ID("$Id$")
aValue,NSStringFromClass([component class]),self]; aValue,NSStringFromClass([component class]),self];
} }
NS_DURING { NS_DURING
{
[component validateTakeValue:aValue [component validateTakeValue:aValue
forKeyPath:_keyPath]; forKeyPath:_keyPath];
} NS_HANDLER { }
NS_HANDLER
{
ex = localException; ex = localException;
} NS_ENDHANDLER; }
NS_ENDHANDLER;
if (ex != nil) { if (_debugEnabled)
{
[self _logPushValue:aValue
inComponent:component];
}
if (ex != nil)
{
[component validationFailedWithException:ex [component validationFailedWithException:ex
value:aValue value:aValue
keyPath:_keyPath]; keyPath:_keyPath];
} }
} }
- (void) _setValueNoValidation:(id) aValue inComponent:(GSWComponent*) component - (void) _setValueNoValidation:(id) aValue
inComponent:(GSWComponent*) component
{ {
if (_isValueSettable) { if (_isValueSettable)
[component setValue:aValue forKeyPath:_keyPath]; {
[component setValue:aValue
forKeyPath:_keyPath];
} }
} }
@ -128,30 +145,18 @@ RCS_ID("$Id$")
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)description -(NSString*)description
{ {
NSString* dscr=nil; return [NSString stringWithFormat:@"<%s %p - keyPath=%@>",
dscr=[NSString stringWithFormat:@"<%s %p -",
object_getClassName(self), object_getClassName(self),
(void*)self]; (void*)self,
dscr=[dscr stringByAppendingFormat:@" keyPath=%@>",
_keyPath]; _keyPath];
return dscr;
}; };
//-------------------------------------------------------------------- //--------------------------------------------------------------------
-(NSString*)keyPath -(NSString*)keyPath
{ {
return _keyPath; return _keyPath;
}; };
//--------------------------------------------------------------------
-(NSString*)debugDescription
{
[self notImplemented: _cmd]; //TODOFN
return nil;
};
@end @end