-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.cpp
81 lines (61 loc) · 1.5 KB
/
Util.cpp
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
79
80
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>
#include <utility>
#include "3D.h"
#include "Util.hh"
Util::Util(){}
Util::~Util(){}
bool
Util::isLittleEndian(){
short int one =1;
char * byte = (char*) & one;
return (byte[0]?1:0);
}
//reverse the order of elements in an array. n is the actual number of elements, excluding the ending null.
void
Util::reverse(unsigned char * bytes, int n){
/* #ifdef DEBUG
std::cout<<"=====DEBUG INFO====="<<std::endl;
std::cout<<"old array 0x";
for (int i = 0; i< n;i++){
std::cout<<std::setfill('0')<<std::setw(2)<<std::hex<<(int) bytes[i] <<" ";
}
std::cout<<std::endl;
std::cout<<"==END OF DEBUG INFO==\n"<<std::endl;
#endif*/
for(int i = 0; i<n/2; i++){
std::swap(bytes[i], bytes[n-i-1]);
}
/* #ifdef DEBUG
std::cout<<"=====DEBUG INFO====="<<std::endl;
std::cout<<"new array 0x";
for (int i = 0; i< n;i++){
std::cout<<std::setfill('0')<<std::setw(2)<<std::hex<<(int) bytes[i] <<" ";
}
std::cout<<std::endl;
std::cout<<"==END OF DEBUG INFO==\n"<<std::endl;
#endif*/
}
void
Util::print_mat(const matrix_unit * matrix){
for(int i = 0; i <4; i++){
for(int j = 0; j<4; j++){
std::cout<<matrix->mat[i][j]<< " ";
}
std::cout<<std::endl;
}
}
void
Util::debug_head(std::string filename){
//#ifdef DEBUG
std::cout<<"=====DEBUG INFO====="<<std::endl;
std::cout<<"file:"<<filename<<std::endl;
}
void
Util::debug_tail(){
std::cout<<"==END OF DEBUG INFO==\n"<<std::endl;
//#endif
}