How can i collect those queue's in a short form.

Hi. I have a switch case
How can i collect those queue's in a short form.
My code seems very complicated


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
                    switch (pars.id.c[1])
                    {
                        // udp yayınla
//                    xp_rx = new QUdpSocket(this);
//                    xp_rx->bind(QHostAddress(QString(XP_IP)),49005);
                         case TM_ID_AVI:
                            qDebug() << "avi" ;


                            for (int i=0; i<10; i++ )
                            {
                                queuee[115].enqueue(pars.t[TM_AV_1_vol_rpm].f);
                             //   queuee[116].enqueue(pars.t[TM_AV_sag_ana_knt_vol].f);
                                queuee[117].enqueue(pars.t[TM_AV_sag_ana_knt_vol].f);
                               // queuee[118].enqueue(pars.t[TM_K_rp_iv].f);
//                                queuee[119].enqueue(pars.t[TM_AV_sol_ana_knt_vol].f);
//                                queuee[120].enqueue(pars.t[TM_K_roll_olcu].f);
                                queuee[121].enqueue(pars.t[TM_AV_sag_RK_knt_vol].f);
                               // queuee[122].enqueue(pars.t[TM_K_yaw_olcu].f);
                                queuee[123].enqueue(pars.t[TM_AV_sol_RK_knt_vol].f);
//                                queuee[124].enqueue(pars.t[TM_K_rp_dv].f);
//                                queuee[125].enqueue(pars.t[TM_K_rp_u].f);
//                                queuee[126].enqueue(pars.t[TM_K_pp_pv].f);
//                                queuee[127].enqueue(pars.t[TM_K_pp_iv].f);
//                                queuee[128].enqueue(pars.t[TM_K_pp_dv].f);
                                queuee[129].enqueue(pars.t[TM_AV_pitot_hava_hizi].f);
                                queuee[130].enqueue(pars.t[TM_AV_pitot_hava_hizi].f);
//                                queuee[131].enqueue(pars.t[TM_K_roll_olcu].f);
//                                queuee[132].enqueue(pars.t[TM_K_pitch_olcu].f);
//                                queuee[133].enqueue(pars.t[TM_K_yaw_olcu].f);
                                queuee[134].enqueue(pars.t[TM_ic_sicaklik].f);
                                queuee[135].enqueue(pars.t[TM_dis_sicaklik].f);
                               // queuee[136].enqueue(pars.t[TM_K_rp_u].f);
                                queuee[137].enqueue(pars.t[TM_nem].f);
                                queuee[138].enqueue(pars.t[TM_ize_olan_msf].f);
                                queuee[139].enqueue(pars.t[TM_AV_lrf_irtifa].f);
                                queuee[140].enqueue(pars.t[TM_AV_lrf_sinyal_vol].f);
                                queuee[141].enqueue(pars.t[TM_AV_lrf_sicaklik].f);
//                                queuee[142].enqueue(pars.t[TM_K_roll_olcu].f);
//                                queuee[143].enqueue(pars.t[TM_K_pitch_olcu].f);
//                                queuee[144].enqueue(pars.t[TM_K_yaw_olcu].f);
//                                queuee[145].enqueue(pars.t[TM_K_alt_olcu].f);
//                                queuee[146].enqueue(pars.t[TM_K_rp_dv].f);
//                                queuee[147].enqueue(pars.t[TM_K_rp_u].f);
//                                queuee[148].enqueue(pars.t[TM_K_pp_pv].f);
//                                queuee[149].enqueue(pars.t[TM_K_pp_iv].f);
//                                queuee[150].enqueue(pars.t[TM_K_pp_dv].f);
//                                queuee[151].enqueue(pars.t[TM_K_pp_u].f);
//                                queuee[152].enqueue(pars.t[TM_K_yp_pv].f);
                            }

                             break;
                         case TM_ID_GPS:
                          qDebug() << "gps" ;

                          for (int i=0; i<10; i++ )
                          {
                              queuee[0].enqueue(pars.t[TM_GPS_yer_basi].f);
                              queuee[1].enqueue(pars.t[TM_GPS_hdop].f);
                              queuee[2].enqueue(pars.t[TM_GPS_vdop].f);
                              queuee[3].enqueue(pars.t[TM_GPS_utc].f);
                              queuee[4].enqueue(pars.t[TM_GPS_lat].f);
                              queuee[5].enqueue(pars.t[TM_GPS_lon].f);
                              queuee[6].enqueue(pars.t[TM_GPS_alt].f);
                              queuee[7].enqueue(pars.t[TM_GPS_yer_hizi].f);
                              queuee[8].enqueue(pars.t[TM_GPS_dikey_hiz].f);
                              queuee[9].enqueue(pars.t[TM_GPS_yatay_dogruluk].f);
                              queuee[10].enqueue(pars.t[TM_GPS_dikey_dogruluk].f);

                          }

                             break;
If you have a bunch of data that's related to each other arbitrarily, there isn't much you can do to avoid stating that relationship in the code somewhere. At best, you can separate the data itself from the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
struct Relation{
    size_t queue;
    SomeEnum enum_value;
};

const Relation relations1[] = {
    {115, TM_AV_1_vol_rpm},
    {117, TM_AV_sag_ana_knt_vol},
    //...
};

const Relation relations2[] = {
    {0, TM_GPS_yer_basi},
    //...
};

//...

for (int i=0; i<10; i++ ){
    for (auto &r : relations1)
        queuee[r.queue].enqueue(pars.t[r.enum_value].f);
}

//...

for (int i=0; i<10; i++ ){
    for (auto &r : relations2)
        queuee[r.queue].enqueue(pars.tr.enum_value].f);
}

This is what's known as "pushing down the waterbed". You can push down on a lump all you want, but all you're doing really is creating a new lump in a different place.
Last edited on
Thank you so much for your answer
Topic archived. No new replies allowed.