-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytearray.cpp
More file actions
executable file
·65 lines (52 loc) · 1.16 KB
/
bytearray.cpp
File metadata and controls
executable file
·65 lines (52 loc) · 1.16 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
#include "bytearray.h"
#include <Arduino.h>
ByteArray::ByteArray(const char* data, int len){
_len = len;
_data = new char[_len];
copyLen(data,_data,_len);
}
ByteArray::ByteArray(const char* data){
_len=strlen(data);
_data = new char[_len];
copyLen(data,_data,_len);
}
ByteArray::ByteArray(const ByteArray& src){
_len = src._len;
_data = new char[_len];
copyLen(src.cdata() ,_data,_len);
}
void ByteArray::copyLen(const char* from, char* to,const int len){
for(int i=0;i<len;i++){
to[i]=from[i];
}
}
void ByteArray::fillLen(char smb, char* to,const int len){
for(int i=0;i<len;i++){
to[i]=smb;
}
}
bool ByteArray::operator==(const ByteArray& other) const{
if(_len!= other._len){
return false;
}
for(int i=0;i<_len;i++){
if(_data[i]!=other._data[i]){
return false;
}
}
return true;
}
ByteArray::ByteArray(int len){
_len = len;
_data = new char[len];
fillLen(0,_data,_len);
}
ByteArray::ByteArray(){
_len = 0;
_data = NULL;
}
ByteArray::~ByteArray(){
if(_data){
delete[] _data;
}
}