proxygen
HTTPSettings.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
11 
12 #include <algorithm>
13 
14 namespace proxygen {
15 
17  auto iter = getSettingIter(id);
18  if (iter != settings_.end()) {
19  (*iter).value = val;
20  } else {
21  settings_.emplace_back(id, val);
22  }
23 }
24 
26  auto iter = getSettingIter(id);
27  if (iter != settings_.end()) {
28  *iter = settings_.back();
29  settings_.pop_back();
30  }
31 }
32 
34  auto iter = getSettingConstIter(id);
35  if (iter != settings_.end()) {
36  return &(*iter);
37  } else {
38  return nullptr;
39  }
40 }
41 
43  SettingsValue defaultValue) const {
44  auto iter = getSettingConstIter(id);
45  if (iter != settings_.end()) {
46  return (*iter).value;
47  } else {
48  return defaultValue;
49  }
50 }
51 
52 std::vector<HTTPSetting>::iterator HTTPSettings::getSettingIter(SettingsId id) {
53  return std::find_if(settings_.begin(),
54  settings_.end(),
55  [&](HTTPSetting const& s) { return s.id == id; });
56 }
57 
58 std::vector<HTTPSetting>::const_iterator HTTPSettings::getSettingConstIter(
59  SettingsId id) const {
60  return std::find_if(settings_.begin(),
61  settings_.end(),
62  [&](HTTPSetting const& s) { return s.id == id; });
63 }
64 
65 } // namespace proxygen
std::vector< HTTPSetting >::iterator getSettingIter(SettingsId id)
std::vector< HTTPSetting >::const_iterator getSettingConstIter(SettingsId id) const
double val
Definition: String.cpp:273
std::vector< HTTPSetting > settings_
Definition: HTTPSettings.h:78
uint64_t SettingsValue
Definition: HTTPSettings.h:25
void unsetSetting(SettingsId id)
static set< string > s
const HTTPSetting * getSetting(SettingsId id) const
void setSetting(SettingsId id, SettingsValue val)