Extends the direct access model to other collections

This commit is contained in:
Felipe Zimmerle
2017-01-26 23:13:38 -03:00
committed by Felipe Zimmerle
parent ca24b6bb06
commit f2d149fc5f
157 changed files with 7711 additions and 4959 deletions

View File

@@ -155,11 +155,11 @@ void InMemoryPerProcess::resolveRegularExpression(const std::string& var,
}
std::string* InMemoryPerProcess::resolveFirst(const std::string& var) {
std::unique_ptr<std::string> InMemoryPerProcess::resolveFirst(const std::string& var) {
auto range = equal_range(var);
for (auto it = range.first; it != range.second; ++it) {
return &it->second;
return std::unique_ptr<std::string>(new std::string(it->second));
}
return NULL;

View File

@@ -82,7 +82,7 @@ class InMemoryPerProcess :
void del(const std::string& key) override;
std::string* resolveFirst(const std::string& var) override;
std::unique_ptr<std::string> resolveFirst(const std::string& var) override;
void resolveSingleMatch(const std::string& var,
std::vector<const Variable *> *l) override;

View File

@@ -161,7 +161,7 @@ void LMDB::lmdb_debug(int rc, std::string op, std::string scope) {
}
std::string* LMDB::resolveFirst(const std::string& var) {
std::unique_ptr<std::string> LMDB::resolveFirst(const std::string& var) {
int rc;
MDB_val mdb_key;
MDB_val mdb_value;
@@ -188,10 +188,9 @@ std::string* LMDB::resolveFirst(const std::string& var) {
goto end_get;
}
// FIXME: Memory leak here.
ret = new std::string(
ret = std::unique_ptr<std::string>(new std::string(
reinterpret_cast<char *>(mdb_value_ret.mv_data),
mdb_value_ret.mv_size);
mdb_value_ret.mv_size));
end_get:
mdb_dbi_close(m_env, dbi);

View File

@@ -61,7 +61,7 @@ class LMDB :
void del(const std::string& key) override;
std::string* resolveFirst(const std::string& var) override;
std::unique_ptr<std::string> resolveFirst(const std::string& var) override;
void resolveSingleMatch(const std::string& var,
std::vector<const Variable *> *l) override;

View File

@@ -125,26 +125,27 @@ void Collections::del(const std::string& key) {
}
std::string* Collections::resolveFirst(const std::string& var) {
std::string *transientVar = m_transient->resolveFirst(var);
std::unique_ptr<std::string> Collections::resolveFirst(const std::string& var) {
std::unique_ptr<std::string> transientVar = m_transient->resolveFirst(var);
if (transientVar != NULL) {
return transientVar;
}
for (auto &a : *this) {
std::string *res = a.second->resolveFirst(
std::unique_ptr<std::string> res = a.second->resolveFirst(
utils::string::toupper(a.first) + ":" + var);
if (res != NULL) {
return res;
}
}
return NULL;
return nullptr;
}
std::string* Collections::resolveFirst(const std::string& collectionName,
std::unique_ptr<std::string> Collections::resolveFirst(const std::string& collectionName,
const std::string& var) {
if (utils::string::tolower(collectionName) == "ip"
&& !m_ip_collection_key.empty()) {
@@ -177,7 +178,7 @@ std::string* Collections::resolveFirst(const std::string& collectionName,
for (auto &a : *this) {
if (utils::string::tolower(a.first)
== utils::string::tolower(collectionName)) {
std::string *res = a.second->resolveFirst(
std::unique_ptr<std::string> res = a.second->resolveFirst(
utils::string::toupper(a.first)
+ ":" + var);
if (res != NULL) {