Ignore:
Timestamp:
05/29/18 16:32:45 (6 years ago)
Author:
Maciej Komosinski
Message:

Code formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/mutparamlist.cpp

    r286 r792  
    88struct ParamInfo
    99{
    10 ParamInterface *pi;
    11 MutableParamInterface *mpi;
    12 CallbackNode *anode,*dnode,*ganode,*gdnode,*cnode,*gcnode,*panode;
    13 int firstprop, firstgroup;
    14 int propcount, groupcount;
     10        ParamInterface *pi;
     11        MutableParamInterface *mpi;
     12        CallbackNode *anode, *dnode, *ganode, *gdnode, *cnode, *gcnode, *panode;
     13        int firstprop, firstgroup;
     14        int propcount, groupcount;
    1515};
    1616
    1717ParamInfo* MutableParamList::getParamInfo(int i)
    1818{
    19 return (ParamInfo*)list(i);
    20 }
    21 
    22 void MutableParamList::addPI(int pos,ParamInfo *pi)
    23 {
    24 int propcount=pi->propcount;
    25 int groupcount=pi->groupcount;
    26 if (pos==0)
    27         { pi->firstprop=0; pi->firstgroup=0; }
    28 else
    29         {
    30         ParamInfo *prev_pi=getParamInfo(pos-1);
    31         pi->firstprop=prev_pi->firstprop+prev_pi->propcount;
    32         pi->firstgroup=prev_pi->firstgroup+prev_pi->groupcount;
    33         }
    34 list.insert(pos,pi);
    35 pi->propcount=0;
    36 pi->groupcount=0;
    37 for (int i=0;i<groupcount;i++)
    38         {
    39         pi->groupcount=i+1;
    40         adjustPI(pos+1,0,1);
    41         ongroupadd.action(pi->firstgroup+i);
    42         }
    43 for (int i=0;i<propcount;i++)
    44         {
    45         pi->propcount=i+1;
    46         adjustPI(pos+1,1,0);
    47         onadd.action(pi->firstprop+i);
    48         }
    49 if (pi->mpi)
    50         {
    51         pi->anode=pi->mpi->onadd.add(STATRICKCALLBACK(this,&MutableParamList::onPropAdd,pi));
    52         pi->ganode=pi->mpi->ongroupadd.add(STATRICKCALLBACK(this,&MutableParamList::onGroupAdd,pi));
    53         pi->dnode=pi->mpi->ondelete.add(STATRICKCALLBACK(this,&MutableParamList::onPropDelete,pi));
    54         pi->gdnode=pi->mpi->ongroupdelete.add(STATRICKCALLBACK(this,&MutableParamList::onGroupDelete,pi));
    55         pi->cnode=pi->mpi->onchange.add(STATRICKCALLBACK(this,&MutableParamList::onPropChange,pi));
    56         pi->gcnode=pi->mpi->ongroupchange.add(STATRICKCALLBACK(this,&MutableParamList::onGroupChange,pi));
    57         pi->panode=pi->mpi->onactivate.add(STATRICKCALLBACK(this,&MutableParamList::onPropActivate,pi));
     19        return (ParamInfo*)list(i);
     20}
     21
     22void MutableParamList::addPI(int pos, ParamInfo *pi)
     23{
     24        int propcount = pi->propcount;
     25        int groupcount = pi->groupcount;
     26        if (pos == 0)
     27        {
     28                pi->firstprop = 0;
     29                pi->firstgroup = 0;
     30        }
     31        else
     32        {
     33                ParamInfo *prev_pi = getParamInfo(pos - 1);
     34                pi->firstprop = prev_pi->firstprop + prev_pi->propcount;
     35                pi->firstgroup = prev_pi->firstgroup + prev_pi->groupcount;
     36        }
     37        list.insert(pos, pi);
     38        pi->propcount = 0;
     39        pi->groupcount = 0;
     40        for (int i = 0; i < groupcount; i++)
     41        {
     42                pi->groupcount = i + 1;
     43                adjustPI(pos + 1, 0, 1);
     44                ongroupadd.action(pi->firstgroup + i);
     45        }
     46        for (int i = 0; i < propcount; i++)
     47        {
     48                pi->propcount = i + 1;
     49                adjustPI(pos + 1, 1, 0);
     50                onadd.action(pi->firstprop + i);
     51        }
     52        if (pi->mpi)
     53        {
     54                pi->anode = pi->mpi->onadd.add(STATRICKCALLBACK(this, &MutableParamList::onPropAdd, pi));
     55                pi->ganode = pi->mpi->ongroupadd.add(STATRICKCALLBACK(this, &MutableParamList::onGroupAdd, pi));
     56                pi->dnode = pi->mpi->ondelete.add(STATRICKCALLBACK(this, &MutableParamList::onPropDelete, pi));
     57                pi->gdnode = pi->mpi->ongroupdelete.add(STATRICKCALLBACK(this, &MutableParamList::onGroupDelete, pi));
     58                pi->cnode = pi->mpi->onchange.add(STATRICKCALLBACK(this, &MutableParamList::onPropChange, pi));
     59                pi->gcnode = pi->mpi->ongroupchange.add(STATRICKCALLBACK(this, &MutableParamList::onGroupChange, pi));
     60                pi->panode = pi->mpi->onactivate.add(STATRICKCALLBACK(this, &MutableParamList::onPropActivate, pi));
    5861        }
    5962}
     
    6164int MutableParamList::findPI(ParamInfo *pi)
    6265{
    63 return list.find((void*)pi);
     66        return list.find((void*)pi);
    6467}
    6568
    6669int MutableParamList::findPI(ParamInterface *p)
    6770{
    68 ParamInfo *pi;
    69 for(int i=0;pi=(ParamInfo*)list(i);i++)
    70         if ((!pi->mpi)&&(pi->pi==p)) return i;
    71 return -1;
     71        ParamInfo *pi;
     72        for (int i = 0; pi = (ParamInfo*)list(i); i++)
     73                if ((!pi->mpi) && (pi->pi == p)) return i;
     74        return -1;
    7275}
    7376
    7477int MutableParamList::findPI(MutableParamInterface *p)
    7578{
    76 ParamInfo *pi;
    77 for(int i=0;pi=(ParamInfo*)list(i);i++)
    78         if ((pi->mpi)&&(pi->mpi==p)) return i;
    79 return -1;
    80 }
    81 
    82 void MutableParamList::adjustPI(int firstPI,int addprop,int addgroup)
    83 {
    84 ParamInfo *pi;
    85 for (int i=firstPI;pi=getParamInfo(i);i++)
    86         {
    87         pi->firstprop+=addprop;
    88         pi->firstgroup+=addgroup;
     79        ParamInfo *pi;
     80        for (int i = 0; pi = (ParamInfo*)list(i); i++)
     81                if ((pi->mpi) && (pi->mpi == p)) return i;
     82        return -1;
     83}
     84
     85void MutableParamList::adjustPI(int firstPI, int addprop, int addgroup)
     86{
     87        ParamInfo *pi;
     88        for (int i = firstPI; pi = getParamInfo(i); i++)
     89        {
     90                pi->firstprop += addprop;
     91                pi->firstgroup += addgroup;
    8992        }
    9093}
     
    9295void MutableParamList::removePI(int pi_index)
    9396{
    94 if (pi_index<0) return;
    95 ParamInfo *pi=getParamInfo(pi_index);
    96 for (int i=pi->propcount-1;i>=0;i--)
    97         {
    98         pi->propcount=i;
    99         adjustPI(pi_index+1,-1,0);
    100         ondelete.action(i);
    101         }
    102 for (int i=pi->groupcount-1;i>=0;i--)
    103         {
    104         pi->groupcount=i;
    105         adjustPI(pi_index+1,0,-1);
    106         ongroupdelete.action(i);
    107         }
    108 list-=(pi_index);
    109 if (pi->mpi)
    110         {
    111         pi->mpi->onadd.remove(pi->anode);
    112         pi->mpi->ongroupadd.remove(pi->ganode);
    113         pi->mpi->ondelete.remove(pi->dnode);
    114         pi->mpi->ongroupdelete.remove(pi->gdnode);
    115         pi->mpi->onchange.remove(pi->cnode);
    116         pi->mpi->ongroupchange.remove(pi->gcnode);
    117         pi->mpi->onactivate.remove(pi->panode);
    118         }
    119 delete pi;
     97        if (pi_index < 0) return;
     98        ParamInfo *pi = getParamInfo(pi_index);
     99        for (int i = pi->propcount - 1; i >= 0; i--)
     100        {
     101                pi->propcount = i;
     102                adjustPI(pi_index + 1, -1, 0);
     103                ondelete.action(i);
     104        }
     105        for (int i = pi->groupcount - 1; i >= 0; i--)
     106        {
     107                pi->groupcount = i;
     108                adjustPI(pi_index + 1, 0, -1);
     109                ongroupdelete.action(i);
     110        }
     111        list -= (pi_index);
     112        if (pi->mpi)
     113        {
     114                pi->mpi->onadd.remove(pi->anode);
     115                pi->mpi->ongroupadd.remove(pi->ganode);
     116                pi->mpi->ondelete.remove(pi->dnode);
     117                pi->mpi->ongroupdelete.remove(pi->gdnode);
     118                pi->mpi->onchange.remove(pi->cnode);
     119                pi->mpi->ongroupchange.remove(pi->gcnode);
     120                pi->mpi->onactivate.remove(pi->panode);
     121        }
     122        delete pi;
    120123}
    121124
    122125MutableParamList::~MutableParamList()
    123126{
    124 for (int i=list.size()-1;i>=0;i--)
     127        for (int i = list.size() - 1; i >= 0; i--)
     128                removePI(i);
     129}
     130
     131void MutableParamList::onPropAdd(void* data, intptr_t i)
     132{
     133        ParamInfo *pi = (ParamInfo*)data;
     134        pi->propcount++;
     135        int j = findPI(pi);
     136        if (j >= 0)
     137                adjustPI(j + 1, 1, 0);
     138        onadd.action(pi->firstprop + i);
     139}
     140
     141void MutableParamList::onPropDelete(void* data, intptr_t i)
     142{
     143        ParamInfo *pi = (ParamInfo*)data;
     144        pi->propcount--;
     145        int j = findPI(pi);
     146        if (j >= 0)
     147                adjustPI(j + 1, -1, 0);
     148        ondelete.action(pi->firstprop + i);
     149}
     150
     151void MutableParamList::onPropChange(void* data, intptr_t i)
     152{
     153        ParamInfo *pi = (ParamInfo*)data;
     154        onchange.action(pi->firstprop + i);
     155}
     156
     157void MutableParamList::onPropActivate(void* data, intptr_t i)
     158{
     159        ParamInfo *pi = (ParamInfo*)data;
     160        onactivate.action(pi->firstprop + i);
     161}
     162
     163void MutableParamList::onGroupAdd(void* data, intptr_t i)
     164{
     165        ParamInfo *pi = (ParamInfo*)data;
     166        pi->groupcount++;
     167        int j = findPI(pi);
     168        if (j >= 0)
     169                adjustPI(j + 1, 0, 1);
     170        ongroupadd.action(pi->firstgroup + i);
     171}
     172
     173void MutableParamList::onGroupDelete(void* data, intptr_t i)
     174{
     175        ParamInfo *pi = (ParamInfo*)data;
     176        pi->groupcount--;
     177        int j = findPI(pi);
     178        if (j >= 0)
     179                adjustPI(j + 1, 0, -1);
     180        ongroupdelete.action(pi->firstgroup + i);
     181}
     182
     183void MutableParamList::onGroupChange(void* data, intptr_t i)
     184{
     185        ParamInfo *pi = (ParamInfo*)data;
     186        ongroupchange.action(pi->firstgroup + i);
     187}
     188
     189void MutableParamList::insert(int pos, MutableParamInterface *p)
     190{
     191        ParamInfo *pi = new ParamInfo();
     192        pi->pi = (ParamInterface*)p;
     193        pi->mpi = p;
     194        pi->propcount = p->getPropCount();
     195        pi->groupcount = p->getGroupCount();
     196        addPI(pos, pi);
     197}
     198
     199void MutableParamList::insert(int pos, ParamInterface *p)
     200{
     201        ParamInfo *pi = new ParamInfo();
     202        pi->pi = p;
     203        pi->mpi = 0;
     204        pi->propcount = p->getPropCount();
     205        pi->groupcount = p->getGroupCount();
     206        addPI(pos, pi);
     207}
     208
     209
     210void MutableParamList::operator+=(ParamInterface *p)
     211{
     212        insert(list.size(), p);
     213}
     214
     215void MutableParamList::operator+=(MutableParamInterface *p)
     216{
     217        insert(list.size(), p);
     218}
     219
     220
     221void MutableParamList::operator-=(ParamInterface *p)
     222{
     223        int i = findPI(p);
    125224        removePI(i);
    126225}
    127226
    128 void MutableParamList::onPropAdd(void* data,intptr_t i)
    129 {
    130 ParamInfo *pi=(ParamInfo*)data;
    131 pi->propcount++;
    132 int j=findPI(pi);
    133 if (j>=0)
    134         adjustPI(j+1,1,0);
    135 onadd.action(pi->firstprop+i);
    136 }
    137 
    138 void MutableParamList::onPropDelete(void* data,intptr_t i)
    139 {
    140 ParamInfo *pi=(ParamInfo*)data;
    141 pi->propcount--;
    142 int j=findPI(pi);
    143 if (j>=0)
    144         adjustPI(j+1,-1,0);
    145 ondelete.action(pi->firstprop+i);
    146 }
    147 
    148 void MutableParamList::onPropChange(void* data,intptr_t i)
    149 {
    150 ParamInfo *pi=(ParamInfo*)data;
    151 onchange.action(pi->firstprop+i);
    152 }
    153 
    154 void MutableParamList::onPropActivate(void* data,intptr_t i)
    155 {
    156 ParamInfo *pi=(ParamInfo*)data;
    157 onactivate.action(pi->firstprop+i);
    158 }
    159 
    160 void MutableParamList::onGroupAdd(void* data,intptr_t i)
    161 {
    162 ParamInfo *pi=(ParamInfo*)data;
    163 pi->groupcount++;
    164 int j=findPI(pi);
    165 if (j>=0)
    166         adjustPI(j+1,0,1);
    167 ongroupadd.action(pi->firstgroup+i);
    168 }
    169 
    170 void MutableParamList::onGroupDelete(void* data,intptr_t i)
    171 {
    172 ParamInfo *pi=(ParamInfo*)data;
    173 pi->groupcount--;
    174 int j=findPI(pi);
    175 if (j>=0)
    176         adjustPI(j+1,0,-1);
    177 ongroupdelete.action(pi->firstgroup+i);
    178 }
    179 
    180 void MutableParamList::onGroupChange(void* data,intptr_t i)
    181 {
    182 ParamInfo *pi=(ParamInfo*)data;
    183 ongroupchange.action(pi->firstgroup+i);
    184 }
    185 
    186 void MutableParamList::insert(int pos,MutableParamInterface *p)
    187 {
    188 ParamInfo *pi=new ParamInfo();
    189 pi->pi=(ParamInterface*)p;
    190 pi->mpi=p;
    191 pi->propcount=p->getPropCount();
    192 pi->groupcount=p->getGroupCount();
    193 addPI(pos,pi);
    194 }
    195 
    196 void MutableParamList::insert(int pos,ParamInterface *p)
    197 {
    198 ParamInfo *pi=new ParamInfo();
    199 pi->pi=p;
    200 pi->mpi=0;
    201 pi->propcount=p->getPropCount();
    202 pi->groupcount=p->getGroupCount();
    203 addPI(pos,pi);
    204 }
    205 
    206 
    207 void MutableParamList::operator+=(ParamInterface *p)
    208 {
    209 insert(list.size(),p);
    210 }
    211 
    212 void MutableParamList::operator+=(MutableParamInterface *p)
    213 {
    214 insert(list.size(),p);
    215 }
    216 
    217 
    218 void MutableParamList::operator-=(ParamInterface *p)
    219 {
    220 int i=findPI(p);
    221 removePI(i);
    222 }
    223 
    224227void MutableParamList::operator-=(MutableParamInterface *p)
    225228{
    226 int i=findPI(p);
    227 removePI(i);
     229        int i = findPI(p);
     230        removePI(i);
    228231}
    229232
    230233void MutableParamList::operator-=(int i)
    231234{
    232 removePI(i);
     235        removePI(i);
    233236}
    234237
    235238int MutableParamList::getGroupCount()
    236239{
    237 int count=0;
    238 FOREACH(ParamInfo*,pi,list)
    239         count+=pi->groupcount;
    240 return count;
     240        int count = 0;
     241        FOREACH(ParamInfo*, pi, list)
     242                count += pi->groupcount;
     243        return count;
    241244}
    242245
    243246int MutableParamList::getPropCount()
    244247{
    245 int count=0;
    246 FOREACH(ParamInfo*,pi,list)
    247         count+=pi->propcount;
    248 return count;
    249 }
    250 
    251 int MutableParamList::getSubParam(int i,ParamInterface **sub_p,int *sub_i)
    252 {
    253 int n;
    254 FOREACH(ParamInfo*,pi,list)
    255         {
    256         if (i<(n=pi->propcount))
     248        int count = 0;
     249        FOREACH(ParamInfo*, pi, list)
     250                count += pi->propcount;
     251        return count;
     252}
     253
     254int MutableParamList::getSubParam(int i, ParamInterface **sub_p, int *sub_i)
     255{
     256        int n;
     257        FOREACH(ParamInfo*, pi, list)
     258        {
     259                if (i < (n = pi->propcount))
    257260                {
    258                 *sub_p=pi->pi;
    259                 *sub_i=i;
    260                 return 1;
     261                        *sub_p = pi->pi;
     262                        *sub_i = i;
     263                        return 1;
    261264                }
    262         i-=n;
    263         }
    264 return 0;
    265 }
    266 
    267 int MutableParamList::getSubGroup(int i,ParamInterface **sub_p,int *sub_i)
    268 {
    269 int n;
    270 FOREACH(ParamInfo*,pi,list)
    271         {
    272         if (i<(n=pi->groupcount))
     265                i -= n;
     266        }
     267        return 0;
     268}
     269
     270int MutableParamList::getSubGroup(int i, ParamInterface **sub_p, int *sub_i)
     271{
     272        int n;
     273        FOREACH(ParamInfo*, pi, list)
     274        {
     275                if (i < (n = pi->groupcount))
    273276                {
    274                 *sub_p=pi->pi;
    275                 *sub_i=i;
    276                 return 1;
     277                        *sub_p = pi->pi;
     278                        *sub_i = i;
     279                        return 1;
    277280                }
    278         i-=n;
    279         }
    280 return 0;
     281                i -= n;
     282        }
     283        return 0;
    281284}
    282285
     
    289292}
    290293
    291 FUN(const char*,id,0)
    292 FUN(const char*,name,0)
    293 FUN(const char*,type,0)
    294 FUN(const char*,help,0)
    295 FUN(int,flags,0)
    296 FUN(SString,getString,SString())
    297 FUN(paInt,getInt,0)
    298 FUN(double,getDouble,0)
    299 FUN(ExtValue,getExtValue,ExtValue((paInt)0))
    300 FUN(ExtObject,getObject,ExtObject())
     294FUN(const char*, id, 0)
     295FUN(const char*, name, 0)
     296FUN(const char*, type, 0)
     297FUN(const char*, help, 0)
     298FUN(int, flags, 0)
     299FUN(SString, getString, SString())
     300FUN(paInt, getInt, 0)
     301FUN(double, getDouble, 0)
     302FUN(ExtValue, getExtValue, ExtValue((paInt)0))
     303FUN(ExtObject, getObject, ExtObject())
    301304
    302305int MutableParamList::group(int i)
    303306{
    304 int n;
    305 int g=0;
    306 FOREACH(ParamInfo*,pi,list)
    307         {
    308         if (i<(n=pi->propcount))
    309                 return g + pi->pi->group(i);
    310         g+=pi->groupcount;
    311         i-=n;
    312         }
    313 return 0;
     307        int n;
     308        int g = 0;
     309        FOREACH(ParamInfo*, pi, list)
     310        {
     311                if (i < (n = pi->propcount))
     312                        return g + pi->pi->group(i);
     313                g += pi->groupcount;
     314                i -= n;
     315        }
     316        return 0;
    314317}
    315318
     
    322325}
    323326
    324 FUN2(int,setInt,paInt)
    325 FUN2(int,setDouble,double)
    326 FUN2(int,setString,const SString &)
    327 FUN2(int,setObject,const ExtObject &)
    328 FUN2(int,setExtValue,const ExtValue &)
    329 
    330 void MutableParamList::call(int i,ExtValue* args,ExtValue *ret)
    331 {
    332 int j; ParamInterface *pi;
    333 if (!getSubParam(i,&pi,&j)) return;
    334 pi->call(j,args,ret);
     327FUN2(int, setInt, paInt)
     328FUN2(int, setDouble, double)
     329FUN2(int, setString, const SString &)
     330FUN2(int, setObject, const ExtObject &)
     331FUN2(int, setExtValue, const ExtValue &)
     332
     333void MutableParamList::call(int i, ExtValue* args, ExtValue *ret)
     334{
     335        int j; ParamInterface *pi;
     336        if (!getSubParam(i, &pi, &j)) return;
     337        pi->call(j, args, ret);
    335338}
    336339
    337340const char *MutableParamList::grname(int i)
    338341{
    339 int j; ParamInterface *pi;
    340 if (!getSubGroup(i,&pi,&j)) return 0;
    341 return pi->grname(j);
    342 }
    343 
    344 int MutableParamList::grmember(int gi,int i)
    345 {
    346 int n;
    347 int count=0;
    348 FOREACH(ParamInfo*,pi,list)
    349         {
    350         if (gi<(n=pi->groupcount))
     342        int j; ParamInterface *pi;
     343        if (!getSubGroup(i, &pi, &j)) return 0;
     344        return pi->grname(j);
     345}
     346
     347int MutableParamList::grmember(int gi, int i)
     348{
     349        int n;
     350        int count = 0;
     351        FOREACH(ParamInfo*, pi, list)
     352        {
     353                if (gi < (n = pi->groupcount))
    351354                {
    352                 int prop=pi->pi->grmember(gi,i);
    353                 if (prop>=pi->propcount) return -9999;
    354                 return count+prop;
     355                        int prop = pi->pi->grmember(gi, i);
     356                        if (prop >= pi->propcount) return -9999;
     357                        return count + prop;
    355358                }
    356         count+=pi->propcount;
    357         gi-=n;
    358         }
    359 return -9999;
     359                count += pi->propcount;
     360                gi -= n;
     361        }
     362        return -9999;
    360363}
    361364
    362365void MutableParamList::clear()
    363366{
    364 for (int i=list.size()-1;i>=0;i--)
    365         operator-=(i);
    366 }
     367        for (int i = list.size() - 1; i >= 0; i--)
     368                operator-=(i);
     369}
Note: See TracChangeset for help on using the changeset viewer.