From 70ccbe4e400d5271bdd954a533b366b58d4d00d4 Mon Sep 17 00:00:00 2001
From: Adrien Beraud <adrien.beraud@savoirfairelinux.com>
Date: Mon, 3 Apr 2017 18:43:18 +0200
Subject: [PATCH] value: remove FieldSelectorDescription

FieldSelectorDescription is just Value::Field and
adds nothing on top of it.

Remove it in favor of Value::Field.
---
 include/opendht/default_types.h |  2 --
 include/opendht/value.h         | 34 ++++-----------------------------
 src/value.cpp                   |  2 +-
 3 files changed, 5 insertions(+), 33 deletions(-)

diff --git a/include/opendht/default_types.h b/include/opendht/default_types.h
index 8b55a6de..1b02d67f 100644
--- a/include/opendht/default_types.h
+++ b/include/opendht/default_types.h
@@ -21,8 +21,6 @@
 
 #include "value.h"
 
-MSGPACK_ADD_ENUM(dht::Value::Field)
-
 namespace dht {
 enum class ImStatus : uint8_t {
     NONE = 0,
diff --git a/include/opendht/value.h b/include/opendht/value.h
index c498a7ae..cb9e4433 100644
--- a/include/opendht/value.h
+++ b/include/opendht/value.h
@@ -630,30 +630,6 @@ private:
     Blob blobValue {};
 };
 
-
-/**
- * @struct  FieldSelectorDescription
- * @brief   Describes a selection.
- * @details
- * This is meant to narrow data to a set of specified fields. This structure is
- * used to construct a Select structure.
- */
-struct OPENDHT_PUBLIC FieldSelectorDescription
-{
-    FieldSelectorDescription() {}
-    FieldSelectorDescription(Value::Field f) : field(f) {}
-
-    Value::Field getField() const { return field; }
-
-    bool operator==(const FieldSelectorDescription& fd) const { return field == fd.field; }
-
-    template <typename Packer>
-    void msgpack_pack(Packer& p) const { p.pack(static_cast<uint8_t>(field)); }
-    void msgpack_unpack(msgpack::object msg) { field = static_cast<Value::Field>(msg.as<int>()); }
-private:
-    Value::Field field {Value::Field::None};
-};
-
 /**
  * @class   Select
  * @brief   Serializable Value field selection.
@@ -686,11 +662,7 @@ struct OPENDHT_PUBLIC Select
      * @return the set of fields.
      */
     std::set<Value::Field> getSelection() const {
-        std::set<Value::Field> fields {};
-        for (const auto& f : fieldSelection_) {
-            fields.insert(f.getField());
-        }
-        return fields;
+        return std::set<Value::Field>(fieldSelection_.begin(), fieldSelection_.end());
     }
 
     template <typename Packer>
@@ -702,7 +674,7 @@ struct OPENDHT_PUBLIC Select
 
     OPENDHT_PUBLIC friend std::ostream& operator<<(std::ostream& s, const dht::Select& q);
 private:
-    std::vector<FieldSelectorDescription> fieldSelection_ {};
+    std::vector<Value::Field> fieldSelection_ {};
 };
 
 /**
@@ -953,3 +925,5 @@ unpackVector(const std::vector<std::shared_ptr<Value>>& vals) {
 }
 
 }
+
+MSGPACK_ADD_ENUM(dht::Value::Field)
diff --git a/src/value.cpp b/src/value.cpp
index fac0e63f..68ee10fb 100644
--- a/src/value.cpp
+++ b/src/value.cpp
@@ -427,7 +427,7 @@ bool Query::isSatisfiedBy(const Query& q) const {
 std::ostream& operator<<(std::ostream& s, const dht::Select& select) {
     s << "SELECT " << (select.fieldSelection_.empty() ? "*" : "");
     for (auto fs = select.fieldSelection_.begin() ; fs != select.fieldSelection_.end() ; ++fs) {
-        switch (fs->getField()) {
+        switch (*fs) {
             case Value::Field::Id:
                 s << "id";
                 break;
-- 
GitLab