CelestiaDestination.mm
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:3k
源码类别:

OpenGL

开发平台:

Visual C++

  1. //
  2. //  CelestiaDestination.mm
  3. //  celestia
  4. //
  5. //  Created by Bob Ippolito on Fri Jun 07 2002.
  6. //  Copyright (c) 2002 Chris Laurel. All rights reserved.
  7. //
  8. #import "CelestiaDestination.h"
  9. #import "CelestiaDestination_PrivateAPI.h"
  10. #import "NSString_ObjCPlusPlus.h"
  11. @implementation CelestiaDestination(PrivateAPI)
  12. -(CelestiaDestination *)initWithDestination:(Destination *)dst 
  13. {
  14.     self = [super init];
  15.     _data = [[NSValue alloc] initWithBytes:reinterpret_cast<void*>(&dst) objCType:@encode(Destination*)];
  16.     return self;
  17. }
  18. -(Destination *)destination
  19. {
  20.     return reinterpret_cast<Destination*>([_data pointerValue]);
  21. }
  22. @end
  23. @implementation CelestiaDestination
  24. -(void)dealloc
  25. {
  26.     if (_data != nil) {
  27.         [_data release];
  28.         _data = nil;
  29.     }
  30.     [super dealloc];
  31. }
  32. -(NSString*)name
  33. {
  34.     return [NSString stringWithStdString:[self destination]->name];
  35. }
  36. -(void)setName:(NSString*)name
  37. {
  38.     [self destination]->name = [name stdString];
  39. }
  40. -(NSString*)target
  41. {
  42.     return [NSString stringWithStdString:[self destination]->target];
  43. }
  44. -(void)setTarget:(NSString*)target
  45. {
  46.     [self destination]->target = [target stdString];
  47. }
  48. -(NSNumber*)distance
  49. {
  50.     return [NSNumber numberWithDouble:[self destination]->distance];
  51. }
  52. -(void)setDistance:(NSNumber*)distance
  53. {
  54.     [self destination]->distance = [distance doubleValue];
  55. }
  56. -(NSString*)description
  57. {
  58.     return [NSString stringWithStdString:[self destination]->description];
  59. }
  60. -(void)setDescription:(NSString*)description
  61. {
  62.     [self destination]->description = [description stdString];
  63. }
  64. @end
  65. @implementation CelestiaDestinations(PrivateAPI)
  66. -(CelestiaDestinations *)initWithDestinations:(const DestinationList *)dsts 
  67. {
  68.     self = [super init];
  69.     _data = [[NSValue alloc] initWithBytes:reinterpret_cast<void*>(&dsts) objCType:@encode(DestinationList*)];
  70.     return self;
  71. }
  72. -(DestinationList *)destinations
  73. {
  74.     return reinterpret_cast<DestinationList*>([_data pointerValue]);
  75. }
  76. @end
  77. @implementation CelestiaDestinations
  78. -(void)setSynchronize:(NSInvocation*)sync
  79. {
  80.     if (_synchronize == nil) {
  81.         [_synchronize release];
  82.         _synchronize = nil;
  83.     }
  84.     _synchronize = [sync retain];
  85.     [_synchronize setArgument:&self atIndex:2];
  86. }
  87. -(void)synchronize
  88. {
  89.     if (_synchronize == nil)
  90.         return;
  91.     [_synchronize invoke];
  92. }
  93. -(void)dealloc
  94. {
  95.     if (_data != nil) {
  96.         [_data release];
  97.         _data = nil;
  98.     }
  99.     if (_synchronize != nil) {
  100.         [_synchronize release];
  101.         _synchronize = nil;
  102.     }
  103.     [super dealloc];
  104. }
  105. -(unsigned)count
  106. {
  107.     return [self destinations]->size();
  108. }
  109. -(id)objectAtIndex:(unsigned)index
  110. {
  111.     return [[[CelestiaDestination alloc] initWithDestination:(*[self destinations])[index]] autorelease];
  112. }
  113. -(void)addObject:(CelestiaDestination*)o
  114. {
  115.     Destination* d=[o destination];
  116.     [self destinations]->push_back(d);
  117.     [self synchronize];
  118. }
  119. -(void)insertObject:(CelestiaDestination*)o atIndex:(unsigned)index
  120. {
  121.     Destination* d=[o destination];
  122.     [self destinations]->insert([self destinations]->begin()+index, d);
  123.     [self synchronize];
  124. }
  125. -(void)removeLastObject
  126. {
  127.     [self destinations]->pop_back();
  128.     [self synchronize];
  129. }
  130. -(void)removeObjectAtIndex:(unsigned)index
  131. {
  132.     [self destinations]->erase([self destinations]->begin()+index);
  133.     [self synchronize];
  134. }
  135. -(void)replaceObjectAtIndex:(unsigned)index withObject:(CelestiaDestination*)o
  136. {
  137.     [self removeObjectAtIndex:index];
  138.     [self insertObject:o atIndex:index];
  139. }
  140. @end