Menu

FirstByteOfHeader.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2008-2010 Michael Schulze <mschulze@ivs.cs.uni-magdeburg.de>
00004  *                    2010 Marcus Foerster <MarcusFoerster1@gmx.de>
00005  * All rights reserved.
00006  *
00007  *    Redistribution and use in source and binary forms, with or without
00008  *    modification, are permitted provided that the following conditions
00009  *    are met:
00010  *
00011  *    * Redistributions of source code must retain the above copyright
00012  *      notice, this list of conditions and the following disclaimer.
00013  *
00014  *    * Redistributions in binary form must reproduce the above copyright
00015  *      notice, this list of conditions and the following disclaimer in
00016  *      the documentation and/or other materials provided with the
00017  *      distribution.
00018  *
00019  *    * Neither the name of the copyright holders nor the names of
00020  *      contributors may be used to endorse or promote products derived
00021  *      from this software without specific prior written permission.
00022  *
00023  *
00024  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00025  *    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026  *    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027  *    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00028  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00029  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00030  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00031  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00032  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00033  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *
00037  * $Id$
00038  *
00039  ******************************************************************************/
00040 
00041 #ifndef _First_Byte_Of_Header_
00042 #define _First_Byte_Of_Header_
00043 
00044 #include <stdint.h>
00045 
00046 #include "mw/attributes/detail/ValueByteCount.h"
00047 #include "mw/attributes/detail/CaseSelector.h"
00048 
00049 namespace famouso {
00050     namespace mw {
00051         namespace attributes {
00052             namespace detail {
00053 
00062                 template <typename Attr>
00063                 struct FirstByteOfHeader {
00064                     private:
00065                         // The type starts from the 5th bit (for high density attributes)
00066                         static const uint8_t typeOffset = 4;
00067                         // The extension bit is always the 4th bit
00068                         static const uint8_t extBitOffset = 3;
00069                         // For system attributes the LVS (length/value-switch) bit is the 3rd
00070                         static const uint8_t lvsBitOffset = 2;
00071 
00072                         // TODO: I will not apply any line breaking to this until anyone tells me how
00073                         //  to make the building of the values as descriptive as it is now ;)
00074 
00075                         // High density
00076                         //                            TYPE                               EXT                     LVS                     LEN
00077                         static const uint8_t case1 = ((Attr::id & 0xF) << typeOffset) | (0x0 << extBitOffset) | (0x0 << lvsBitOffset) | (0x00); // Value fits unextended
00078                         static const uint8_t case2 = ((Attr::id & 0xF) << typeOffset) | (0x1 << extBitOffset) | (0x0 << lvsBitOffset) | (0x00); // Value fits extended
00079                         static const uint8_t case3 = ((Attr::id & 0xF) << typeOffset) | (0x0 << extBitOffset) | (0x1 << lvsBitOffset) | (ValueByteCount<Attr>::value & 0x3); // Length fits unextended
00080                         static const uint8_t case4 = ((Attr::id & 0xF) << typeOffset) | (0x1 << extBitOffset) | (0x1 << lvsBitOffset) | ((ValueByteCount<Attr>::value >> 8) & 0x3); // Length fits extended
00081 
00082                         // Low density
00083                         //                           TYPE                   EXT                     LEN
00084                         static const uint8_t case5 = (0xF << typeOffset) | (0x0 << extBitOffset) | (ValueByteCount<Attr>::value & 0x7); // Length fits unextended
00085                         static const uint8_t case6 = (0xF << typeOffset) | (0x1 << extBitOffset) | ((ValueByteCount<Attr>::value >> 8) & 0x7); // Length fits extended
00086 
00087                     public:
00091                         static const uint8_t value = CaseSelector<uint8_t, case1, case2, case3, case4, case5, case6>::template select_ct<Attr>::value;
00092                 };
00093 
00094             } // end namespace detail
00095         } // end namespace attributes
00096     } // end namespace mw
00097 } // end namespace famouso
00098 
00099 #endif