From 6a457c43c3f1f5ff31734d67a5411f25e27c80a1 Mon Sep 17 00:00:00 2001 From: Andrea Bulgarelli Date: Wed, 21 May 2014 09:26:04 +0200 Subject: [PATCH] added get-setFieldValue(string fieldname) in SourceDataField, SDFBlock, PartOfPacket --- include/PartOfPacket.h | 98 ++++++++++++++++++++++++++++++- include/SDFBlock.h | 89 ++++++++++++++++++++++++++++ include/SourceDataField.h | 89 ++++++++++++++++++++++++++++ src/PartOfPacket.cpp | 120 +++++++++++++++++++++++++++++++++++++- src/SDFBlock.cpp | 95 ++++++++++++++++++++++++++++++ src/SourceDataField.cpp | 96 ++++++++++++++++++++++++++++++ 6 files changed, 584 insertions(+), 3 deletions(-) diff --git a/include/PartOfPacket.h b/include/PartOfPacket.h index 8bb91cc..54ddf1e 100644 --- a/include/PartOfPacket.h +++ b/include/PartOfPacket.h @@ -86,7 +86,7 @@ public: /// (depends by the size of the field in bits) /// \param index Represent the index in the list. virtual word getFieldValue(word index); - + /// Returns the value of a field in the list of fields of this part of packet. /// The value returned is interpreted as a 16 bit signed integer. /// \param index Represent the index of the field. @@ -232,6 +232,102 @@ public: /// \param index Represent the index of the field. /// \param value The real double precision value virtual void setFieldValue_64f(word index, double value); + + //-------------------------------- + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a unsigned integer of less of equal 16 bits dimension + /// (depends by the size of the field in bits) + /// \param fieldname Represent the name of the field. + virtual word getFieldValue(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + virtual signed short getFieldValue_16i(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit unsigned integer. + /// \param fieldname Represent the name of the field. + virtual word getFieldValue_16ui(string fieldname); + + /// 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. + /// This corresponds with the PTC=4, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual signed long getFieldValue_32i(string fieldname); + + /// 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. + /// This corresponds with the PTC=3, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual unsigned long getFieldValue_32ui(string fieldname); + + /// 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). + /// This corresponds with the PTC=5, PFC = 1 <=> float or 32f + /// \param fieldname Represent the name of the field. + virtual float getFieldValue_32f(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a real double precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. <=> double or 64f + /// \param fieldname Represent the name of the field. + virtual double getFieldValue_64f(string fieldname); + + ///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 + /// value contained in the .stream is used. + /// \param fieldname Represent the name of the field. + /// \param value The value must be set. + virtual void setFieldValue(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit signed integer value. + virtual void setFieldValue_16i(string fieldname, signed short value); + + /// Sets the value of a field. The value is interpreted as a 16 bit unsigned integer (word). + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit unsigned integer value. + virtual void setFieldValue_16ui(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 32 bit signed integer. + /// --------------------------------- + /// This corresponds with the PTC=4, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit signed integer value. + virtual void setFieldValue_32i(string fieldname, signed long value); + + /// Sets the value of a field. The value is interpreted as a 32 bit unsigned integer. + /// This corresponds with the PTC=3, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit unsigned integer value. + virtual void setFieldValue_32ui(string fieldname, unsigned long value); + + /// Set the value of a field. The value is interpreted as a real single + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 1. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real single precision value + virtual void setFieldValue_32f(string fieldname, float value); + + /// Set the value of a field. The value is interpreted as a real double + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real double precision value + virtual void setFieldValue_64f(string fieldname, double value); + + virtual word getFieldIndex(string fieldname); + + + //-------------------------------- /// Returns the number of fields. virtual inline word getNumberOfFields() diff --git a/include/SDFBlock.h b/include/SDFBlock.h index ed19679..58f938c 100644 --- a/include/SDFBlock.h +++ b/include/SDFBlock.h @@ -286,6 +286,95 @@ public: { return getTotalNumberOfFields(); }; + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a unsigned integer of less of equal 16 bits dimension + /// (depends by the size of the field in bits) + /// \param fieldname Represent the name of the field. + virtual word getFieldValue(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + virtual signed short getFieldValue_16i(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit unsigned integer. + /// \param fieldname Represent the name of the field. + virtual word getFieldValue_16ui(string fieldname); + + /// 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. + /// This corresponds with the PTC=4, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual signed long getFieldValue_32i(string fieldname); + + /// 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. + /// This corresponds with the PTC=3, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual unsigned long getFieldValue_32ui(string fieldname); + + /// 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). + /// This corresponds with the PTC=5, PFC = 1 <=> float or 32f + /// \param fieldname Represent the name of the field. + virtual float getFieldValue_32f(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a real double precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. <=> double or 64f + /// \param fieldname Represent the name of the field. + virtual double getFieldValue_64f(string fieldname); + + ///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 + /// value contained in the .stream is used. + /// \param fieldname Represent the name of the field. + /// \param value The value must be set. + virtual void setFieldValue(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit signed integer value. + virtual void setFieldValue_16i(string fieldname, signed short value); + + /// Sets the value of a field. The value is interpreted as a 16 bit unsigned integer (word). + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit unsigned integer value. + virtual void setFieldValue_16ui(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 32 bit signed integer. + /// --------------------------------- + /// This corresponds with the PTC=4, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit signed integer value. + virtual void setFieldValue_32i(string fieldname, signed long value); + + /// Sets the value of a field. The value is interpreted as a 32 bit unsigned integer. + /// This corresponds with the PTC=3, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit unsigned integer value. + virtual void setFieldValue_32ui(string fieldname, unsigned long value); + + /// Set the value of a field. The value is interpreted as a real single + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 1. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real single precision value + virtual void setFieldValue_32f(string fieldname, float value); + + /// Set the value of a field. The value is interpreted as a real double + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real double precision value + virtual void setFieldValue_64f(string fieldname, double value); /// Returns the number of fields of the overall block virtual word getTotalNumberOfFields(); diff --git a/include/SourceDataField.h b/include/SourceDataField.h index edd84d0..aa08086 100644 --- a/include/SourceDataField.h +++ b/include/SourceDataField.h @@ -121,6 +121,95 @@ public: /// \param index Represent the index in the list. /// \param value The value must be set. virtual void setFieldValue_64f(word index, double value); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a unsigned integer of less of equal 16 bits dimension + /// (depends by the size of the field in bits) + /// \param fieldname Represent the name of the field. + virtual word getFieldValue(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + virtual signed short getFieldValue_16i(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a 16 bit unsigned integer. + /// \param fieldname Represent the name of the field. + virtual word getFieldValue_16ui(string fieldname); + + /// 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. + /// This corresponds with the PTC=4, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual signed long getFieldValue_32i(string fieldname); + + /// 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. + /// This corresponds with the PTC=3, PFC = 14. + /// \param fieldname Represent the name of the field. + virtual unsigned long getFieldValue_32ui(string fieldname); + + /// 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). + /// This corresponds with the PTC=5, PFC = 1 <=> float or 32f + /// \param fieldname Represent the name of the field. + virtual float getFieldValue_32f(string fieldname); + + /// Returns the value of a field in the list of fields of this part of packet. + /// The value returned is interpreted as a real double precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. <=> double or 64f + /// \param fieldname Represent the name of the field. + virtual double getFieldValue_64f(string fieldname); + + ///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 + /// value contained in the .stream is used. + /// \param fieldname Represent the name of the field. + /// \param value The value must be set. + virtual void setFieldValue(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 16 bit signed integer. + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit signed integer value. + virtual void setFieldValue_16i(string fieldname, signed short value); + + /// Sets the value of a field. The value is interpreted as a 16 bit unsigned integer (word). + /// \param fieldname Represent the name of the field. + /// \param value The 16 bit unsigned integer value. + virtual void setFieldValue_16ui(string fieldname, word value); + + /// Sets the value of a field. The value is interpreted as a 32 bit signed integer. + /// --------------------------------- + /// This corresponds with the PTC=4, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit signed integer value. + virtual void setFieldValue_32i(string fieldname, signed long value); + + /// Sets the value of a field. The value is interpreted as a 32 bit unsigned integer. + /// This corresponds with the PTC=3, PFC = 14. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The 32 bit unsigned integer value. + virtual void setFieldValue_32ui(string fieldname, unsigned long value); + + /// Set the value of a field. The value is interpreted as a real single + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 1. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real single precision value + virtual void setFieldValue_32f(string fieldname, float value); + + /// Set the value of a field. The value is interpreted as a real double + /// precision (IEEE 754). + /// This corresponds with the PTC=5, PFC = 2. + /// See setFieldValue(word index, word value) for general considerations. + /// \param fieldname Represent the name of the field. + /// \param value The real double precision value + virtual void setFieldValue_64f(string fieldname, double value); /// Returns the number of fields. diff --git a/src/PartOfPacket.cpp b/src/PartOfPacket.cpp index 1180e3a..5f1f6d8 100644 --- a/src/PartOfPacket.cpp +++ b/src/PartOfPacket.cpp @@ -472,14 +472,19 @@ word PartOfPacket::getFieldValue(word index) decode(); if(index < numberOfFields) return fields[index]->value; - else - return 0; + else { + throw new PacketException("getFieldValue(index) error: index out of range"); + } + return 0; + }; void PartOfPacket::setFieldValue(word index, word value) { if(index < numberOfFields) fields[index]->value = (value & pattern[fields[index]->size()]); + else + throw new PacketException("setFieldValue(index, value) error: index out of range"); } float PartOfPacket::getFieldValue_32f(word index) @@ -617,3 +622,114 @@ void PartOfPacket::setFieldValue_16ui(word index, word value) void PacketLib::PartOfPacket::memByteStream(ByteStreamPtr stream) { this->stream = stream; } + + + +word PartOfPacket::getFieldValue(string fieldname) { + word index = getFieldIndex(fieldname); + return getFieldValue(index); +} + + +signed short PartOfPacket::getFieldValue_16i(string fieldname) { + word index = getFieldIndex(fieldname); + return getFieldValue_16i(index); +} + + + +word PartOfPacket::getFieldValue_16ui(string fieldname) { + word index = getFieldIndex(fieldname); + return getFieldValue_16ui(index); +} + + + +signed long PartOfPacket::getFieldValue_32i(string fieldname){ + word index = getFieldIndex(fieldname); + return getFieldValue_32i(index); +} + + + +unsigned long PartOfPacket::getFieldValue_32ui(string fieldname){ + word index = getFieldIndex(fieldname); + return getFieldValue_32ui(index); +} + + + +float PartOfPacket::getFieldValue_32f(string fieldname){ + word index = getFieldIndex(fieldname); + return getFieldValue_32f(index); +} + + + +double PartOfPacket::getFieldValue_64f(string fieldname){ + word index = getFieldIndex(fieldname); + return getFieldValue_64f(index); +} + + + +void PartOfPacket::setFieldValue(string fieldname, word value){ + word index = getFieldIndex(fieldname); + setFieldValue(index, value); +} + + + +void PartOfPacket::setFieldValue_16i(string fieldname, signed short value){ + word index = getFieldIndex(fieldname); + setFieldValue_16i(index, value); +} + + + +void PartOfPacket::setFieldValue_16ui(string fieldname, word value){ + word index = getFieldIndex(fieldname); + setFieldValue_16ui(index, value); +} + + + +void PartOfPacket::setFieldValue_32i(string fieldname, signed long value){ + word index = getFieldIndex(fieldname); + setFieldValue_32i(index, value); +} + + + +void PartOfPacket::setFieldValue_32ui(string fieldname, unsigned long value){ + word index = getFieldIndex(fieldname); + setFieldValue_32ui(index, value); + +} + + + +void PartOfPacket::setFieldValue_32f(string fieldname, float value){ + word index = getFieldIndex(fieldname); + setFieldValue_32f(index, value); +} + + + +void PartOfPacket::setFieldValue_64f(string fieldname, double value){ + word index = getFieldIndex(fieldname); + setFieldValue_64f(index, value); +} + +word PartOfPacket::getFieldIndex(string fieldname) { + word index = 0; + for(word i=0; igetName(); + if(fieldname == fname) + return i; + } + throw new PacketException("getFieldIndex(fieldname) error: no field found in this section"); + return index; +} + diff --git a/src/SDFBlock.cpp b/src/SDFBlock.cpp index 1b4be7c..841a70f 100644 --- a/src/SDFBlock.cpp +++ b/src/SDFBlock.cpp @@ -666,4 +666,99 @@ word SDFBlock::getTotalNumberOfFields() return dim; } +word SDFBlock::getFieldValue(string fieldname) { + return fixed.getFieldValue(fieldname); + +} + + +signed short SDFBlock::getFieldValue_16i(string fieldname) { + return fixed.getFieldValue_16i(fieldname); + +} + + + +word SDFBlock::getFieldValue_16ui(string fieldname) { + return fixed.getFieldValue_16ui(fieldname); + +} + + + +signed long SDFBlock::getFieldValue_32i(string fieldname){ + return fixed.getFieldValue_32i(fieldname); + +} + + + +unsigned long SDFBlock::getFieldValue_32ui(string fieldname){ + return fixed.getFieldValue_32ui(fieldname); + +} + + + +float SDFBlock::getFieldValue_32f(string fieldname){ + return fixed.getFieldValue_32f(fieldname); + +} + + + +double SDFBlock::getFieldValue_64f(string fieldname){ + return fixed.getFieldValue_64f(fieldname); + +} + + + +void SDFBlock::setFieldValue(string fieldname, word value){ + fixed.setFieldValue(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_16i(string fieldname, signed short value){ + fixed.setFieldValue_16i(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_16ui(string fieldname, word value){ + fixed.setFieldValue_16ui(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_32i(string fieldname, signed long value){ + fixed.setFieldValue_32i(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_32ui(string fieldname, unsigned long value){ + fixed.setFieldValue_32ui(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_32f(string fieldname, float value){ + fixed.setFieldValue_32f(fieldname, value); + +} + + + +void SDFBlock::setFieldValue_64f(string fieldname, double value){ + fixed.setFieldValue_64f(fieldname, value); + +} + diff --git a/src/SourceDataField.cpp b/src/SourceDataField.cpp index e183231..3dd6137 100644 --- a/src/SourceDataField.cpp +++ b/src/SourceDataField.cpp @@ -246,4 +246,100 @@ double SourceDataField::getFieldValue_64f(word index) { return block[0].getFieldValue_64f(index); } +word SourceDataField::getFieldValue(string fieldname) { + return block[0].getFieldValue(fieldname); + +} + + +signed short SourceDataField::getFieldValue_16i(string fieldname) { + return block[0].getFieldValue_16i(fieldname); + +} + + + +word SourceDataField::getFieldValue_16ui(string fieldname) { + return block[0].getFieldValue_16ui(fieldname); + +} + + + +signed long SourceDataField::getFieldValue_32i(string fieldname){ + return block[0].getFieldValue_32i(fieldname); + +} + + + +unsigned long SourceDataField::getFieldValue_32ui(string fieldname){ + return block[0].getFieldValue_32ui(fieldname); + +} + + + +float SourceDataField::getFieldValue_32f(string fieldname){ + return block[0].getFieldValue_32f(fieldname); + +} + + + +double SourceDataField::getFieldValue_64f(string fieldname){ + return block[0].getFieldValue_64f(fieldname); + +} + + + +void SourceDataField::setFieldValue(string fieldname, word value){ + block[0].setFieldValue(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_16i(string fieldname, signed short value){ + block[0].setFieldValue_16i(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_16ui(string fieldname, word value){ + block[0].setFieldValue_16ui(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_32i(string fieldname, signed long value){ + block[0].setFieldValue_32i(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_32ui(string fieldname, unsigned long value){ + block[0].setFieldValue_32ui(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_32f(string fieldname, float value){ + block[0].setFieldValue_32f(fieldname, value); + +} + + + +void SourceDataField::setFieldValue_64f(string fieldname, double value){ + block[0].setFieldValue_64f(fieldname, value); + +} + + -- GitLab