Skip to content

Commit 30b412a

Browse files
authored
Merge pull request #464 from secure-software-engineering/f-ClangTidyRenameHexastore
clang-tidy: Renames in Hexastore
2 parents 37a106a + 9bdec7f commit 30b412a

3 files changed

Lines changed: 68 additions & 63 deletions

File tree

include/phasar/DB/Hexastore.h

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,29 @@ namespace psr {
2525
/**
2626
* @brief Holds the results of a query to the Hexastore.
2727
*/
28-
struct hs_result {
28+
struct HSResult {
2929
/// Used for the source node.
30-
std::string subject;
30+
std::string Subject;
3131
/// Used for the edge.
32-
std::string predicate;
32+
std::string Predicate;
3333
/// Used for the destination node.
34-
std::string object;
35-
hs_result() = default;
36-
hs_result(std::string s, std::string p, std::string o)
37-
: subject(s), predicate(p), object(o) {}
34+
std::string Object;
35+
HSResult() = default;
36+
HSResult(const std::string Subject, // NOLINT
37+
std::string Predicate, // NOLINT
38+
std::string Object) // NOLINT
39+
: Subject(Subject), Predicate(std::move(Predicate)),
40+
Object(std::move(Object)) {}
3841
/// Prints an entry of the results to the command-line
39-
friend std::ostream &operator<<(std::ostream &os, const hs_result &hsr) {
40-
return os << "[ subject: " << hsr.subject
41-
<< " | predicate: " << hsr.predicate
42-
<< " | object: " << hsr.object << " ]";
42+
friend std::ostream &operator<<(std::ostream &OS, const HSResult &Result) {
43+
return OS << "[ subject: " << Result.Subject
44+
<< " | predicate: " << Result.Predicate
45+
<< " | object: " << Result.Object << " ]";
4346
}
4447

45-
friend bool operator==(const hs_result LHS, const hs_result RHS) {
46-
return LHS.subject == RHS.subject && LHS.predicate == RHS.predicate &&
47-
LHS.object == RHS.object;
48+
friend bool operator==(const HSResult &LHS, const HSResult &RHS) {
49+
return LHS.Subject == RHS.Subject && LHS.Predicate == RHS.Predicate &&
50+
LHS.Object == RHS.Object;
4851
}
4952
};
5053
/**
@@ -67,9 +70,10 @@ struct hs_result {
6770
*/
6871
class Hexastore {
6972
private:
70-
sqlite3 *hs_internal_db{};
71-
static int callback(void *NotUsed, int argc, char **argv, char **azColName);
72-
void doPut(const std::string &query, std::array<std::string, 3> edge);
73+
sqlite3 *HSInternalDB{};
74+
static int callback(void * /*NotUsed*/, int Argc, char **Argv,
75+
char **AzColName);
76+
void doPut(const std::string &Query, std::array<std::string, 3> Edge);
7377

7478
public:
7579
/**
@@ -80,7 +84,8 @@ class Hexastore {
8084
* @brief Constructs a Hexastore under the given filename.
8185
* @param filename Filename of the Hexastore.
8286
*/
83-
Hexastore(const std::string &filename);
87+
Hexastore(const std::string &FileName);
88+
Hexastore(const Hexastore &) = delete;
8489
Hexastore &operator=(const Hexastore &) = delete;
8590

8691
/**
@@ -99,7 +104,7 @@ class Hexastore {
99104
* hexastore.put({{"subject", "predicate", "object"}});
100105
* @param edge New entry in the form of a 3-tuple.
101106
*/
102-
void put(const std::array<std::string, 3> &edge);
107+
void put(const std::array<std::string, 3> &Edge);
103108

104109
/**
105110
* A query is always in the form of a 3-tuple (source, edge, destination)
@@ -116,8 +121,8 @@ class Hexastore {
116121
* @param result_size_hint Used for possible optimization.
117122
* @return An object of hs_result, holding the queried information.
118123
*/
119-
std::vector<hs_result> get(std::array<std::string, 3> EdgeQuery,
120-
size_t ResultSizeHint = 0);
124+
std::vector<HSResult> get(std::array<std::string, 3> EdgeQuery,
125+
size_t ResultSizeHint = 0);
121126
};
122127

123128
} // namespace psr

lib/DB/Hexastore.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ using namespace boost;
1818
namespace psr {
1919

2020
Hexastore::Hexastore(const string &Filename) {
21-
sqlite3_open(Filename.c_str(), &hs_internal_db);
21+
sqlite3_open(Filename.c_str(), &HSInternalDB);
2222
const string Query = INIT;
2323
char *Err;
24-
sqlite3_exec(hs_internal_db, Query.c_str(), callback, nullptr, &Err);
24+
sqlite3_exec(HSInternalDB, Query.c_str(), callback, nullptr, &Err);
2525
if (Err != nullptr) {
2626
cout << Err << "\n\n";
2727
}
2828
}
2929

30-
Hexastore::~Hexastore() { sqlite3_close(hs_internal_db); }
30+
Hexastore::~Hexastore() { sqlite3_close(HSInternalDB); }
3131

32-
int Hexastore::callback(void *NotUsed, int Argc, char **Argv,
32+
int Hexastore::callback(void * /*NotUsed*/, int Argc, char **Argv,
3333
char **AzColName) {
3434
for (int Idx = 0; Idx < Argc; ++Idx) {
3535
cout << AzColName[Idx] << " " << (Argv[Idx] ? Argv[Idx] : "NULL") << endl;
@@ -49,15 +49,15 @@ void Hexastore::put(const array<string, 3> &Edge) {
4949
void Hexastore::doPut(const string &Query, array<string, 3> Edge) {
5050
string CompiledQuery = str(format(Query) % Edge[0] % Edge[1] % Edge[2]);
5151
char *Err;
52-
sqlite3_exec(hs_internal_db, CompiledQuery.c_str(), callback, nullptr, &Err);
52+
sqlite3_exec(HSInternalDB, CompiledQuery.c_str(), callback, nullptr, &Err);
5353
if (Err != nullptr) {
5454
cout << Err;
5555
}
5656
}
5757

58-
vector<hs_result> Hexastore::get(array<string, 3> EdgeQuery,
59-
size_t ResultSizeHint) {
60-
vector<hs_result> Result;
58+
vector<HSResult> Hexastore::get(array<string, 3> EdgeQuery,
59+
size_t ResultSizeHint) {
60+
vector<HSResult> Result;
6161
Result.reserve(ResultSizeHint);
6262
string QueryString;
6363
if (EdgeQuery[0] == "?") {
@@ -93,14 +93,14 @@ vector<hs_result> Hexastore::get(array<string, 3> EdgeQuery,
9393
str(format(QueryString) % EdgeQuery[0] % EdgeQuery[1] % EdgeQuery[2]);
9494
// this lambda will collect all of our results, since it is called on every
9595
// row of the result set
96-
auto SqliteCBResultCollector = [](void *CB, int Argc, char **Argv,
97-
char **AzColName) {
98-
auto *Res = static_cast<vector<hs_result> *>(CB);
96+
auto SqliteCBResultCollector = [](void *CB, int /*Argc*/, char **Argv,
97+
char ** /*AzColName*/) {
98+
auto *Res = static_cast<vector<HSResult> *>(CB);
9999
Res->emplace_back(Argv[0], Argv[1], Argv[2]);
100100
return 0;
101101
};
102102
char *Err;
103-
sqlite3_exec(hs_internal_db, CompiledQuery.c_str(), SqliteCBResultCollector,
103+
sqlite3_exec(HSInternalDB, CompiledQuery.c_str(), SqliteCBResultCollector,
104104
&Result, &Err);
105105
if (Err != nullptr) {
106106
cout << Err;

unittests/DB/HexastoreTest.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ TEST(HexastoreTest, QueryBlankFieldEntries) {
2020
H.put({{"one", "", "four"}});
2121

2222
// query results
23-
hs_result FirstRes("one", "", "");
24-
hs_result SecondRes("one", "", "four");
23+
HSResult FirstRes("one", "", "");
24+
HSResult SecondRes("one", "", "four");
2525

2626
auto Result = H.get({{"one", "", ""}});
2727
ASSERT_EQ(Result.size(), 1U);
@@ -42,13 +42,13 @@ TEST(HexastoreTest, AllQueryTypes) {
4242
H.put({{"peter", "hates", "hexastores"}});
4343
H.put({{"frank", "admires", "bananas"}});
4444

45-
std::vector<hs_result> GroundTruth;
46-
GroundTruth.emplace_back(hs_result("mary", "likes", "hexastores"));
47-
GroundTruth.emplace_back(hs_result("mary", "likes", "apples"));
48-
GroundTruth.emplace_back(hs_result("mary", "hates", "oranges"));
49-
GroundTruth.emplace_back(hs_result("peter", "likes", "apples"));
50-
GroundTruth.emplace_back(hs_result("peter", "hates", "hexastores"));
51-
GroundTruth.emplace_back(hs_result("frank", "admires", "bananas"));
45+
std::vector<HSResult> GroundTruth;
46+
GroundTruth.emplace_back(HSResult("mary", "likes", "hexastores"));
47+
GroundTruth.emplace_back(HSResult("mary", "likes", "apples"));
48+
GroundTruth.emplace_back(HSResult("mary", "hates", "oranges"));
49+
GroundTruth.emplace_back(HSResult("peter", "likes", "apples"));
50+
GroundTruth.emplace_back(HSResult("peter", "hates", "hexastores"));
51+
GroundTruth.emplace_back(HSResult("frank", "admires", "bananas"));
5252

5353
// Does peter hate hexastores? (SPO query in 'spo' tables)
5454
auto Result = H.get({{"peter", "hates", "hexastores"}});
@@ -159,20 +159,20 @@ TEST(HexastoreTest, StoreGraphNoEdgeLabels) {
159159
set<string> Recognized;
160160
map<string, vertex_t> Vertices;
161161

162-
vector<hs_result> ResultSet = HS.get({{"?", "no label", "?"}}, 20);
162+
vector<HSResult> ResultSet = HS.get({{"?", "no label", "?"}}, 20);
163163

164164
for (const auto &Entry : ResultSet) {
165-
if (Recognized.find(Entry.subject) == Recognized.end()) {
166-
Vertices[Entry.subject] = boost::add_vertex(H);
167-
H[Vertices[Entry.subject]].Name = Entry.subject;
165+
if (Recognized.find(Entry.Subject) == Recognized.end()) {
166+
Vertices[Entry.Subject] = boost::add_vertex(H);
167+
H[Vertices[Entry.Subject]].Name = Entry.Subject;
168168
}
169-
if (Recognized.find(Entry.object) == Recognized.end()) {
170-
Vertices[Entry.object] = boost::add_vertex(H);
171-
H[Vertices[Entry.object]].Name = Entry.object;
169+
if (Recognized.find(Entry.Object) == Recognized.end()) {
170+
Vertices[Entry.Object] = boost::add_vertex(H);
171+
H[Vertices[Entry.Object]].Name = Entry.Object;
172172
}
173-
boost::add_edge(Vertices[Entry.subject], Vertices[Entry.object], H);
174-
Recognized.insert(Entry.subject);
175-
Recognized.insert(Entry.object);
173+
boost::add_edge(Vertices[Entry.Subject], Vertices[Entry.Object], H);
174+
Recognized.insert(Entry.Subject);
175+
Recognized.insert(Entry.Object);
176176
}
177177

178178
// boost::print_graph(H, boost::get(&Vertex::name, H));
@@ -246,20 +246,20 @@ TEST(HexastoreTest, StoreGraphWithEdgeLabels) {
246246
graph_t J;
247247
set<string> RecognizedVertices;
248248
map<string, vertex_t> Vertices;
249-
vector<hs_result> HsiRes = HS.get({{"?", "?", "?"}}, 10);
249+
vector<HSResult> HsiRes = HS.get({{"?", "?", "?"}}, 10);
250250
for (const auto &Entry : HsiRes) {
251-
if (RecognizedVertices.find(Entry.subject) == RecognizedVertices.end()) {
252-
Vertices[Entry.subject] = boost::add_vertex(J);
253-
J[Vertices[Entry.subject]].Name = Entry.subject;
251+
if (RecognizedVertices.find(Entry.Subject) == RecognizedVertices.end()) {
252+
Vertices[Entry.Subject] = boost::add_vertex(J);
253+
J[Vertices[Entry.Subject]].Name = Entry.Subject;
254254
}
255-
if (RecognizedVertices.find(Entry.object) == RecognizedVertices.end()) {
256-
Vertices[Entry.object] = boost::add_vertex(J);
257-
J[Vertices[Entry.object]].Name = Entry.object;
255+
if (RecognizedVertices.find(Entry.Object) == RecognizedVertices.end()) {
256+
Vertices[Entry.Object] = boost::add_vertex(J);
257+
J[Vertices[Entry.Object]].Name = Entry.Object;
258258
}
259-
RecognizedVertices.insert(Entry.subject);
260-
RecognizedVertices.insert(Entry.object);
261-
boost::add_edge(Vertices[Entry.subject], Vertices[Entry.object],
262-
Edge(Entry.predicate), J);
259+
RecognizedVertices.insert(Entry.Subject);
260+
RecognizedVertices.insert(Entry.Object);
261+
boost::add_edge(Vertices[Entry.Subject], Vertices[Entry.Object],
262+
Edge(Entry.Predicate), J);
263263
}
264264

265265
// boost::print_graph(J, boost::get(&Vertex::name, J));

0 commit comments

Comments
 (0)