Skip to content

Commit 683aefe

Browse files
committed
fixing up todo comments; other code cleanup
1 parent 3f82cf7 commit 683aefe

14 files changed

+78
-93
lines changed

jsonld-cpp/CMakeLists.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ set_target_properties(jsonld-cpp PROPERTIES CXX_EXTENSIONS OFF)
107107

108108
# Set version
109109

110-
target_compile_definitions(jsonld-cpp PRIVATE -DJSONLDCPP_VERSION_MAJOR=${JSONLDCPP_VERSION_MAJOR})
111-
target_compile_definitions(jsonld-cpp PRIVATE -DJSONLDCPP_VERSION_MINOR=${JSONLDCPP_VERSION_MINOR})
112-
target_compile_definitions(jsonld-cpp PRIVATE -DJSONLDCPP_VERSION_PATCH=${JSONLDCPP_VERSION_PATCH})
110+
target_compile_definitions(jsonld-cpp PRIVATE -DJSONLDCPP_VERSION=${JSONLDCPP_VERSION})
113111

114112
if(JSONLDCPP_BUILD_TESTS)
115113
enable_testing()

jsonld-cpp/Context.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ class Context {
6161

6262
std::string getDefaultBaseDirection() const; // used by expansion processor
6363

64-
const JsonLdOptions &getOptions() const;// used by expansion processor
64+
const JsonLdOptions &getOptions() const;// used by context and expansion processor
6565

6666
void setDefaultBaseDirection(const std::string & direction); // used by context processor
6767

68-
const nlohmann::ordered_json &getTermDefinitions() const;
68+
const nlohmann::ordered_json &getTermDefinitions() const; // used by context processor
6969

70-
nlohmann::ordered_json &getTermDefinitions() ;
70+
nlohmann::ordered_json &getTermDefinitions(); // used by context processor
7171
};
7272

7373
#endif //LIBJSONLD_CPP_CONTEXT_H

jsonld-cpp/ContextProcessor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef JSONLD_CPP_LIBRARY_CONTEXTPROCESSOR_H
2-
#define JSONLD_CPP_LIBRARY_CONTEXTPROCESSOR_H
1+
#ifndef LIBJSONLD_CPP_CONTEXTPROCESSOR_H
2+
#define LIBJSONLD_CPP_CONTEXTPROCESSOR_H
33

44
#include "jsonld-cpp/Context.h"
55
#include "jsonld-cpp/jsoninc.h"
@@ -38,4 +38,4 @@ struct ContextProcessor {
3838
};
3939

4040

41-
#endif //JSONLD_CPP_LIBRARY_CONTEXTPROCESSOR_H
41+
#endif //LIBJSONLD_CPP_CONTEXTPROCESSOR_H

jsonld-cpp/ExpansionProcessor.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,15 @@ namespace {
281281
return activeContext;
282282
}
283283

284-
void expandObjectElement_step13(const std::string *activeProperty, const json &element, const std::string &baseUrl,
285-
Context &typeScopedContext, const std::string &inputType, Context &activeContext, json &result,
286-
json &nests);
284+
void expandObjectElement_step13(
285+
const std::string *activeProperty, const json &element, const std::string &baseUrl,
286+
Context &typeScopedContext, const std::string &inputType, Context &activeContext, json &result,
287+
json &nests);
287288

288-
void expandObjectElement_step14(Context &activeContext, const std::string *activeProperty, const json &element,
289-
const std::string &baseUrl, Context &typeScopedContext, json &result,
290-
json &nests, const std::string &inputType);
289+
void expandObjectElement_step14(
290+
Context &activeContext, const json &element,
291+
const std::string &baseUrl, Context &typeScopedContext, json &result,
292+
json &nests, const std::string &inputType);
291293

