AttributeSet_RT.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 _AttributeSet_RT_h_ 00042 #define _AttributeSet_RT_h_ 00043 00044 #include <stdint.h> 00045 00046 #include "mw/attributes/access/AttributeSetHeader_RT.h" 00047 00048 namespace famouso { 00049 namespace mw { 00050 namespace attributes { 00051 namespace access { 00052 00053 class AttributeSet_RT : public AttributeSetHeader_RT { 00054 protected: 00055 AttributeSet_RT() { 00056 // Visibility 00057 } 00058 00059 public: 00073 template <typename Attr> 00074 Attr* find_rt() { 00075 uint8_t* const data = reinterpret_cast<uint8_t* const>(this); 00076 00077 return (famouso::mw::attributes::detail::find<Attr>(&data[0])); 00078 } 00079 00094 template <typename Attr> 00095 const Attr* find_rt() const { 00096 const uint8_t* const data = reinterpret_cast<const uint8_t* const>(this); 00097 00098 return (famouso::mw::attributes::detail::find<Attr>(&data[0])); 00099 } 00100 00109 uint16_t length() const { 00110 return (contentLength() + headerLength()); 00111 } 00112 00118 uint16_t size() const { 00119 const uint8_t* ptr = reinterpret_cast<const uint8_t*>(this); 00120 00121 uint16_t result = 0; 00122 00123 // TODO: This is a copy-paste-version of the find method, consider implementing 00124 // an iterator class 00125 00126 ptr += headerLength(); 00127 00128 // The pointer were the given sequence ends 00129 const uint8_t* const targetPtr = ptr + contentLength(); 00130 00131 typedef famouso::mw::attributes::access::Attribute_RT attrType; 00132 00133 while (ptr < targetPtr) { 00134 ++result; 00135 00136 // We let the attribute class determine its overall size to skip it 00137 ptr += reinterpret_cast<const attrType* const>(&ptr[0])->length(); 00138 } 00139 00140 // We iterated the complete set and so return the counted attributes 00141 return (result); 00142 } 00143 00148 void content(uint8_t* buffer) const { 00149 const uint8_t* const data = reinterpret_cast<const uint8_t* const>(this); 00150 00151 memcpy(buffer, &data[headerLength()], contentLength()); 00152 } 00153 00154 // TODO: Implement methods for manipulation of the attribute set at runtime 00155 }; 00156 00157 } // end namespace access 00158 } // end namespace attributes 00159 } // end namespace mw 00160 } // end namespace famouso 00161 00162 #endif // _Attribute_h_