} // 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();
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) {
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> { \
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(); \
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) \
#undef T_INSTANTIATION2
-StorageBackendFlatbuffers::StorageBackendFlatbuffers()
- : pimpl{new StorageBackendFlatbuffersImpl} {
-}
-
-StorageBackendFlatbuffers::~StorageBackendFlatbuffers() {
- pimpl->release();
-}
+StorageBackendFlatbuffers::StorageBackendFlatbuffers() {}
+StorageBackendFlatbuffers::~StorageBackendFlatbuffers() {}
}