1 /* Interface for NSValueTransformer for GNUStep 2 Copyright (C) 2006 Free Software Foundation, Inc. 3 4 Written Dr. H. Nikolaus Schaller 5 Created on Mon Mar 21 2005. 6 Updatesd and documented by Richard Frith-Macdonald 7 8 This file is part of the GNUstep Base Library. 9 10 This library is free software; you can redistribute it and/or 11 modify it under the terms of the GNU Lesser General Public 12 License as published by the Free Software Foundation; either 13 version 2 of the License, or (at your option) any later version. 14 15 This library is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 Lesser General Public License for more details. 19 20 You should have received a copy of the GNU Lesser General Public 21 License along with this library; if not, write to the Free 22 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 Boston, MA 02110 USA. 24 */ 25 26 #ifndef __NSValueTransformer_h_GNUSTEP_BASE_INCLUDE 27 #define __NSValueTransformer_h_GNUSTEP_BASE_INCLUDE 28 #import <GNUstepBase/GSVersionMacros.h> 29 30 #if OS_API_VERSION(MAC_OS_X_VERSION_10_3,GS_API_LATEST) && GS_API_VERSION( 10200,GS_API_LATEST) 31 32 #import <Foundation/NSObject.h> 33 34 #if defined(__cplusplus) 35 extern "C" { 36 #endif 37 38 @class NSArray; 39 @class NSString; 40 41 /** This transformer converts a YES to a NO and a NO to a YES. 42 */ 43 GS_EXPORT NSString* const NSNegateBooleanTransformerName; 44 45 /** This transformer converts a nil value to a YES.<br /> 46 * Not reversible. 47 */ 48 GS_EXPORT NSString* const NSIsNilTransformerName; 49 50 /** This transformer converts a non-nil value to a YES.<br /> 51 * Not reversible. 52 */ 53 GS_EXPORT NSString* const NSIsNotNilTransformerName; 54 55 /** This transformer converts an [NSData] instance to the object 56 * archived in it, or archives an object inot an [NSData]. 57 */ 58 GS_EXPORT NSString* const NSUnarchiveFromDataTransformerName; 59 60 /** Instances of the NSValueTransformer class are used to convert 61 * values from one representation to another. The base class is 62 * abstract and its methods must be overridden by subclasses to do 63 * the actual work. 64 */ 65 @interface NSValueTransformer : NSObject 66 67 /** <override-subclass /> 68 * Returns a flag indicating whether the transformer permits reverse 69 * transformations. 70 */ 71 + (BOOL) allowsReverseTransformation; 72 73 /** 74 * Registers transformer to handle transformations with the specified 75 * name. 76 */ 77 + (void) setValueTransformer: (NSValueTransformer *)transformer 78 forName: (NSString *)name; 79 80 /** <override-subclass /> 81 * Returns the class of the value produced by this transformer. 82 */ 83 + (Class) transformedValueClass; 84 85 /** 86 * Returns the transformer registered for the specified name, or nil 87 * if no transformer is registered for name. 88 * 89 * If no transformer is found, but the name corresponds to a valid 90 * NSValueTransformer subclass name, the receiver instantiates this subclass 91 * using -init and registers it automatically for name. 92 */ 93 + (NSValueTransformer *) valueTransformerForName: (NSString *)name; 94 95 /** 96 * Returns an array listing the names of all registered value transformers. 97 */ 98 + (NSArray *) valueTransformerNames; 99 100 /** 101 * Performs a reverse transformation on the specified value and returns the 102 * resulting object.<br /> 103 * The default implementation raises an exception if 104 * +allowsReverseTransformation returns NO, otherwise it calls 105 * -transformedValue: and returns the result. 106 */ 107 - (id) reverseTransformedValue: (id)value; 108 109 /** <override-subclass/> 110 * Subclasses should override this method to perform the actual transformation 111 * (and reverse transformation if applicable) and return the result. 112 */ 113 - (id) transformedValue: (id)value; 114 115 @end 116 117 #if defined(__cplusplus) 118 } 119 #endif 120 121 #endif /* OS_API_VERSION */ 122 123 #endif /* __NSValueTransformer_h_GNUSTEP_BASE_INCLUDE */ 124