Updated Danish translation
[dasher.git] / Src / MacOSX / ZippyCache.m
bloba38fa92497ecfbc431a6287969a6ac4d3cb1151e
1 //
2 //  ZippyCache.m
3 //  RectAl
4 //
5 //  Created by Doug Dickinson on Mon May 26 2003.
6 //  Copyright (c) 2003 Doug Dickinson (dasher AT DressTheMonkey DOT plus DOT com). All rights reserved.
7 //
9 #import <Foundation/Foundation.h>
11 #import "ZippyCache.h"
12 #import "ZippyStringImage.h"
13 #import "ZippyStringGlyph.h"
15 #if defined(ZIPPY_STRING_GLYPH)
16             
17 // ZippyStringGlyph is not yet ready for primetime
18 #define ZIPPY_STRING_CLASS ZippyStringGlyph
19 #else            
20 // not terribly sophisticated way of choosing which Zippy string type to use
21 #define ZIPPY_STRING_CLASS ZippyStringImage
22 #endif
23             
24 @implementation ZippyCache
26 - (ZippyString *)zippyStringWithString:(NSString *)aString size:(int)aSize attributes:(NSDictionary *)someAttributes {
27   ZippyString *result = nil;
28   NSMutableDictionary *sizeCache;
30   sizeCache = [[self cache] objectForKey:[self sizeKeyForSize:aSize]];
31   if (sizeCache == nil) {
32     sizeCache = [NSMutableDictionary dictionary];
33     [[self cache] setObject:sizeCache forKey:[self sizeKeyForSize:aSize]];
34   }
36   result = [sizeCache objectForKey:aString];
37   if (result == nil) {
38     result = [ZIPPY_STRING_CLASS zippyStringWithString:aString attributes:someAttributes];
39     if ([aString length] == 1) {
40       [sizeCache setObject:result forKey:aString];
41     }
42   }
44   return result;
47 - (NSNumber *)sizeKeyForSize:(int)aSize {
48 //#if defined(ZIPPY_STRING_GLYPH)
49 //  return [NSNumber numberWithInt:42]; // just testing
50 //#else 
51   return [NSNumber numberWithInt:aSize];
52 //#endif
55 + zippyCache {
56   return [[[self alloc] init] autorelease];
59 - init {
60   if (self = [super init]) {
61     [self flush];
62   }
64   return self;
67 - (void)flush
69   [self setCache:[NSMutableDictionary dictionary]];
72 - (NSMutableDictionary *)cache {
73   return _cache;
76 - (void)setCache:(NSMutableDictionary *)newCache {
77   if (_cache != newCache) {
78     NSMutableDictionary *oldValue = _cache;
79     _cache = [newCache retain];
80     [oldValue release];
81   }
84 - (void)dealloc {
85   [_cache release];
86   [super dealloc];
89 @end