-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
78 lines (61 loc) · 1.44 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Helper functions
#ifndef UTIL_H
#define UTIL_H
//#define DEBUG_MODE
#ifdef DEBUG_MODE
#define DEBUG(code) code
#else
#define DEBUG(code)
#endif
#include <iostream>
#include <boost/program_options.hpp>
#include "Data.h"
namespace po = boost::program_options;
struct init_parameters
{
std::vector<std::string> inputfile_buffer, message_buffer;
std::string message, inputfile;
int eclevel;
void parse(int argc, char* argv[]);
};
struct varNum
{
varNum() : dat(0), len(0){};
varNum(unsigned short data, short length)
: dat(data), len(length){};
unsigned short dat;
short len;
};
struct qrInfo
{
Byte mask;
int version, size;
Err_Level error_level;
Encoding encoding;
};
Byte c2alpha(const char t);
void printLongBit(std::vector<bool>& vec);
void pushBits(unsigned data, std::vector<bool>& vec, int amount);
std::ostream& operator<<(std::ostream& stream, const varNum& num);
template<typename T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& vec);
template<typename C> bool isAlphaNum(const C t)
{
if (t > 255) return false;
switch (t){
case ' ': case '$': case '%': case '*':
case '+': case '-': case '.': case '/':
case ':': return true;
default:
if (isdigit(t)) return true;
return isupper(t) && isalpha(t);
}
}
template<typename T> void printBit(const T data)
{
for (T p = (T)0x1 << (sizeof(data) * 8 - 1); p; p >>= 1){
std::cout << (p & data ? 1 : 0);
}
std::cout << '\n';
}
#endif // UTIL_H