DevSlashLirc
IrSequence.cpp
Go to the documentation of this file.
1 #include "IrSequence.h"
2 #include <string.h>
3 #include <string>
4 #include <sstream>
5 
6 IrSequence::IrSequence() : durations(NULL), length(0U), toBeFreed(false) {
7 };
8 
9 IrSequence::IrSequence(const microseconds_t *durations_, size_t length_, bool toBeFreed_)
10 : durations(durations_), length(length_), toBeFreed(toBeFreed_) {
11 }
12 
13 IrSequence::IrSequence(const IrSequence& orig) : durations(orig.durations), length(orig.length), toBeFreed(orig.toBeFreed) {
14 };
15 
16 IrSequence::IrSequence(const IrSequence& orig, bool toBeFreed_) : durations(orig.durations), length(orig.length), toBeFreed(toBeFreed_) {
17 };
18 
20  if (toBeFreed)
21  delete [] durations;
22 }
23 
25  microseconds_t *durationsClone = new microseconds_t[length];
26  memcpy(durationsClone, durations, length*sizeof(microseconds_t));
27  return new IrSequence(durationsClone, length, true);
28 }
29 
30 void IrSequence::dump(std::ostream& stream, bool usingSigns) const {
31  for (unsigned int i = 0U; i < length; i++) {
32  if (i > 0U)
33  stream << ' ';
34  if (usingSigns)
35  stream << ((i & 1) ? '-' : '+');
36  stream << durations[i];
37  }
38  stream << std::endl;
39 }
40 
41 const char* IrSequence::toString() const {
42  std::stringstream os;
43  dump(os, true);
44  std::string s = os.str();
45  char* buf = new char[s.length()+1];
46  strncpy(buf, s.c_str(), s.length());
47  return buf;
48 }
49 
51  microseconds_t sum = 0;
52  for (unsigned int i = 0; i < length; i++)
53  sum += durations[i];
54 
55  return sum;
56 }
IrSequence * clone() const
Creates a (deep) clone of the current object.
Definition: IrSequence.cpp:24
const char * toString() const
Definition: IrSequence.cpp:41
microseconds_t getTotalDuration() const
Definition: IrSequence.cpp:50
uint32_t microseconds_t
Type for durations in micro seconds.
Definition: InfraredTypes.h:20
This class consists of a vector of durations.
Definition: IrSequence.h:15
void dump(std::ostream &stream=std::cout, bool usingSigns=false) const
Prints the IrSequence on the stream provided.
Definition: IrSequence.cpp:30
virtual ~IrSequence()
Definition: IrSequence.cpp:19
IrSequence()
Create an empty sequence.
Definition: IrSequence.cpp:6