Commit d8788298 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

Added buffer management in InputTextFile

parent c2f7d677
Loading
Loading
Loading
Loading
+1 −21
Original line number Diff line number Diff line
@@ -21,52 +21,32 @@

namespace PacketLib {

//##ModelId=3C0F6C1902FA
//##Documentation
//##	$Date: 2005/03/09 10:57:50 $
//##	$Header: /home/repository/cvs/gtb/PacketLib/include/Field.h,v 1.2 2005/03/09 10:57:50 bulgarelli Exp $
//##	$Id: Field.h,v 1.2 2005/03/09 10:57:50 bulgarelli Exp $
//##	$Revision: 1.2 $
//##	\brief This is a single field of a packet
//A single field of a telemtry packet
class Field
{
    public:

        //##ModelId=3C0F6C1A0001
        //##Documentation
        //## Constructor of class.
        Field(char* name, char* dimension, char* predefinedValue, int progressiv);

        //##ModelId=3ACCD75E036B
        //##Documentation
        //## Destructor of class.
        ~Field();

        //##Documentation
        //## Dimension of field in bit.
        word dimension;

        //##ModelId=3C0F6C1A0000
        //##Documentation
        //## It indicates that there's a predefined value for this field.
        bool thereIsPredefinedValue;

        //##ModelId=3C0F6C1903E5
        //##Documentation
        //## Predefined value of field (for the generation of packet).
        int predefinedValue;

        //##ModelId=3C0F6C1903E6
        //##Documentation
        //## Index of packet in the list of packet.
        int progressiv;

        //##ModelId=3ACCD75E033C
        //##Documentation
        //## Name of the field.
        char* name;

        //##Documentation
        //## Value reads from stream of byte (from packet).
        word value;

+1 −17
Original line number Diff line number Diff line
@@ -23,47 +23,31 @@

namespace PacketLib {

//##ModelId=3C87743F029E
//##Documentation
//##	$Date: 2012/06/08 15:14:29 $
//##	$Header: /home/repository/cvs/gtb/PacketLib/include/InputText.h,v 1.4 2012/06/08 15:14:29 bulgarelli Exp $
//##	$Id: InputText.h,v 1.4 2012/06/08 15:14:29 bulgarelli Exp $
//##	$Revision: 1.4 $
//##	\brief This class represents generic type of input. The input must be a text input. This class is used
//##	for the configuration files
//This class represents generic type of input. The input must be a text input. This class is used for the configuration files
class InputText
{
    public:

        //##ModelId=3AA6490E015C
        InputText();

        //##ModelId=3AA6490E016F
        virtual ~InputText();

        //##ModelId=3AA6490E018D
        virtual char* getLine() throw(PacketExceptionIO*) = 0 ;

        //##ModelId=3AA6490E01AB
        virtual char* getLine(const char* s) throw(PacketExceptionIO*) = 0;

        //##ModelId=3AA6490E01FB
        virtual char* getLastLineRead() = 0;

        virtual char* getInputTextName() = 0;

        //##ModelId=3EADC12902FB
        virtual bool isClosed();

        //##ModelId=3EADC1290322
        virtual bool isEOF();

    protected:

        //##ModelId=3EADC1290274
        bool eof;

        //##ModelId=3EADC12902AC
        bool closed;

};
+9 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "InputText.h"
#include "File.h"
#include "PacketExceptionIO.h"
#include "MemoryBuffer.h"

namespace PacketLib {

@@ -70,8 +71,6 @@ class InputTextFile : public InputText
        //##ModelId=3AA64922020E
        virtual int setFirstPos();

        //##ModelId=3AA64922022C

        virtual bool setLastBookmarkPos();

        //##ModelId=3AA64922025E
@@ -84,6 +83,14 @@ class InputTextFile : public InputText

        File file;
    
    private:
    
        //for caching mechanism
        static MemoryBuffer** listOfBuffers;
        static int nListOfBuffers;
        MemoryBuffer* buffer;
        bool usebuffer;

};

}
+22 −5
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#ifndef MEMORYBUFFER_H
#define MEMORYBUFFER_H
#include "PacketLibDefinition.h"
#include "InputTextFile.h"
#include "PacketExceptionIO.h"

namespace PacketLib {

@@ -51,6 +51,8 @@ class MemoryBuffer
        //## Read property of char** buffer.
        char* getbuffer();
        
        char* getlastbuffer();

        //##ModelId=3EADC12A00CD
        char* getbuffer(dword index);

@@ -71,21 +73,36 @@ class MemoryBuffer
	
		void freebuffer();
		
		void setName(char* name);
		
		char* getName() { return bufferName; };
		
		int getpos();
		
		bool memBookmarkPos();
		
		bool setLastBookmarkPos();
		
		long setpos(int index);

    private:
	//##ModelId=3EADC12A0088
    
    	int bookmarkpos;
    
        dword dim;

        //##ModelId=3EADC12A0091
        char** buffer;

	//##ModelId=3EADC12A0099
        dword indexwrite;

