Changeset 455 for cpp/frams/_demos


Ignore:
Timestamp:
12/05/15 18:31:38 (9 years ago)
Author:
oriona
Message:

Malloc/free replaced by new/delete, pointers-to-vectors changed into vectors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/simil_test.cpp

    r451 r455  
    7171
    7272    // prepare output parameters from .gen file
    73     vector<Geno *> *pvGenos = new vector<Geno *>();
    74     vector<char *> *pvNames = new vector<char *>();
     73    vector<Geno *> pvGenos = vector<Geno *>();
     74    vector<char *> pvNames = vector<char *>();
    7575
    7676    // check if there is a switch
     
    138138        if ((pNextGenotype != NULL) && (pNextGenotype->isValid()))
    139139        {
    140             pvGenos->push_back(pNextGenotype);
     140            pvGenos.push_back(pNextGenotype);
    141141            char *szNewName = new char [ loaded->name.len() + 1];
    142142            strcpy(szNewName, loaded->name.c_str());
    143             pvNames->push_back(szNewName);
     143            pvNames.push_back(szNewName);
    144144        }
    145145        else
     
    157157
    158158    // create the empty array of similarities
    159     aaSimil = new pDouble [pvGenos->size()];
    160     for (unsigned int k = 0; k < pvGenos->size(); k++)
    161     {
    162         aaSimil[k] = new double [pvGenos->size()];
    163                 for (unsigned int l = 0; l < pvGenos->size(); l++)
     159    aaSimil = new pDouble [pvGenos.size()];
     160    for (unsigned int k = 0; k < pvGenos.size(); k++)
     161    {
     162        aaSimil[k] = new double [pvGenos.size()];
     163                for (unsigned int l = 0; l < pvGenos.size(); l++)
    164164            aaSimil[k][l] = 0.0;
    165165    }
    166166
    167167    // compute and remember similarities
    168         for (unsigned int i = 0; i < pvGenos->size(); i++)
    169     {
    170                 for (unsigned int j = 0; j < pvGenos->size(); j++)
    171         {
    172             dSimilarity = M.EvaluateDistance(pvGenos->operator[](i), pvGenos->operator[](j));
     168        for (unsigned int i = 0; i < pvGenos.size(); i++)
     169    {
     170                for (unsigned int j = 0; j < pvGenos.size(); j++)
     171        {
     172            dSimilarity = M.EvaluateDistance(pvGenos.operator[](i), pvGenos.operator[](j));
    173173            aaSimil[i][j] = dSimilarity;
    174174        }
     
    179179        // if "-names" switch was given,
    180180        // print the number of genotypes and their names
    181         printf("%li\n", pvGenos->size());
    182                 for (unsigned int iGen = 0; iGen < pvNames->size(); iGen++)
    183         {
    184             printf("%s\n", pvNames->at(iGen));
     181        printf("%li\n", pvGenos.size());
     182                for (unsigned int iGen = 0; iGen < pvNames.size(); iGen++)
     183        {
     184            printf("%s\n", pvNames.at(iGen));
    185185        }
    186186    }
    187187
    188188    // print out the matrix of similarities
    189         for (unsigned int i = 0; i < pvGenos->size(); i++)
    190     {
    191                 for (unsigned int j = 0; j < pvGenos->size(); j++)
     189        for (unsigned int i = 0; i < pvGenos.size(); i++)
     190    {
     191                for (unsigned int j = 0; j < pvGenos.size(); j++)
    192192        {
    193193            printf("%.2lf\t", aaSimil[i][j]);
     
    197197
    198198    // delete vectors and arrays
    199         for (unsigned int i = 0; i < pvGenos->size(); i++)
    200     {
    201         delete pvGenos->operator[](i);
    202         delete [] pvNames->operator[](i);
     199        for (unsigned int i = 0; i < pvGenos.size(); i++)
     200    {
     201        delete pvGenos.operator[](i);
     202        delete [] pvNames.operator[](i);
    203203        delete [] aaSimil[i];
    204204    }
    205205
    206     delete pvGenos;
    207     delete pvNames;
    208206    delete [] aaSimil;
    209207
Note: See TracChangeset for help on using the changeset viewer.