00001 00002 // Product: QF/C++ 00003 // Last Updated for Version: 4.0.00 00004 // Date of the Last Update: Apr 06, 2008 00005 // 00006 // Q u a n t u m L e a P s 00007 // --------------------------- 00008 // innovating embedded systems 00009 // 00010 // Copyright (C) 2002-2008 Quantum Leaps, LLC. All rights reserved. 00011 // 00012 // This software may be distributed and modified under the terms of the GNU 00013 // General Public License version 2 (GPL) as published by the Free Software 00014 // Foundation and appearing in the file GPL.TXT included in the packaging of 00015 // this file. Please note that GPL Section 2[b] requires that all works based 00016 // on this software must also be made publicly available under the terms of 00017 // the GPL ("Copyleft"). 00018 // 00019 // Alternatively, this software may be distributed and modified under the 00020 // terms of Quantum Leaps commercial licenses, which expressly supersede 00021 // the GPL and are specifically designed for licensees interested in 00022 // retaining the proprietary status of their code. 00023 // 00024 // Contact information: 00025 // Quantum Leaps Web site: http://www.quantum-leaps.com 00026 // e-mail: info@quantum-leaps.com 00028 #ifndef qpset_h 00029 #define qpset_h 00030 00037 00038 // external declarations of QF lookup tables used inline 00039 extern uint8_t const Q_ROM Q_ROM_VAR QF_log2Lkup[256]; 00040 extern uint8_t const Q_ROM Q_ROM_VAR QF_pwr2Lkup[65]; 00041 extern uint8_t const Q_ROM Q_ROM_VAR QF_invPwr2Lkup[65]; 00042 extern uint8_t const Q_ROM Q_ROM_VAR QF_div8Lkup[65]; 00043 00051 class QPSet8 { 00054 uint8_t m_bits; 00055 00056 public: 00057 00060 uint8_t isEmpty(void) volatile { 00061 return (uint8_t)(m_bits == (uint8_t)0); 00062 } 00063 00066 uint8_t notEmpty(void) volatile { 00067 return (uint8_t)(m_bits != (uint8_t)0); 00068 } 00069 00072 uint8_t hasElement(uint8_t n) volatile { 00073 return (uint8_t)((m_bits & Q_ROM_BYTE(QF_pwr2Lkup[n])) != 0); 00074 } 00075 00077 void insert(uint8_t n) volatile { 00078 m_bits |= Q_ROM_BYTE(QF_pwr2Lkup[n]); 00079 } 00080 00082 void remove(uint8_t n) volatile { 00083 m_bits &= Q_ROM_BYTE(QF_invPwr2Lkup[n]); 00084 } 00085 00088 uint8_t findMax(void) volatile { 00089 return Q_ROM_BYTE(QF_log2Lkup[m_bits]); 00090 } 00091 }; 00092 00104 class QPSet64 { 00105 00118 uint8_t m_bytes; 00119 00129 uint8_t m_bits[8]; 00130 00131 public: 00132 00135 uint8_t isEmpty(void) volatile { 00136 return (uint8_t)(m_bytes == (uint8_t)0); 00137 } 00138 00141 uint8_t notEmpty(void) volatile { 00142 return (uint8_t)(m_bytes != (uint8_t)0); 00143 } 00144 00147 uint8_t hasElement(uint8_t n) volatile { 00148 return (uint8_t)((m_bits[Q_ROM_BYTE(QF_div8Lkup[n])] 00149 & Q_ROM_BYTE(QF_pwr2Lkup[Q_ROM_BYTE(QF_div8Lkup[n]) + 1])) 00150 != 0); 00151 } 00152 00154 void insert(uint8_t n) volatile { 00155 m_bits[Q_ROM_BYTE(QF_div8Lkup[n])] |= Q_ROM_BYTE(QF_pwr2Lkup[n]); 00156 m_bytes |= Q_ROM_BYTE(QF_pwr2Lkup[Q_ROM_BYTE(QF_div8Lkup[n]) + 1]); 00157 } 00158 00160 void remove(uint8_t n) volatile { 00161 m_bits[Q_ROM_BYTE(QF_div8Lkup[n])] &= Q_ROM_BYTE(QF_invPwr2Lkup[n]); 00162 if (m_bits[Q_ROM_BYTE(QF_div8Lkup[n])] == (uint8_t)0) { 00163 m_bytes &= 00164 Q_ROM_BYTE(QF_invPwr2Lkup[Q_ROM_BYTE(QF_div8Lkup[n]) + 1]); 00165 } 00166 } 00167 00170 uint8_t findMax(void) volatile { 00171 uint8_t n = (uint8_t)(Q_ROM_BYTE(QF_log2Lkup[m_bytes]) - 1); 00172 return (uint8_t)((n << 3) + Q_ROM_BYTE(QF_log2Lkup[m_bits[n]])); 00173 } 00174 }; 00175 00176 #endif // qpset_h 00177
1.5.4