Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
DmxBuffer.h
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * DmxBuffer.h
17 * Interface for the DmxBuffer
18 * Copyright (C) 2005 Simon Newton
19 */
20
26#ifndef INCLUDE_OLA_DMXBUFFER_H_
27#define INCLUDE_OLA_DMXBUFFER_H_
28
29#include <stdint.h>
30#include <iostream>
31#include <string>
32
33
34namespace ola {
35
49class DmxBuffer {
50 public:
55 DmxBuffer();
56
63 DmxBuffer(const DmxBuffer &other);
64
70 DmxBuffer(const uint8_t *data, unsigned int length);
71
79 explicit DmxBuffer(const std::string &data);
80
84 ~DmxBuffer();
85
91 DmxBuffer& operator=(const DmxBuffer &other);
92
98 bool operator==(const DmxBuffer &other) const;
99
105 bool operator!=(const DmxBuffer &other) const;
106
111 unsigned int Size() const { return m_length; }
112
118 bool HTPMerge(const DmxBuffer &other);
119
127 bool Set(const uint8_t *data, unsigned int length);
128
135 bool Set(const std::string &data);
136
144 bool Set(const DmxBuffer &other);
145
166 bool SetFromString(const std::string &data);
167
178 bool SetRangeToValue(unsigned int offset, uint8_t data,
179 unsigned int length);
180
190 bool SetRange(unsigned int offset, const uint8_t *data,
191 unsigned int length);
192
201 void SetChannel(unsigned int channel, uint8_t data);
202
211 void Get(uint8_t *data, unsigned int *length) const;
212
219 void GetRange(unsigned int slot, uint8_t *data,
220 unsigned int *length) const;
221
229 uint8_t Get(unsigned int channel) const;
230
235 const uint8_t *GetRaw() const { return m_data; }
236
241 std::string Get() const;
242
247 bool Blackout();
248
253 void Reset();
254
265 std::string ToString() const;
266
267 private:
268 bool Init();
269 bool DuplicateIfNeeded();
270 void CopyFromOther(const DmxBuffer &other);
271 void CleanupMemory();
272 unsigned int *m_ref_count;
273 mutable bool m_copy_on_write;
274 uint8_t *m_data;
275 unsigned int m_length;
276};
277
290std::ostream& operator<<(std::ostream &out, const DmxBuffer &data);
291} // namespace ola
292#endif // INCLUDE_OLA_DMXBUFFER_H_
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
DmxBuffer()
Definition DmxBuffer.cpp:47
bool SetFromString(const std::string &data)
Set values from a string. Convert a comma separated list of values into for the DmxBuffer....
Definition DmxBuffer.cpp:163
unsigned int Size() const
Current size of DmxBuffer.
Definition DmxBuffer.h:111
void SetChannel(unsigned int channel, uint8_t data)
Set a single channel. Calling this on an uninitialized buffer will call Blackout() first....
Definition DmxBuffer.cpp:232
bool Blackout()
Set the buffer to all zeros.
Definition DmxBuffer.cpp:294
const uint8_t * GetRaw() const
Get a raw pointer to the internal data.
Definition DmxBuffer.h:235
bool SetRange(unsigned int offset, const uint8_t *data, unsigned int length)
Set a range of data. Calling this on an uninitialized buffer will call Blackout() first....
Definition DmxBuffer.cpp:210
void GetRange(unsigned int slot, uint8_t *data, unsigned int *length) const
Get a range of values starting from a particular slot.
Definition DmxBuffer.cpp:262
bool operator!=(const DmxBuffer &other) const
Inequality operator used to check if two DmxBuffers are not equal.
Definition DmxBuffer.cpp:108
void Reset()
Reset the buffer to hold no data.
Definition DmxBuffer.cpp:309
bool Set(const uint8_t *data, unsigned int length)
Set the contents of this DmxBuffer.
Definition DmxBuffer.cpp:137
bool SetRangeToValue(unsigned int offset, uint8_t data, unsigned int length)
Set a Range of data to a single value. Calling this on an uninitialized buffer will call Blackout() f...
Definition DmxBuffer.cpp:188
std::string ToString() const
Convert the DmxBuffer to a human readable representation.
Definition DmxBuffer.cpp:316
std::string Get() const
Get the raw contents of the DmxBuffer as a string.
Definition DmxBuffer.cpp:287
bool HTPMerge(const DmxBuffer &other)
HTP Merge from another DmxBuffer.
Definition DmxBuffer.cpp:113
bool operator==(const DmxBuffer &other) const
Equality operator used to check if two DmxBuffers are equal.
Definition DmxBuffer.cpp:101
~DmxBuffer()
Destructor.
Definition DmxBuffer.cpp:85
DmxBuffer & operator=(const DmxBuffer &other)
Assignment operator used to make this buffer equal to another buffer.
Definition DmxBuffer.cpp:90
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
std::ostream & operator<<(std::ostream &out, const DmxBuffer &data)
Stream operator to allow DmxBuffer to be output to stdout.
Definition DmxBuffer.cpp:402