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

« back to all changes in this revision

Viewing changes to libFoundation/Foundation/NSClassDescription.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
   NSClassDescription.m
 
3
 
 
4
   Copyright (C) 2000, MDlink online service center GmbH, Helge Hess
 
5
   All rights reserved.
 
6
 
 
7
   Author: Helge Hess <helge.hess@mdlink.de>
 
8
 
 
9
   This file is part of libFoundation.
 
10
 
 
11
   Permission to use, copy, modify, and distribute this software and its
 
12
   documentation for any purpose and without fee is hereby granted, provided
 
13
   that the above copyright notice appear in all copies and that both that
 
14
   copyright notice and this permission notice appear in supporting
 
15
   documentation.
 
16
 
 
17
   We disclaim all warranties with regard to this software, including all
 
18
   implied warranties of merchantability and fitness, in no event shall
 
19
   we be liable for any special, indirect or consequential damages or any
 
20
   damages whatsoever resulting from loss of use, data or profits, whether in
 
21
   an action of contract, negligence or other tortious action, arising out of
 
22
   or in connection with the use or performance of this software.
 
23
*/
 
24
 
 
25
#include <Foundation/NSClassDescription.h>
 
26
#include <Foundation/NSNotification.h>
 
27
#include <Foundation/NSString.h>
 
28
#include <common.h>
 
29
 
 
30
LF_DECLARE NSString *NSClassDescriptionNeededForClassNotification =
 
31
  @"NSClassDescriptionNeededForClass";
 
32
 
 
33
@implementation NSClassDescription
 
34
 
 
35
static NSMapTable *classToDesc  = NULL; // THREAD
 
36
 
 
37
+ (void)initialize
 
38
{
 
39
  if (classToDesc == NULL) {
 
40
    classToDesc = NSCreateMapTable(NSObjectMapKeyCallBacks,
 
41
                                   NSObjectMapValueCallBacks,
 
42
                                   32);
 
43
  }
 
44
}
 
45
 
 
46
/* registry */
 
47
 
 
48
+ (NSClassDescription *)classDescriptionForClass:(Class)_class
 
49
{
 
50
  NSClassDescription *d;
 
51
  
 
52
  if ((d = NSMapGet(classToDesc, _class)))
 
53
    return d;
 
54
 
 
55
  [[NSNotificationCenter defaultCenter]
 
56
                         postNotificationName:
 
57
                           NSClassDescriptionNeededForClassNotification
 
58
                         object:_class];
 
59
  
 
60
  return NSMapGet(classToDesc, _class);
 
61
}
 
62
 
 
63
+ (void)registerClassDescription:(NSClassDescription *)_clazzDesc
 
64
  forClass:(Class)_class
 
65
{
 
66
  if (_clazzDesc == nil)
 
67
    return;
 
68
 
 
69
  if (_class)
 
70
    NSMapInsert(classToDesc,  _class, _clazzDesc);
 
71
}
 
72
 
 
73
+ (void)invalidateClassDescriptionCache
 
74
{
 
75
  NSResetMapTable(classToDesc);
 
76
}
 
77
 
 
78
/* accessors */
 
79
 
 
80
- (NSArray *)attributeKeys
 
81
{
 
82
  return nil;
 
83
}
 
84
 
 
85
- (NSArray *)toManyRelationshipKeys
 
86
{
 
87
  return nil;
 
88
}
 
89
- (NSArray *)toOneRelationshipKeys
 
90
{
 
91
  return nil;
 
92
}
 
93
- (NSString *)inverseForRelationshipKey:(NSString *)_key
 
94
{
 
95
  return nil;
 
96
}
 
97
 
 
98
@end /* NSClassDescription */
 
99
 
 
100
@implementation NSObject(ClassDescriptionForwards)
 
101
 
 
102
static Class NSClassDescriptionClass = Nil;
 
103
 
 
104
- (NSClassDescription *)classDescription
 
105
{
 
106
  if (NSClassDescriptionClass == Nil)
 
107
    NSClassDescriptionClass = [NSClassDescription class];
 
108
  
 
109
  return [NSClassDescriptionClass classDescriptionForClass:[self class]];
 
110
}
 
111
 
 
112
- (NSArray *)attributeKeys
 
113
{
 
114
  return [[self classDescription] attributeKeys];
 
115
}
 
116
 
 
117
- (NSArray *)toManyRelationshipKeys
 
118
{
 
119
  return [[self classDescription] toManyRelationshipKeys];
 
120
}
 
121
 
 
122
- (NSArray *)toOneRelationshipKeys
 
123
{
 
124
  return [[self classDescription] toOneRelationshipKeys];
 
125
}
 
126
 
 
127
- (NSString *)inverseForRelationshipKey:(NSString *)_key
 
128
{
 
129
  return [[self classDescription] inverseForRelationshipKey:_key];
 
130
}
 
131
 
 
132
@end /* NSObject(ClassDescriptionForwards) */