Skip to content

Commit ff1a440

Browse files
committed
Prettify some code
1 parent ede45a2 commit ff1a440

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

libhdt/src/bitsequence/BitSequence375.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,20 @@ void BitSequence375::set(const size_t i, bool val) {
158158
}
159159
if(val) {
160160
#ifdef __EMSCRIPTEN__
161-
/* EDITED BY @lucafabbian, TODO: check */
162-
fprintf(stderr, "[WARN] Unsafe cast called\n");
161+
/* Webassembly size_t differs from the one of
162+
other architectures.
163+
EDITED BY @lucafabbian, TODO: check */
164+
// fprintf(stderr, "[WARN] Unsafe cast called\n");
163165
bitset((uint64_t*) &array[0], i);
164166
#else
165167
bitset(&array[0], i);
166168
#endif
167169
} else {
168170
#ifdef __EMSCRIPTEN__
169-
/* EDITED BY @lucafabbian, TODO: check */
170-
fprintf(stderr, "[WARN] Unsafe cast called\n");
171+
/* Webassembly size_t differs from the one of
172+
other architectures.
173+
EDITED BY @lucafabbian, TODO: check */
174+
// fprintf(stderr, "[WARN] Unsafe cast called\n");
171175
bitclean((uint64_t*)&array[0], i);
172176
#else
173177
bitclean(&array[0], i);
@@ -186,8 +190,10 @@ void BitSequence375::append(bool bit) {
186190
bool BitSequence375::access(const size_t i) const
187191
{
188192
#ifdef __EMSCRIPTEN__
189-
/* EDITED BY @lucafabbian, TODO: check */
190-
fprintf(stderr, "[WARN] Unsafe cast called\n");
193+
/* Webassembly size_t differs from the one of
194+
other architectures.
195+
EDITED BY @lucafabbian, TODO: check */
196+
//fprintf(stderr, "[WARN] Unsafe cast called\n");
191197
return bitget((uint64_t*)array, i);
192198
#else
193199
return bitget(array, i);

libhdt/src/hdt/BasicModifiableHDT.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ BasicModifiableHDT::~BasicModifiableHDT() {
2828

2929
void BasicModifiableHDT::createComponents() {
3030
#ifndef __EMSCRIPTEN__
31-
try{
31+
try {
3232
std::string dictType = spec.get("dictionary.type");
3333
std::string triplesType = spec.get("triples.type");
34-
}
35-
catch (std::exception& e)
36-
{
37-
}
34+
}catch (std::exception& e){ }
3835

3936
#endif
4037

libhdt/src/hdt/HDTSpecification.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,24 @@ const std::string& HDTSpecification::get(const std::string& key) {
6666
const std::string emptyString = "";
6767

6868
const std::string& HDTSpecification::getOrEmpty(const std::string& key) {
69-
if(map.count(key) == 0) return emptyString;
70-
return map.at(key);
69+
70+
/* Webassembly does not play nice with C++
71+
72+
https://emscripten.org/docs/porting/exceptions.html
73+
https://stackoverflow.com/questions/69608789/c-exception-to-exception-less
74+
75+
*/
76+
#ifdef __EMSCRIPTEN__
77+
auto it = map.find(key);
78+
return it == map.end() ? emptyString : it->second;
79+
80+
#else
81+
try {
82+
return map.at(key);
83+
}catch (std::exception& e) {
84+
return emptyString;
85+
}
86+
#endif
7187
}
7288

7389
void HDTSpecification::set(const std::string& key, const std::string& value) {

0 commit comments

Comments
 (0)