summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/data
diff options
context:
space:
mode:
authordufourj2005-05-01 15:37:34 +0000
committerdufourj2005-05-01 15:37:34 +0000
commitaecaf24c22013482de84ac6567249bec5ae7c78e (patch)
tree1aeb3d2ced48f6cdda6d39665fdb4062d83189da /2005/i/robert/src/data
parent714e86c96ff93fb78d4340cb607c12927091417b (diff)
DataBuffer :
Rajout du type de données Socket : Non-bloquant
Diffstat (limited to '2005/i/robert/src/data')
-rw-r--r--2005/i/robert/src/data/data_buffer.cc14
-rw-r--r--2005/i/robert/src/data/data_buffer.hh25
2 files changed, 28 insertions, 11 deletions
diff --git a/2005/i/robert/src/data/data_buffer.cc b/2005/i/robert/src/data/data_buffer.cc
index 4fc7c56..c0d8cef 100644
--- a/2005/i/robert/src/data/data_buffer.cc
+++ b/2005/i/robert/src/data/data_buffer.cc
@@ -32,24 +32,26 @@ static const unsigned min_size = 10;
/// Constructeur par defaut
DataBuffer::DataBuffer (void)
- : size_ (min_size), headPos_ (0), tailPos_ (0)
+ : size_ (min_size), headPos_ (0), tailPos_ (0), type_ (NoType)
{
buffer_ = new uint8_t [size_];
}
/// Constructeur par recopie.
DataBuffer::DataBuffer (const DataBuffer &d)
- : headPos_ (0)
+ : headPos_ (0), type_ (NoType)
{
unsigned sizeUse = d.tailPos_ - d.headPos_;
size_ = tailPos_ = sizeUse;
+ type_ = d.type_;
buffer_ = new uint8_t [size_];
std::memcpy (buffer_, &d.buffer_[headPos_], sizeUse);
}
/// Constructeur avec données.
-DataBuffer::DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated)
- : size_ (sizeAllocated), headPos_ (0), tailPos_ (size)
+DataBuffer::DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated,
+ dataType_e type)
+ : size_ (sizeAllocated), headPos_ (0), tailPos_ (size), type_ (type)
{
if (!data || size > sizeAllocated)
throw std::invalid_argument ("Paramêtres invalides");
@@ -110,7 +112,8 @@ DataBuffer::grow (const unsigned size)
if (tailleLibre < size)
{
// On augmente de deux fois la taille
- DataBuffer d (&buffer_[headPos_], tailPos_ - headPos_, 2 * size + size_);
+ DataBuffer d (&buffer_[headPos_], tailPos_ - headPos_,
+ 2 * size + size_, type_);
d.swap (*this);
}
}
@@ -123,4 +126,5 @@ DataBuffer::swap (DataBuffer &d)
std::swap (size_, d.size_);
std::swap (headPos_, d.headPos_);
std::swap (tailPos_, d.tailPos_);
+ std::swap (type_, d.type_);
}
diff --git a/2005/i/robert/src/data/data_buffer.hh b/2005/i/robert/src/data/data_buffer.hh
index 11724d8..5e6b55d 100644
--- a/2005/i/robert/src/data/data_buffer.hh
+++ b/2005/i/robert/src/data/data_buffer.hh
@@ -33,19 +33,33 @@
/// écriture.
class DataBuffer : public DataInput, public DataOutput
{
+ public:
+ /// Type de données possible du buffer.
+ enum dataType_e {
+ NoType,
+ Image
+ };
+ private:
/// Buffer de données.
uint8_t *buffer_;
/// Taille alloué en mémoire pour le buffer.
unsigned size_;
/// Position du début et de la fin des données dans le buffer.
unsigned headPos_, tailPos_;
+ /// Type de données du buffer.
+ dataType_e type_;
+ /// Augmente la taille du buffer pour correspondre à size.
+ void grow (const unsigned size);
+ /// Echange les buffers.
+ void swap (DataBuffer &d);
public:
/// Constructeur par défaut.
DataBuffer (void);
/// Constructeur par recopie.
DataBuffer (const DataBuffer &d);
/// Constructeur avec données.
- DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated);
+ DataBuffer (uint8_t *data, unsigned size, unsigned sizeAllocated,
+ dataType_e type = NoType);
/// Destructeur par défaut.
~DataBuffer (void) { delete [] buffer_; }
/// Surcharge de l'opérateur d'affectation
@@ -58,10 +72,9 @@ class DataBuffer : public DataInput, public DataOutput
void write (const uint8_t *buf, unsigned size);
/// Taille utile du buffer.
unsigned size (void) const { return tailPos_ - headPos_; }
- private:
- /// Augmente la taille du buffer pour correspondre à size.
- void grow (const unsigned size);
- /// Echange les buffers.
- void swap (DataBuffer &d);
+ /// Type de données du buffer.
+ dataType_e type (void) const { return type_; }
+ /// Change le type de données du buffer.
+ void setType (const dataType_e type) { type_ = type; }
};
#endif // data_buffer_hh