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

Side by Side Diff: base/mac/scoped_launch_data.h

Issue 1551943002: Rewrite most of the scopers in //base/mac to use ScopedTypeRef or ScopedGeneric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_MAC_SCOPED_LAUNCH_DATA_H_ 5 #ifndef BASE_MAC_SCOPED_LAUNCH_DATA_H_
6 #define BASE_MAC_SCOPED_LAUNCH_DATA_H_ 6 #define BASE_MAC_SCOPED_LAUNCH_DATA_H_
7 7
8 #include <launch.h> 8 #include <launch.h>
9 9
10 #include <algorithm> 10 #include "base/scoped_generic.h"
11
12 #include "base/compiler_specific.h"
13 #include "base/macros.h"
14 11
15 namespace base { 12 namespace base {
16 namespace mac { 13 namespace mac {
17 14
15 namespace internal {
16
17 struct ScopedLaunchDataTraits {
18 static launch_data_t InvalidValue() { return nullptr; }
19 static void Free(launch_data_t ldt) { launch_data_free(ldt); }
Mark Mentovai 2016/01/06 16:22:58 I had to ignore -Wdeprecated-declarations to use l
20 };
21
22 } // namespace internal
23
18 // Just like scoped_ptr<> but for launch_data_t. 24 // Just like scoped_ptr<> but for launch_data_t.
19 class ScopedLaunchData { 25 using ScopedLaunchData =
20 public: 26 ScopedGeneric<launch_data_t, internal::ScopedLaunchDataTraits>;
21 typedef launch_data_t element_type;
22
23 explicit ScopedLaunchData(launch_data_t object = NULL)
24 : object_(object) {
25 }
26
27 ~ScopedLaunchData() {
28 if (object_)
29 launch_data_free(object_);
30 }
31
32 void reset(launch_data_t object = NULL) {
33 if (object != object_) {
34 if (object_)
35 launch_data_free(object_);
36 object_ = object;
37 }
38 }
39
40 bool operator==(launch_data_t that) const {
41 return object_ == that;
42 }
43
44 bool operator!=(launch_data_t that) const {
45 return object_ != that;
46 }
47
48 operator launch_data_t() const {
49 return object_;
50 }
51
52 launch_data_t get() const {
53 return object_;
54 }
55
56 void swap(ScopedLaunchData& that) {
57 std::swap(object_, that.object_);
58 }
59
60 launch_data_t release() WARN_UNUSED_RESULT {
61 launch_data_t temp = object_;
62 object_ = NULL;
63 return temp;
64 }
65
66 private:
67 launch_data_t object_;
68
69 DISALLOW_COPY_AND_ASSIGN(ScopedLaunchData);
70 };
71 27
72 } // namespace mac 28 } // namespace mac
73 } // namespace base 29 } // namespace base
74 30
75 #endif // BASE_MAC_SCOPED_LAUNCH_DATA_H_ 31 #endif // BASE_MAC_SCOPED_LAUNCH_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698