[Xfce4-commits] <glib-objc:no-foundation-dep> turn GOCValue/Number into essentially NSValue/Number replacements
Brian J. Tarricone
noreply at xfce.org
Sun Nov 22 04:02:14 CET 2009
Updating branch refs/heads/no-foundation-dep
to 90c17545bc9353440cbb17f8d1a8c5db712ad49d (commit)
from 74d6eb3048508eab2cd405d9947afcc17db1409f (commit)
commit 90c17545bc9353440cbb17f8d1a8c5db712ad49d
Author: Brian J. Tarricone <brian at tarricone.org>
Date: Wed Jul 8 16:53:08 2009 -0700
turn GOCValue/Number into essentially NSValue/Number replacements
gobject-objc/GOCNumber.h | 62 ++++++---
gobject-objc/GOCNumber.m | 336 ++++++++++++++++++++++++++++++++++++++++------
gobject-objc/GOCValue.h | 40 ++++--
gobject-objc/GOCValue.m | 127 ++++++++++++------
4 files changed, 448 insertions(+), 117 deletions(-)
diff --git a/gobject-objc/GOCNumber.h b/gobject-objc/GOCNumber.h
index 2809436..b02ce15 100644
--- a/gobject-objc/GOCNumber.h
+++ b/gobject-objc/GOCNumber.h
@@ -20,32 +20,32 @@
#ifndef __GOC_NUMBER_H__
#define __GOC_NUMBER_H__
-#import <glib-objc/GOCObjectBase.h>
+#import <gobject-objc/GOCValue.h>
- at interface GOCNumber : GOCObjectBase
-{
- @protected
- int type;
+typedef struct _GOCNumberPriv GOCNumberPriv;
+ at interface GOCNumber : GOCValue
+{
@private
- union
- {
- BOOL b;
- unsigned char uc;
- char c;
- unsigned short us;
- short s;
- unsigned int ui;
- int i;
- unsigned long ul;
- long l;
- unsigned long long ull;
- long long ll;
- float f;
- double d;
- } data;
+ GOCNumberPriv *gnpriv;
}
++ (id)numberWithBool:(BOOL)boolValue;
++ (id)numberWithUChar:(unsigned char)uCharValue;
++ (id)numberWithChar:(char)charValue;
++ (id)numberWithUShort:(unsigned short)uShortValue;
++ (id)numberWithShort:(short)shortValue;
++ (id)numberWithUInt:(unsigned int)uIntValue;
++ (id)numberWithInt:(int)intValue;
++ (id)numberWithULong:(unsigned long)uLongValue;
++ (id)numberWithLong:(long)longValue;
++ (id)numberWithUInt64:(unsigned long long)uInt64Value;
++ (id)numberWithInt64:(long long)int64Value;
++ (id)numberWithFloat:(float)floatValue;
++ (id)numberWithDouble:(double)doubleValue;
++ (id)numberWithEnum:(int)enumValue;
++ (id)numberWithFlags:(unsigned int)flagsValue;
+
- (id)initWithBool:(BOOL)boolValue;
- (id)initWithUChar:(unsigned char)uCharValue;
- (id)initWithChar:(char)charValue;
@@ -59,6 +59,24 @@
- (id)initWithInt64:(long long)int64Value;
- (id)initWithFloat:(float)floatValue;
- (id)initWithDouble:(double)doubleValue;
+- (id)initWithEnum:(int)enumValue;
+- (id)initWithFlags:(unsigned int)flagsValue;
+
+- (BOOL)holdsBool;
+- (BOOL)holdsUChar;
+- (BOOL)holdsChar;
+- (BOOL)holdsUShort;
+- (BOOL)holdsShort;
+- (BOOL)holdsUInt;
+- (BOOL)holdsInt;
+- (BOOL)holdsULong;
+- (BOOL)holdsLong;
+- (BOOL)holdsUInt64;
+- (BOOL)holdsInt64;
+- (BOOL)holdsFloat;
+- (BOOL)holdsDouble;
+- (BOOL)holdsEnum;
+- (BOOL)holdsFlags;
- (BOOL)boolValue;
- (unsigned char)uCharValue;
@@ -73,6 +91,8 @@
- (long long)int64Value;
- (float)floatValue;
- (double)doubleValue;
+- (int)enumValue;
+- (unsigned int)flagsValue;
@end
diff --git a/gobject-objc/GOCNumber.m b/gobject-objc/GOCNumber.m
index 3977656..b7beb0d 100644
--- a/gobject-objc/GOCNumber.m
+++ b/gobject-objc/GOCNumber.m
@@ -32,7 +32,7 @@
typedef enum
{
GN_TYPE_INVALID = 0,
- GN_TYPE_BOOL,
+ GN_TYPE_BOOL = 0x1000,
GN_TYPE_UCHAR,
GN_TYPE_CHAR,
GN_TYPE_USHORT,
@@ -45,225 +45,477 @@ typedef enum
GN_TYPE_INT64,
GN_TYPE_FLOAT,
GN_TYPE_DOUBLE,
+ GN_TYPE_ENUM,
+ GN_TYPE_FLAGS,
} GOCNumberType;
+struct _GOCNumberPriv
+{
+ union
+ {
+ BOOL b;
+ unsigned char uc;
+ char c;
+ unsigned short us;
+ short s;
+ unsigned int ui;
+ int i;
+ unsigned long ul;
+ long l;
+ unsigned long long ull;
+ long long ll;
+ float f;
+ double d;
+ } data;
+};
+
++ (id)numberWithBool:(BOOL)boolValue
+{
+ return [[[GOCNumber alloc] initWithBool:boolValue] autounref];
+}
+
++ (id)numberWithUChar:(unsigned char)uCharValue
+{
+ return [[[GOCNumber alloc] initWithUChar:uCharValue] autounref];
+}
+
++ (id)numberWithChar:(char)charValue
+{
+ return [[[GOCNumber alloc] initWithChar:charValue] autounref];
+}
+
++ (id)numberWithUShort:(unsigned short)uShortValue
+{
+ return [[[GOCNumber alloc] initWithUShort:uShortValue] autounref];
+}
+
++ (id)numberWithShort:(short)shortValue
+{
+ return [[[GOCNumber alloc] initWithShort:shortValue] autounref];
+}
+
++ (id)numberWithUInt:(unsigned int)uIntValue
+{
+ return [[[GOCNumber alloc] initWithUInt:uIntValue] autounref];
+}
+
++ (id)numberWithInt:(int)intValue
+{
+ return [[[GOCNumber alloc] initWithInt:intValue] autounref];
+}
+
++ (id)numberWithULong:(unsigned long)uLongValue
+{
+ return [[[GOCNumber alloc] initWithULong:uLongValue] autounref];
+}
+
++ (id)numberWithLong:(long)longValue
+{
+ return [[[GOCNumber alloc] initWithLong:longValue] autounref];
+}
+
++ (id)numberWithUInt64:(unsigned long long)uInt64Value
+{
+ return [[[GOCNumber alloc] initWithUInt64:uInt64Value] autounref];
+}
+
++ (id)numberWithInt64:(long long)int64Value
+{
+ return [[[GOCNumber alloc] initWithInt64:int64Value] autounref];
+}
+
++ (id)numberWithFloat:(float)floatValue
+{
+ return [[[GOCNumber alloc] initWithFloat:floatValue] autounref];
+}
+
++ (id)numberWithDouble:(double)doubleValue
+{
+ return [[[GOCNumber alloc] initWithDouble:doubleValue] autounref];
+}
+
++ (id)numberWithEnum:(int)enumValue
+{
+ return [[[GOCNumber alloc] initWithEnum:enumValue] autounref];
+}
+
++ (id)numberWithFlags:(unsigned int)flagsValue
+{
+ return [[[GOCNumber alloc] initWithFlags:flagsValue] autounref];
+}
+
+
- (id)init
{
self = [super init];
if(self) {
- type = GN_TYPE_INVALID;
- memset(&data, 0, sizeof(data));
+ gnpriv = g_slice_new0(GOCNumberPriv);
}
return self;
}
- (id)initWithBool:(BOOL)boolValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_BOOL;
- data.b = boolValue;
+ gnpriv->data.b = boolValue;
}
return self;
}
- (id)initWithUChar:(unsigned char)uCharValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_UCHAR;
- data.uc = uCharValue;
+ gnpriv->data.uc = uCharValue;
}
return self;
}
- (id)initWithChar:(char)charValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_CHAR;
- data.c = charValue;
+ gnpriv->data.c = charValue;
}
return self;
}
- (id)initWithUShort:(unsigned short)uShortValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_USHORT;
- data.us = uShortValue;
+ gnpriv->data.us = uShortValue;
}
return self;
}
- (id)initWithShort:(short)shortValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_SHORT;
- data.s = shortValue;
+ gnpriv->data.s = shortValue;
}
return self;
}
- (id)initWithUInt:(unsigned int)uIntValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_UINT;
- data.ui = uIntValue;
+ gnpriv->data.ui = uIntValue;
}
return self;
}
- (id)initWithInt:(int)intValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_INT;
- data.i = intValue;
+ gnpriv->data.i = intValue;
}
return self;
}
- (id)initWithULong:(unsigned long)uLongValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_ULONG;
- data.ul = uLongValue;
+ gnpriv->data.ul = uLongValue;
}
return self;
}
- (id)initWithLong:(long)longValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_LONG;
- data.l = longValue;
+ gnpriv->data.l = longValue;
}
return self;
}
- (id)initWithUInt64:(unsigned long long)uInt64Value
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_UINT64;
- data.ull = uInt64Value;
+ gnpriv->data.ull = uInt64Value;
}
return self;
}
- (id)initWithInt64:(long long)int64Value
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_INT64;
- data.ll = int64Value;
+ gnpriv->data.ll = int64Value;
}
return self;
}
- (id)initWithFloat:(float)floatValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_FLOAT;
- data.f = floatValue;
+ gnpriv->data.f = floatValue;
}
return self;
}
- (id)initWithDouble:(double)doubleValue
{
- self = [super init];
+ self = [self init];
if(self) {
type = GN_TYPE_DOUBLE;
- data.d = doubleValue;
+ gnpriv->data.d = doubleValue;
+ }
+ return self;
+}
+
+- (id)initWithEnum:(int)enumValue
+{
+ self = [self init];
+ if(self) {
+ type = GN_TYPE_ENUM;
+ gnpriv->data.i = enumValue;
+ }
+ return self;
+}
+
+- (id)initWithFlags:(unsigned int)flagsValue
+{
+ self = [self init];
+ if(self) {
+ type = GN_TYPE_FLAGS;
+ gnpriv->data.ui = flagsValue;
}
return self;
}
+- (BOOL)holdsBool
+{
+ return type == GN_TYPE_BOOL ? YES : NO;
+}
+
+- (BOOL)holdsUChar
+{
+ return type == GN_TYPE_UCHAR ? YES : NO;
+}
+
+- (BOOL)holdsChar
+{
+ return type == GN_TYPE_CHAR ? YES : NO;
+}
+
+- (BOOL)holdsUShort
+{
+ return type == GN_TYPE_USHORT ? YES : NO;
+}
+
+- (BOOL)holdsShort
+{
+ return type == GN_TYPE_SHORT ? YES : NO;
+}
+
+- (BOOL)holdsUInt
+{
+ return type == GN_TYPE_UINT ? YES : NO;
+}
+
+- (BOOL)holdsInt
+{
+ return type == GN_TYPE_INT ? YES : NO;
+}
+
+- (BOOL)holdsULong
+{
+ return type == GN_TYPE_ULONG ? YES : NO;
+}
+
+- (BOOL)holdsLong
+{
+ return type == GN_TYPE_LONG ? YES : NO;
+}
+
+- (BOOL)holdsUInt64
+{
+ return type == GN_TYPE_UINT64 ? YES : NO;
+}
+
+- (BOOL)holdsInt64
+{
+ return type == GN_TYPE_INT64 ? YES : NO;
+}
+
+- (BOOL)holdsFloat
+{
+ return type == GN_TYPE_FLOAT ? YES : NO;
+}
+
+- (BOOL)holdsDouble
+{
+ return type == GN_TYPE_DOUBLE ? YES : NO;
+}
+
+- (BOOL)holdsEnum
+{
+ return type == GN_TYPE_ENUM ? YES : NO;
+}
+
+- (BOOL)holdsFlags
+{
+ return type == GN_TYPE_FLAGS ? YES : NO;
+}
+
+
+
- (BOOL)boolValue
{
g_return_val_if_fail(type == GN_TYPE_BOOL, NO);
- return data.b;
+ return gnpriv->data.b;
}
- (unsigned char)uCharValue
{
g_return_val_if_fail(type == GN_TYPE_UCHAR, 0);
- return data.uc;
+ return gnpriv->data.uc;
}
- (char)charValue
{
g_return_val_if_fail(type == GN_TYPE_CHAR, 0);
- return data.c;
+ return gnpriv->data.c;
}
- (unsigned short)uShortValue
{
g_return_val_if_fail(type == GN_TYPE_USHORT, 0);
- return data.us;
+ return gnpriv->data.us;
}
- (short)shortValue
{
g_return_val_if_fail(type == GN_TYPE_SHORT, 0);
- return data.s;
+ return gnpriv->data.s;
}
- (unsigned int)uIntValue
{
g_return_val_if_fail(type == GN_TYPE_UINT, 0);
- return data.ui;
+ return gnpriv->data.ui;
}
- (int)intValue
{
g_return_val_if_fail(type == GN_TYPE_INT, 0);
- return data.i;
+ return gnpriv->data.i;
}
- (unsigned long)uLongValue
{
g_return_val_if_fail(type == GN_TYPE_ULONG, 0);
- return data.ul;
+ return gnpriv->data.ul;
}
- (long)longValue
{
g_return_val_if_fail(type == GN_TYPE_LONG, 0);
- return data.l;
+ return gnpriv->data.l;
}
- (unsigned long long)uInt64Value
{
g_return_val_if_fail(type == GN_TYPE_UINT64, 0);
- return data.ull;
+ return gnpriv->data.ull;
}
- (long long)int64Value
{
g_return_val_if_fail(type == GN_TYPE_INT64, 0);
- return data.ll;
+ return gnpriv->data.ll;
}
- (float)floatValue
{
g_return_val_if_fail(type == GN_TYPE_FLOAT, 0.0);
- return data.f;
+ return gnpriv->data.f;
}
- (double)doubleValue
{
g_return_val_if_fail(type == GN_TYPE_DOUBLE, 0.0);
- return data.d;
+ return gnpriv->data.d;
+}
+
+- (int)enumValue
+{
+ g_return_val_if_fail(type == GN_TYPE_ENUM, 0);
+ return gnpriv->data.i;
+}
+
+- (unsigned int)flagsValue
+{
+ g_return_val_if_fail(type == GN_TYPE_FLAGS, 0);
+ return gnpriv->data.ui;
+}
+
+
+- (const char *)objCSignature
+{
+ switch(type) {
+ case GN_TYPE_BOOL:
+ return @encode(BOOL);
+ case GN_TYPE_UCHAR:
+ return @encode(unsigned char);
+ case GN_TYPE_CHAR:
+ return @encode(char);
+ case GN_TYPE_USHORT:
+ return @encode(unsigned short);
+ case GN_TYPE_SHORT:
+ return @encode(short);
+ case GN_TYPE_UINT:
+ return @encode(unsigned int);
+ case GN_TYPE_INT:
+ return @encode(int);
+ case GN_TYPE_ULONG:
+ return @encode(unsigned long);
+ case GN_TYPE_LONG:
+ return @encode(long);
+ case GN_TYPE_UINT64:
+ return @encode(unsigned long long);
+ case GN_TYPE_INT64:
+ return @encode(long long);
+ case GN_TYPE_FLOAT:
+ return @encode(float);
+ case GN_TYPE_DOUBLE:
+ return @encode(double);
+ case GN_TYPE_ENUM:
+ return @encode(int);
+ case GN_TYPE_FLAGS:
+ return @encode(unsigned int);
+ }
+
+ return [super objCSignature];
+}
+
+
+- (void)free
+{
+ g_slice_free(GOCNumberPriv, gnpriv);
+ [super free];
}
@end
diff --git a/gobject-objc/GOCValue.h b/gobject-objc/GOCValue.h
index f5cbd55..9b0baa6 100644
--- a/gobject-objc/GOCValue.h
+++ b/gobject-objc/GOCValue.h
@@ -17,32 +17,42 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GLIB_OBJC_VALUE_H__
-#define __GLIB_OBJC_VALUE_H__
+#ifndef __GOC_VALUE_H__
+#define __GOC_VALUE_H__
#if !defined(GLIB_OBJC_COMPILATION) && !defined(__IN_GLIB_OBJC_H)
-#error "Do not include GLIBValue.h directly, as this file may change or disappear in the future. Include <glib-objc/glib-objc.h> instead."
+#error "Do not include GOCValue.h directly, as this file may change or disappear in the future. Include <gobject-objc.h> instead."
#endif
-#import <Foundation/Foundation.h>
+#import <glib-objc/GOCObjectBase.h>
- at interface GLIBValue : NSNumber
+typedef struct _GOCValuePriv GOCValuePriv;
+
+ at interface GOCValue : GOCObjectBase
{
- at private
- unsigned int _valueType;
+ @protected
+ int type; /* subclasses must always use 0 for unknown/unset/invalid */
- int _enumValue;
- unsigned int _flagsValue;
+ @private
+ GOCValuePriv *gvpriv;
}
-+ (id)valueWithEnum:(int)enumValue;
-+ (id)valueWithFlags:(unsigned int)flagsValue;
++ (id)valueWithVoid;
++ (id)valueWithObject:(id <GOCObject>)objectValue;
++ (id)valueWithPointer:(void *)pointerValue;
+
+- (id)initWithVoid;
+- (id)initWithObject:(id <GOCObject>)objectValue;
+- (id)initWithPointer:(void *)pointerValue;
+
+- (BOOL)holdsVoid;
+- (BOOL)holdsObject;
+- (BOOL)holdsPointer;
-- (id)initWithEnum:(int)enumValue;
-- (id)initWithFlags:(unsigned int)flagsValue;
+- (id <GOCObject>)objectValue;
+- (void *)pointerValue;
-- (int)enumValue;
-- (unsigned int)flagsValue;
+- (const char *)objCSignature;
@end
diff --git a/gobject-objc/GOCValue.m b/gobject-objc/GOCValue.m
index c3002c2..d6fb1c3 100644
--- a/gobject-objc/GOCValue.m
+++ b/gobject-objc/GOCValue.m
@@ -23,79 +23,128 @@
#include <glib.h>
-#import "GLIBValue.h"
+#import "GOCValue.h"
-enum
+ at implementation GOCValue
+
+typedef enum
+{
+ GV_TYPE_INVALID = 0,
+ GV_TYPE_VOID,
+ GV_TYPE_OBJECT,
+ GV_TYPE_POINTER,
+} GOCValueType;
+
+struct _GOCValuePriv
{
- VALUE_TYPE_INVALID = 0,
- VALUE_TYPE_ENUM,
- VALUE_TYPE_FLAGS,
+ union
+ {
+ id <GOCObject> o;
+ void *p;
+ } data;
};
- at implementation GLIBValue
++ (id)valueWithVoid
+{
+ return [[[GOCValue alloc] initWithVoid] autounref];
+}
-+ (id)valueWithEnum:(int)enumValue
++ (id)valueWithObject:(id <GOCObject>)objectValue
{
- return [[[GLIBValue alloc] initWithEnum:enumValue] autorelease];
+ return [[[GOCValue alloc] initWithObject:objectValue] autounref];
}
-+ (id)valueWithFlags:(unsigned int)flagsValue
++ (id)valueWithPointer:(void *)pointerValue
{
- return [[[GLIBValue alloc] initWithFlags:flagsValue] autorelease];
+ return [[[GOCValue alloc] initWithPointer:pointerValue] autounref];
}
-- (id)initWithEnum:(int)enumValue
+
+- (id)init
{
- if((self = [super init])) {
- _valueType = VALUE_TYPE_ENUM;
- _enumValue = enumValue;
+ self = [super init];
+ if(self) {
+ gvpriv = g_slice_new0(GOCValuePriv);
}
-
return self;
}
-- (id)initWithFlags:(unsigned int)flagsValue
+- (id)initWithVoid
{
- if((self = [super init])) {
- _valueType = VALUE_TYPE_FLAGS;
- _flagsValue = flagsValue;
+ self = [self init];
+ if(self) {
+ type = GV_TYPE_VOID;
}
-
return self;
}
-- (id)init
+- (id)initWithObject:(id <GOCObject>)objectValue
{
- if((self = [super init]))
- _valueType = VALUE_TYPE_INVALID;
-
+ self = [self init];
+ if(self) {
+ type = GV_TYPE_OBJECT;
+ gvpriv->data.o = objectValue;
+ }
return self;
}
-- (int)enumValue
+- (id)initWithPointer:(void *)pointerValue
{
- if(_valueType != VALUE_TYPE_ENUM)
- return 0;
- return _enumValue;
+ self = [self init];
+ if(self) {
+ type = GV_TYPE_POINTER;
+ gvpriv->data.p = pointerValue;
+ }
+ return self;
}
-- (unsigned int)flagsValue
+- (BOOL)holdsVoid
{
- if(_valueType != VALUE_TYPE_FLAGS)
- return 0;
- return _flagsValue;
+ return type == GV_TYPE_VOID ? YES : NO;
}
-- (const char *)objCType
+- (BOOL)holdsObject
{
- switch(_valueType) {
- case VALUE_TYPE_ENUM:
- return @encode(gint);
- case VALUE_TYPE_FLAGS:
- return @encode(guint);
+ return type == GV_TYPE_OBJECT ? YES : NO;
+}
+
+- (BOOL)holdsPointer
+{
+ return type == GV_TYPE_POINTER ? YES : NO;
+}
+
+- (id <GOCObject>)objectValue
+{
+ g_return_val_if_fail(type == GV_TYPE_OBJECT, nil);
+ return gvpriv->data.o;
+}
+
+- (void *)pointerValue
+{
+ g_return_val_if_fail(type == GV_TYPE_POINTER, NULL);
+ return gvpriv->data.p;
+}
+
+
+- (const char *)objCSignature
+{
+ switch(type) {
+ case GV_TYPE_VOID:
+ return @encode(void);
+ case GV_TYPE_OBJECT:
+ return @encode(id);
+ case GV_TYPE_POINTER:
+ return @encode(void *);
}
- return [super objCType];
+ return NULL;
+}
+
+
+- (void)free
+{
+ g_slice_free(GOCValuePriv, gvpriv);
+ [super free];
}
@end
More information about the Xfce4-commits
mailing list