Skip to content

Commit 28046f8

Browse files
committed
Added external dependencies
1 parent e772c8a commit 28046f8

94 files changed

Lines changed: 37617 additions & 107 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Makevars

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#ifndef _MACARON_BASE64_H_
2+
#define _MACARON_BASE64_H_
3+
4+
/**
5+
* The MIT License (MIT)
6+
* Copyright (c) 2016 tomykaira
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining
9+
* a copy of this software and associated documentation files (the
10+
* "Software"), to deal in the Software without restriction, including
11+
* without limitation the rights to use, copy, modify, merge, publish,
12+
* distribute, sublicense, and/or sell copies of the Software, and to
13+
* permit persons to whom the Software is furnished to do so, subject to
14+
* the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be
17+
* included in all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
#include <cstdint>
29+
#include <string>
30+
31+
namespace macaron {
32+
33+
class Base64 {
34+
public:
35+
36+
static std::string Encode(const std::string data) {
37+
static constexpr char sEncodingTable[] = {
38+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
39+
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
40+
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
41+
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
42+
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
43+
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
44+
'w', 'x', 'y', 'z', '0', '1', '2', '3',
45+
'4', '5', '6', '7', '8', '9', '+', '/'
46+
};
47+
48+
size_t in_len = data.size();
49+
size_t out_len = 4 * ((in_len + 2) / 3);
50+
std::string ret(out_len, '\0');
51+
size_t i;
52+
char *p = const_cast<char*>(ret.c_str());
53+
54+
for (i = 0; i < in_len - 2; i += 3) {
55+
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
56+
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
57+
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)];
58+
*p++ = sEncodingTable[data[i + 2] & 0x3F];
59+
}
60+
if (i < in_len) {
61+
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
62+
if (i == (in_len - 1)) {
63+
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
64+
*p++ = '=';
65+
}
66+
else {
67+
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
68+
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
69+
}
70+
*p++ = '=';
71+
}
72+
73+
return ret;
74+
}
75+
76+
static std::string Decode(const std::string& input, std::string& out) {
77+
static constexpr unsigned char kDecodingTable[] = {
78+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
79+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
80+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
81+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
82+
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
83+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
84+
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
85+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
86+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
87+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
88+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
89+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
90+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
91+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
92+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
93+
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
94+
};
95+
96+
size_t in_len = input.size();
97+
if (in_len % 4 != 0) return "Input data size is not a multiple of 4";
98+
99+
size_t out_len = in_len / 4 * 3;
100+
if (input[in_len - 1] == '=') out_len--;
101+
if (input[in_len - 2] == '=') out_len--;
102+
103+
out.resize(out_len);
104+
105+
for (size_t i = 0, j = 0; i < in_len;) {
106+
uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
107+
uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
108+
uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
109+
uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
110+
111+
uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6);
112+
113+
if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF;
114+
if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF;
115+
if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF;
116+
}
117+
118+
return "";
119+
}
120+
121+
};
122+
123+
}
124+
125+
#endif /* _MACARON_BASE64_H_ */
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* IXBench.cpp
3+
* Author: Benjamin Sergeant
4+
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
5+
*/
6+
7+
#include "IXBench.h"
8+
9+
#include <iostream>
10+
11+
namespace ix
12+
{
13+
Bench::Bench(const std::string& description)
14+
: _description(description)
15+
{
16+
reset();
17+
}
18+
19+
Bench::~Bench()
20+
{
21+
if (!_reported)
22+
{
23+
report();
24+
}
25+
}
26+
27+
void Bench::reset()
28+
{
29+
_start = std::chrono::high_resolution_clock::now();
30+
_reported = false;
31+
}
32+
33+
void Bench::report()
34+
{
35+
auto now = std::chrono::high_resolution_clock::now();
36+
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now - _start);
37+
38+
_duration = microseconds.count();
39+
std::cerr << _description << " completed in " << _duration << " us" << std::endl;
40+
41+
setReported();
42+
}
43+
44+
void Bench::record()
45+
{
46+
auto now = std::chrono::high_resolution_clock::now();
47+
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now - _start);
48+
49+
_duration = microseconds.count();
50+
}
51+
52+
void Bench::setReported()
53+
{
54+
_reported = true;
55+
}
56+
57+
uint64_t Bench::getDuration() const
58+
{
59+
return _duration;
60+
}
61+
} // namespace ix
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* IXBench.h
3+
* Author: Benjamin Sergeant
4+
* Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved.
5+
*/
6+
#pragma once
7+
8+
#include <chrono>
9+
#include <cstdint>
10+
#include <string>
11+
12+
namespace ix
13+
{
14+
class Bench
15+
{
16+
public:
17+
Bench(const std::string& description);
18+
~Bench();
19+
20+
void reset();
21+
void record();
22+
void report();
23+
void setReported();
24+
uint64_t getDuration() const;
25+
26+
private:
27+
std::string _description;
28+
std::chrono::time_point<std::chrono::high_resolution_clock> _start;
29+
uint64_t _duration;
30+
bool _reported;
31+
};
32+
} // namespace ix
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* IXCancellationRequest.cpp
3+
* Author: Benjamin Sergeant
4+
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
5+
*/
6+
7+
#include "IXCancellationRequest.h"
8+
9+
#include <cassert>
10+
#include <chrono>
11+
12+
namespace ix
13+
{
14+
CancellationRequest makeCancellationRequestWithTimeout(
15+
int secs, std::atomic<bool>& requestInitCancellation)
16+
{
17+
assert(secs > 0);
18+
19+
auto start = std::chrono::system_clock::now();
20+
auto timeout = std::chrono::seconds(secs);
21+
22+
auto isCancellationRequested = [&requestInitCancellation, start, timeout]() -> bool {
23+
// Was an explicit cancellation requested ?
24+
if (requestInitCancellation) return true;
25+
26+
auto now = std::chrono::system_clock::now();
27+
if ((now - start) > timeout) return true;
28+
29+
// No cancellation request
30+
return false;
31+
};
32+
33+
return isCancellationRequested;
34+
}
35+
} // namespace ix
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* IXCancellationRequest.h
3+
* Author: Benjamin Sergeant
4+
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
5+
*/
6+
7+
#pragma once
8+
9+
#include <atomic>
10+
#include <functional>
11+
12+
namespace ix
13+
{
14+
using CancellationRequest = std::function<bool()>;
15+
16+
CancellationRequest makeCancellationRequestWithTimeout(
17+
int seconds, std::atomic<bool>& requestInitCancellation);
18+
} // namespace ix

0 commit comments

Comments
 (0)