Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Side by Side Diff: base/memory/singleton_objc.h

Issue 10735044: Remove #pragma once. Just from base/ for now. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/memory/singleton.h ('k') | base/memory/weak_ptr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Support for using the Singleton<T> pattern with Objective-C objects. A 5 // Support for using the Singleton<T> pattern with Objective-C objects. A
6 // SingletonObjC is the same as a Singleton, except the default traits are 6 // SingletonObjC is the same as a Singleton, except the default traits are
7 // appropriate for Objective-C objects. A typical Objective-C object of type 7 // appropriate for Objective-C objects. A typical Objective-C object of type
8 // NSExampleType can be maintained as a singleton and accessed with: 8 // NSExampleType can be maintained as a singleton and accessed with:
9 // 9 //
10 // NSExampleType* exampleSingleton = SingletonObjC<NSExampleType>::get(); 10 // NSExampleType* exampleSingleton = SingletonObjC<NSExampleType>::get();
(...skipping 11 matching lines...) Expand all
22 // struct FooSingletonTraits : public DefaultSingletonObjCTraits<Foo> { 22 // struct FooSingletonTraits : public DefaultSingletonObjCTraits<Foo> {
23 // static Foo* New() { 23 // static Foo* New() {
24 // return [[Foo alloc] initWithName:@"selecty"]; 24 // return [[Foo alloc] initWithName:@"selecty"];
25 // } 25 // }
26 // }; 26 // };
27 // ... 27 // ...
28 // Foo* widgetSingleton = SingletonObjC<Foo, FooSingletonTraits>::get(); 28 // Foo* widgetSingleton = SingletonObjC<Foo, FooSingletonTraits>::get();
29 29
30 #ifndef BASE_MEMORY_SINGLETON_OBJC_H_ 30 #ifndef BASE_MEMORY_SINGLETON_OBJC_H_
31 #define BASE_MEMORY_SINGLETON_OBJC_H_ 31 #define BASE_MEMORY_SINGLETON_OBJC_H_
32 #pragma once
33 32
34 #import <Foundation/Foundation.h> 33 #import <Foundation/Foundation.h>
35 #include "base/memory/singleton.h" 34 #include "base/memory/singleton.h"
36 35
37 // Singleton traits usable to manage traditional Objective-C objects, which 36 // Singleton traits usable to manage traditional Objective-C objects, which
38 // are instantiated by sending |alloc| and |init| messages, and are deallocated 37 // are instantiated by sending |alloc| and |init| messages, and are deallocated
39 // in a memory-managed environment when their retain counts drop to 0 by 38 // in a memory-managed environment when their retain counts drop to 0 by
40 // sending |release| messages. 39 // sending |release| messages.
41 template<typename Type> 40 template<typename Type>
42 struct DefaultSingletonObjCTraits : public DefaultSingletonTraits<Type> { 41 struct DefaultSingletonObjCTraits : public DefaultSingletonTraits<Type> {
43 static Type* New() { 42 static Type* New() {
44 return [[Type alloc] init]; 43 return [[Type alloc] init];
45 } 44 }
46 45
47 static void Delete(Type* object) { 46 static void Delete(Type* object) {
48 [object release]; 47 [object release];
49 } 48 }
50 }; 49 };
51 50
52 // Exactly like Singleton, but without the DefaultSingletonObjCTraits as the 51 // Exactly like Singleton, but without the DefaultSingletonObjCTraits as the
53 // default trait class. This makes it straightforward for Objective-C++ code 52 // default trait class. This makes it straightforward for Objective-C++ code
54 // to hold Objective-C objects as singletons. 53 // to hold Objective-C objects as singletons.
55 template<typename Type, 54 template<typename Type,
56 typename Traits = DefaultSingletonObjCTraits<Type>, 55 typename Traits = DefaultSingletonObjCTraits<Type>,
57 typename DifferentiatingType = Type> 56 typename DifferentiatingType = Type>
58 class SingletonObjC : public Singleton<Type, Traits, DifferentiatingType> { 57 class SingletonObjC : public Singleton<Type, Traits, DifferentiatingType> {
59 }; 58 };
60 59
61 #endif // BASE_MEMORY_SINGLETON_OBJC_H_ 60 #endif // BASE_MEMORY_SINGLETON_OBJC_H_
OLDNEW
« no previous file with comments | « base/memory/singleton.h ('k') | base/memory/weak_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698