MPEG CDVA Experimentation Model (CXM)  1.0
Compact Descriptors for Visual Analisys
Buffer.h
Go to the documentation of this file.
1 /*
2 The copyright in this software is being made available under this MPEG Reference Software Copyright License. This software may be subject to other third party and contributor rights, including patent rights, and no such rights are granted under this license.
3 
4 Copyright (c) 2016, Telecom Italia
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 * Neither the name of Telecom Italia nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 */
11 #pragma once
12 #include <cstddef> // std::size_t
13 
14 namespace mpeg7cdva
15 {
16 
17 
25 class Buffer
26 {
27 public:
28  Buffer();
29  virtual ~Buffer();
30  Buffer (size_t size);
31  Buffer (unsigned char * data, size_t size);
32 
33  Buffer (const Buffer&);
34  Buffer& operator= (const Buffer&);
35 
36  void swap (Buffer& x);
37  void fill (unsigned char value = 0);
38 
39  size_t size () const;
40 
41  bool resize (size_t newsize);
42 
43  bool empty () const;
44 
45  void clear ();
46 
47  bool assign(const unsigned char * data, size_t size);
48 
49  bool equals(Buffer & buffer);
50 
51  unsigned char* data ();
52 
53  const unsigned char* data () const;
54 
55  char* sdata ();
56 
57  const char* sdata () const;
58 
59  void read(const char * fname);
60 
61  void write(const char * fname) const;
62 
68  int compare(const Buffer & other) const;
69 
70  bool operator== (const Buffer& other) const;
71 
72 private:
73  unsigned char* mydata;
74  size_t mysize;
75 };
76 
77 
78 } // end of namespace
Buffer & operator=(const Buffer &)
assign a Buffer to another
unsigned char * data()
access to Buffer&#39;s data as unsigned char (writable)
void fill(unsigned char value=0)
fill a Buffer with the given value
void write(const char *fname) const
write Buffer to file
void swap(Buffer &x)
swap the content of two Buffer(s)
Namespace used to encapsulate all MPEG-7 CDVA declarations.
Definition: Buffer.h:14
bool operator==(const Buffer &other) const
compare if two Buffer(s) are equal (i.e. if they have the same size and contain the same data) ...
size_t size() const
return the current size of the Buffer
A container class for a byte array, intended to replace all malloc() and new() instructions in the ma...
Definition: Buffer.h:25
void clear()
clear the Buffer
bool empty() const
return true if the Buffer is empty
bool assign(const unsigned char *data, size_t size)
assign the given data to Buffer
void read(const char *fname)
read Buffer from a file
int compare(const Buffer &other) const
Compare this buffer with another; return the number of different bytes.
bool resize(size_t newsize)
change buffer size; content is lost if newsize if less than the current size
bool equals(Buffer &buffer)
compare if two Buffer(s) are equal (i.e. if they have the same size and contain the same data) ...
char * sdata()
access to Buffer&#39;s data as signed char (writable)