Skip to content

Commit

Permalink
Use lambda to resolve attribute symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
shermp committed Jul 12, 2023
1 parent 9b8ce21 commit 2b3e8a9
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/ndb/NDBMetadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@
Setting 16 bytes just to be safe here. */
#define VOLUME_SIZE 16

#define NDB_RESOLVE_ATTR(attr, required) \
resolveSymbolRTLD("ATTRIBUTE_" #attr, nh_symoutptr(tmp_attr)); \
if ((required) && !(tmp_attr)) \
{ \
nh_log("could not dlsym attribute %s", #attr); \
initResult = SymbolError; \
return; \
} \
if ((tmp_attr)) \
{ \
attr = *tmp_attr; \
availableAttr.insert(attr); \
}
#define NDB_RESOLVE_ATTR(attr, required) if (!resolve_attr(attr, "ATTRIBUTE_" #attr, required)) return

namespace NDB {

Expand Down Expand Up @@ -81,7 +69,20 @@ NDBMetadata::NDBMetadata(QObject* parent) : QObject(parent) {
return;
}

QString *tmp_attr = nullptr;
auto resolve_attr = [&](QString& attr, const char* name, bool required) {
QString *tmp_attr = nullptr;
resolveSymbolRTLD(name, nh_symoutptr(tmp_attr));
if (required && !tmp_attr) {
nh_log("could not dlsym attribute %s", name);
initResult = SymbolError;
return false;
}
if (tmp_attr) {
attr = *tmp_attr;
availableAttr.insert(attr);
}
return true;
};
// Getting/setting Volume/Content attribute/keys
NDB_RESOLVE_ATTR(ATTRIBUTION, true);
NDB_RESOLVE_ATTR(CONTENT_ID, true);
Expand Down

0 comments on commit 2b3e8a9

Please sign in to comment.