292294
json expandObjectElement(
293295
Context activeContext,
@@ -366,7 +368,7 @@ namespace {
366368

367369
// 14)
368370
// For each key nesting-key in nests, ordered lexicographically if ordered is true:
369-
expandObjectElement_step14(activeContext, activeProperty, element, baseUrl, typeScopedContext, result,
371+
expandObjectElement_step14(activeContext, element, baseUrl, typeScopedContext, result,
370372
nests, inputType);
371373

372374
// 15)
@@ -1009,7 +1011,7 @@ namespace {
10091011
for (json::iterator it = element_value.begin(); it != element_value.end(); ++it) {
10101012
value_keys.push_back(it.key());
10111013
}
1012-
// todo: if I comment the next line then I fix 7 tests, but that doesn't seem right
1014+
10131015
if(activeContext.getOptions().isOrdered())
10141016
std::sort(value_keys.begin(), value_keys.end());
10151017

@@ -1349,7 +1351,7 @@ namespace {
13491351
}
13501352
}
13511353

1352-
void expandObjectElement_step14(Context &activeContext, const std::string *activeProperty, const json &element,
1354+
void expandObjectElement_step14(Context &activeContext, const json &element,
13531355
const std::string &baseUrl, Context &typeScopedContext, json &result,
13541356
json &nests, const std::string &inputType) {
13551357
// 14)
@@ -1421,7 +1423,7 @@ namespace {
14211423

14221424
// 14)
14231425
// For each key nesting-key in nests, ordered lexicographically if ordered is true:
1424-
expandObjectElement_step14(copyActiveContext, &nestingKey, nestedValue, baseUrl, typeScopedContext, result,
1426+
expandObjectElement_step14(copyActiveContext, nestedValue, baseUrl, typeScopedContext, result,
14251427
localNests, inputType);
14261428

14271429
}
@@ -1450,7 +1452,7 @@ json ExpansionProcessor::expand(
14501452
// 2)
14511453
// If active property is @default, initialize the frameExpansion flag to false.
14521454
if (activeProperty != nullptr && *activeProperty == JsonLdConsts::DEFAULT) {
1453-
//todo: activeContext.getOptions().setFrameExpansion(false);
1455+
// todo: activeContext.getOptions().setFrameExpansion(false);
14541456
}
14551457

14561458
// 3)

jsonld-cpp/ExpansionProcessor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef JSONLD_CPP_LIBRARY_EXPANSIONPROCESSOR_H
2-
#define JSONLD_CPP_LIBRARY_EXPANSIONPROCESSOR_H
1+
#ifndef LIBJSONLD_CPP_EXPANSIONPROCESSOR_H
2+
#define LIBJSONLD_CPP_EXPANSIONPROCESSOR_H
33

44
#include "jsonld-cpp/jsoninc.h"
55

@@ -34,4 +34,4 @@ struct ExpansionProcessor {
3434
};
3535

3636

37-
#endif //JSONLD_CPP_LIBRARY_EXPANSIONPROCESSOR_H
37+
#endif //LIBJSONLD_CPP_EXPANSIONPROCESSOR_H

jsonld-cpp/JsonLdOptions.cpp

+24-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
#include "jsonld-cpp/JsonLdOptions.h"
22

3-
4-
// definitions needed here for static members (though not necessary in c++17)
5-
//constexpr const char JsonLdOptions::JSON_LD_1_0[];
6-
//constexpr const char JsonLdOptions::JSON_LD_1_1[];
7-
//constexpr bool JsonLdOptions::DEFAULT_COMPACT_ARRAYS;
8-
9-
bool JsonLdOptions::isFrameExpansion() const {
10-
return frameExpansion_;
11-
}
12-
13-
void JsonLdOptions::setFrameExpansion(bool frameExpansion) {
14-
frameExpansion_ = frameExpansion;
15-
}
16-
17-
bool JsonLdOptions::isOrdered() const {
18-
return ordered_;
19-
}
20-
21-
void JsonLdOptions::setOrdered(bool ordered) {
22-
ordered_ = ordered;
23-
}
24-
25-
const std::string &JsonLdOptions::getHashAlgorithm() const {
26-
return hashAlgorithm_;
27-
}
28-
29-
void JsonLdOptions::setHashAlgorithm(const std::string &hashAlgorithm) {
30-
hashAlgorithm_ = hashAlgorithm;
31-
}
3+
//
4+
//bool JsonLdOptions::isFrameExpansion() const {
5+
// return frameExpansion_;
6+
//}
7+
//
8+
//void JsonLdOptions::setFrameExpansion(bool frameExpansion) {
9+
// frameExpansion_ = frameExpansion;
10+
//}
11+
//
12+
//bool JsonLdOptions::isOrdered() const {
13+
// return ordered_;
14+
//}
15+
//
16+
//void JsonLdOptions::setOrdered(bool ordered) {
17+
// ordered_ = ordered;
18+
//}
19+
//
20+
//const std::string &JsonLdOptions::getHashAlgorithm() const {
21+
// return hashAlgorithm_;
22+
//}
23+
//
24+
//void JsonLdOptions::setHashAlgorithm(const std::string &hashAlgorithm) {
25+
// hashAlgorithm_ = hashAlgorithm;
26+
//}
3227
//todo: why are these functions defined here? can they just all be in the header file?

jsonld-cpp/JsonLdOptions.h

+18-9
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,21 @@ class JsonLdOptions {
159159
return *this;
160160
}
161161

162-
bool isFrameExpansion() const;
162+
bool isFrameExpansion() const {
163+
return frameExpansion_;
164+
}
163165

164-
void setFrameExpansion(bool frameExpansion);
166+
void setFrameExpansion(bool frameExpansion) {
167+
frameExpansion_ = frameExpansion;
168+
}
165169

166-
bool isOrdered() const;
170+
bool isOrdered() const {
171+
return ordered_;
172+
}
167173

168-
void setOrdered(bool ordered);
174+
void setOrdered(bool ordered) {
175+
ordered_ = ordered;
176+
}
169177

170178
bool getCompactArrays() const {
171179
return compactArrays_;
@@ -197,9 +205,6 @@ class JsonLdOptions {
197205

198206
void setProcessingMode(const std::string& processingMode) {
199207
this->processingMode_ = processingMode;
200-
// if (processingMode == JsonLdConsts::JSON_LD_1_1) {
201-
// omitGraph_ = true;
202-
// }
203208
}
204209

205210
std::string getBase() const {
@@ -250,9 +255,13 @@ class JsonLdOptions {
250255
this->documentLoader_ = std::move(documentLoader);
251256
}
252257

253-
const std::string &getHashAlgorithm() const;
258+
const std::string &getHashAlgorithm() const {
259+
return hashAlgorithm_;
260+
}
254261

255-
void setHashAlgorithm(const std::string &hashAlgorithm);
262+
void setHashAlgorithm(const std::string &hashAlgorithm) {
263+
hashAlgorithm_ = hashAlgorithm;
264+
}
256265

257266
};
258267

jsonld-cpp/JsonLdProcessor.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ RDFDataset JsonLdProcessor::toRDF(const std::string& documentLocation, JsonLdOpt
127127

128128
// 1)
129129
// Create a new Promise promise and return it. The following steps are then deferred.
130-
// Note: we do not feel Promises are appropriate in this spec
131-
// todo: word more nicely and make sure you denote personal notes from spec notes
130+
// Note: the current implementation of jsonld-cpp does not use Promises.
132131

133132
// 2)
134133
// Set expanded input to the result of using the expand() method using input and options

jsonld-cpp/RDFSerializationProcessor.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ namespace {
161161
if (!graph.contains(id)) {
162162
json tmp = { { JsonLdConsts::ID, id } };
163163
graph[id] = tmp;
164-
// knowing the insertion order comes in handy later in RDFDataset::graphToRDF()
165-
// todo: does it still come in handy?
166-
graph["key_insertion_order"].push_back(id);
167164
}
168165
// 6.4)
169166
// Reference the value of the id entry of graph using the variable node.
@@ -653,9 +650,7 @@ namespace {
653650
// For each subject and node in graph ordered by subject:
654651
std::vector<std::string> subjects;
655652
for (auto& el : graph.items()) {
656-
// skip the key_insertion_order helper we added in generateNodeMap()
657-
if(el.key() != "key_insertion_order") // todo: do i still need to bother with the key insertion order?
658-
subjects.push_back(el.key());
653+
subjects.push_back(el.key());
659654
}
660655
std::sort(subjects.begin(), subjects.end());
661656

jsonld-cpp/RDFSerializationProcessor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef JSONLD_CPP_LIBRARY_RDFSERIALIZATIONPROCESSOR_H
2-
#define JSONLD_CPP_LIBRARY_RDFSERIALIZATIONPROCESSOR_H
1+
#ifndef LIBJSONLD_CPP_RDFSERIALIZATIONPROCESSOR_H
2+
#define LIBJSONLD_CPP_RDFSERIALIZATIONPROCESSOR_H
33

44
#include "jsonld-cpp/jsoninc.h"
55

@@ -28,4 +28,4 @@ struct RDFSerializationProcessor {
2828
};
2929

3030

31-
#endif //JSONLD_CPP_LIBRARY_RDFSERIALIZATIONPROCESSOR_H
31+
#endif //LIBJSONLD_CPP_RDFSERIALIZATIONPROCESSOR_H

jsonld-cpp/WellFormed.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <regex>
22
#include "WellFormed.h"
33
#include "JsonLdUtils.h"
4-
#include "BlankNodeNames.h"
54
#include "RDFRegex.h"
65

76
bool WellFormed::iri(const std::string &str) {
@@ -14,13 +13,6 @@ bool WellFormed::blankNodeIdentifier(const std::string &str) {
1413
return std::regex_match(str, match, re);
1514
}
1615

17-
/**
18-
* Check if str is a well-formed language.
19-
*
20-
*
21-
* @param str
22-
* @return
23-
*/
2416
bool WellFormed::language(const std::string &str) {
2517
// The JSON-LD spec mentions in several places that a "language is
2618
// well-formed according to section 2.2.9 of [BCP47]" and BCP47 contains
@@ -33,7 +25,6 @@ bool WellFormed::language(const std::string &str) {
3325
return std::regex_match(str, match, re);
3426
}
3527

36-
3728
bool WellFormed::literal(const std::string &str) {
3829
std::regex re(RDFRegex::LITERAL);
3930
std::smatch match;
@@ -56,4 +47,3 @@ bool WellFormed::rdf_graph_name(const std::string &str) {
5647
return iri(str) || blankNodeIdentifier(str);
5748
}
5849

59-

jsonld-cpp/WellFormed.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef JSONLD_CPP_LIBRARY_WELLFORMED_H
2-
#define JSONLD_CPP_LIBRARY_WELLFORMED_H
1+
#ifndef LIBJSONLD_CPP_WELLFORMED_H
2+
#define LIBJSONLD_CPP_WELLFORMED_H
33

44

55
#include <string>
@@ -101,4 +101,4 @@ class WellFormed {
101101
};
102102

103103

104-
#endif //JSONLD_CPP_LIBRARY_WELLFORMED_H
104+
#endif //LIBJSONLD_CPP_WELLFORMED_H

jsonld-cpp/jsoninc.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#pragma GCC diagnostic ignored "-Wall"
1313
#pragma GCC diagnostic ignored "-Wextra"
1414
#define JSON_USE_IMPLICIT_CONVERSIONS 0
15+
#define JSON_USE_GLOBAL_UDLS 0
1516
#include "jsonld-cpp/json.hpp"
1617
#pragma clang diagnostic pop
1718
#pragma GCC diagnostic pop

jsonld-cpp/test/testjsonld-cpp/test_ObjectComparisons.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ namespace {
107107
};
108108

109109
// sort order should be: A < C < B ... similar to literals < blanknode < IRI
110-
struct BasePtrLess :
111-
public std::binary_function<const std::shared_ptr<Base>, const std::shared_ptr<Base>, bool> {
110+
struct BasePtrLess {
112111
bool operator()(const std::shared_ptr<Base> & ps1, const std::shared_ptr<Base> & ps2) const {
113112
if(ps1->isB()) {
114113
if(!ps2->isB())
@@ -128,22 +127,19 @@ namespace {
128127
}
129128
};
130129

131-
struct APtrLess :
132-
public std::binary_function<const std::shared_ptr<A>, const std::shared_ptr<A>, bool> {
130+
struct APtrLess {
133131
bool operator()(const std::shared_ptr<A> & ps1, const std::shared_ptr<A> & ps2) const {
134132
return ps1->getValue() < ps2->getValue();
135133
}
136134
};
137135

138-
struct BPtrLess :
139-
public std::binary_function<const std::shared_ptr<B>, const std::shared_ptr<B>, bool> {
136+
struct BPtrLess {
140137
bool operator()(const std::shared_ptr<B> & ps1, const std::shared_ptr<B> & ps2) const {
141138
return ps1->getValue() < ps2->getValue();
142139
}
143140
};
144141

145-
struct CPtrLess :
146-
public std::binary_function<const std::shared_ptr<C>, const std::shared_ptr<C>, bool> {
142+
struct CPtrLess {
147143
bool operator()(const std::shared_ptr<C> & ps1, const std::shared_ptr<C> & ps2) const {
148144
return ps1->getValue() < ps2->getValue();
149145
}

0 commit comments

Comments
 (0)