006
27.07.2013, 19:41 Uhr
YumiFerrari
|
C++: |
map<string, ODK_DATA_STRUCT> TableReader::loadMapFromCSV () { ifstream MyFile; string String; int z=0; // Used for endless while loops string Zeile = " "; char delimiter[] = ";"; char* pointer_mychar; map<string, ODK_DATA_STRUCT> names; MyFile.open (FILEPATH); if (!MyFile) { printf ("Fehler beim Oeffnen der Datei!\n"); throw 10; } else // printf ("Die Datei wurde geoeffnet!\n"); MyFile.seekg (0, ios::beg); while(z<1) { string shortName; // The short name given in the CSV file string rtName; // The rtName given in the CSV file string datatypeStringFromTable; // The data Type given in the CSV int dataTypeNumRep; // An integer representation of the datatypeStringFromTable ODK_DATA_STRUCT dataStruct; // The data struct to be filled vector<string> v; // Initing the vector where we are going to put the two parts of the rtName getline(MyFile, String); if (String != Zeile) // If the line is not empty { Zeile = String; pointer_mychar = &String[0]; pointer_mychar = strtok(pointer_mychar, delimiter); int i=0; int pairfind = 0; while(pointer_mychar != NULL) { if (i>MinColumnSize && i< MaxColumnSize) // Reading column 2-4 only. { if (pairfind == 0) { shortName = pointer_mychar; // First collum is the short Name pairfind = 1; } else if(pairfind == 1) { rtName = pointer_mychar; // Second collum is the rtName which will be analyzed here size_t position =rtName.find("]"); rtName.erase(0, position+1);
split(rtName, ',', v); // Splitting by a , pairfind = 2; } else { datatypeStringFromTable = pointer_mychar; dataTypeNumRep = i; pairfind = 0; // Resetting pairfind for a new round } } pointer_mychar = strtok(NULL, delimiter); i++; } } else { break; } string firstPartOfrtName; string secondPartOfrtName; if (v.size() == 2) { firstPartOfrtName = v[0]; secondPartOfrtName = v[1]; } else { firstPartOfrtName = ""; secondPartOfrtName = ""; } if (firstPartOfrtName.find("DB") != string::npos) { dataStruct.memoryArea = ODK_MEM_AREA_DB; replaceAll(firstPartOfrtName, "DB", ""); dataStruct.dbNumber = shortFromString(firstPartOfrtName); } else if (firstPartOfrtName.find("PAB")!= string::npos) { dataStruct.memoryArea = ODK_MEM_AREA_A; replaceAll(firstPartOfrtName, "PAB", ""); dataStruct.areaOffset = shortFromString(firstPartOfrtName); } else if (firstPartOfrtName.find("PEB")!= string::npos) { dataStruct.memoryArea = ODK_MEM_AREA_E; replaceAll(firstPartOfrtName, "PEB", ""); dataStruct.areaOffset = shortFromString(firstPartOfrtName); } else if (firstPartOfrtName.find("M")!= string::npos) { // klappt nocht nicht, wenn Merker eine offset und bit number angibt replaceAll(secondPartOfrtName, "M", ""); dataStruct.dataType = ODK_MEM_AREA_M; vector<string> p; if (firstPartOfrtName.find(".") != string::npos ) { split(firstPartOfrtName, '.', p); if (p.size() >= 1) { dataStruct.areaOffset = shortFromString(firstPartOfrtName); dataStruct.bitNumber = shortFromString(p[1]); } } else { dataStruct.areaOffset = shortFromString(firstPartOfrtName); } } else if (firstPartOfrtName.find("MD")!= string::npos) { dataStruct.memoryArea = ODK_MEM_AREA_M; replaceAll(firstPartOfrtName, "MD", ""); dataStruct.areaOffset = shortFromString(firstPartOfrtName); } else if (firstPartOfrtName.find("MW")!= string::npos) { dataStruct.memoryArea = ODK_MEM_AREA_M; replaceAll(firstPartOfrtName, "MW", ""); dataStruct.areaOffset = shortFromString(firstPartOfrtName); }
/* Second part of RTName after the comma */
if (secondPartOfrtName.find("STRING") != string::npos) { replaceAll(secondPartOfrtName, "STRING", ""); dataStruct.dataType = ODK_DATA_TYPE_STRING; vector<string> p; if (secondPartOfrtName.find(".") != string::npos ) { split(secondPartOfrtName, '.', p); if (p.size() >= 1) { dataStruct.areaOffset = shortFromString(secondPartOfrtName); dataStruct.maxSize = shortFromString(p[1]); } } else { dataStruct.areaOffset = shortFromString(firstPartOfrtName); }
} else if (secondPartOfrtName.find("DWORD") != string::npos) { replaceAll(secondPartOfrtName, "DWORD", ""); dataStruct.dataType = ODK_DATA_TYPE_DWORD; vector<string> p; if (secondPartOfrtName.find(".") != string::npos ) { split(secondPartOfrtName, '.', p); if (p.size() >= 1) { dataStruct.areaOffset = shortFromString(p[0]); dataStruct.bitNumber = shortFromString(p[1]); } } else { dataStruct.areaOffset = shortFromString(secondPartOfrtName); } int size; size = 4;
dataStruct.maxSize = size;
}
|
----- Edit: cpp-Tags eingefügt Dieser Post wurde am 28.07.2013 um 00:15 Uhr von Hans editiert. |