달력

122025  이전 다음

  • 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

GrpKeyTable.cpp

Programs 2014. 8. 14. 20:17

#include "Inc.hpp"

//----------------------------------------------------------------
//GrpKeyTable 클래스 함수들
//----------------------------------------------------------------

void GrpKeyTable::Init(char* path_key)
{
    char  rec[1000];
    char* pch;
    long  num = 0;

    this->KeyListNum = 0;

    //키테이블 파일 open
    KeyList.open(path_key, ifstream::in);
    if (KeyList==NULL)
    {
        gLogFile << "Error : Key File missing !!!   : " << path_key << endl;
        cout     << "Error : Key File missing !!!   : " << path_key << endl;
        system("PAUSE"); exit(0);
    }

    while(1)
    {
        KeyList.getline(rec,1000,'\n');

        if (KeyList.eof()==true) break;
        if (strlen(rec)==0)      break;

        if (KeyListNum==0)
        {
            pch = strtok(rec, ",");
            this->KeyFieldNum++;
            for (int m=1; m<100; m++)
            {
                pch = strtok(NULL, ","); if (pch==0) break;
                this->KeyFieldNum++;
            }
        }

        this->KeyListNum ++;
    }

    this->KeyFieldNum = KeyFieldNum - 2; //Prod와 Spcode는 키갯수에서 제외
    this->KeyListNum  = KeyListNum  - 1; //필드명 레코드는 갯수에서 제외

 KeyList.close();

    KeyLabel = new char* [KeyFieldNum];
    KeyError = new char* [KeyFieldNum];
    for(int i=0; i<KeyFieldNum; i++)
    {
        KeyLabel[i] = new char [20];
        KeyError[i] = new char [30];

        strcpy(KeyLabel[i],"Key");
        strcpy(KeyError[i],"*");
    }
    strcpy(KeyError[0],"KeyError");

    Product = new char*  [KeyListNum];
    Spcode  = new long   [KeyListNum];
    Key     = new char** [KeyListNum];
    for (int i=0; i<KeyListNum; i++)
    {
        Product[i] = new char [20]; strcpy(Product[i],"");

        Spcode[i] = 0;

        Key[i] = new char* [KeyFieldNum];
        for(int j=0; j<KeyFieldNum; j++)
        {
            Key[i][j] = new char [30];
            strcpy(Key[i][j],"");
        }
    }

    ifstream KeyList2;      //그룹핑키 목록 파일
    KeyList2.open(path_key, ifstream::in);
    while(1)
    {
        KeyList2.getline(rec,1000,'\n');

        if (KeyList2.eof()==true) break;
        if (strlen(rec)==0)       break;

        if (num==0)
        {
            for (int i=0; i<KeyFieldNum+2; i++)
            {
                if (i==0) pch = strtok(rec, ",");   
                else      pch = strtok(NULL,","); 
               
                if (i>1)
                {
                    strcpy(KeyLabel[i-2], pch);
                }
            }
        }
        else
        {
            for (int i=0; i<KeyFieldNum+2; i++)
            {
                if (i==0) pch = strtok(rec, ",");   
                else      pch = strtok(NULL,","); 
           
                     if (i==0) strcpy(Product[num-1], pch);
                else if (i==1) Spcode[num-1] = atoi(pch);
                else           strcpy(Key[num-1][i-2], pch);
            }
        }

        num++;
    }

 KeyList2.close();

    return;
}

GrpKeyTable::~GrpKeyTable()
{
    for(int i=0; i<KeyFieldNum; i++)
    {
        delete [] KeyLabel[i];
        delete [] KeyError[i];
    }

    delete [] KeyLabel;
    delete [] KeyError;

    for (int i=0; i<KeyListNum; i++)
    {
        delete [] Product[i];

        for(int j=0; j<KeyFieldNum; j++)
        {
            delete [] Key[i][j];
        }

        delete [] Key[i];
    }

    delete [] Product;
    delete [] Spcode;
    delete [] Key;

    return;
}

char** GrpKeyTable::KeySearch(char* prod, long spcode)
{
    for (int i=0; i<KeyListNum; i++)
    {
        if (strcmp(prod, Product[i])==0 && spcode==Spcode[i]) return Key[i];
    }
   
    gLogFile << "Error : Key Missing !!!         : " << prod << " : " << spcode << endl;
    //cout     << "Error : Key Missing !!!         : " << prod << " : " << spcode << endl;

    return KeyError;
}

char* GrpKeyTable::KeySearch(char* prod, long spcode, char* keylabel)
{
    for (int i=0; i<KeyListNum; i++)
    {
        if (strcmp(prod, Product[i])==0 && spcode==Spcode[i])
        {
            for (int j=0; j<KeyFieldNum; j++)
            {
                if (strcmp(keylabel, KeyLabel[j])==0) return Key[i][j];
            }
        }
    }
   
    return "?";
}

 

 


 

'Programs' 카테고리의 다른 글

ModelEV.cpp  (2) 2014.08.14
ResultUnit.cpp  (0) 2014.08.14
FieldInfoSet.cpp  (0) 2014.08.14
Inc.hpp  (0) 2014.08.14
Group.cpp  (0) 2014.08.14
Posted by Analytical Warrior
|