Skip to content

Commit

Permalink
Fix compilation with C++98
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Nov 10, 2024
1 parent 9f50590 commit 520b1f7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ Event::Event(Event::Type type, int id, const std::string& msg, clock_t evtTime)
_hashType = NO_HASH;
}

Event::Event(Event::Type type, int id, int64 size, clock_t evtTime, uint64 hash, HashType hashType)
Event::Event(Event::Type type, int id, int64 size, clock_t evtTime, uint64 hash, HashType hashType, int64 offset)
: _type(type)
, _time(evtTime)
, _id(id)
, _size(size)
, _offset(offset)
, _hash(hash)
, _hashType(hashType)
{
Expand Down
5 changes: 4 additions & 1 deletion src/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace kanzi

Event(Type type, int id, const std::string& msg, clock_t evtTime = 0);

Event(Type type, int id, int64 size, clock_t evtTime, uint64 hash = 0, HashType hashType = NO_HASH);
Event(Type type, int id, int64 size, clock_t evtTime, uint64 hash = 0, HashType hashType = NO_HASH, int64 offset = -1);

virtual ~Event() {}

Expand All @@ -63,6 +63,8 @@ namespace kanzi

uint64 getHash() const { return _hashType != NO_HASH ? _hash : 0; }

int64 getOffset() const { return _offset; }

HashType getHashType() const { return _hashType; }

std::string toString() const;
Expand All @@ -73,6 +75,7 @@ namespace kanzi
std::string _msg;
int _id;
int64 _size;
int64 _offset;
uint64 _hash;
HashType _hashType;
};
Expand Down
15 changes: 1 addition & 14 deletions src/io/CompressedInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -878,20 +878,7 @@ T DecodingTask<T>::run()
if (_listeners.size() > 0) {
#if !defined(_MSC_VER) || _MSC_VER > 1500
if (_ctx.getInt("verbosity", 0) > 4) {
char buf1[9] = { 0 };
uint8 sf = uint8(skipFlags);

for (int i = 7; i >= 0; i--) {
buf1[i] = (sf & 1) ? '1' : '0';
sf >>= 1;
}

// Create message (use snprintf because stringstream is too slow)
char buf2[100];
snprintf(buf2, sizeof(buf2),
"{ \"type\":\"%s\", \"id\":%d, \"offset\":%lli, \"skipFlags\":%s }",
"BLOCK_INFO", blockId, (long long)blockOffset, buf1);
Event evt1(Event::BLOCK_INFO, blockId, string(buf2));
Event evt1(Event::BLOCK_INFO, blockId, int64(r), clock(), checksum1, hashType, blockOffset);
CompressedInputStream::notifyListeners(_listeners, evt1);
}
#endif
Expand Down
17 changes: 3 additions & 14 deletions src/io/CompressedOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.

#include <algorithm>
#include <sstream>
#include <stdio.h>
#include "CompressedOutputStream.hpp"
#include "IOException.hpp"
#include "../Error.hpp"
Expand Down Expand Up @@ -779,20 +780,8 @@ T EncodingTask<T>::run()
}

const int64 blockOffset = (oName != "NONE") ? _obs->tell() : _obs->written();
char buf1[9] = { 0 };
uint8 sf = uint8(skipFlags);

for (int i = 7; i >= 0; i--) {
buf1[i] = (sf & 1) ? '1' : '0';
sf >>= 1;
}

// Create message (use snprintf because stringstream is too slow)
char buf2[100];
snprintf(buf2, sizeof(buf2),
"{ \"type\":\"%s\", \"id\":%d, \"offset\":%lli, \"skipFlags\":%s }",
"BLOCK_INFO", blockId, (long long)blockOffset, buf1);
Event evt2(Event::BLOCK_INFO, blockId, string(buf2));
Event evt2(Event::BLOCK_INFO, blockId,
int64((written + 7) >> 3), clock(), checksum, hashType, blockOffset);
CompressedOutputStream::notifyListeners(_listeners, evt2);
}
#endif
Expand Down
20 changes: 13 additions & 7 deletions src/util/XXHash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ namespace kanzi
class XXHash32
{
private:
enum PrimeSeeds {
PRIME32_1 = uint32(-1640531535),
PRIME32_2 = uint32(-2048144777),
PRIME32_3 = uint32(-1028477379),
PRIME32_4 = uint32(668265263),
PRIME32_5 = uint32(374761393)
};
#if __cplusplus >= 201103L
static constexpr uint32 PRIME32_1 = uint32(-1640531535);
static constexpr uint32 PRIME32_2 = uint32(-2048144777);
static constexpr uint32 PRIME32_3 = uint32(-1028477379);
static constexpr uint32 PRIME32_4 = uint32(668265263);
static constexpr uint32 PRIME32_5 = uint32(374761393);
#else
static const uint32 PRIME32_1 = uint32(-1640531535);
static const uint32 PRIME32_2 = uint32(-2048144777);
static const uint32 PRIME32_3 = uint32(-1028477379);
static const uint32 PRIME32_4 = uint32(668265263);
static const uint32 PRIME32_5 = uint32(374761393);
#endif

int _seed;

Expand Down

0 comments on commit 520b1f7

Please sign in to comment.