YARP
Yet Another Robot Platform
yarp::os::ManagedBytes Class Reference

An abstraction for a block of bytes, with optional responsibility for allocating/destroying that block. More...

#include <yarp/os/ManagedBytes.h>

+ Inheritance diagram for yarp::os::ManagedBytes:

Detailed Description

An abstraction for a block of bytes, with optional responsibility for allocating/destroying that block.

Definition at line 24 of file ManagedBytes.h.

Public Member Functions

 ManagedBytes ()
 Constructor. More...
 
 ManagedBytes (size_t len)
 Constructor. More...
 
 ManagedBytes (const Bytes &ext, bool owned=false)
 Constructor. More...
 
 ManagedBytes (const ManagedBytes &alt)
 Copy constructor. More...
 
const ManagedBytesoperator= (const ManagedBytes &alt)
 Assignment operator. More...
 
virtual ~ManagedBytes ()
 Destructor. More...
 
void allocate (size_t len)
 Makes a data block of the specified length that will be deleted if this object is destroyed. More...
 
bool allocateOnNeed (size_t neededLen, size_t allocateLen)
 
void copy ()
 Makes sure data block is owned, making a copy if necessary. More...
 
size_t length () const
 
size_t used () const
 
const char * get () const
 
char * get ()
 
void clear ()
 Disassociate object with any data block (deleting block if appropriate). More...
 
const Bytesbytes () const
 
Bytesbytes ()
 
Bytes usedBytes ()
 
size_t setUsed (size_t used)
 explicitly declare how many of the bytes are in use. More...
 
size_t resetUsed ()
 
bool read (ConnectionReader &reader) override
 Read this object from a network connection. More...
 
bool write (ConnectionWriter &writer) const override
 Write this object to a network connection. More...
 
bool isOwner () const
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType () const
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
virtual Type getReadType () const
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations. More...
 
virtual yarp::os::Type getWriteType () const
 

Private Attributes

Bytes b
 
bool owned
 
size_t use
 
bool use_set
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 

Constructor & Destructor Documentation

◆ ManagedBytes() [1/4]

ManagedBytes::ManagedBytes ( )
explicit

Constructor.

No data present.

Definition at line 20 of file ManagedBytes.cpp.

◆ ManagedBytes() [2/4]

ManagedBytes::ManagedBytes ( size_t  len)
explicit

Constructor.

Makes a data block of the specified length that will be deleted if this object is destroyed.

Parameters
lenlength of data block

Definition at line 28 of file ManagedBytes.cpp.

◆ ManagedBytes() [3/4]

ManagedBytes::ManagedBytes ( const Bytes ext,
bool  owned = false 
)

Constructor.

Represent external data.

Parameters
extaddress and length of data
ownedtrue if data should be deleted if this object is destroyed

Definition at line 36 of file ManagedBytes.cpp.

◆ ManagedBytes() [4/4]

ManagedBytes::ManagedBytes ( const ManagedBytes alt)

Copy constructor.

Parameters
altthe data to copy. If it is "owned" an independent copy is made.

Definition at line 44 of file ManagedBytes.cpp.

◆ ~ManagedBytes()

ManagedBytes::~ManagedBytes ( )
virtual

Destructor.

Definition at line 69 of file ManagedBytes.cpp.

Member Function Documentation

◆ allocate()

void ManagedBytes::allocate ( size_t  len)

Makes a data block of the specified length that will be deleted if this object is destroyed.

Parameters
lenlength of data block

Definition at line 74 of file ManagedBytes.cpp.

◆ allocateOnNeed()

bool ManagedBytes::allocateOnNeed ( size_t  neededLen,
size_t  allocateLen 
)

Definition at line 83 of file ManagedBytes.cpp.

◆ bytes() [1/2]

const Bytes & ManagedBytes::bytes ( ) const
Returns
description of data block associated with this object (const version)

Definition at line 138 of file ManagedBytes.cpp.

◆ bytes() [2/2]

Bytes & ManagedBytes::bytes ( )
Returns
description of data block associated with this object

Definition at line 142 of file ManagedBytes.cpp.

◆ clear()

void ManagedBytes::clear ( )

Disassociate object with any data block (deleting block if appropriate).

Definition at line 126 of file ManagedBytes.cpp.

◆ copy()

void ManagedBytes::copy ( )

Makes sure data block is owned, making a copy if necessary.

Definition at line 99 of file ManagedBytes.cpp.

◆ get() [1/2]

const char * ManagedBytes::get ( ) const
Returns
address of data block (const version)

Definition at line 118 of file ManagedBytes.cpp.

◆ get() [2/2]

char * ManagedBytes::get ( )
Returns
address of data block

Definition at line 122 of file ManagedBytes.cpp.

◆ isOwner()

bool yarp::os::ManagedBytes::isOwner ( ) const
inline
Returns
true iff the managed data block is owned by this object

Definition at line 146 of file ManagedBytes.h.

◆ length()

size_t ManagedBytes::length ( ) const
Returns
length of data block

Definition at line 110 of file ManagedBytes.cpp.

◆ operator=()

const ManagedBytes & ManagedBytes::operator= ( const ManagedBytes alt)

Assignment operator.

Parameters
altthe data to copy. If it is "owned" an independent copy is made.
Returns
this object

Definition at line 55 of file ManagedBytes.cpp.

◆ read()

bool ManagedBytes::read ( ConnectionReader reader)
overridevirtual

Read this object from a network connection.

Override this for your particular class.

Parameters
readeran interface to the network connection for reading
Returns
true iff the object is successfully read

Implements yarp::os::Portable.

Definition at line 163 of file ManagedBytes.cpp.

◆ resetUsed()

size_t ManagedBytes::resetUsed ( )

Definition at line 156 of file ManagedBytes.cpp.

◆ setUsed()

size_t ManagedBytes::setUsed ( size_t  used)

explicitly declare how many of the bytes are in use.

Parameters
usedbyte count
Returns
a confirmation of the number of bytes declared to be in use.

Definition at line 150 of file ManagedBytes.cpp.

◆ used()

size_t ManagedBytes::used ( ) const
Returns
length of used portion of data block - by default, this is the same as length(), unless setUsed() is called

Definition at line 114 of file ManagedBytes.cpp.

◆ usedBytes()

Bytes ManagedBytes::usedBytes ( )
Returns
description of used portion of data block associated with this object

Definition at line 146 of file ManagedBytes.cpp.

◆ write()

bool ManagedBytes::write ( ConnectionWriter writer) const
overridevirtual

Write this object to a network connection.

Override this for your particular class. Be aware that depending on the nature of the connections a port has, and what protocol they use, and how efficient the YARP implementation is, this method may be called once, twice, or many times, as the result of a single call to Port::write

Parameters
writeran interface to the network connection for writing
Returns
true iff the object is successfully written

Implements yarp::os::Portable.

Definition at line 184 of file ManagedBytes.cpp.

Member Data Documentation

◆ b

Bytes yarp::os::ManagedBytes::b
private

Definition at line 152 of file ManagedBytes.h.

◆ owned

bool yarp::os::ManagedBytes::owned
private

Definition at line 153 of file ManagedBytes.h.

◆ use

size_t yarp::os::ManagedBytes::use
private

Definition at line 154 of file ManagedBytes.h.

◆ use_set

bool yarp::os::ManagedBytes::use_set
private

Definition at line 155 of file ManagedBytes.h.


The documentation for this class was generated from the following files: