OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // Callers that access options too often are encouraged to cache the result. | 64 // Callers that access options too often are encouraged to cache the result. |
65 // Returned references are owned by this. | 65 // Returned references are owned by this. |
66 // | 66 // |
67 // Requires std::is_default_constructible<T> | 67 // Requires std::is_default_constructible<T> |
68 template<typename T> const T& Get() const; | 68 template<typename T> const T& Get() const; |
69 | 69 |
70 // Set the option, deleting any previous instance of the same. | 70 // Set the option, deleting any previous instance of the same. |
71 // This instance gets ownership of the newly set value. | 71 // This instance gets ownership of the newly set value. |
72 template<typename T> void Set(T* value); | 72 template<typename T> void Set(T* value); |
73 | 73 |
74 Config() {} | 74 Config(); |
75 ~Config() { | 75 ~Config(); |
76 // Note: this method is inline so webrtc public API depends only | |
77 // on the headers. | |
kwiberg-webrtc
2016/08/29 08:28:18
I had to remove this comment, because it's not tru
kjellander_webrtc
2016/08/29 19:18:09
Right, if moving this breaks anything it's the rig
| |
78 for (OptionMap::iterator it = options_.begin(); | |
79 it != options_.end(); ++it) { | |
80 delete it->second; | |
81 } | |
82 } | |
83 | 76 |
84 private: | 77 private: |
85 struct BaseOption { | 78 struct BaseOption { |
86 virtual ~BaseOption() {} | 79 virtual ~BaseOption() {} |
87 }; | 80 }; |
88 | 81 |
89 template<typename T> | 82 template<typename T> |
90 struct Option : BaseOption { | 83 struct Option : BaseOption { |
91 explicit Option(T* v): value(v) {} | 84 explicit Option(T* v): value(v) {} |
92 ~Option() { | 85 ~Option() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 template<typename T> | 125 template<typename T> |
133 void Config::Set(T* value) { | 126 void Config::Set(T* value) { |
134 BaseOption*& it = options_[identifier<T>()]; | 127 BaseOption*& it = options_[identifier<T>()]; |
135 delete it; | 128 delete it; |
136 it = new Option<T>(value); | 129 it = new Option<T>(value); |
137 } | 130 } |
138 | 131 |
139 } // namespace webrtc | 132 } // namespace webrtc |
140 | 133 |
141 #endif // WEBRTC_COMMON_H_ | 134 #endif // WEBRTC_COMMON_H_ |
OLD | NEW |