From cb4aaf57b300c0b6778279f574ca74051662f7ca Mon Sep 17 00:00:00 2001 From: Andrea Zoli <zoli@iasfbo.inaf.it> Date: Fri, 20 Dec 2013 16:18:13 +0100 Subject: [PATCH] Using a SharedPtr for the ByteStream class. --- include/ByteStream.h | 12 ++-- include/File.h | 4 +- include/FileStream.h | 12 ++-- include/Input.h | 2 +- include/InputFile.h | 2 +- include/InputPacketStream.h | 4 +- include/InputSerial.h | 2 +- include/InputSocketServer.h | 2 +- include/Output.h | 2 +- include/OutputFile.h | 2 +- include/OutputSerial.h | 2 +- include/OutputSocketClient.h | 2 +- include/Packet.h | 52 ++++++++-------- include/PacketDataField.h | 4 +- include/PacketNotRecognized.h | 2 +- include/PartOfPacket.h | 17 +++--- include/SDFBVBlock.h | 4 +- include/SDFBlockFixed.h | 8 +-- include/SDFBlockVariable.h | 8 +-- include/SDFRBBlock.h | 10 ++-- include/SDFRBlock.h | 6 +- include/Socket.h | 4 +- src/ByteStream.cpp | 15 +++-- src/File.cpp | 12 ++-- src/FileStream.cpp | 6 +- src/InputFile.cpp | 4 +- src/InputPacketStream.cpp | 11 ++-- src/InputPacketStreamFile.cpp | 32 ++-------- src/InputSerial.cpp | 8 +-- src/InputSocketServer.cpp | 4 +- src/OutputFile.cpp | 2 +- src/OutputPacketStream.cpp | 3 +- src/OutputSerial.cpp | 2 +- src/OutputSocketClient.cpp | 2 +- src/Packet.cpp | 108 ++++++++++------------------------ src/PacketDataField.cpp | 7 +-- src/PacketNotRecognized.cpp | 2 +- src/PartOfPacket.cpp | 20 +++---- src/SDFBVBlock.cpp | 4 +- src/SDFBlockFixed.cpp | 15 ++--- src/SDFBlockVariable.cpp | 11 ++-- src/SDFRBBlock.cpp | 17 +++--- src/SDFRBlock.cpp | 6 +- src/Socket.cpp | 8 +-- 44 files changed, 185 insertions(+), 277 deletions(-) diff --git a/include/ByteStream.h b/include/ByteStream.h index a5f13e1..9920f83 100644 --- a/include/ByteStream.h +++ b/include/ByteStream.h @@ -19,10 +19,13 @@ #define _BYTESTREAM_H #include "PacketLibDefinition.h" +#include "SharedPtr.h" namespace PacketLib { +class ByteStream; +typedef SharedPtr<ByteStream> ByteStreamPtr; /// \brief Represent a stream of byte. class ByteStream @@ -45,7 +48,7 @@ public: /// passed as input. /// It's possibile to pass 0 as pointer. /// The mamory of byte* is allocated. - ByteStream(ByteStream* b0, ByteStream* b1, ByteStream* b2); + ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStreamPtr b2); ~ByteStream(); @@ -62,17 +65,17 @@ public: /// Returns a subset of the current stream. If there is problemas return NULL /// \remarks This method don't allocate a new stream structure in memory, /// but create only a new ByteStream object that points in the same memory area. - ByteStream* getSubByteStream(dword first, dword last); + ByteStreamPtr getSubByteStream(dword first, dword last); /// Returns a subset of the current stream. If there is problemas return NULL /// \remarks This method allocate a new stream structure in memory. - ByteStream* getSubByteStreamCopy(dword first, dword last); + ByteStreamPtr getSubByteStreamCopy(dword first, dword last); /// Sets the stream from arguments. bool setStream(byte* b, dword dim, bool bigendian, bool memory_sharing = true); /// Get the stream from another object of the same type. Don't allocate new memory - bool setStream(ByteStream* b, dword first, dword last); + bool setStream(ByteStreamPtr b, dword first, dword last); /// Copy the stream in argument of dimension dim. /// \remarks This method delete old stream and creates a new stream in memory @@ -157,6 +160,7 @@ private: bool mem_allocation_constructor; }; + } diff --git a/include/File.h b/include/File.h index 3839cb6..eafc1f1 100644 --- a/include/File.h +++ b/include/File.h @@ -61,7 +61,7 @@ public: /// Reads a pair number of byte from opened file and manages the big or little endian /// format. If the format of machine is little endian, a pair of byte is swapped. /// \pre The file must be opened. - virtual ByteStream* getNByte( dword N = 1 ); + virtual ByteStreamPtr getNByte( dword N = 1 ); /// Get the current line. /// \pre The file must be opened. @@ -110,7 +110,7 @@ public: /// Writes a stream of byte into opend file. /// \pre The file must be opened in w mode - bool writeByteStream(ByteStream* b) throw(PacketExceptionIO*); + bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); /// Count the number of string lines into a text file. long getNumberOfStringLines(); diff --git a/include/FileStream.h b/include/FileStream.h index 61736dd..ebccb50 100644 --- a/include/FileStream.h +++ b/include/FileStream.h @@ -30,11 +30,11 @@ public: FileStream(bool prefix, bool bigen, word dimprefix, long startposition = 0); - ByteStream* readPrefix(); + ByteStreamPtr readPrefix(); - ByteStream* readHeader(unsigned int dimHeader); + ByteStreamPtr readHeader(unsigned int dimHeader); - ByteStream* readDataField(unsigned int dimDataField); + ByteStreamPtr readDataField(unsigned int dimDataField); private: /// Indicates if it's present a prefix for each packet @@ -42,11 +42,11 @@ private: /// \li false if it isn't present bool thereIsPrefix; - ByteStream* header; + ByteStreamPtr header; - ByteStream* dataField; + ByteStreamPtr dataField; - ByteStream* prefix; + ByteStreamPtr prefix; word dimPrefix; diff --git a/include/Input.h b/include/Input.h index 49dd221..031d799 100644 --- a/include/Input.h +++ b/include/Input.h @@ -35,7 +35,7 @@ public: virtual bool open( char** parameters ) throw(PacketExceptionIO*) = 0; - virtual ByteStream* readByteStream(dword n_byte) throw(PacketExceptionIO*) = 0; + virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*) = 0; virtual char* readString() throw(PacketExceptionIO*) = 0; diff --git a/include/InputFile.h b/include/InputFile.h index b802db4..0697cf0 100644 --- a/include/InputFile.h +++ b/include/InputFile.h @@ -37,7 +37,7 @@ public: virtual void close() throw(PacketExceptionIO*); - virtual ByteStream* readByteStream(dword n_byte) throw(PacketExceptionIO*); + virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); virtual char* readString() throw(PacketExceptionIO*); diff --git a/include/InputPacketStream.h b/include/InputPacketStream.h index de3f744..34a2e05 100644 --- a/include/InputPacketStream.h +++ b/include/InputPacketStream.h @@ -40,12 +40,12 @@ public: /// \param prefix A ByteStream that contains the prefix of packet (if present). /// \param packetHeader A ByteStream that contains the packet header. /// \param packetDataField A ByteStream that contains the packet data field. - int detPacketType(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + int detPacketType(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); /// \return The index of packet type if it's recognized. 0 if packet isn't recognized. /// \param prefix A ByteStream that contains the prefix of packet (if present). /// \param packet A ByteStream that contains the packet. - int detPacketType(ByteStream* prefix, ByteStream* packet); + int detPacketType(ByteStreamPtr prefix, ByteStreamPtr packet); ///It returns the index of the packet type contained in the stream. The stream* contains also the prefix (if present) /// \return The index of packet type if it's recognized. 0 if packet isn't recognized. diff --git a/include/InputSerial.h b/include/InputSerial.h index 30b397d..c721e4d 100644 --- a/include/InputSerial.h +++ b/include/InputSerial.h @@ -37,7 +37,7 @@ public: virtual void close() throw(PacketExceptionIO*); - virtual ByteStream* readByteStream(int n_byte) throw(PacketExceptionIO*); + virtual ByteStreamPtr readByteStream(int n_byte) throw(PacketExceptionIO*); virtual char* readString() throw(PacketExceptionIO*); diff --git a/include/InputSocketServer.h b/include/InputSocketServer.h index 7fcb8c4..30ac632 100644 --- a/include/InputSocketServer.h +++ b/include/InputSocketServer.h @@ -37,7 +37,7 @@ public: virtual void close() throw(PacketExceptionIO*); - virtual ByteStream* readByteStream(dword n_byte) throw(PacketExceptionIO*); + virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); virtual char* readString() throw(PacketExceptionIO*); diff --git a/include/Output.h b/include/Output.h index ab14441..980dbf5 100644 --- a/include/Output.h +++ b/include/Output.h @@ -39,7 +39,7 @@ public: virtual bool isBigendian(); - virtual bool writeByteStream(ByteStream* b) throw(PacketExceptionIO*) = 0; + virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) = 0; virtual bool writeString(const char* str) throw(PacketExceptionIO*) = 0; diff --git a/include/OutputFile.h b/include/OutputFile.h index 893f992..bf0e98b 100644 --- a/include/OutputFile.h +++ b/include/OutputFile.h @@ -38,7 +38,7 @@ public: virtual bool open(char** parameters) throw(PacketExceptionIO*); - virtual bool writeByteStream(ByteStream* b) throw(PacketExceptionIO*); + virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*); diff --git a/include/OutputSerial.h b/include/OutputSerial.h index 570c587..0a316a0 100644 --- a/include/OutputSerial.h +++ b/include/OutputSerial.h @@ -38,7 +38,7 @@ public: virtual bool open(char** parameters) throw(PacketExceptionIO*); - virtual bool writeByteStream(ByteStream* b) throw(PacketExceptionIO*); + virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*); diff --git a/include/OutputSocketClient.h b/include/OutputSocketClient.h index aa41ca3..1ad7838 100644 --- a/include/OutputSocketClient.h +++ b/include/OutputSocketClient.h @@ -37,7 +37,7 @@ public: virtual bool open(char** parameters) throw(PacketExceptionIO*); - virtual bool writeByteStream(ByteStream* b) throw(PacketExceptionIO*); + virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*); diff --git a/include/Packet.h b/include/Packet.h index 5eec893..0e31e55 100644 --- a/include/Packet.h +++ b/include/Packet.h @@ -55,14 +55,14 @@ public: /// contains a packet of this type. This method overloads another method. /// \post A side effects of this method is that the value of fields of packet are set with /// correct value. - virtual bool setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); /// This method verifies if the ByteStream on argument contains the correct value /// in the identifiers. If this is true, the method returns true and the stream /// contains a packet of this type. This method overloads another method. /// \post A side effect of this method is that the values of fields of packet are set with /// correct value - virtual bool setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packet); + virtual bool setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet); /// Sets all the fields of the packet with correct value contained into the input ByteStream. /// \pre The structure of the stream must be loaded. @@ -70,21 +70,21 @@ public: /// \param packetHeader This is the header of the packet /// \param packetDataField This is the data field of the packet /// \post If return is true all the fields are set with the correct value. - virtual bool setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); /// Sets all the fields of the packet with correct value contained into the input ByteStream. /// \pre The structure of the stream must be loaded. /// \param prefix This is the prefix of the packet /// \param packet This is the packet /// \post If return is true all the fields are set with the correct value. - virtual bool setPacketValue(ByteStream* prefix, ByteStream* packet); + virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet); /// Verifies if within the ByteStream passed with arguments it's present a correct packet. /// \pre The structure of the stream must be loaded. /// \param prefix This is the prefix of the packet /// \param packet This is the packet /// \return True if the ByteStream contains a packet - bool verifyPacketValue(ByteStream* prefix, ByteStream* packet); + bool verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet); /// Verifies if within the byte* stream passed with arguments it's present a correct packet. The stream* contains also the prefix (if present) /// \param stream A pointer to the stream of byte, with prefix and packet @@ -100,7 +100,7 @@ public: /// \param packetHeader This is the header of the packet. /// \param packetDataField This is the data field of the packet. /// \return True if the ByteStream contains a packet. - bool verifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + bool verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); /// Prints to stdout the value of packet data field in a formatted mode. virtual void printPacketValue(); @@ -148,12 +148,12 @@ public: /// Gets the ByteStream received as input - ByteStream* getInputStream(); + ByteStreamPtr getInputStream(); /// Gets the packet generated with the generateStream() method. The output /// packet is generated during this call. - ByteStream* getOutputStream(); + ByteStreamPtr getOutputStream(); /// Gets the name of packet. @@ -174,10 +174,6 @@ public: virtual void printIdentifiers(); - /// Deletes the ByteStream passed as arguments. - virtual void deleteExternalByteStream(); - - /// Writes property of byte packetID. virtual void setPacketID(const byte& value); @@ -202,15 +198,15 @@ public: /// the prefix of the packet. - ByteStream* prefix; + ByteStreamPtr prefix; /// The ByteStrem of the packet read - ByteStream* packet; + ByteStreamPtr packet; /// This is the ByteStream generated with generateStream(). - ByteStream* packet_output; + ByteStreamPtr packet_output; protected: @@ -246,21 +242,21 @@ protected: unsigned number_of_identifier; - bool setPacketValuePrefix(ByteStream* prefix); + bool setPacketValuePrefix(ByteStreamPtr prefix); - bool setPacketValueVerify(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + bool setPacketValueVerify(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); - bool setPacketValueDataFieldHeader(ByteStream* packetDataField); + bool setPacketValueDataFieldHeader(ByteStreamPtr packetDataField); - bool setPacketValueSourceDataField(ByteStream* packetDataField); + bool setPacketValueSourceDataField(ByteStreamPtr packetDataField); - bool setPacketValueHeader(ByteStream* header); + bool setPacketValueHeader(ByteStreamPtr header); - bool setPacketValueTail(ByteStream* packetDataField); + bool setPacketValueTail(ByteStreamPtr packetDataField); - void memByteStream(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + void memByteStream(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); - void memByteStream(ByteStream* prefix, ByteStream* packet); + void memByteStream(ByteStreamPtr prefix, ByteStreamPtr packet); bool bigendian; @@ -274,15 +270,15 @@ protected: private: - ByteStream* tempHeader; + ByteStreamPtr tempHeader; - ByteStream* tempDataField; + ByteStreamPtr tempDataField; - ByteStream* tempDataFieldHeader; + ByteStreamPtr tempDataFieldHeader; - ByteStream* tempPacketDataField; + ByteStreamPtr tempPacketDataField; - ByteStream* tempTail; + ByteStreamPtr tempTail; bool first_output_stream_setted; diff --git a/include/PacketDataField.h b/include/PacketDataField.h index 4a92aad..d562466 100644 --- a/include/PacketDataField.h +++ b/include/PacketDataField.h @@ -53,10 +53,10 @@ public: dword getMaxDimension(); /// Creates the outputstream ByteStream for the generation of the output stream - virtual bool setOutputStream(ByteStream* os, word first); + virtual bool setOutputStream(ByteStreamPtr os, word first); - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); /// Represents the data field header. DataFieldHeader *dataFieldHeader; diff --git a/include/PacketNotRecognized.h b/include/PacketNotRecognized.h index 7d48d9b..814fe70 100644 --- a/include/PacketNotRecognized.h +++ b/include/PacketNotRecognized.h @@ -35,7 +35,7 @@ public: virtual bool createPacketType(char* fileName, bool prefix, word dimprefix) throw (PacketException*); - virtual bool setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); + virtual bool setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField); }; } diff --git a/include/PartOfPacket.h b/include/PartOfPacket.h index 74a6d1e..0b25c7a 100644 --- a/include/PartOfPacket.h +++ b/include/PartOfPacket.h @@ -243,27 +243,24 @@ public: }; /// Sets the stream of byte. This method assigns the value of stream for each field of part of packet - virtual bool setByteStream(ByteStream* s); + virtual bool setByteStream(ByteStreamPtr s); /// Get the current ByteStream - virtual ByteStream* getByteStream() + virtual ByteStreamPtr getByteStream() { return stream; } - /// Delete the current ByteStream - virtual void deleteByteStream(); - - virtual void memByteStream(ByteStream* stream); + virtual void memByteStream(ByteStreamPtr stream); /// Represent current stream writes to output. - ByteStream* outputstream; + ByteStreamPtr outputstream; /// Generates the stream. - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); /// Creates the outputstream ByteStream for the generation of the output stream - virtual bool setOutputStream(ByteStream* os, dword first); + virtual bool setOutputStream(ByteStreamPtr os, dword first); /// In a recoursive structure, the PartOfPacket that contains this PartOfPacket PartOfPacket* previous; @@ -273,7 +270,7 @@ public: protected: /// Represent current stream reads from input. - ByteStream* stream; + ByteStreamPtr stream; /// List of field of part of packet. Field** fields; diff --git a/include/SDFBVBlock.h b/include/SDFBVBlock.h index a796385..9ad1b7c 100644 --- a/include/SDFBVBlock.h +++ b/include/SDFBVBlock.h @@ -47,9 +47,9 @@ public: /// Total max dimension in bytes of block dword getMaxDimension(); - bool setOutputStream(ByteStream* os, dword first); + bool setOutputStream(ByteStreamPtr os, dword first); - ByteStream* generateStream(bool bigendian); + ByteStreamPtr generateStream(bool bigendian); virtual word getNumberOfRealElement(); diff --git a/include/SDFBlockFixed.h b/include/SDFBlockFixed.h index c3035bd..7fea2be 100644 --- a/include/SDFBlockFixed.h +++ b/include/SDFBlockFixed.h @@ -45,7 +45,7 @@ public: virtual word getNumberOfFields(); - virtual bool setByteStream(ByteStream* s); + virtual bool setByteStream(ByteStreamPtr s); /// Prints the value of each field of this part of packet. virtual char** printValue(char* addString = ""); @@ -87,9 +87,9 @@ public: /// \param value The value must be set. virtual void setFieldValue(word block, word index, word value); - virtual bool setOutputStream(ByteStream* os, dword first); + virtual bool setOutputStream(ByteStreamPtr os, dword first); - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); /// Returns the number of fields for each block. virtual word getNumberOfFields(word block); @@ -97,7 +97,7 @@ public: private: SDFBFBlock *block; - ByteStream* tempBlock; + ByteStreamPtr tempBlock; }; } diff --git a/include/SDFBlockVariable.h b/include/SDFBlockVariable.h index fe02eac..11bbd54 100644 --- a/include/SDFBlockVariable.h +++ b/include/SDFBlockVariable.h @@ -48,7 +48,7 @@ public: virtual word getNumberOfFields(); - virtual bool setByteStream(ByteStream* s); + virtual bool setByteStream(ByteStreamPtr s); virtual dword getDimension(); @@ -99,10 +99,10 @@ public: virtual void setFieldValue(word block, word index, word value); - virtual bool setOutputStream(ByteStream* os, dword first); + virtual bool setOutputStream(ByteStreamPtr os, dword first); - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); /// Get the number of elements for each block @@ -124,7 +124,7 @@ private: SDFBVBlock* blocks; - ByteStream* tempBlock; + ByteStreamPtr tempBlock; }; } diff --git a/include/SDFRBBlock.h b/include/SDFRBBlock.h index 525211e..c1ed4e3 100644 --- a/include/SDFRBBlock.h +++ b/include/SDFRBBlock.h @@ -142,13 +142,13 @@ public: return ID; }; - virtual bool setOutputStream(ByteStream* os, dword first); + virtual bool setOutputStream(ByteStreamPtr os, dword first); - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); - virtual bool setByteStream(ByteStream* s); + virtual bool setByteStream(ByteStreamPtr s); - virtual ByteStream* getByteStream() + virtual ByteStreamPtr getByteStream() { return stream; } @@ -212,7 +212,7 @@ protected: bool reset_output_stream; - ByteStream* tempBlock1; + ByteStreamPtr tempBlock1; SDFRBBlockType* type; diff --git a/include/SDFRBlock.h b/include/SDFRBlock.h index ee13cdf..177e5e5 100644 --- a/include/SDFRBlock.h +++ b/include/SDFRBlock.h @@ -66,11 +66,11 @@ public: virtual dword getDimension(); - virtual bool setByteStream(ByteStream* s); + virtual bool setByteStream(ByteStreamPtr s); - virtual bool setOutputStream(ByteStream* os, dword first); + virtual bool setOutputStream(ByteStreamPtr os, dword first); - virtual ByteStream* generateStream(bool bigendian); + virtual ByteStreamPtr generateStream(bool bigendian); /// Set the number of blocks (the number of times that a block of a diff --git a/include/Socket.h b/include/Socket.h index a3ec92a..7782e4f 100644 --- a/include/Socket.h +++ b/include/Socket.h @@ -51,9 +51,9 @@ public: } /// Data Transimission - virtual bool send ( ByteStream* b ) const throw(PacketExceptionIO*) ; + virtual bool send ( ByteStreamPtr b ) const throw(PacketExceptionIO*) ; - virtual ByteStream* recv (word dim, int & status) throw(PacketExceptionIO*) ; + virtual ByteStreamPtr recv (word dim, int & status) throw(PacketExceptionIO*) ; virtual bool connect ( const std::string host, const int port ) throw(PacketExceptionIO*); diff --git a/src/ByteStream.cpp b/src/ByteStream.cpp index 49b65c9..575dfe3 100644 --- a/src/ByteStream.cpp +++ b/src/ByteStream.cpp @@ -32,7 +32,7 @@ dword ByteStream::count_object_deleted2 = 0; /// Returns a pointer of a field in the list of fields of this part of packet. /// \remarks mem_allocation = true indicates that the allocated memory must be released by the destroyer. /// \remarks memory_sharing=false In all methods of constructor or set type accepting byte*, it indicates that the swap is applied. -/// In all methods of constructor or set type accepting ByteStream* the swap is never applied. +/// In all methods of constructor or set type accepting ByteStreamPtr the swap is never applied. PacketLib::ByteStream::ByteStream(bool bigendian) { @@ -76,7 +76,7 @@ PacketLib::ByteStream::ByteStream(byte* stream, dword dim, bool bigendian, bool } -PacketLib::ByteStream::ByteStream(ByteStream* b0, ByteStream* b1, ByteStream* b2) +PacketLib::ByteStream::ByteStream(ByteStreamPtr b0, ByteStreamPtr b1, ByteStreamPtr b2) { mem_allocation_constructor = true; @@ -201,20 +201,20 @@ long PacketLib::ByteStream::getValue(dword start, word dim) -ByteStream* PacketLib::ByteStream::getSubByteStream(dword first, dword last) +ByteStreamPtr PacketLib::ByteStream::getSubByteStream(dword first, dword last) { DEMORET0; if(first > last) return NULL; if(last > byteInTheStream) return NULL; - ByteStream* b = new ByteStream((stream + first), last-first+1, bigendian, true); + ByteStreamPtr b = ByteStreamPtr(new ByteStream((stream + first), last-first+1, bigendian, true)); return b; } -ByteStream* PacketLib::ByteStream::getSubByteStreamCopy(dword first, dword last) +ByteStreamPtr PacketLib::ByteStream::getSubByteStreamCopy(dword first, dword last) { DEMORET0; if(first > last) @@ -224,8 +224,7 @@ ByteStream* PacketLib::ByteStream::getSubByteStreamCopy(dword first, dword last) byte* streamtemp = (byte*) new byte[last-first+1]; for(dword i=0; i<last-first+1; i++) streamtemp[i] = stream[first+i]; - ByteStream* b = new ByteStream(streamtemp, last-first+1, bigendian, false); - return b; + return ByteStreamPtr(new ByteStream(streamtemp, last-first+1, bigendian, false)); } @@ -292,7 +291,7 @@ bool PacketLib::ByteStream::setStream(byte* b, dword dim, bool bigendian, bool m -bool PacketLib::ByteStream::setStream(ByteStream* b, dword first, dword last) +bool PacketLib::ByteStream::setStream(ByteStreamPtr b, dword first, dword last) { if(first > last) return false; diff --git a/src/File.cpp b/src/File.cpp index 9745902..4c51abb 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -106,18 +106,18 @@ int File::getByte() } -ByteStream* File::getNByte(dword N) +ByteStreamPtr File::getNByte(dword N) { dword i = 0; int c1, c2; if(N == 0) - return new ByteStream(0, bigendian); + return ByteStreamPtr(new ByteStream(0, bigendian)); //solo un numero pari di byte //if(N%2 != 0 || !fileOpened) return NULL; if(closed) return NULL; - //ByteStream* b = new ByteStream(N, bigendian); + //ByteStreamPtr b = new ByteStream(N, bigendian); byte* stream = (byte*) new byte[N]; for(i = 0; i<N && (c1 = getByte()) != EOI && (c2 = getByte()) != EOI; i+=2) @@ -141,7 +141,7 @@ ByteStream* File::getNByte(dword N) } /*if(i != N) { - ByteStream* b1 = new ByteStream(i, bigendian); + ByteStreamPtr b1 = new ByteStream(i, bigendian); for(int j = 0; j<i; j++) b1->stream[j] = b->stream[j]; delete b; @@ -150,7 +150,7 @@ ByteStream* File::getNByte(dword N) //for(; i<N; i++) // b->stream[i] = 0; //return b; - return new ByteStream(stream, i, bigendian, false); + return ByteStreamPtr(new ByteStream(stream, i, bigendian, false)); } @@ -336,7 +336,7 @@ bool File::writeString(const char* str) throw(PacketExceptionIO*) -bool File::writeByteStream(ByteStream* b) throw(PacketExceptionIO*) +bool File::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) { byte* stream = b->getOutputStream(); if(fwrite((void*)stream, b->getDimension(), 1, fp)<1) diff --git a/src/FileStream.cpp b/src/FileStream.cpp index 3ff1b55..c0d5394 100644 --- a/src/FileStream.cpp +++ b/src/FileStream.cpp @@ -27,21 +27,21 @@ FileStream::FileStream(bool prefix, bool bigen, word dimprefix, long startpositi } -ByteStream* FileStream::readHeader(unsigned int dimHeader) +ByteStreamPtr FileStream::readHeader(unsigned int dimHeader) { header = getNByte(dimHeader); return header; } -ByteStream* FileStream::readDataField(unsigned int dimDataField) +ByteStreamPtr FileStream::readDataField(unsigned int dimDataField) { dataField = getNByte(dimDataField); return dataField; } -ByteStream* FileStream::readPrefix() +ByteStreamPtr FileStream::readPrefix() { if(thereIsPrefix) prefix = getNByte(dimPrefix); diff --git a/src/InputFile.cpp b/src/InputFile.cpp index 69c93f2..8176966 100644 --- a/src/InputFile.cpp +++ b/src/InputFile.cpp @@ -49,9 +49,9 @@ void InputFile::close() throw(PacketExceptionIO*) } -ByteStream* InputFile::readByteStream(dword n_byte) throw(PacketExceptionIO*) +ByteStreamPtr InputFile::readByteStream(dword n_byte) throw(PacketExceptionIO*) { - ByteStream* bs; + ByteStreamPtr bs; if(!closed) bs = file->getNByte(n_byte); else diff --git a/src/InputPacketStream.cpp b/src/InputPacketStream.cpp index a58055a..3edb07d 100644 --- a/src/InputPacketStream.cpp +++ b/src/InputPacketStream.cpp @@ -40,7 +40,7 @@ InputPacketStream::~InputPacketStream() } -int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +int InputPacketStream::detPacketType(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { /// Iterate through list and output each element. /// The packetType 0 is the packet not recognized @@ -55,7 +55,7 @@ int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packetHeade -int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packet) +int InputPacketStream::detPacketType(ByteStreamPtr prefix, ByteStreamPtr packet) { /// Iterate through list and output each element. /// The packetType 0 is the packet not recognized @@ -93,7 +93,7 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*) { unsigned dimHeader = getHeaderDimension(); unsigned dimPrefix = getPrefixDimension(); - ByteStream* b1 = 0, *b2 = 0, *b0 = 0; + ByteStreamPtr b0, b1, b2; dword pl, dim, pindex; try { @@ -162,16 +162,15 @@ dword InputPacketStream::getPacketDimension(byte* stream) { dword dimPre = 0; if(prefix) dimPre += dimPrefix; - //ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + //ByteStreamPtr prefix = new ByteStream(stream, dimPre, bigendian); dword dim = 0; dword dimHeader = headerReference->getDimension(); dim += dimHeader; - ByteStream* tempHeader = new ByteStream(); + ByteStreamPtr tempHeader = ByteStreamPtr(new ByteStream()); tempHeader->setStream(stream+dimPre, dimHeader, bigendian); headerReference->setByteStream(tempHeader); dim += headerReference->getPacketLength(); - delete tempHeader; return dim; } diff --git a/src/InputPacketStreamFile.cpp b/src/InputPacketStreamFile.cpp index 0abdb34..da260b0 100644 --- a/src/InputPacketStreamFile.cpp +++ b/src/InputPacketStreamFile.cpp @@ -90,7 +90,7 @@ bool InputPacketStreamFile::openInputStream() throw(PacketExceptionIO*) bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*) { - ByteStream* b1 = 0, *b2 = 0, *b0 = 0; + ByteStreamPtr b0, b1, b2; word pl, dim; long pointer; @@ -110,10 +110,8 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*) pointer = inputStream->getpos(); b0 = inputStream->readPrefix(); if(inputStream->isEOF()) - { - delete b0; return true; - } + b1 = inputStream->readHeader(dimHeader); if(b1->getDimension() != dimHeader) { @@ -121,8 +119,6 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*) pindex = 0; else { - delete b0; - delete b1; numberOfFileStreamPointer = count; return false; } @@ -139,9 +135,6 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*) pindex = 0; else { - delete b0; - delete b1; - delete b2; numberOfFileStreamPointer = count; return false; } @@ -149,9 +142,6 @@ bool InputPacketStreamFile::freeRun() throw(PacketExceptionIO*) else pindex = detPacketType(b0, b1, b2); } - delete b0; - delete b1; - delete b2; FileStreamPointer* fsp = new FileStreamPointer; fsp->typeOfPacket = pindex; fsp->pointerStart = pointer; @@ -187,7 +177,7 @@ Packet* InputPacketStreamFile::getPacketFromFileStreamPointer(int index, bool ne //int i; long pos; int type; - ByteStream* b1 = 0, *b2 = 0, *b0 = 0; + ByteStreamPtr b0, b1, b2; word pl; if(index > numberOfFileStreamPointer) @@ -275,7 +265,7 @@ long InputPacketStreamFile::getNumberOfFileStreamPointer() Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO * ) { - ByteStream* b1 = 0, *b2 = 0, *b0 = 0; + ByteStreamPtr b0, b1, b2; word pl, dim; unsigned dimHeader = headerReference->getDimension(); @@ -283,29 +273,17 @@ Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO * return 0; b0 = inputStream->readPrefix(); if(inputStream->isEOF()) - { - delete b0; return 0; - } b1 = inputStream->readHeader(dimHeader); if(b1->getDimension() != dimHeader) - { - delete b0; - delete b1; return 0; - } headerReference->setByteStream(b1); pl = headerReference->getPacketLength(); b2 = inputStream->readDataField(pl); dim = b2->getDimension(); if(dim != pl) - { - delete b0; - delete b1; - delete b2; return 0; - } Packet* p; for (int i = 1; i<numberOfPacketType; i++) @@ -316,9 +294,7 @@ Packet* InputPacketStreamFile::getPacketFromStream() throw (PacketExceptionIO * return p; } } - p->deleteExternalByteStream(); return 0; - } diff --git a/src/InputSerial.cpp b/src/InputSerial.cpp index 2234559..90f5d75 100644 --- a/src/InputSerial.cpp +++ b/src/InputSerial.cpp @@ -56,10 +56,10 @@ void InputSerial::close() throw(PacketExceptionIO*) -ByteStream* InputSerial::readByteStream(int n_byte) throw(PacketExceptionIO*) +ByteStreamPtr InputSerial::readByteStream(int n_byte) throw(PacketExceptionIO*) { //cout << "waiting " << n_byte << endl; - ByteStream* bs; + ByteStreamPtr bs; byte* buff = new byte[n_byte]; int current = 0; if(!closed) @@ -71,12 +71,12 @@ ByteStream* InputSerial::readByteStream(int n_byte) throw(PacketExceptionIO*) current += readed; if( current == 0 ) { - bs = new ByteStream(0, bigendian); + bs = ByteStreamPtr(new ByteStream(0, bigendian)); break; } } if(current != 0) - bs = new ByteStream( buff, n_byte, bigendian ); + bs = ByteStreamPtr(new ByteStream(buff, n_byte, bigendian)); } else return 0; diff --git a/src/InputSocketServer.cpp b/src/InputSocketServer.cpp index 00f5feb..7cb5853 100644 --- a/src/InputSocketServer.cpp +++ b/src/InputSocketServer.cpp @@ -57,7 +57,7 @@ void InputSocketServer::close() throw(PacketExceptionIO*) -ByteStream* InputSocketServer::readByteStream(dword n_byte) throw(PacketExceptionIO*) +ByteStreamPtr InputSocketServer::readByteStream(dword n_byte) throw(PacketExceptionIO*) { int status = 0; if(!accepted) @@ -68,7 +68,7 @@ ByteStream* InputSocketServer::readByteStream(dword n_byte) throw(PacketExceptio eof = false; } - ByteStream* bl = new_sock->recv(n_byte, status); + ByteStreamPtr bl = new_sock->recv(n_byte, status); if(status == 0) { accepted = false; diff --git a/src/OutputFile.cpp b/src/OutputFile.cpp index 3b3f9e2..f6a93db 100644 --- a/src/OutputFile.cpp +++ b/src/OutputFile.cpp @@ -52,7 +52,7 @@ bool OutputFile::open(char** parameters) throw(PacketExceptionIO*) -bool OutputFile::writeByteStream(ByteStream* b) throw(PacketExceptionIO*) +bool OutputFile::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) { if(!isclosed) file->writeByteStream(b); diff --git a/src/OutputPacketStream.cpp b/src/OutputPacketStream.cpp index 9ab1236..4297eeb 100644 --- a/src/OutputPacketStream.cpp +++ b/src/OutputPacketStream.cpp @@ -35,14 +35,13 @@ OutputPacketStream::OutputPacketStream(const char* fileNameConfig) : PacketStrea bool OutputPacketStream::writePacket(Packet* p) throw(PacketExceptionIO*) { - ByteStream* bs; + ByteStreamPtr bs; try { bs = p->getOutputStream(); if(out == 0) throw new PacketExceptionIO("No output set.."); out->writeByteStream(bs); - delete bs; return true; } catch(PacketExceptionIO* e) diff --git a/src/OutputSerial.cpp b/src/OutputSerial.cpp index 73d5699..2403936 100644 --- a/src/OutputSerial.cpp +++ b/src/OutputSerial.cpp @@ -53,7 +53,7 @@ bool OutputSerial::open(char** parameters) throw(PacketExceptionIO*) -bool OutputSerial::writeByteStream(ByteStream* b) throw(PacketExceptionIO*) +bool OutputSerial::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) { byte* buff = b->getStream(); unsigned n_byte = b->getDimension(); diff --git a/src/OutputSocketClient.cpp b/src/OutputSocketClient.cpp index e06b4f2..1a0f707 100644 --- a/src/OutputSocketClient.cpp +++ b/src/OutputSocketClient.cpp @@ -52,7 +52,7 @@ bool OutputSocketClient::open(char** argv) throw(PacketExceptionIO*) -bool OutputSocketClient::writeByteStream(ByteStream* b) throw(PacketExceptionIO*) +bool OutputSocketClient::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) { if(!isclosed) socketclient->send(b); diff --git a/src/Packet.cpp b/src/Packet.cpp index 2b13795..53c9307 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -27,20 +27,16 @@ Packet::Packet(bool bigendian) header = (PacketHeader*) new PacketHeader(); dataField = (PacketDataField*) new PacketDataField(); name = 0; - prefix = 0; // tail = new PartOfPacket(); number_of_identifier = 0; identifiers = 0; - prefix = 0; - packet = 0; - packet_output = 0; this->bigendian = bigendian; /// temp - tempHeader = new ByteStream(); - tempDataField = new ByteStream(); - tempDataFieldHeader = new ByteStream(); - tempPacketDataField = new ByteStream(); - tempTail = new ByteStream(); + tempHeader = ByteStreamPtr(new ByteStream); + tempDataField = ByteStreamPtr(new ByteStream); + tempDataFieldHeader = ByteStreamPtr(new ByteStream); + tempPacketDataField = ByteStreamPtr(new ByteStream); + tempTail = ByteStreamPtr(new ByteStream); first_output_stream_setted = false; } @@ -57,19 +53,6 @@ Packet::~Packet() for(unsigned i = 0; i < number_of_identifier; i++) delete identifiers[i]; delete[] identifiers; - delete packet_output; - packet_output = 0; - delete tempHeader; - tempHeader = 0; - delete tempDataField; - tempDataField = 0; - //ANDREA: ricordato di indagare perche' non si riesce ad effettuare il delete - delete tempDataFieldHeader; - tempDataFieldHeader = 0; - delete tempPacketDataField; - tempPacketDataField = 0; - delete tempTail; - tempTail = 0; } @@ -184,7 +167,7 @@ bool Packet::createPacketType(char* fileName, bool isprefix, word dimprefix) thr /// Memory allocation for the output stream dword dimpo = getMaxDimension(); dword dimpr = (isprefix?dimprefix:0); - packet_output = new ByteStream(dimpo + dimpr, bigendian); + packet_output = ByteStreamPtr(new ByteStream(dimpo + dimpr, bigendian)); file.close(); return true; @@ -310,11 +293,11 @@ void Packet::printIdentifiers() } -bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +bool Packet::setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { //cout << "@ " << packetDataField->getDimension() << endl; memByteStream(prefix, packetHeader, packetDataField); - ByteStream* packet = new ByteStream(packetHeader, packetDataField, 0); + ByteStreamPtr packet = ByteStreamPtr(new ByteStream(packetHeader, packetDataField, 0)); memByteStream(prefix, packet); /// 1) if(!setPacketValueVerify(prefix, packetHeader, packetDataField)) @@ -358,7 +341,7 @@ bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteSt -bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packet) +bool Packet::setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet) { dword dimHeader = header->getDimension(); memByteStream(prefix, packet); @@ -369,7 +352,7 @@ bool Packet::setPacketValue(ByteStream* prefix, ByteStream* packet) -bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packet) +bool Packet::verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet) { dword dimHeader = header->getDimension(); memByteStream(prefix, packet); @@ -380,7 +363,7 @@ bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packet) -bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +bool Packet::verifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { bool verified = true; memByteStream(prefix, packetHeader, packetDataField); @@ -441,7 +424,7 @@ bool Packet::verifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, Byt } -bool Packet::setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packet) +bool Packet::setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packet) { dword dimHeader = header->getDimension(); memByteStream(prefix, packet); @@ -451,10 +434,10 @@ bool Packet::setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packet) } -bool Packet::setAndVerifyPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +bool Packet::setAndVerifyPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { memByteStream(prefix, packetHeader, packetDataField); - ByteStream* packet = new ByteStream(packetHeader, packetDataField, 0); + ByteStreamPtr packet = ByteStreamPtr(new ByteStream(packetHeader, packetDataField, 0)); memByteStream(prefix, packet); if(verifyPacketValue(prefix, packetHeader, packetDataField)==false) { @@ -572,7 +555,7 @@ void Packet::generateStream() -bool Packet::setPacketValueVerify(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +bool Packet::setPacketValueVerify(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { /// 1) Checking /// First check: pointers control @@ -586,7 +569,7 @@ bool Packet::setPacketValueVerify(ByteStream* prefix, ByteStream* packetHeader, -bool Packet::setPacketValuePrefix(ByteStream* prefix) +bool Packet::setPacketValuePrefix(ByteStreamPtr prefix) { //2) prefix this->prefix = prefix; @@ -595,7 +578,7 @@ bool Packet::setPacketValuePrefix(ByteStream* prefix) -bool Packet::setPacketValueDataFieldHeader(ByteStream* packetDataField) +bool Packet::setPacketValueDataFieldHeader(ByteStreamPtr packetDataField) { bool b; dword packetLength; @@ -613,7 +596,7 @@ bool Packet::setPacketValueDataFieldHeader(ByteStream* packetDataField) } -bool Packet::setPacketValueSourceDataField(ByteStream* packetDataField) +bool Packet::setPacketValueSourceDataField(ByteStreamPtr packetDataField) { bool b; dword packetLength; @@ -652,7 +635,7 @@ bool Packet::setPacketValueSourceDataField(ByteStream* packetDataField) } -bool Packet::setPacketValueTail(ByteStream* packetDataField) +bool Packet::setPacketValueTail(ByteStreamPtr packetDataField) { bool b; dword s, e; @@ -678,7 +661,7 @@ bool Packet::setPacketValueTail(ByteStream* packetDataField) -bool Packet::setPacketValueHeader(ByteStream* packetHeader) +bool Packet::setPacketValueHeader(ByteStreamPtr packetHeader) { /// 3) Header /// Reading and setting the packet header @@ -688,38 +671,7 @@ bool Packet::setPacketValueHeader(ByteStream* packetHeader) return true; } - - -void Packet::deleteExternalByteStream() -{ - if(prefix != 0) - if(prefix->getMemAllocation()) - { - delete prefix; - prefix = 0; - } - if(packet !=0) - if(packet->getMemAllocation()) - { - delete packet; - packet = 0; - } - if(dataField->getByteStream() != 0) - if(dataField->getByteStream()->getMemAllocation()) - { - dataField->deleteByteStream(); - - } - if(header->getByteStream() != 0) - if(header->getByteStream()->getMemAllocation()) - { - header->deleteByteStream(); - } -} - - - -void Packet::memByteStream(ByteStream* prefix, ByteStream* packet) +void Packet::memByteStream(ByteStreamPtr prefix, ByteStreamPtr packet) { this->prefix = prefix; this->packet = packet; @@ -727,7 +679,7 @@ void Packet::memByteStream(ByteStream* prefix, ByteStream* packet) -void Packet::memByteStream(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +void Packet::memByteStream(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { this->prefix = prefix; //this->packet = 0; @@ -737,17 +689,17 @@ void Packet::memByteStream(ByteStream* prefix, ByteStream* packetHeader, ByteStr -ByteStream* Packet::getOutputStream() +ByteStreamPtr Packet::getOutputStream() { generateStream(); - ByteStream* b = new ByteStream(packet_output->stream, getDimension() + (thereisprefix?dimPrefix:0), bigendian); + ByteStreamPtr b = ByteStreamPtr(new ByteStream(packet_output->stream, getDimension() + (thereisprefix?dimPrefix:0), bigendian)); return b; } -ByteStream* Packet::getInputStream() +ByteStreamPtr Packet::getInputStream() { if(packet == 0) - packet = new ByteStream(header->getByteStream(), dataField->getByteStream(), 0); + packet = ByteStreamPtr(new ByteStream(header->getByteStream(), dataField->getByteStream(), 0)); return packet; } @@ -841,7 +793,7 @@ bool Packet::verifyPacketValue(byte* stream) { dword dimPre = 0; if(thereisprefix) dimPre += dimPrefix; - ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + ByteStreamPtr prefix = ByteStreamPtr(new ByteStream(stream, dimPre, bigendian)); dword dim = 0; dword dimHeader = header->getDimension(); @@ -849,7 +801,7 @@ bool Packet::verifyPacketValue(byte* stream) { tempHeader->setStream(stream+dimPre, dimHeader, bigendian); header->setByteStream(tempHeader); dim += header->getDimensionOfPacketLength() + 1; - ByteStream* packet = new ByteStream(stream+dimPre, dim, bigendian); + ByteStreamPtr packet = ByteStreamPtr(new ByteStream(stream+dimPre, dim, bigendian)); return verifyPacketValue(prefix, packet); } @@ -858,7 +810,7 @@ bool Packet::setPacketValue(byte* stream) { dword dimPre = 0; if(thereisprefix) dimPre += dimPrefix; - ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + ByteStreamPtr prefix = ByteStreamPtr(new ByteStream(stream, dimPre, bigendian)); dword dim = 0; dword dimHeader = header->getDimension(); @@ -866,7 +818,7 @@ bool Packet::setPacketValue(byte* stream) { tempHeader->setStream(stream+dimPre, dimHeader, bigendian); header->setByteStream(tempHeader); dim += header->getPacketLength() + 1; - ByteStream* packet = new ByteStream(stream+dimPre, dim, bigendian); + ByteStreamPtr packet = ByteStreamPtr(new ByteStream(stream+dimPre, dim, bigendian)); return setPacketValue(prefix, packet); diff --git a/src/PacketDataField.cpp b/src/PacketDataField.cpp index 48ce785..c0f274e 100644 --- a/src/PacketDataField.cpp +++ b/src/PacketDataField.cpp @@ -98,10 +98,9 @@ void PacketDataField::setNumberOfRealDataBlock(word number) -bool PacketDataField::setOutputStream(ByteStream* os, word first) +bool PacketDataField::setOutputStream(ByteStreamPtr os, word first) { - delete outputstream; - outputstream = new ByteStream((os->stream + first), getDimension(), os->isBigendian()); + outputstream = ByteStreamPtr(new ByteStream((os->stream + first), getDimension(), os->isBigendian())); dataFieldHeader->setOutputStream(os, first); word sdfstart = first + dataFieldHeader->getDimension(); sourceDataField->setOutputStream(os, sdfstart); @@ -115,7 +114,7 @@ bool PacketDataField::setOutputStream(ByteStream* os, word first) -ByteStream* PacketDataField::generateStream(bool bigendian) +ByteStreamPtr PacketDataField::generateStream(bool bigendian) { dataFieldHeader->generateStream(bigendian); sourceDataField->generateStream(bigendian); diff --git a/src/PacketNotRecognized.cpp b/src/PacketNotRecognized.cpp index f2b01eb..c7eac34 100644 --- a/src/PacketNotRecognized.cpp +++ b/src/PacketNotRecognized.cpp @@ -72,7 +72,7 @@ PacketNotRecognized::~PacketNotRecognized() -bool PacketNotRecognized::setPacketValue(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField) +bool PacketNotRecognized::setPacketValue(ByteStreamPtr prefix, ByteStreamPtr packetHeader, ByteStreamPtr packetDataField) { /// It reads and sets the packet header if(!header->setByteStream(packetHeader)) diff --git a/src/PartOfPacket.cpp b/src/PartOfPacket.cpp index e2db068..4194a4e 100644 --- a/src/PartOfPacket.cpp +++ b/src/PartOfPacket.cpp @@ -25,7 +25,7 @@ word PacketLib::pattern[] = {0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16 PartOfPacket::PartOfPacket(const char* popName) { fieldsDimension = 0; - stream = new ByteStream(); + stream = ByteStreamPtr(new ByteStream()); numberOfFields = 0; fields = 0; outputstream = 0; @@ -201,7 +201,7 @@ MemoryBuffer* PartOfPacket::loadFieldsInBuffer(InputText & fp) } -bool PartOfPacket::setByteStream(ByteStream* s) +bool PartOfPacket::setByteStream(ByteStreamPtr s) { Field* ftemp; @@ -384,7 +384,7 @@ void PartOfPacket::deleteFields() } -ByteStream* PartOfPacket::generateStream(bool bigendian) +ByteStreamPtr PartOfPacket::generateStream(bool bigendian) { word w = 0, wtemp = 0; int posbit = 0; @@ -393,7 +393,7 @@ ByteStream* PartOfPacket::generateStream(bool bigendian) /// Dimension of the current field byte dimbit = 0; if(outputstream == 0) - outputstream = new ByteStream(getDimension(), bigendian); + outputstream = ByteStreamPtr(new ByteStream(getDimension(), bigendian)); for(unsigned i = 0; i<numberOfFields; i++) { if(!fields[i]->thereIsPredefinedValue()) @@ -446,10 +446,9 @@ ByteStream* PartOfPacket::generateStream(bool bigendian) }; -bool PartOfPacket::setOutputStream(ByteStream* os, dword first) +bool PartOfPacket::setOutputStream(ByteStreamPtr os, dword first) { - delete outputstream; - outputstream = new ByteStream((os->stream + first), getDimension(), os->isBigendian()); + outputstream = ByteStreamPtr(new ByteStream((os->stream + first), getDimension(), os->isBigendian())); return true; } @@ -582,11 +581,6 @@ void PartOfPacket::setFieldValue_4_13(word index, signed long value) throw(Packe setFieldValue_3_14(index, value2); } -void PacketLib::PartOfPacket::deleteByteStream() { - delete stream; - stream = 0; -} - -void PacketLib::PartOfPacket::memByteStream(ByteStream* stream) { +void PacketLib::PartOfPacket::memByteStream(ByteStreamPtr stream) { this->stream = stream; } diff --git a/src/SDFBVBlock.cpp b/src/SDFBVBlock.cpp index 1a2389f..dd73be3 100644 --- a/src/SDFBVBlock.cpp +++ b/src/SDFBVBlock.cpp @@ -83,7 +83,7 @@ dword SDFBVBlock::getMaxDimension() -bool SDFBVBlock::setOutputStream(ByteStream* os, dword first) +bool SDFBVBlock::setOutputStream(ByteStreamPtr os, dword first) { fixed.setOutputStream(os, first); dword nrb = fixed.getNumberOfRealElement(); @@ -98,7 +98,7 @@ bool SDFBVBlock::setOutputStream(ByteStream* os, dword first) -ByteStream* SDFBVBlock::generateStream(bool bigendian) +ByteStreamPtr SDFBVBlock::generateStream(bool bigendian) { fixed.generateStream(bigendian); word nrb = fixed.getNumberOfRealElement(); diff --git a/src/SDFBlockFixed.cpp b/src/SDFBlockFixed.cpp index c7735d4..02c0462 100644 --- a/src/SDFBlockFixed.cpp +++ b/src/SDFBlockFixed.cpp @@ -88,19 +88,15 @@ SDFBlockFixed::SDFBlockFixed() : SourceDataField("SDF Block Fixed") rblock = false; block = NULL; subFromNBlock[0] = 0; - tempBlock = new ByteStream(); + tempBlock = ByteStreamPtr(new ByteStream()); } SDFBlockFixed::~SDFBlockFixed() { - delete tempBlock; - tempBlock = 0; //for(int i=0; i< maxNumberOfBlock; i++) // delete &block[i]; - delete[] block; - block = 0; } @@ -177,7 +173,7 @@ word SDFBlockFixed::getNumberOfFields() -bool SDFBlockFixed::setByteStream(ByteStream* s) +bool SDFBlockFixed::setByteStream(ByteStreamPtr s) { bool b; word bytestart=0, bytestop=0; @@ -296,12 +292,11 @@ string* SDFBlockFixed::printStructure() } -bool SDFBlockFixed::setOutputStream(ByteStream* os, dword first) +bool SDFBlockFixed::setOutputStream(ByteStreamPtr os, dword first) { dword mnb = getNumberOfRealDataBlock(); dword start = first; - delete outputstream; - outputstream = new ByteStream((os->stream + first), getDimension(), os->isBigendian()); + outputstream = ByteStreamPtr(new ByteStream((os->stream + first), getDimension(), os->isBigendian())); for(dword i = 0; i<mnb; i++) { block[i].setOutputStream(os, start); @@ -311,7 +306,7 @@ bool SDFBlockFixed::setOutputStream(ByteStream* os, dword first) } -ByteStream* SDFBlockFixed::generateStream(bool bigendian) +ByteStreamPtr SDFBlockFixed::generateStream(bool bigendian) { word mnb = getNumberOfRealDataBlock(); for(word i = 0; i<mnb; i++) diff --git a/src/SDFBlockVariable.cpp b/src/SDFBlockVariable.cpp index e89c979..b166fc2 100644 --- a/src/SDFBlockVariable.cpp +++ b/src/SDFBlockVariable.cpp @@ -161,7 +161,7 @@ SDFBlockVariable::SDFBlockVariable() : SourceDataField("SDF Block Variable") fixed = false; rblock = false; blocks = 0; - tempBlock = new ByteStream(); + tempBlock = ByteStreamPtr(new ByteStream()); } @@ -189,7 +189,7 @@ word SDFBlockVariable::getNumberOfFields() -bool SDFBlockVariable::setByteStream(ByteStream* s) +bool SDFBlockVariable::setByteStream(ByteStreamPtr s) { word bytestart=0, bytestop=0; word number_of_real_element; @@ -396,12 +396,11 @@ void SDFBlockVariable::setFieldValue(word block, word index, word value) -bool SDFBlockVariable::setOutputStream(ByteStream* os, dword first) +bool SDFBlockVariable::setOutputStream(ByteStreamPtr os, dword first) { dword mnb = getNumberOfRealDataBlock(); dword start = first; - delete outputstream; - outputstream = new ByteStream((os->stream + first), getDimension(), os->isBigendian()); + outputstream = ByteStreamPtr(new ByteStream((os->stream + first), getDimension(), os->isBigendian())); for(dword i = 0; i<mnb; i++) { blocks[i].setOutputStream(os, start); @@ -412,7 +411,7 @@ bool SDFBlockVariable::setOutputStream(ByteStream* os, dword first) -ByteStream* SDFBlockVariable::generateStream(bool bigendian) +ByteStreamPtr SDFBlockVariable::generateStream(bool bigendian) { word mnb = getNumberOfRealDataBlock(); for(word i = 0; i<mnb; i++) diff --git a/src/SDFRBBlock.cpp b/src/SDFRBBlock.cpp index 6e44308..a952080 100644 --- a/src/SDFRBBlock.cpp +++ b/src/SDFRBBlock.cpp @@ -211,7 +211,7 @@ bool SDFRBBlockType::loadType(InputText& fp) throw(PacketException*) SDFRBBlock::SDFRBBlock() : block(0) { - tempBlock1 = new ByteStream(); + tempBlock1 = ByteStreamPtr(new ByteStream()); counter++; //cout << counter << " " << sizeof(SDFRBBlock) << endl; @@ -449,15 +449,14 @@ word SDFRBBlock::getCurrentNumberOfBlocks() return nblock; } -bool SDFRBBlock::setOutputStream(ByteStream* os, dword first) +bool SDFRBBlock::setOutputStream(ByteStreamPtr os, dword first) { dword start = first; /// It sets the output stream for the fixed part (if present) if(type->fixedPresent) { fixed.setOutputStream(os, start); - delete outputstream; - outputstream = new ByteStream((os->stream + start), getDimension(), os->isBigendian()); + outputstream = ByteStreamPtr(new ByteStream((os->stream + start), getDimension(), os->isBigendian())); start += fixed.getDimension(); } if(type->variablePresent) @@ -481,7 +480,7 @@ bool SDFRBBlock::setOutputStream(ByteStream* os, dword first) return true; } -ByteStream* SDFRBBlock::generateStream(bool bigendian) +ByteStreamPtr SDFRBBlock::generateStream(bool bigendian) { if(type->fixedPresent) fixed.generateStream(bigendian); @@ -507,15 +506,15 @@ ByteStream* SDFRBBlock::generateStream(bool bigendian) return outputstream; } -bool SDFRBBlock::setByteStream(ByteStream* s) +bool SDFRBBlock::setByteStream(ByteStreamPtr s) { - //cout << "bool SDFRBBlock::setByteStream(ByteStream* s)" << " " << s << endl; //AB + //cout << "bool SDFRBBlock::setByteStream(ByteStreamPtr s)" << " " << s << endl; //AB dword bytestart=0; dword bytestop=0; this->stream->setStream(s, 0, s->getDimension() - 1); - //ByteStream* tmpstream = new ByteStream(s->stream, s->getDimension(), s->isBigendian()); - //ByteStream* s = new ByteStream(k->stream, k->getDimension(), k->isBigendian()); + //ByteStreamPtr tmpstream = new ByteStream(s->stream, s->getDimension(), s->isBigendian()); + //ByteStreamPtr s = new ByteStream(k->stream, k->getDimension(), k->isBigendian()); // It sets the output stream for the fixed part (if present) if(type->fixedPresent) { diff --git a/src/SDFRBlock.cpp b/src/SDFRBlock.cpp index 5206bb0..f92b40d 100644 --- a/src/SDFRBlock.cpp +++ b/src/SDFRBlock.cpp @@ -97,17 +97,17 @@ word SDFRBlock::getNumberOfRealDataBlock(word rblockIndex) } -bool SDFRBlock::setOutputStream(ByteStream* os, dword first) +bool SDFRBlock::setOutputStream(ByteStreamPtr os, dword first) { return block[0].setOutputStream(os, first); } -ByteStream* SDFRBlock::generateStream(bool bigendian) +ByteStreamPtr SDFRBlock::generateStream(bool bigendian) { return block[0].generateStream(bigendian); } -bool SDFRBlock::setByteStream(ByteStream* s) +bool SDFRBlock::setByteStream(ByteStreamPtr s) { stream = s; return block[0].setByteStream(s); diff --git a/src/Socket.cpp b/src/Socket.cpp index c364aa3..760a841 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -75,7 +75,7 @@ bool Socket::close() throw(PacketExceptionIO*) -bool Socket::send ( ByteStream * b ) const throw(PacketExceptionIO*) +bool Socket::send ( ByteStreamPtr b ) const throw(PacketExceptionIO*) { byte* stream = b->getOutputStream(); //MSG_NOSIGNAL @@ -93,9 +93,9 @@ bool Socket::send ( ByteStream * b ) const throw(PacketExceptionIO*) -ByteStream* Socket::recv (word dim, int & status ) throw(PacketExceptionIO*) +ByteStreamPtr Socket::recv (word dim, int & status ) throw(PacketExceptionIO*) { - //ByteStream* b = new ByteStream(dim, bigendian); + //ByteStreamPtr b = new ByteStream(dim, bigendian); byte* stream = (byte*) new byte[dim]; /*byte* temp = (byte*) new byte[1]; int i; @@ -130,7 +130,7 @@ ByteStream* Socket::recv (word dim, int & status ) throw(PacketExceptionIO*) } else { - ByteStream* b = new ByteStream(stream, dim, bigendian, false); + ByteStreamPtr b = ByteStreamPtr(new ByteStream(stream, dim, bigendian, false)); return b; } -- GitLab