	//##ModelId=3EADC12A00A4
        dword indexread;

        //##ModelId=3EADC12A00AF
        char* currentpwd;
        
        // The name of the buffer
        char* bufferName;
};

}
+29 −81
Original line number Diff line number Diff line
@@ -30,67 +30,45 @@ namespace PacketLib {

extern word pattern[17];

//##ModelId=3C0F6C190370
//##Documentation
//##	This class represent a subset of the packet. This class has been created for grouping
//##	the common behaviours of PacketHeader, DataFieldHeader and SourceDataField
//##	$Date: 2012/06/08 15:14:29 $
//##	$Header: /home/repository/cvs/gtb/PacketLib/include/PartOfPacket.h,v 1.8 2012/06/08 15:14:29 bulgarelli Exp $
//##	$Id: PartOfPacket.h,v 1.8 2012/06/08 15:14:29 bulgarelli Exp $
//##	$Revision: 1.8 $
//##	\brief Single part of packet.
//This class represent a subset of the packet. This class has been created for grouping
//the common behaviours of PacketHeader, DataFieldHeader and SourceDataField
//\brief Single part of packet.
class PartOfPacket
{
    public:

        //##ModelId=3C0F6C1A0223
        //##Documentation
        //## Constructor
        //Constructor
        PartOfPacket(const char* popName = 0);

        //##ModelId=3C35860301F9
        //##Documentation
        //## Virtual destructor
        //Virtual destructor
        virtual ~PartOfPacket();

        //##ModelId=3CAEAC8B0280
        //##Documentation
        //## Prints the structure of this part of packet.
        //Prints the structure of this part of packet.
        virtual string* printStructure();

        //##ModelId=3CAEAC8B02FD
        //##Documentation
        //## Prints the value of each field of this part of packet.
        //Prints the value of each field of this part of packet.
        virtual char** printValue(const char* addString = "");

        //##ModelId=3C0F6C1A0228
        //##Documentation
        //## This method loads the field present into the InputText (passed with the
        //## parameter).
        //## The InputText must be open and the internal pointer of the file must
        //## be in the first line that describes the fields.
        //This method loads the field present into the InputText (passed with the
        //parameter).
        //The InputText must be open and the internal pointer of the file must
        //be in the first line that describes the fields.
        virtual bool loadFields(InputText& fp) throw(PacketException*);

        //##ModelId=3EADC13B032C
        //##Documentation
        //## This method loads the field present into the MemoryBuffer (passed with the
        //## parameter).
        //This method loads the field present into the MemoryBuffer (passed with the
        //parameter).
        virtual bool loadFields(MemoryBuffer* mb) throw(PacketException*);

        //##ModelId=3EADC13C029C
        virtual MemoryBuffer* loadFieldsInBuffer(InputText & fp);

        //##ModelId=3C358603027B
        //##Documentation
        //## Returns the dimension (in byte) of this part of packet.
        //Returns the dimension (in byte) of this part of packet.
        virtual  inline word getDimension() {
          return fieldsDimension / 8;
        };

        //##ModelId=3C187751015F
        //##Documentation
        //## Returns a pointer of a field in the list of fields of this part of packet.
        //## \param index Represent the index in the list.
        //Returns a pointer of a field in the list of fields of this part of packet.
        //\param index Represent the index in the list.
        virtual  inline  Field* getFields(word index) {
          if(index < numberOfFields)
            return fields[index];
@@ -98,10 +76,8 @@ class PartOfPacket
              return 0;            
        };

        //##ModelId=3EADC13D0294
        //##Documentation
        //## Returns the value of a field in the list of fields of this part of packet.
        //## \param index Represent the index in the list.
        //Returns the value of a field in the list of fields of this part of packet.
        //\param index Represent the index in the list.
        virtual  inline word getFieldValue(word index) {
          if(index < numberOfFields)
            return fields[index]->value;
@@ -109,21 +85,19 @@ class PartOfPacket
            return 0;
        };
	
	//##Documentation
	//## Returns the value of a field in the list of fields of this part of packet. 
	//## The value returned is interpreted as a real single precision (IEEE 754).
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
	//## the 32 bit real single precision. The layout foreseen is the following:
	//##	---------------------------------
	//##	-	float last 16 bits	-	the index passed as argument
	//##	---------------------------------
	//##	-	float first 16 bits	-	the index + 1
	//##	---------------------------------	
	//## This corresponds with the PTC=5, PFC = 1.
	//## \param index Represent the index of the field.
	//Returns the value of a field in the list of fields of this part of packet. 
	//The value returned is interpreted as a real single precision (IEEE 754).
	//The index of the argument is the first 16 bit field of the 2 fields that compound
	//the 32 bit real single precision. The layout foreseen is the following:
	//---------------------------------
	//-	float last 16 bits	-	the index passed as argument
	//---------------------------------
	//-	float first 16 bits	-	the index + 1
	//---------------------------------	
	//This corresponds with the PTC=5, PFC = 1.
	//\param index Represent the index of the field.
	virtual float getFieldValue_5_1(word index);
	
	//##Documentation
	//## Set the value of a field. The value is interpreted as a real single
	//## precision (IEEE 754). 
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -139,7 +113,6 @@ class PartOfPacket
	//## \param value The real single precision value	
	virtual void setFieldValue_5_1(word index, float value);
	
	//##Documentation
	//## Returns the value of a field in the list of fields of this part of packet. 
	//## The value returned is interpreted as a 32 bit signed integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -153,7 +126,6 @@ class PartOfPacket
	//## \param index Represent the index of the field.
	virtual signed long getFieldValue_4_14(word index);

	//##Documentation
	//## Sets the value of a field. The value is interpreted as a 32 bit signed integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
	//## the 32 bit signed integer. The layout foreseen is the following:
@@ -168,7 +140,6 @@ class PartOfPacket
	//## \param value The 32 bit signed integer value.		
	virtual void setFieldValue_4_14(word index, signed long value);
	
	//##Documentation
	//## Returns the value of a field in the list of fields of this part of packet. 
	//## The value returned is interpreted as a 24 bit signed integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -183,7 +154,6 @@ class PartOfPacket
	//## \return the 24 bit signed data converted in a long 32 bit
	virtual signed long getFieldValue_4_13(word index);

	//##Documentation
	//## Sets the value of a field. The value is interpreted as a 24 bit signed integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
	//## the 24 bit signed integer. The layout foreseen is the following:
@@ -199,7 +169,6 @@ class PartOfPacket
	//## 24 bit data format (bit0 with the sign became 24 bit)
	virtual void setFieldValue_4_13(word index, signed long value) throw(PacketException*);	
	
	//##Documentation
	//## Returns the value of a field in the list of fields of this part of packet. 
	//## The value returned is interpreted as a 32 bit unsigned integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -213,7 +182,6 @@ class PartOfPacket
	//## \param index Represent the index of the field.
	virtual unsigned long getFieldValue_3_14(word index);

	//##Documentation
	//## Sets the value of a field. The value is interpreted as a 32 bit unsigned integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
	//## the 32 bit unsigned long. The layout foreseen is the following:
@@ -228,7 +196,6 @@ class PartOfPacket
	//## \param value The 32 bit unsigned integer value.		
	virtual void setFieldValue_3_14(word index, unsigned long value);
	
	//##Documentation
	//## Returns the value of a field in the list of fields of this part of packet. 
	//## The value returned is interpreted as a 24 bit unsigned integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -242,7 +209,6 @@ class PartOfPacket
	//## \param index Represent the index of the field.
	virtual unsigned long getFieldValue_3_13(word index);

	//##Documentation
	//## Sets the value of a field. The value is interpreted as a 24 bit unsigned integer.
	//## The index of the argument is the first 16 bit field of the 2 fields that compound
	//## the 24 bit unsigned long. The layout foreseen is the following:
@@ -257,7 +223,6 @@ class PartOfPacket
	//## \param value The 24 bit unsigned integer value.		
	virtual void setFieldValue_3_13(word index, unsigned long value) throw(PacketException*);		

        //##ModelId=3EADC13E0246
        //##Documentation
        //## Sets the value of a field in the list of fields of this part of packet. Remember that
	//## if a predefined value is specified in the .stream, this method has not effect and the 
@@ -266,38 +231,26 @@ class PartOfPacket
        //## \param value The value must be setted.
        virtual void setFieldValue(word index, word value);

        //##ModelId=3C187751018C
        //##Documentation
        //## Returns the number of fields.
        virtual  inline word getNumberOfFields() {
          return numberOfFields;
        };

        //##ModelId=3C18AB2E037F
        //##Documentation
        //## Sets the stream of byte. This method assigns the value of stream for each field of part of packet
        virtual bool setByteStream(ByteStream* s);

        //##Documentation
        //## Represent current stream reads from input.
        ByteStream* stream;

	      //##ModelId=3EADC13B024B
        //##Documentation
        //## Represent current stream writes to output.
        ByteStream* outputstream;

        //##ModelId=3EADC1400007
        //##Documentation
        //## Generates the stream.
        virtual ByteStream* generateStream(bool bigendian);

        //##ModelId=3EADC14003CC
        //##Documentation
        //## Creates the outputstream ByteStream for the generation of the output stream
        virtual bool setOutputStream(ByteStream* os, word first);

        //##Documentation
        //## In a recoursive structure, the PartOfPacket that contains this PartOfPacket
        PartOfPacket* previous;

@@ -305,22 +258,17 @@ class PartOfPacket

    protected:

        //##Documentation
        //## List of field of part of packet.
        Field** fields;

        //##Documentation
        //## Dimension in bit of fields.
        word fieldsDimension;

	//##ModelId=3EADC13B0295
        //##Documentation
        //## Number of fields.
        word numberOfFields;

    private:

        //##ModelId=3EADC14201B1
        void deleteFields();
};

Loading