| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2010 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 |
| 11 #include "webrtc/p2p/base/sessiondescription.h" | 11 #include "webrtc/p2p/base/sessiondescription.h" |
| 12 | 12 |
| 13 namespace cricket { | 13 namespace cricket { |
| 14 | 14 |
| 15 ContentInfo* FindContentInfoByName( | 15 ContentInfo* FindContentInfoByName( |
| 16 ContentInfos& contents, const std::string& name) { | 16 ContentInfos& contents, const std::string& name) { |
| 17 for (ContentInfos::iterator content = contents.begin(); | 17 for (ContentInfos::iterator content = contents.begin(); |
| 18 content != contents.end(); ++content) { | 18 content != contents.end(); ++content) { |
| 19 if (content->name == name) { | 19 if (content->name == name) { |
| 20 return &(*content); | 20 return &(*content); |
| 21 } | 21 } |
| 22 } | 22 } |
| 23 return NULL; | 23 return nullptr; |
| 24 } | 24 } |
| 25 | 25 |
| 26 const ContentInfo* FindContentInfoByName( | 26 const ContentInfo* FindContentInfoByName( |
| 27 const ContentInfos& contents, const std::string& name) { | 27 const ContentInfos& contents, const std::string& name) { |
| 28 for (ContentInfos::const_iterator content = contents.begin(); | 28 for (ContentInfos::const_iterator content = contents.begin(); |
| 29 content != contents.end(); ++content) { | 29 content != contents.end(); ++content) { |
| 30 if (content->name == name) { | 30 if (content->name == name) { |
| 31 return &(*content); | 31 return &(*content); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 return NULL; | 34 return nullptr; |
| 35 } | 35 } |
| 36 | 36 |
| 37 const ContentInfo* FindContentInfoByType( | 37 const ContentInfo* FindContentInfoByType( |
| 38 const ContentInfos& contents, const std::string& type) { | 38 const ContentInfos& contents, const std::string& type) { |
| 39 for (ContentInfos::const_iterator content = contents.begin(); | 39 for (ContentInfos::const_iterator content = contents.begin(); |
| 40 content != contents.end(); ++content) { | 40 content != contents.end(); ++content) { |
| 41 if (content->type == type) { | 41 if (content->type == type) { |
| 42 return &(*content); | 42 return &(*content); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 return NULL; | 45 return nullptr; |
| 46 } | 46 } |
| 47 | 47 |
| 48 const std::string* ContentGroup::FirstContentName() const { | 48 const std::string* ContentGroup::FirstContentName() const { |
| 49 return (!content_names_.empty()) ? &(*content_names_.begin()) : NULL; | 49 return (!content_names_.empty()) ? &(*content_names_.begin()) : nullptr; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool ContentGroup::HasContentName(const std::string& content_name) const { | 52 bool ContentGroup::HasContentName(const std::string& content_name) const { |
| 53 return (std::find(content_names_.begin(), content_names_.end(), | 53 return (std::find(content_names_.begin(), content_names_.end(), |
| 54 content_name) != content_names_.end()); | 54 content_name) != content_names_.end()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ContentGroup::AddContentName(const std::string& content_name) { | 57 void ContentGroup::AddContentName(const std::string& content_name) { |
| 58 if (!HasContentName(content_name)) { | 58 if (!HasContentName(content_name)) { |
| 59 content_names_.push_back(content_name); | 59 content_names_.push_back(content_name); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 ContentInfo* SessionDescription::GetContentByName( | 88 ContentInfo* SessionDescription::GetContentByName( |
| 89 const std::string& name) { | 89 const std::string& name) { |
| 90 return FindContentInfoByName(contents_, name); | 90 return FindContentInfoByName(contents_, name); |
| 91 } | 91 } |
| 92 | 92 |
| 93 const ContentDescription* SessionDescription::GetContentDescriptionByName( | 93 const ContentDescription* SessionDescription::GetContentDescriptionByName( |
| 94 const std::string& name) const { | 94 const std::string& name) const { |
| 95 const ContentInfo* cinfo = FindContentInfoByName(contents_, name); | 95 const ContentInfo* cinfo = FindContentInfoByName(contents_, name); |
| 96 if (cinfo == NULL) { | 96 if (cinfo == nullptr) { |
| 97 return NULL; | 97 return nullptr; |
| 98 } | 98 } |
| 99 | 99 |
| 100 return cinfo->description; | 100 return cinfo->description; |
| 101 } | 101 } |
| 102 | 102 |
| 103 ContentDescription* SessionDescription::GetContentDescriptionByName( | 103 ContentDescription* SessionDescription::GetContentDescriptionByName( |
| 104 const std::string& name) { | 104 const std::string& name) { |
| 105 ContentInfo* cinfo = FindContentInfoByName(contents_, name); | 105 ContentInfo* cinfo = FindContentInfoByName(contents_, name); |
| 106 if (cinfo == NULL) { | 106 if (cinfo == nullptr) { |
| 107 return NULL; | 107 return nullptr; |
| 108 } | 108 } |
| 109 | 109 |
| 110 return cinfo->description; | 110 return cinfo->description; |
| 111 } | 111 } |
| 112 | 112 |
| 113 const ContentInfo* SessionDescription::FirstContentByType( | 113 const ContentInfo* SessionDescription::FirstContentByType( |
| 114 const std::string& type) const { | 114 const std::string& type) const { |
| 115 return FindContentInfoByType(contents_, type); | 115 return FindContentInfoByType(contents_, type); |
| 116 } | 116 } |
| 117 | 117 |
| 118 const ContentInfo* SessionDescription::FirstContent() const { | 118 const ContentInfo* SessionDescription::FirstContent() const { |
| 119 return (contents_.empty()) ? NULL : &(*contents_.begin()); | 119 return (contents_.empty()) ? nullptr : &(*contents_.begin()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void SessionDescription::AddContent(const std::string& name, | 122 void SessionDescription::AddContent(const std::string& name, |
| 123 const std::string& type, | 123 const std::string& type, |
| 124 ContentDescription* description) { | 124 ContentDescription* description) { |
| 125 contents_.push_back(ContentInfo(name, type, description)); | 125 contents_.push_back(ContentInfo(name, type, description)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SessionDescription::AddContent(const std::string& name, | 128 void SessionDescription::AddContent(const std::string& name, |
| 129 const std::string& type, | 129 const std::string& type, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 148 delete content->description; | 148 delete content->description; |
| 149 contents_.erase(content); | 149 contents_.erase(content); |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool SessionDescription::AddTransportInfo(const TransportInfo& transport_info) { | 157 bool SessionDescription::AddTransportInfo(const TransportInfo& transport_info) { |
| 158 if (GetTransportInfoByName(transport_info.content_name) != NULL) { | 158 if (GetTransportInfoByName(transport_info.content_name) != nullptr) { |
| 159 return false; | 159 return false; |
| 160 } | 160 } |
| 161 transport_infos_.push_back(transport_info); | 161 transport_infos_.push_back(transport_info); |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 bool SessionDescription::RemoveTransportInfoByName(const std::string& name) { | 165 bool SessionDescription::RemoveTransportInfoByName(const std::string& name) { |
| 166 for (TransportInfos::iterator transport_info = transport_infos_.begin(); | 166 for (TransportInfos::iterator transport_info = transport_infos_.begin(); |
| 167 transport_info != transport_infos_.end(); ++transport_info) { | 167 transport_info != transport_infos_.end(); ++transport_info) { |
| 168 if (transport_info->content_name == name) { | 168 if (transport_info->content_name == name) { |
| 169 transport_infos_.erase(transport_info); | 169 transport_infos_.erase(transport_info); |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 const TransportInfo* SessionDescription::GetTransportInfoByName( | 176 const TransportInfo* SessionDescription::GetTransportInfoByName( |
| 177 const std::string& name) const { | 177 const std::string& name) const { |
| 178 for (TransportInfos::const_iterator iter = transport_infos_.begin(); | 178 for (TransportInfos::const_iterator iter = transport_infos_.begin(); |
| 179 iter != transport_infos_.end(); ++iter) { | 179 iter != transport_infos_.end(); ++iter) { |
| 180 if (iter->content_name == name) { | 180 if (iter->content_name == name) { |
| 181 return &(*iter); | 181 return &(*iter); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 return NULL; | 184 return nullptr; |
| 185 } | 185 } |
| 186 | 186 |
| 187 TransportInfo* SessionDescription::GetTransportInfoByName( | 187 TransportInfo* SessionDescription::GetTransportInfoByName( |
| 188 const std::string& name) { | 188 const std::string& name) { |
| 189 for (TransportInfos::iterator iter = transport_infos_.begin(); | 189 for (TransportInfos::iterator iter = transport_infos_.begin(); |
| 190 iter != transport_infos_.end(); ++iter) { | 190 iter != transport_infos_.end(); ++iter) { |
| 191 if (iter->content_name == name) { | 191 if (iter->content_name == name) { |
| 192 return &(*iter); | 192 return &(*iter); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 return NULL; | 195 return nullptr; |
| 196 } | 196 } |
| 197 | 197 |
| 198 void SessionDescription::RemoveGroupByName(const std::string& name) { | 198 void SessionDescription::RemoveGroupByName(const std::string& name) { |
| 199 for (ContentGroups::iterator iter = content_groups_.begin(); | 199 for (ContentGroups::iterator iter = content_groups_.begin(); |
| 200 iter != content_groups_.end(); ++iter) { | 200 iter != content_groups_.end(); ++iter) { |
| 201 if (iter->semantics() == name) { | 201 if (iter->semantics() == name) { |
| 202 content_groups_.erase(iter); | 202 content_groups_.erase(iter); |
| 203 break; | 203 break; |
| 204 } | 204 } |
| 205 } | 205 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 216 } | 216 } |
| 217 | 217 |
| 218 const ContentGroup* SessionDescription::GetGroupByName( | 218 const ContentGroup* SessionDescription::GetGroupByName( |
| 219 const std::string& name) const { | 219 const std::string& name) const { |
| 220 for (ContentGroups::const_iterator iter = content_groups_.begin(); | 220 for (ContentGroups::const_iterator iter = content_groups_.begin(); |
| 221 iter != content_groups_.end(); ++iter) { | 221 iter != content_groups_.end(); ++iter) { |
| 222 if (iter->semantics() == name) { | 222 if (iter->semantics() == name) { |
| 223 return &(*iter); | 223 return &(*iter); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 return NULL; | 226 return nullptr; |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace cricket | 229 } // namespace cricket |
| OLD | NEW |