summaryrefslogtreecommitdiff
path: root/deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm
diff options
context:
space:
mode:
Diffstat (limited to 'deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm')
-rw-r--r--deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm63
1 files changed, 63 insertions, 0 deletions
diff --git a/deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm b/deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm
new file mode 100644
index 0000000000..cbf431f28d
--- /dev/null
+++ b/deps/gyp/test/mac/framework/TestFramework/ObjCVector.mm
@@ -0,0 +1,63 @@
+// Copyright (c) 2011 Google Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ObjCVectorInternal.h"
+#import "ObjCVector.h"
+
+#include <vector>
+
+@interface ObjCVector (Private)
+- (std::vector<id>::iterator)makeIterator:(NSUInteger)index;
+@end
+
+@implementation ObjCVector
+
+- (id)init {
+ if ((self = [super init])) {
+ imp_ = new ObjCVectorImp();
+ }
+ return self;
+}
+
+- (void)dealloc {
+ delete imp_;
+ [super dealloc];
+}
+
+- (void)addObject:(id)obj {
+ imp_->v.push_back([obj retain]);
+}
+
+- (void)addObject:(id)obj atIndex:(NSUInteger)index {
+ imp_->v.insert([self makeIterator:index], [obj retain]);
+}
+
+- (void)removeObject:(id)obj {
+ for (std::vector<id>::iterator it = imp_->v.begin();
+ it != imp_->v.end();
+ ++it) {
+ if ([*it isEqual:obj]) {
+ [*it autorelease];
+ imp_->v.erase(it);
+ return;
+ }
+ }
+}
+
+- (void)removeObjectAtIndex:(NSUInteger)index {
+ [imp_->v[index] autorelease];
+ imp_->v.erase([self makeIterator:index]);
+}
+
+- (id)objectAtIndex:(NSUInteger)index {
+ return imp_->v[index];
+}
+
+- (std::vector<id>::iterator)makeIterator:(NSUInteger)index {
+ std::vector<id>::iterator it = imp_->v.begin();
+ it += index;
+ return it;
+}
+
+@end