-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathece2400-stdlib.h
More file actions
104 lines (76 loc) · 2.83 KB
/
Copy pathece2400-stdlib.h
File metadata and controls
104 lines (76 loc) · 2.83 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//========================================================================
// ece2400-stdlib.h
//========================================================================
// Utility functions and classes for PA4.
//
// Author: Yanghui Ou
// Date: Oct 28, 2019
#ifndef ECE2400_STDLIB_H
#define ECE2400_STDLIB_H
#include <string>
namespace ece2400 {
//------------------------------------------------------------------------
// Exception
//------------------------------------------------------------------------
// Base class for exceptions.
class Exception {
};
//------------------------------------------------------------------------
// OutOfRangeException
//------------------------------------------------------------------------
// Exception for out of range access.
class OutOfRange : Exception {
public:
OutOfRange();
OutOfRange( const char* err_msg );
std::string to_str() const;
private:
std::string m_err_msg;
};
//------------------------------------------------------------------------
// InvalidArgumentException
//------------------------------------------------------------------------
// Exception for out of range access.
class InvalidArgument : Exception {
public:
InvalidArgument();
InvalidArgument( const char* err_msg );
std::string to_str() const;
private:
std::string m_err_msg;
};
//------------------------------------------------------------------------
// abs_diff
//------------------------------------------------------------------------
// Absolute comparison suitable for comparing integers and images.
template < typename T >
int abs_dist( const T& a, const T& b );
//------------------------------------------------------------------------
// log2
//------------------------------------------------------------------------
// Return nearest log base 2.
int log2( int x );
//------------------------------------------------------------------------
// print_array
//------------------------------------------------------------------------
// Prints the contents in an integer array.
void print_array( int* a, size_t size );
//------------------------------------------------------------------------
// sort
//------------------------------------------------------------------------
// Sorts an array of integer in ascending order using std::sort.
void sort( int* a, size_t size );
//------------------------------------------------------------------------
// timer_reset
//------------------------------------------------------------------------
// Resets the timer.
void timer_reset();
//------------------------------------------------------------------------
// timer_get_elapsed
//------------------------------------------------------------------------
// Return the elapsed time in seconds.
double timer_get_elapsed();
} // namespace ece2400
// Inline and template definitions
#include "ece2400-stdlib.inl"
#endif