]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Add with_val to md_config_t
authorAdam C. Emerson <aemerson@redhat.com>
Mon, 20 Nov 2017 21:06:28 +0000 (16:06 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 7 Dec 2017 20:46:07 +0000 (15:46 -0500)
Since passing back references that persist after we drop a lock is
unsafe, allow functions to be called on a reference under the lock.

This way we can compare strings or otherwise examine them without
needing to make a copy.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/config.h

index df06f6af044938eddef4aa3b4fbc55ea103ce864..25305d461864195d75cd04633cf7769101333303 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef CEPH_CONFIG_H
 #define CEPH_CONFIG_H
 
+#include "common/backport14.h"
 #include "common/ConfUtils.h"
 #include "common/entity_name.h"
 #include "common/code_environment.h"
@@ -165,6 +166,13 @@ public:
   int _get_val(const std::string &key, char **buf, int len) const;
   Option::value_t get_val_generic(const std::string &key) const;
   template<typename T> const T get_val(const std::string &key) const;
+  template<typename T, typename Callback, typename...Args>
+  auto with_val(const string& key, Callback&& cb, Args&&... args) const ->
+    ceph::result_of_t<Callback(const T&, Args...)> {
+    return std::forward<Callback>(cb)(
+      boost::get<T>(this->get_val_generic(key)),
+      std::forward<Args>(args)...);
+  }
 
   void get_all_keys(std::vector<std::string> *keys) const;