Skip to content

Commit

Permalink
fix: Add constructor interface to file adapters.
Browse files Browse the repository at this point in the history
Signed-off-by: divy9881 <divy9881@gmail.com>
  • Loading branch information
divy9881 committed Jul 24, 2020
1 parent 7d857d9 commit 9b56abe
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
6 changes: 1 addition & 5 deletions casbin/persist/file_adapter/batch_file_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
#include "../../exception/unsupported_operation_exception.h"

// NewAdapter is the constructor for Adapter.
BatchFileAdapter* BatchFileAdapter :: NewAdapter(string file_path) {
BatchFileAdapter* adapter = new BatchFileAdapter;
adapter->file_path = file_path;
adapter->filtered = false;
return adapter;
BatchFileAdapter :: BatchFileAdapter(string file_path): FileAdapter(file_path) {
}

void BatchFileAdapter :: AddPolicies(string sec, string p_type, vector<vector<string>> rules) {
Expand Down
2 changes: 1 addition & 1 deletion casbin/persist/file_adapter/batch_file_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BatchFileAdapter: public BatchAdapter, public FileAdapter {
public:

// NewAdapter is the constructor for Adapter.
static BatchFileAdapter* NewAdapter(string file_path);
BatchFileAdapter(string file_path);

void AddPolicies(string sec, string p_type, vector<vector<string>> rules);

Expand Down
12 changes: 5 additions & 7 deletions casbin/persist/file_adapter/file_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
#include "../../exception/casbin_adapter_exception.h"

// NewAdapter is the constructor for Adapter.
FileAdapter* FileAdapter :: NewAdapter(string file_path) {
FileAdapter* adapter = new FileAdapter;
adapter->file_path = file_path;
adapter->filtered = false;
return adapter;
FileAdapter :: FileAdapter(string file_path) {
this->file_path = file_path;
this->filtered = false;
}

// LoadPolicy loads all policy rules from the storage.
Expand All @@ -34,15 +32,15 @@ void FileAdapter :: SavePolicy(Model* model) {

string tmp;

for (unordered_map<string, Assertion*> :: iterator it = model->m["p"].assertion_map.begin() ; it != model->m["p"].assertion_map.begin() ; it++){
for (unordered_map<string, shared_ptr<Assertion>> :: iterator it = model->m["p"].assertion_map.begin() ; it != model->m["p"].assertion_map.begin() ; it++){
for (int i = 0 ; i < it->second->policy.size() ; i++){
tmp += it->first + ", ";
tmp += ArrayToString(it->second->policy[i]);
tmp += "\n";
}
}

for (unordered_map <string, Assertion*> :: iterator it = model->m["g"].assertion_map.begin() ; it != model->m["g"].assertion_map.begin() ; it++){
for (unordered_map <string, shared_ptr<Assertion>> :: iterator it = model->m["g"].assertion_map.begin() ; it != model->m["g"].assertion_map.begin() ; it++){
for (int i = 0 ; i < it->second->policy.size() ; i++){
tmp += it->first + ", ";
tmp += ArrayToString(it->second->policy[i]);
Expand Down
2 changes: 1 addition & 1 deletion casbin/persist/file_adapter/file_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FileAdapter : virtual public Adapter {
public:

// NewAdapter is the constructor for Adapter.
static FileAdapter* NewAdapter(string file_path);
FileAdapter(string file_path);

// LoadPolicy loads all policy rules from the storage.
void LoadPolicy(Model* model);
Expand Down
7 changes: 2 additions & 5 deletions casbin/persist/file_adapter/filtered_file_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ void FilteredFileAdapter :: loadFilteredPolicyFile(Model* model, Filter* filter,
}

// NewFilteredAdapter is the constructor for FilteredAdapter.
FilteredFileAdapter* FilteredFileAdapter :: NewFilteredAdapter(string file_path) {
FilteredFileAdapter* a = new FilteredFileAdapter;
a->filtered = true;
a->file_path = file_path;
return a;
FilteredFileAdapter :: FilteredFileAdapter(string file_path): FileAdapter(file_path) {
this->filtered = true;
}

// LoadPolicy loads all policy rules from the storage.
Expand Down
2 changes: 1 addition & 1 deletion casbin/persist/file_adapter/filtered_file_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FilteredFileAdapter : public FileAdapter, public FilteredAdapter {
public:

// NewFilteredAdapter is the constructor for FilteredAdapter.
static FilteredFileAdapter* NewFilteredAdapter(string file_path);
FilteredFileAdapter(string file_path);

// LoadPolicy loads all policy rules from the storage.
void LoadPolicy(Model* model);
Expand Down

0 comments on commit 9b56abe

Please sign in to comment.