Phoenard
DataBuffer.h
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 This file is part of the Phoenard Arduino library
5 Copyright (c) 2014 Phoenard
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 */
25 
31 #include <Arduino.h>
32 #include "PHNTextContainer.h"
33 
34 #ifndef _DATA_BUFFER_H_
35 #define _DATA_BUFFER_H_
36 
44 class DataBuffer : public PHN_TextContainer {
45 public:
47  DataBuffer() : data(NULL), dataSize(0) {}
49  DataBuffer(const void* data, int dataSize);
51  ~DataBuffer();
53  void resize(int newDataSize);
55  void growToFit(int newDataSize);
57  void set(const void* data, int dataSize);
59  DataBuffer& operator=( const DataBuffer& other );
60 
61  // Implementation for PHN_TextContainer
62  virtual const char* text() { return (char*) data; }
63  virtual void setTextRaw(const char* text, int textLen);
64 
65  void* data;
66  int dataSize;
67 };
68 
69 #endif
virtual void setTextRaw(const char *text, int textLen)
Sets the new text to display using a buffer and length.
Definition: DataBuffer.cpp:56
DataBuffer()
Creates a new buffer without any data.
Definition: DataBuffer.h:47
Abstraction for a widget that can store and update text.
Definition: PHNTextContainer.h:41
Maintains data stored on the heap and frees it when the class is destructed.
Definition: DataBuffer.h:44
virtual const char * text()
Gets the text displayed.
Definition: DataBuffer.h:62
void growToFit(int newDataSize)
Resizes the buffer preserving contents to fit newDataSize.
Definition: DataBuffer.cpp:37
~DataBuffer()
Destructor frees the memory.
Definition: DataBuffer.cpp:33
Holds the PHN_TextContainer class used to dynamically access text using various datatypes.
void resize(int newDataSize)
Resizes the buffer preserving contents to newDataSize, shrinking if needed.
Definition: DataBuffer.cpp:43
DataBuffer & operator=(const DataBuffer &other)
Assigns data from one buffer to another.
Definition: DataBuffer.cpp:60
void set(const void *data, int dataSize)
Sets new data to be stored, the data is copied into this buffer.
Definition: DataBuffer.cpp:49