1/*
2 * Copyright (c) 2006-2008, The RubyCocoa Project.
3 * Copyright (c) 2001-2006, FUJIMOTO Hisakuni.
4 * All Rights Reserved.
5 *
6 * RubyCocoa is free software, covered under either the Ruby's license or the
7 * LGPL. See the COPYRIGHT file for more information.
8 */
9
10#import <Foundation/Foundation.h>
11#import "RBObject.h"
12#import "RBSlaveObject.h"
13#import "RBClassUtils.h"
14#import "osx_ruby.h"
15#import "ocdata_conv.h"
16#import "mdl_osxobjc.h"
17
18static VALUE rbobj_for(VALUE rbclass, id master)
19{
20  static BOOL in_rbobj_for = NO;
21  VALUE val;
22  if (in_rbobj_for == YES) return Qnil;
23  in_rbobj_for = YES;
24  val = rb_funcall(rbclass, rb_intern("new_with_ocid"), 1, OCID2NUM(master));
25  in_rbobj_for = NO;
26  return val;
27}
28
29@implementation RBObject(RBSlaveObject)
30
31- initWithMasterObject: master
32{
33  return [self initWithClass: [self class] masterObject: master];
34}
35
36- initWithClass: (Class)occlass masterObject: master
37{
38  VALUE rb_class = RBRubyClassFromObjcClass (occlass);
39  self = [self initWithRubyClass: rb_class masterObject: master];
40  oc_master = occlass;
41  return self;
42}
43
44///////
45
46- initWithRubyClass: (VALUE)rbclass masterObject: master
47{
48  VALUE rbobj;
49  rbobj = rbobj_for(rbclass, master);
50  return [self initWithRubyObject: rbobj];
51}
52
53@end
54