QP/C++
qpset.h
Go to the documentation of this file.
00001 
00002 // Product: QF/C++
00003 // Last Updated for Version: 4.2.00
00004 // Date of the Last Update:  Jul 05, 2011
00005 //
00006 //                    Q u a n t u m     L e a P s
00007 //                    ---------------------------
00008 //                    innovating embedded systems
00009 //
00010 // Copyright (C) 2002-2011 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 #ifdef Q_USE_NAMESPACE
00039 namespace QP {
00040 #endif
00041 
00042                       // external declarations of QF lookup tables used inline
00043 extern uint8_t const Q_ROM Q_ROM_VAR QF_log2Lkup[256];
00044 extern uint8_t const Q_ROM Q_ROM_VAR QF_pwr2Lkup[65];
00045 extern uint8_t const Q_ROM Q_ROM_VAR QF_invPwr2Lkup[65];
00046 extern uint8_t const Q_ROM Q_ROM_VAR QF_div8Lkup[65];
00047 
00055 class QPSet8 {
00056 protected:
00059     uint8_t m_bits;
00060 
00061 public:
00062 
00065     uint8_t isEmpty(void) volatile {
00066         return (uint8_t)(m_bits == (uint8_t)0);
00067     }
00068 
00071     uint8_t notEmpty(void) volatile {
00072         return (uint8_t)(m_bits != (uint8_t)0);
00073     }
00074 
00077     uint8_t hasElement(uint8_t n) volatile {
00078         return (uint8_t)((m_bits & Q_ROM_BYTE(QF_pwr2Lkup[n])) != 0);
00079     }
00080 
00082     void insert(uint8_t n) volatile {
00083         m_bits |= Q_ROM_BYTE(QF_pwr2Lkup[n]);
00084     }
00085 
00087     void remove(uint8_t n) volatile {
00088         m_bits &= Q_ROM_BYTE(QF_invPwr2Lkup[n]);
00089     }
00090 
00093     uint8_t findMax(void) volatile {
00094         return Q_ROM_BYTE(QF_log2Lkup[m_bits]);
00095     }
00096 
00097     friend class QPSet64;
00098 };
00099 
00123 class QPSet64 : public QPSet8 {
00124 
00134     QPSet8 m_subset[8];
00135 
00136 public:
00137 
00140     uint8_t hasElement(uint8_t n) volatile {
00141          return m_subset[Q_ROM_BYTE(QF_div8Lkup[n])].QPSet8::hasElement(n);
00142     }
00143 
00145     void insert(uint8_t n) volatile {
00146         QPSet8::insert(Q_ROM_BYTE(QF_div8Lkup[n]) + 1);
00147         m_subset[Q_ROM_BYTE(QF_div8Lkup[n])].QPSet8::insert(n);
00148     }
00149 
00151     void remove(uint8_t n) volatile {
00152         if ((m_subset[Q_ROM_BYTE(QF_div8Lkup[n])].m_bits
00153                  &= Q_ROM_BYTE(QF_invPwr2Lkup[n])) == (uint8_t)0)
00154         {
00155             QPSet8::remove(Q_ROM_BYTE(QF_div8Lkup[n]) + 1);
00156         }
00157     }
00158 
00161     uint8_t findMax(void) volatile {
00162         if (m_bits != (uint8_t)0) {
00163             uint8_t n = (uint8_t)(Q_ROM_BYTE(QF_log2Lkup[m_bits]) - 1);
00164             return (uint8_t)(Q_ROM_BYTE(QF_log2Lkup[m_subset[n].m_bits])
00165                              + (n << 3));
00166         }
00167         else {
00168             return (uint8_t)0;
00169         }
00170     }
00171 };
00172 
00173 #ifdef Q_USE_NAMESPACE
00174 }                                                              // namespace QP
00175 #endif
00176 
00177 #endif                                                              // qpset_h
00178