Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:43:50

0001 #ifndef PACKET_H
0002 #define PACKET_H
0003 
0004 /**
0005  * @file Packet.h
0006  * @author Bryan BERTHOU (SPhN / CEA Saclay)
0007  * @date 13 January 2016
0008  * @version 1.0
0009  */
0010 
0011 #include <cstddef>
0012 #include <string>
0013 #include <vector>
0014 
0015 namespace ElemUtils {
0016 
0017 /**
0018  * @class Packet
0019  *
0020  * @brief FIFO generic container.
0021  */
0022 class Packet {
0023 public:
0024     /**
0025      * Default constructor.
0026      */
0027     Packet();
0028 
0029     /**
0030      * Default destructor.
0031      */
0032     virtual ~Packet();
0033 
0034     ////////////////////////////////////////////////////////////
0035     /// \brief Append data to the end of the packet
0036     ///
0037     /// \param data        Pointer to the sequence of bytes to append
0038     /// \param sizeInBytes Number of bytes to append
0039     ///
0040     /// \see clear
0041     ///
0042     ////////////////////////////////////////////////////////////
0043     void append(const void* data, std::size_t sizeInBytes);
0044 
0045     ////////////////////////////////////////////////////////////
0046 
0047     ////////////////////////////////////////////////////////////
0048     /// Overloads of operator >> to read data from the packet
0049     ///
0050     ////////////////////////////////////////////////////////////
0051     Packet& operator >>(bool& data);
0052     Packet& operator >>(double& data);
0053     Packet& operator >>(unsigned int &data);
0054     Packet& operator >>(int &data);
0055     Packet& operator >>(unsigned short &data);
0056     Packet& operator >>(short &data);
0057     Packet& operator >>(const std::string &data);
0058 
0059     ////////////////////////////////////////////////////////////
0060     /// Overloads of operator << to write data into the packet
0061     ///
0062     ////////////////////////////////////////////////////////////
0063     Packet& operator <<(bool data);
0064     Packet& operator <<(double data);
0065     Packet& operator <<(unsigned int data);
0066     Packet& operator <<(int data);
0067     Packet& operator <<(unsigned short data);
0068     Packet& operator <<(short data);
0069     Packet& operator <<(const std::string &data);
0070 
0071 private:
0072     std::vector<char> m_data; ///< Data stored in the packet
0073     std::size_t m_readPos; ///< Current reading position in the packet
0074     bool m_isValid; ///< Reading state of the packet
0075 
0076     ////////////////////////////////////////////////////////////
0077     /// \brief Check if the packet can extract a given number of bytes
0078     ///
0079     /// This function updates accordingly the state of the packet.
0080     ///
0081     /// \param size Size to check
0082     ///
0083     /// \return True if \a size bytes can be read from the packet
0084     ///
0085     ////////////////////////////////////////////////////////////
0086     bool checkSize(std::size_t size);
0087 
0088     ////////////////////////////////////////////////////////////
0089     /// Disallow comparisons between GenericTypes
0090     ////////////////////////////////////////////////////////////
0091     bool operator ==(const Packet& right) const;
0092     bool operator !=(const Packet& right) const;
0093 };
0094 
0095 } // namespace ElemUtils
0096 
0097 #endif /*  PACKET_H */