/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#ifndef ECXX_CTL_GFX_COLOR_ANIMATOR_ARRAY_H
#define ECXX_CTL_GFX_COLOR_ANIMATOR_ARRAY_H


namespace eCxx {


//
// A simple and generic color animator array with 1 to 9 elements
//
template <uint8_t N, typename ColorAnim1DT, typename ColorFXnDT>
class ColorAnimatorArray;

#define DUP_INIT_1(   INST)                   INST
#define DUP_INIT_2(   INST) DUP_INIT_1(INST), INST
#define DUP_INIT_3(   INST) DUP_INIT_2(INST), INST
#define DUP_INIT_4(   INST) DUP_INIT_3(INST), INST
#define DUP_INIT_5(   INST) DUP_INIT_4(INST), INST
#define DUP_INIT_6(   INST) DUP_INIT_5(INST), INST
#define DUP_INIT_7(   INST) DUP_INIT_6(INST), INST
#define DUP_INIT_8(   INST) DUP_INIT_7(INST), INST
#define DUP_INIT_9(   INST) DUP_INIT_8(INST), INST

#define DUP_INIT_N(N, INST) DUP_INIT_##N(INST)

#define DEFINE_COLOR_ANIMATOR_ARRAY(N)                       \
    template <typename ColorAnim1DT, typename ColorFXnDT>    \
    class ColorAnimatorArray<N, ColorAnim1DT, ColorFXnDT> {  \
        private:                                             \
            ColorAnim1DT _inst[N];                           \
                                                             \
        public:                                              \
            inline ColorAnimatorArray(ColorFXnDT& colorFXnD) \
            : _inst{ DUP_INIT_N(N, colorFXnD) } {}           \
                                                             \
            inline ColorAnim1DT& operator[](uint8_t idx)     \
            { return _inst[idx]; }                           \
    }

DEFINE_COLOR_ANIMATOR_ARRAY(1);
DEFINE_COLOR_ANIMATOR_ARRAY(2);
DEFINE_COLOR_ANIMATOR_ARRAY(3);
DEFINE_COLOR_ANIMATOR_ARRAY(4);
DEFINE_COLOR_ANIMATOR_ARRAY(5);
DEFINE_COLOR_ANIMATOR_ARRAY(6);
DEFINE_COLOR_ANIMATOR_ARRAY(7);
DEFINE_COLOR_ANIMATOR_ARRAY(8);
DEFINE_COLOR_ANIMATOR_ARRAY(9);

#undef DUP_INIT_1
#undef DUP_INIT_2
#undef DUP_INIT_3
#undef DUP_INIT_4
#undef DUP_INIT_5
#undef DUP_INIT_6
#undef DUP_INIT_7
#undef DUP_INIT_8
#undef DUP_INIT_9

#undef DUP_INIT_N

#undef DEFINE_COLOR_ANIMATOR_ARRAY


} // namespace eCxx


#endif
