]> err.no Git - sope/blob - Recycler/NGJavaScript/NGJavaScriptObject.h
removed NGCString
[sope] / Recycler / NGJavaScript / NGJavaScriptObject.h
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #ifndef __NGJavaScriptObject_H__
24 #define __NGJavaScriptObject_H__
25
26 #import <Foundation/NSObject.h>
27 #include "NSObject+JS.h"
28
29 /*
30   NGJavaScriptObject
31   
32   Related: NGJavaScriptObjectHandler, see docu
33   
34   Hm, what is the difference between the handler and the object ?
35   => find out and document
36   
37   Note: this object keeps a retained reference to the context.
38 */
39
40 @class NSEnumerator, NSArray, NSString, NSDictionary;
41 @class NGObjectMappingContext;
42 @class NGJavaScriptObjectMappingContext;
43
44 @interface NGJavaScriptObject : NSObject < NSCoding >
45 {
46   NGJavaScriptObjectMappingContext *ctx;
47   void *jscx;     /* cached JSContext handle         */
48   void *handle;   /* the handle of the object itself */
49   BOOL addedRoot; /* was a root-ref added            */
50 }
51
52 - (id)initWithHandle:(void *)_handle
53   inMappingContext:(NGObjectMappingContext *)_ctx;
54
55 /* private */
56
57 - (void *)handle;
58 - (void)makeGlobal;
59 - (void *)_jsHandleInMapContext:(NGObjectMappingContext *)_ctx;
60
61 /* misc */
62
63 - (void)applyStandardClasses;
64
65 - (void)setParentObject:(id)_parent;
66 - (id)parentObject;
67 - (NSEnumerator *)parentObjectChain;
68
69 - (void)setPrototypeObject:(id)_proto;
70 - (id)prototypeObject;
71 - (NSEnumerator *)prototypeObjectChain;
72
73 - (BOOL)hasPropertyNamed:(NSString *)_key;
74 - (BOOL)hasFunctionNamed:(NSString *)_key;
75
76 /* a function object */
77
78 - (BOOL)isJavaScriptFunction;
79 - (id)callOn:(id)_this;
80 - (id)callOn:(id)_this withObject:(id)_arg0;
81
82 /* mimic an NSDictionary */
83
84 - (void)setObject:(id)_value forKey:(id)_key;
85 - (id)objectForKey:(id)_key;
86 - (void)removeObjectForKey:(id)_key;
87 - (NSEnumerator *)keyEnumerator;
88 - (NSEnumerator *)objectEnumerator;
89 - (NSArray *)allKeys;
90 - (NSArray *)allValues;
91
92 /* convert to dictionary */
93
94 - (NSDictionary *)convertToNSDictionary;
95
96 /* KVC */
97
98 - (void)takeValue:(id)_value forKey:(NSString *)_key;
99 - (id)valueForKey:(NSString *)_key;
100
101 @end
102
103 #import <Foundation/NSArray.h>
104
105 /* this class gets the NSMutableArray behaviour added !!! */
106
107 @interface NGJavaScriptArray : NGJavaScriptObject < NSCopying >
108
109 /* convert to array */
110
111 - (NSArray *)convertToNSArray;
112
113 @end
114
115 @interface NGJavaScriptArray(NSArrayCompatibility)
116
117 - (unsigned)count;
118 - (id)objectAtIndex:(unsigned)_idx;
119 - (NSEnumerator *)objectEnumerator;
120 - (id)lastObject;
121
122 - (NSArray *)arrayByAddingObject:(id)anObject;
123 - (NSArray *)arrayByAddingObjectsFromArray:(NSArray *)anotherArray;
124
125 - (NSArray *)sortedArrayUsingFunction:
126   (int(*)(id element1, id element2, void *userData))comparator
127   context:(void*)context;
128
129 @end
130
131 @interface NGJavaScriptArray(NSMutableArrayCompatibility)
132
133 - (void)setObject:(id)_obj atIndex:(unsigned)_idx;
134
135 - (void)removeObjectsInRange:(NSRange)aRange;
136 - (void)removeAllObjects;
137 - (void)removeLastObject;
138 - (void)removeObjectAtIndex:(unsigned)_idx;
139
140 - (void)insertObject:(id)_object atIndex:(unsigned)_idx;
141 - (void)addObject:(id)_object;
142
143 @end
144
145 #endif /* __NGJavaScriptObject_H__ */