Menu

ExtendedEvent.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 _Extended_Event_
00042 #define _Extended_Event_
00043 
00044 #include <stdint.h>
00045 
00046 #include "boost/mpl/aux_/na.hpp"
00047 
00048 #include "object/PlacementNew.h"
00049 
00050 #include "mw/common/Subject.h"
00051 #include "mw/common/Event.h"
00052 
00053 #include "mw/attributes/detail/AttributeSetProvider.h"
00054 #include "mw/attributes/AttributeSet.h"
00055 #include "mw/attributes/access/Attribute_RT.h"
00056 
00057 namespace famouso {
00058     namespace mw {
00059 
00065         template <famouso::mw::Event::Type payLoadSize = 0,
00066                   typename A1orSeq = boost::mpl::na, typename A2 = boost::mpl::na,
00067                   typename A3 = boost::mpl::na, typename A4 = boost::mpl::na,
00068                   typename A5 = boost::mpl::na, typename A6 = boost::mpl::na,
00069                   typename A7 = boost::mpl::na, typename A8 = boost::mpl::na,
00070                   typename A9 = boost::mpl::na, typename A10 = boost::mpl::na>
00071         class ExtendedEvent: public Event {
00072             private:
00073                 typedef typename famouso::mw::attributes::detail::SetProvider<
00074                                                                    A1orSeq, A2, A3, A4,
00075                                                                    A5, A6, A7, A8, A9, A10
00076                                                                   >::attrSet attrSet;
00077 
00078             public:
00079                 typedef ExtendedEvent type;
00080 
00081             private:
00082                 static const famouso::mw::Event::Type attribsLen = attrSet::overallSize;
00083 
00084                 // the whole event with attributes and payload
00085                 uint8_t _edata[attribsLen + payLoadSize];
00086 
00087             public:
00088                 ExtendedEvent(const famouso::mw::Subject& sub) :
00089                     Event(sub) {
00090                     // Construct the attributes
00091                     new (&_edata[0]) attrSet;
00092 
00093                     // Set the base class' members
00094                     length = attribsLen + payLoadSize;
00095                     data   = _edata;
00096                 }
00097 
00098                 // payload setting as simple as possible
00099                 void operator =(const char* str) {
00100                     Type i = 0;
00101 
00102                     while (str[i] && (i < payLoadSize)) {
00103                         _edata[attribsLen + i] = str[i];
00104                         ++i;
00105                     }
00106                 }
00107 
00108                 template <typename Attr>
00109                 Attr* find() {
00110                     return ((reinterpret_cast<attrSet*>(_edata))->template find_rt<Attr>());
00111                 }
00112 
00113                 template <typename Attr>
00114                 const Attr* find() const {
00115                     return ((reinterpret_cast<attrSet*>(_edata))->template find_rt<Attr>());
00116                 }
00117         };
00118 
00119     } // end namespace mw
00120 } // end namespace famouso
00121 
00122 #endif // _Extended_Event_