refactoring: eliminate StorageBackendFlatbuffersImpl 89/246289/3
authorAdrian Szyndela <adrian.s@samsung.com>
Tue, 27 Oct 2020 13:55:03 +0000 (14:55 +0100)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 30 Oct 2020 11:17:55 +0000 (12:17 +0100)
Change-Id: I73f2a898483fb336518f8b9ef28338ef91e55796

src/internal/storage_backend_flatbuffers.cpp
src/internal/storage_backend_flatbuffers.hpp

index 4867185..1cac9ce 100644 (file)
@@ -110,23 +110,10 @@ ldp_xml_parser::DecisionItem getDecisionItemMaybeNull(const T &item, const P *po
 
 } // anonymous namespace
 
-class StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl {
-       const FB::File *file{nullptr};
+template <typename T, typename M = typename type_helper<T>::policy_set_type>
+const M *getPolicySet(const FB::File *file);
 
-public:
-       bool initFromData(const uint8_t *mem, size_t size, bool verify);
-       void release();
-
-       ldp_xml_parser::DecisionItem getDecisionFromSendIndex(const MatchItemSend &item, const FB::PolicySend *policy);
-
-       void printContent(const bool xml_format = false) const;
-
-       template <typename T, typename M = typename type_helper<T>::policy_set_type>
-       const M *getPolicySet();
-};
-
-ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getDecisionFromSendIndex(const MatchItemSend &item,
-               const FB::PolicySend *policy) {
+ldp_xml_parser::DecisionItem getDecisionFromSendIndex(const MatchItemSend &item, const FB::PolicySend *policy) {
 
        const auto *index = policy->index();
 
@@ -194,11 +181,11 @@ ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::StorageBackendFlatbuffer
        return ldp_xml_parser::DecisionItem(ldp_xml_parser::Decision::ANY);
 }
 
-void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::release() {
+void StorageBackendFlatbuffers::release() {
        file = nullptr;
 }
 
-bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromData(const uint8_t *mem, size_t size, bool verify) {
+bool StorageBackendFlatbuffers::initFromData(const uint8_t *mem, size_t size, bool verify) {
        assert(nullptr == file);
 
        if (verify) {
@@ -222,13 +209,12 @@ bool StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::initFromData(cons
        return file != nullptr;
 }
 
-void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::printContent(const bool xml_format) const {
+void StorageBackendFlatbuffers::printContent(const bool xml_format) const {
        print_content::use_xml_format(xml_format);
        std::cerr << *file;
 }
 
 /*************************************************/
-
 #define TYPE_HELPER(T, t) \
        template <> \
        struct type_helper<ldp_xml_parser::MatchItem##T> { \
@@ -236,7 +222,7 @@ void StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::printContent(cons
                typedef FB::Policy##T policy_type; \
        }; \
        template <> \
-       auto StorageBackendFlatbuffers::StorageBackendFlatbuffersImpl::getPolicySet<ldp_xml_parser::MatchItem##T>() \
+       auto getPolicySet<ldp_xml_parser::MatchItem##T>(const FB::File *file) \
                -> const typename type_helper<ldp_xml_parser::MatchItem##T>::policy_set_type * { \
                assert(file); \
                return file->m_##t##_set(); \
@@ -247,59 +233,47 @@ TYPE_HELPER(Send, send)
 TYPE_HELPER(Receive, receive)
 TYPE_HELPER(Access, access)
 
-bool StorageBackendFlatbuffers::initFromData(const uint8_t *serialized_data, size_t length, bool verify) {
-       return pimpl->initFromData(serialized_data, length, verify);
-}
-
-void StorageBackendFlatbuffers::release() {
-       pimpl->release();
-}
-
-void StorageBackendFlatbuffers::printContent(const bool xml_format) const {
-       pimpl->printContent(xml_format);
-}
-
 template <typename T>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const T &item) const {
-       return getDecisionItem(item, pimpl->getPolicySet<T>()->context_mandatory());
+       return getDecisionItem(item, getPolicySet<T>(file)->context_mandatory());
 }
 
 template <>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextMandatory(const MatchItemSend &item) const {
-       return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet<MatchItemSend>()->context_mandatory());
+       return getDecisionFromSendIndex(item, getPolicySet<MatchItemSend>(file)->context_mandatory());
 }
 
 template <>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const MatchItemSend &item) const {
-       return pimpl->getDecisionFromSendIndex(item, pimpl->getPolicySet<MatchItemSend>()->context_default());
+       return getDecisionFromSendIndex(item, getPolicySet<MatchItemSend>(file)->context_default());
 }
 
 template <>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const MatchItemSend &item) const {
-       auto *policyPair = pimpl->getPolicySet<MatchItemSend>()->user()->LookupByKey(uid);
+       auto *policyPair = getPolicySet<MatchItemSend>(file)->user()->LookupByKey(uid);
        if (nullptr == policyPair)
                return ldp_xml_parser::Decision::ANY;
-       return pimpl->getDecisionFromSendIndex(item, policyPair->policy());
+       return getDecisionFromSendIndex(item, policyPair->policy());
 }
 
 template <typename T>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemContextDefault(const T &item) const {
-       return getDecisionItem(item, pimpl->getPolicySet<T>()->context_default());
+       return getDecisionItem(item, getPolicySet<T>(file)->context_default());
 }
 
 template <typename T>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemUser(uid_t uid, const T &item) const {
-       return getDecisionItemMaybeNull(item, pimpl->getPolicySet<T>()->user()->LookupByKey(uid));
+       return getDecisionItemMaybeNull(item, getPolicySet<T>(file)->user()->LookupByKey(uid));
 }
 
 template <typename T>
 ldp_xml_parser::DecisionItem StorageBackendFlatbuffers::getDecisionItemGroup(gid_t gid, const T &item) const {
-       return getDecisionItemMaybeNull(item, pimpl->getPolicySet<T>()->group()->LookupByKey(gid));
+       return getDecisionItemMaybeNull(item, getPolicySet<T>(file)->group()->LookupByKey(gid));
 }
 
 template <typename T>
 bool StorageBackendFlatbuffers::existsPolicyForGroup(gid_t gid) const {
-       return pimpl->getPolicySet<T>()->group()->LookupByKey(gid) != nullptr;
+       return getPolicySet<T>(file)->group()->LookupByKey(gid) != nullptr;
 }
 
 #define T_INSTANTIATION(T) \
@@ -324,12 +298,7 @@ T_INSTANTIATION2(Receive)
 
 #undef T_INSTANTIATION2
 
-StorageBackendFlatbuffers::StorageBackendFlatbuffers()
-       : pimpl{new StorageBackendFlatbuffersImpl} {
-}
-
-StorageBackendFlatbuffers::~StorageBackendFlatbuffers() {
-       pimpl->release();
-}
+StorageBackendFlatbuffers::StorageBackendFlatbuffers() {}
+StorageBackendFlatbuffers::~StorageBackendFlatbuffers() {}
 
 }
index 6bdd707..d0946fd 100644 (file)
@@ -15,6 +15,7 @@
 */
 #pragma once
 
+#include "include/fb_generated.h"
 #include "policy.hpp"
 
 #include <memory>
@@ -22,8 +23,6 @@
 namespace ldp_serialized {
 
 class StorageBackendFlatbuffers {
-       class StorageBackendFlatbuffersImpl;
-       std::unique_ptr<StorageBackendFlatbuffersImpl> pimpl;
 public:
        StorageBackendFlatbuffers();
        ~StorageBackendFlatbuffers();
@@ -50,6 +49,8 @@ public:
        template <typename T>
        bool existsPolicyForGroup(gid_t gid) const;
 
+private:
+       const FB::File *file{nullptr};
 };
 
 }