Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

l1394_quadlet.h

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #ifndef _L1394_QUADLET_H
00012 #define _L1394_QUADLET_H
00013 
00014 #ifndef TRUE
00015 #define TRUE true
00016 #endif
00017 
00018 #ifndef FALSE
00019 #define FALSE false
00020 #endif
00021 
00022 
00023 #include <string>
00024 
00025 using std::string;
00026 using std::ostream;
00027 using std::istream;
00028 
00029 namespace L1394{
00030 /*! \class Quadlet
00031   * \brief This class stores a Quadlet and provides functions to manipulate it.
00032   *
00033   *  A Quadlet is one of the base data-types of this library and represents
00034   * the atomic unit of information that can be read or write to a FireWire node.
00035   *  The Quadlet stores 4 byte and is realized as an char array.<BR>
00036   * This class provides also a lot of functions to manipulate the bits and
00037   * bytes.
00038   *
00039   *  The location 31 is msb, location 0 is lsb.
00040   *
00041   * @author Michael Mirold, Michael Repplinger
00042   */
00043 
00044 class Quadlet {
00045 
00046 
00047 public:
00048 
00049 /** \name Constructors
00050   *  These are the different constructors to create a Quadlet.
00051   */
00052 
00053 //@{
00054 /*! \fn Quadlet()
00055   * \brief Constructs an empty quadlet.
00056    */
00057   Quadlet();
00058 
00059 /*! \fn Quadlet( const char *data )
00060   * \brief Constructs an quadlet from a char array.
00061   * \param value: const char pointer on an char array containing the data.
00062   */
00063   Quadlet( const char* );
00064 
00065 /*! \fn Quadlet( const u_int32_t data )
00066   * \brief Constructs an quadlet from an int.
00067   * \param data : Integer value representing the data.
00068   */
00069   Quadlet( const u_int32_t );
00070 
00071 /*! \fn Quadlet( const string& data )
00072   * \brief Constructs an quadlet from a string.
00073   * \param data : String representing the data.
00074   */
00075   Quadlet( const string& );
00076 
00077 
00078 /*! \fn Quadlet( const Quadlet& ref )
00079   * \brief Constructs a copy of ref.
00080   */
00081   Quadlet( const Quadlet& );
00082 
00083 
00084 /*! \fn ~Quadlet()
00085   * \brief Destructs the object.
00086   */
00087   ~Quadlet() {};
00088 
00089 //@}
00090 
00091 /** \name Manipulate the Quadlet
00092   *  These functions manipulate the value of a certain range of the Quadlet.
00093   */
00094 
00095 //@{
00096 
00097 /*! \fn getByte( const int byte) const
00098   * \brief This method returns the i'th byte of the quadlet. (value between 0..3)
00099   * \param byte : The position of the byte.
00100   */
00101   u_int32_t getByte( const int ) const;
00102 
00103 
00104 /*! \fn setByte(const int i, const u_int32_t value)
00105   * \brief This method sets the i'th byte (0..3) to value
00106   * \param i : integer i for the position (value between 0..3)
00107   * \param value : u_int32_t with the data
00108   */
00109   void setByte( const int i, const u_int32_t value);
00110 
00111 
00112 /*! \fn getBitRange( const int start, const int end) const
00113   * \brief This method returns the bit range from start to end as integer
00114   * \param start : startvalue of the bitrange.
00115   * \param end : endvalue of the bitrange.
00116   */
00117   u_int32_t getBitRange( const int start, const int end ) const;
00118 
00119 
00120 /*! \fn setBitRange( const int start, const int end, const u_int32_t value )
00121   * \brief This method sets the bitrange from start to end to a value.
00122   *
00123   * The bitrange must big enough to store the value.
00124   * \param start : startvalue of the bitrange
00125   * \param end : endvalue of the bitrange
00126   * \param value : u_int32_t for the value
00127   */
00128   void setBitRange( const int start, const int end, const u_int32_t value );
00129 
00130 /*! \fn getBit( const int bit) const
00131   * \brief This method returns the i'th bit (value between 0..31)
00132   * \param bit : int with the i'th position
00133   * \return int : value 0 or 1.
00134   */
00135   int getBit( const int ) const;
00136 
00137 /*! \fn setBit( const int i, const int value)
00138   * \brief Sets the i'th bit to value
00139   * \param i : integer for the position ( value between 0..31)
00140   * \param value : the i'th bit (0 or 1)
00141   */
00142   void setBit( const int i, const int value);
00143 //@}
00144 
00145 /** \name Convert a Quadlet
00146   *  These functions convert a Quadlet to another basic type.
00147   */
00148 
00149 //@{
00150 
00151 /*! \fn toInt() const
00152   * \brief This method converts a quadlet to a 32 bit integer value
00153   * \return u_int32_t : The integer value of the Quadlet
00154   */
00155   u_int32_t toInt() const;
00156 
00157 /*! \fn fromInt( u_int32_t value)
00158   * \brief This method converts a 32 bit integer to a quadlet
00159   * \param value : value for the Quadlet
00160   */
00161   void fromInt( u_int32_t value);
00162 
00163 /*! \fn toString() const
00164   * \brief This method converts a Quadlet to a string
00165   * \param string : return the Quadlet as string
00166   */
00167   string toString() const;
00168 
00169 /*! \fn toCharArray ( char *, int ) const
00170   * \brief converts a Quadlet to a char*
00171   */
00172   char *toCharArray( char *, int ) const;
00173 
00174 //@}
00175 
00176 /** \name Computing operator
00177   *  These functions implements some computing operators for Quadlets.
00178   */
00179 
00180 //@{
00181 /*! \fn operator=( const Quadlet& q )
00182   * \brief operator= assigns the data q to this quadlet and returns a reference to it.
00183   * \param q : Quadlet that will be assigned
00184   * \return Quadlet : Reference to this Quadlet
00185   */
00186   Quadlet& operator=( const Quadlet& );
00187 
00188 
00189 /*! \fn operator==( const Quadlet& )
00190   * \brief operator== compares two Quadlets and returns true if they are equal, false if not
00191 
00192   * Two Quadlets are equal, if all 4 bytes are equal.
00193   * \param Quadlet reference to quadlet
00194   * \return bool : True if two Quadlets are equal, false if not
00195   */
00196   bool operator== ( const Quadlet& );
00197 
00198 /*! \fn operator!=( const Quadlet& q)
00199   * \brief operator!= compares Quadlet q with this Quadlet
00200   * \param q : Quadlet that should be compared
00201   * \return bool : return true if q is not equal to this Quadlet, false if not.
00202   */
00203   bool operator!= ( const Quadlet& );
00204 
00205 
00206 /*! \fn operator+( const Quadlet& q_1, const Quadlet& q_2)
00207   * \brief operator+ adds the value of Quadlet q_1 and q_2 and returns the reference to it.
00208   *
00209   *  The new value of q1+q2 must be less then 0xffffffff or the value is set to
00210   *  0xffffffff.
00211   * \param q_1 : Reference to the first Quadlet
00212   *  \param q_2 : Reference the the seconf Quadlet
00213   * \return const Quadlet : The new Quadlet
00214   */
00215   friend const Quadlet operator+( const Quadlet&, const Quadlet& );
00216 
00217 
00218 /*! \fn operator+( const u_int32_t& data, const Quadlet& q)
00219   * \brief operator+ adds the value of Quadlet q to this Quadlet and returns the reference to it.
00220   *  \return Quadlet : The new Quadlet
00221   */
00222   friend const Quadlet operator+( const u_int32_t&, const Quadlet&);
00223 
00224 /*! \fn operator-( const u_int32_t& data, const Quadlet&)
00225   * \brief operator+ adds the value of Quadlet q to this Quadlet and returns the reference to it.
00226   *  \return const Quadlet : The new Quadlet
00227   */
00228   friend const Quadlet operator-( const u_int32_t& data, const Quadlet&);
00229 
00230 /*! \fn operator-( const Quadlet& q, const Quadlet&)
00231   * \brief operator- subtract the value of data from this Quadlet and returns the reference to it.
00232   *  \return const Quadlet : The new Quadlet
00233   */
00234   friend const Quadlet operator-( const Quadlet& q, const Quadlet&);
00235 //@}
00236 
00237 /*! \fn operator<<( ostream& , const Quadlet&)
00238   * \brief operator<< writes the Quadlet to a stream and returns a reference to it.
00239 */
00240   friend ostream& operator<<( ostream& , const Quadlet&);
00241 
00242 /*! \fn  operator>>( istream& , Quadlet&)
00243   * \brief operator>> reads 4 bytes from a stream, stores the value in the Quadlet and returns a reference to the stream
00244 */
00245   friend istream& operator>>( istream& , Quadlet&);
00246 
00247 private:
00248 
00249   // these 4 chars contain the quadlet in 'bus byte order', eg
00250   // the most significant byte in quadlet[0]
00251   unsigned char quadlet[ 4 ];
00252   static const int Quadlet_OUTPUTSIZE = 32;
00253 };
00254 
00255 }
00256 
00257 
00258 
00259 
00260 
00261 #endif
00262 

Generated on Wed Aug 24 00:36:40 2005 for L1394 by doxygen 1.4.2
L1394 library (NMM) grahics.cs.uni-sb.de/~repplix/l1394_home/