~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to libFoundation/Foundation/NSObjCRuntime.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   NSObjCRuntime.m
 
3
 
 
4
   Copyright (C) 1995, 1996 Ovidiu Predescu and Mircea Oancea.
 
5
   All rights reserved.
 
6
 
 
7
   Author: Ovidiu Predescu <ovidiu@bx.logicnet.ro>
 
8
           Mircea Oancea <mircea@jupiter.elcom.pub.ro>
 
9
 
 
10
   This file is part of libFoundation.
 
11
 
 
12
   Permission to use, copy, modify, and distribute this software and its
 
13
   documentation for any purpose and without fee is hereby granted, provided
 
14
   that the above copyright notice appear in all copies and that both that
 
15
   copyright notice and this permission notice appear in supporting
 
16
   documentation.
 
17
 
 
18
   We disclaim all warranties with regard to this software, including all
 
19
   implied warranties of merchantability and fitness, in no event shall
 
20
   we be liable for any special, indirect or consequential damages or any
 
21
   damages whatsoever resulting from loss of use, data or profits, whether in
 
22
   an action of contract, negligence or other tortious action, arising out of
 
23
   or in connection with the use or performance of this software.
 
24
*/
 
25
 
 
26
#include <Foundation/common.h>
 
27
#include <Foundation/NSString.h>
 
28
#include <Foundation/NSObjCRuntime.h>
 
29
#include <Foundation/NSUtilities.h>
 
30
 
 
31
#include <extensions/objc-runtime.h>
 
32
 
 
33
/*
 
34
 * Objective-C runtime info
 
35
 */
 
36
 
 
37
LF_DECLARE Class NSClassFromString(NSString *aClassName)
 
38
{
 
39
    unsigned len = [aClassName cStringLength];
 
40
    char  *buf;
 
41
    Class clazz;
 
42
    if (len == 0) return NULL;
 
43
    buf = malloc(len + 1);
 
44
    [aClassName getCString:buf]; buf[len] = '\0';
 
45
    clazz = objc_lookup_class(buf);
 
46
    free(buf);
 
47
    return clazz;
 
48
}
 
49
 
 
50
LF_DECLARE SEL NSSelectorFromString(NSString *aSelectorName)
 
51
{
 
52
    unsigned len = [aSelectorName cStringLength];
 
53
    char *buf;
 
54
    SEL  sel;
 
55
    if (len == 0) return NULL;
 
56
    buf = malloc(len + 1);
 
57
    [aSelectorName getCString:buf]; buf[len] = '\0';
 
58
    sel = sel_get_any_uid(buf);
 
59
    free(buf);
 
60
    return sel;
 
61
}
 
62
 
 
63
LF_DECLARE NSString *NSStringFromClass(Class aClass)
 
64
{
 
65
    return aClass ?
 
66
        [NSString stringWithCStringNoCopy:(char*)class_get_class_name(aClass)
 
67
            freeWhenDone:NO] : nil;
 
68
}
 
69
 
 
70
LF_DECLARE NSString *NSStringFromSelector(SEL aSelector)
 
71
{
 
72
    if (aSelector) {
 
73
        return [NSString stringWithCStringNoCopy:(char*)sel_get_name(aSelector)
 
74
                         freeWhenDone:NO];
 
75
    }
 
76
    else {
 
77
        NSLog(@"WARNING: called %s with NULL-selector !", __PRETTY_FUNCTION__);
 
78
        return nil;
 
79
    }
 
80
}
 
81
 
 
82
/*
 
83
  Local Variables:
 
84
  c-basic-offset: 4
 
85
  tab-width: 8
 
86
  End:
 
87
*/
 
88