-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixel_cpp.h
More file actions
60 lines (45 loc) · 1.53 KB
/
Copy pathPixel_cpp.h
File metadata and controls
60 lines (45 loc) · 1.53 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
#ifndef PIXEL_CPP
#define PIXEL_CPP
#include "Pixel.h"
#include <iostream>
#include <cstring>
using namespace std;
// Default Constructor
Pixel::Pixel() : red(0), green(0), blue(0) {};
// One parameter Constructor
Pixel::Pixel(const Pixel& T) : red(T.red), green(T.green), blue(T.blue) {};
// Three parameter Constructor
Pixel::Pixel(unsigned int Red, unsigned int Green, unsigned int Blue) : red(Red), green(Green), blue(Blue) {};
// Destructor
Pixel::~Pixel() {};
// Indexing Operator (const)
const unsigned int& Pixel::operator[](const char* i) const {
if (strcmp(i, "red") == 0) return red;
else if (strcmp(i, "green") == 0) return green;
else if (strcmp(i, "blue") == 0) return blue;
else {
throw InputOutOfBoundsException("Invalid pixel component", i);
}
}
// Indexing Operator
unsigned int& Pixel::operator[](const char* i) {
if (strcmp(i, "red") == 0) return red;
else if (strcmp(i, "green") == 0) return green;
else if (strcmp(i, "blue") == 0) return blue;
else {
throw InputOutOfBoundsException("Invalid pixel component", i);
}
}
// InputOutOfBoundsException Class
// Constructor
Pixel::InputOutOfBoundsException::InputOutOfBoundsException(const char* err, const char* index)
: errorMessage(err), offendingIndex(index) {}
// Return error message
const char* Pixel::InputOutOfBoundsException::returnError() const {
return errorMessage;
}
// Return offending index
const char* Pixel::InputOutOfBoundsException::returnOffendingIndex() const {
return offendingIndex;
}
#endif