QP/C
qpset.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product:  QF/C
00003 * Last Updated for Version: 4.4.00
00004 * Date of the Last Update:  Jan 05, 2012
00005 *
00006 *                    Q u a n t u m     L e a P s
00007 *                    ---------------------------
00008 *                    innovating embedded systems
00009 *
00010 * Copyright (C) 2002-2012 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
00027 *****************************************************************************/
00028 #ifndef qpset_h
00029 #define qpset_h
00030 
00040 /****************************************************************************/
00050 typedef struct QPSet8Tag {
00051     uint8_t bits;       
00052 } QPSet8;
00053 
00056 #define QPSet8_isEmpty(me_) ((me_)->bits == (uint8_t)0)
00057 
00060 #define QPSet8_notEmpty(me_) ((me_)->bits != (uint8_t)0)
00061 
00065 #define QPSet8_hasElement(me_, n_) \
00066     (((me_)->bits & Q_ROM_BYTE(QF_pwr2Lkup[n_])) != 0)
00067 
00070 #define QPSet8_insert(me_, n_) \
00071     ((me_)->bits |= Q_ROM_BYTE(QF_pwr2Lkup[n_]))
00072 
00075 #define QPSet8_remove(me_, n_) \
00076     ((me_)->bits &= Q_ROM_BYTE(QF_invPwr2Lkup[n_]))
00077 
00081 #define QPSet8_findMax(me_, n_) \
00082     ((n_) = Q_ROM_BYTE(QF_log2Lkup[(me_)->bits]))
00083 
00084 
00085 /****************************************************************************/
00096 typedef struct QPSet64Tag {
00097 
00111     QPSet8 super;                            /* QPSet64 derives from QPSet8 */
00112 
00123     QPSet8 subset[8];
00124 } QPSet64;
00125 
00128 #define QPSet64_isEmpty(me_)    QPSet8_isEmpty(&(me_)->super)
00129 
00132 #define QPSet64_notEmpty(me_)   QPSet8_notEmpty(&(me_)->super)
00133 
00137 #define QPSet64_hasElement(me_, n_) \
00138     QPSet8_hasElement(&(me_)->subset[Q_ROM_BYTE(QF_div8Lkup[n_])], n_)
00139 
00142 #define QPSet64_insert(me_, n_) do { \
00143     QPSet8_insert(&(me_)->super, \
00144                   (uint8_t)(Q_ROM_BYTE(QF_div8Lkup[n_]) + (uint8_t)1)); \
00145     QPSet8_insert(&(me_)->subset[Q_ROM_BYTE(QF_div8Lkup[n_])], n_); \
00146 } while (0)
00147 
00150 #define QPSet64_remove(me_, n_) do { \
00151     if (QPSet8_remove(&(me_)->subset[Q_ROM_BYTE(QF_div8Lkup[n_])], n_) \
00152         == (uint8_t)0) \
00153     { \
00154         QPSet8_remove(&(me_)->super, \
00155                       (uint8_t)(Q_ROM_BYTE(QF_div8Lkup[n_]) + (uint8_t)1)); \
00156     } \
00157 } while (0)
00158 
00162 #define QPSet64_findMax(me_, n_) do { \
00163     if (QPSet64_notEmpty(me_)) { \
00164         (n_) = (uint8_t)(Q_ROM_BYTE(QF_log2Lkup[(me_)->super.bits]) \
00165                          - (uint8_t)1); \
00166         (n_) = (uint8_t)(Q_ROM_BYTE(QF_log2Lkup[(me_)->subset[n_].bits]) \
00167                          + (uint8_t)((n_) << 3)); \
00168     } \
00169     else { \
00170        (n_) = (uint8_t)0; \
00171     } \
00172 } while (0)
00173 
00174 
00175 #endif                                                           /* qpset_h */
00176