ftp.nice.ch/peanuts/GeneralData/Documents/multimedia/hypersense/ExplodingMenusXModule.tar.gz#/ExplodingMenusXModule/XModule/Value.h

This is Value.h in view mode; [Download] [Up]

/*  ----------------------------------------------------------------------
    $Id: Value.h,v 1.5 1993/10/01 09:56:22 doug Exp $
    
    Description:
	Value describes a protocol for storing and retrieving values, and for
    representing HyperSense objects.
    
    	    --- When a Value represents a HyperSense object ---
    When a Value object represents a HyperSense object, you can't store into it
    (with any of the set... methods), unless the object it represents is a
    Field.  Requesting the stringVal will return the LONG ID of the object that
    the Value represents (again, unless it is a Field -- in this case you will
    get the Field contents).
    
    You can determine whether a Value object may be stored into by calling the
    isContainer method.
    
    	    --- When a Value is a Container ---
    When a Value object is a "container" that can store some value, you can set
    its value freely using any of the set... methods.  You can then request its
    value in another format, and the conversion will be done for you.
    
    For example, if you call [val setPoint:123.0 :342.0], then [val stringVal]
    will return the string "123,342" (the exact formatting of numbers depends
    on the current setting of the global numberFormat property).  Similarly,
    if you first store a string, such as [val setString:"20,50"], then calling
    [val getPointVal:&myPoint] will set myPoint to the value {20.0, 50.0}.
    
    Other conversions are also done, including converting between strings and
    numbers, and between strings and colors.
    
    Several methods are available to determine if the current content of a
    Value object is valid as a particular type.  These may be called before
    asking for the value in a particular format to prevent warnings from
    appearing.
    
    In addition, there are two "Chunk" methods which can be used to access (or
    store into) a particular portion of the container.  These both treat the
    contents as a string (converting automatically if necessary).
    
    ----------------------------------------------------------------------------
*/

#import <objc/Object.h>
#import <appkit/color.h>
#import <dpsclient/event.h>	// for NXCoord, NXPoint
#import <objc/hashtable.h>

// special ordinal values for accessing chunks
#define	CHUNK_LAST	(-1)
#define	CHUNK_MIDDLE	(-2)
#define	CHUNK_ANY	(-3)
#define	CHUNK_NONE	(0)
#define	CHUNK_ZERO	(-4)

#define CHUNK_BEFORE	(-1)
#define CHUNK_INTO	(0)
#define CHUNK_AFTER	(1)

@interface Value:Object
{
}

/* Methods for setting the contents of a "Container" */

- setInt:(int)num;
- setUnsigned:(unsigned)num;
- setFloat:(float)num;
- setDouble:(double)num;

- setString:(const char *)str;
	// str must be null-terminated

- setString:(const char *)str ofLength:(unsigned int)length;
	// this method is useful when str is not null-terminated, or is long
	// and its length is known

- setString:(const char *)str1 cat:(const char *)str2;
	// sets the contents to be str1 concatenated with str2

- setString:(const char *)str1 spaceCat:(const char *)str2;
	// sets the contents to be str1 concatenated with str2 with a space in
	// between

- prependString:(const char *)newstr;
	// concatenates newstr in front of the current contents

- appendString:(const char *)newstr;
	// concatenates newstr after the current contents

- setAtom:(NXAtom)atm;
	// this is more efficient than setString: when storing a unique string

- setBool:(BOOL)val;
- setColor:(const NXColor)color;
- setPoint:(NXCoord)x :(NXCoord)y;


/* Methods for accessing the contents of a "Container" */

- (int) intVal;
- (unsigned) unsignedVal;
- (float) floatVal;
- (double) doubleVal;
- (const char *) stringVal;
- (BOOL) boolVal;		// returns YES or NO
- (const char *)boolStrVal;	// returns "true" or "false"
- (NXColor)colorVal;
- getPointVal:(NXPoint *)point;

- assignValueTo:(Value *)anotherContainer;
	// assigns contents to another Value object


/* Methods for analyzing the contents of a "Container" */

- (BOOL)validAsNumber;	// can this value be accessed as a number ??
- (BOOL)validAsColor;	// can this value be accessed as a color ??
- (BOOL)validAsPoint;	// can this value be accessed as a point ??
- (BOOL)hasValue;	// has a value been assigned yet??

- (BOOL) isObject;	// is this Value a "proxy" for a HyperSense object?
- (BOOL) isContainer;	// is this Value a container that we can store into?


/* Chunk support methods */

- (char *)copyChunkFromChar:(int)c1 to:(int)c2 ofWord:(int)w1 to:(int)w2
	ofItem:(int)i1 to:(int)i2 ofLine:(int)l1 to:(int)l2;
	// This method allocates memory and copies part of the Value's
	// contents into it.
	// The caller should free the returned value when done with it.
/*
   Example:
   The following message returns a copy of the first through fourth words
   of the contents of val:
	[val copyChunkFromChar:CHUNK_NONE to:CHUNK_NONE
		ofWord:1 to:4
		ofItem:CHUNK_NONE to:CHUNK_NONE
		ofLine:CHUNK_NONE to:CHUNK_NONE]
*/

- store:(const char *)string where:(int)beforeIntoAfter
    chunkFromChar:(int)c1 to:(int)c2 ofWord:(int)w1 to:(int)w2
    ofItem:(int)i1 to:(int)i2 ofLine:(int)l1 to:(int)l2;
	// This method stores a string into the contents of a Value object, at
	// the location indicated by the chunk.  The string can replace that
	// part of the original contents (if CHUNK_INTO is used) or can be
	// inserted before or after the chunk (using CHUNK_BEFORE or
	// CHUNK_AFTER).
/*
   The following example replaces the second item of the last line of val with
   the number 123:
	[val store:"123" where:CHUNK_INTO
		chunkFromChar:CHUNK_NONE to:CHUNK_NONE
		ofWord:CHUNK_NONE to:CHUNK_NONE
		ofItem:2 to:CHUNK_NONE
		ofLine:CHUNK_LAST to:CHUNK_NONE];
*/

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.