Infrared4Arduino
IrSequence.cpp
Go to the documentation of this file.
1 #include "IrSequence.h"
2 #include <string.h>
3 
4 IrSequence::IrSequence() : durations(NULL), length(0U), toBeFreed(false) {
5 };
6 
7 IrSequence::IrSequence(const microseconds_t *durations_, size_t length_, boolean toBeFreed_)
8 : durations(durations_), length(length_), toBeFreed(toBeFreed_) {
9 }
10 
11 IrSequence::IrSequence(const IrSequence& orig) : durations(orig.durations), length(orig.length), toBeFreed(orig.toBeFreed) {
12 };
13 
14 IrSequence::IrSequence(const IrSequence& orig, boolean toBeFreed_) : durations(orig.durations), length(orig.length), toBeFreed(toBeFreed_) {
15 };
16 
18  if (toBeFreed)
19  delete [] durations;
20 }
21 
23  microseconds_t *durationsClone = new microseconds_t[length];
24  memcpy(durationsClone, durations, length*sizeof(microseconds_t));
25  return new IrSequence(durationsClone, length, true);
26 }
27 
28 void IrSequence::dump(Stream& stream, boolean usingSigns) const {
29  for (unsigned int i = 0U; i < length; i++) {
30  if (i > 0U)
31  stream.print(' ');
32  if (usingSigns)
33  stream.print((i & 1) ? '-' : '+');
34  stream.print(durations[i], DEC);
35  }
36  stream.println();
37 }
uint16_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:16
void dump(Stream &stream, boolean usingSigns=false) const
Prints the IrSequence on the stream provided.
Definition: IrSequence.cpp:28
IrSequence * clone() const
Creates a (deep) clone of the current object.
Definition: IrSequence.cpp:22
This class consists of a vector of durations.
Definition: IrSequence.h:12
virtual ~IrSequence()
Definition: IrSequence.cpp:17
IrSequence()
Create an empty sequence.
Definition: IrSequence.cpp:4