1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- // crclibtest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
- //
- #include <iostream>
- #include <map>
- #include "crc_interface.h"
- using namespace std;
- std::map<std::string, std::string> charPtrToMap(char*** ptr, int n) {
- std::map<std::string, std::string> result;
- for (int i = 0; i < n; i++) {
- char* key = ptr[i][0];
- char* value = ptr[i][1];
- result[key] = value;
- }
- return result;
- }
- void freeCharPtr(char*** ptr, int n) {
- for (int i = 0; i < n; i++) {
- delete[] ptr[i][0];
- delete[] ptr[i][1];
- delete[] ptr[i];
- }
- delete[] ptr;
- }
- int main()
- {
- //输入SCD路径
- string scdPath;
- cout << "Please select the action you want to take:" << endl;
- cout << "1. Calculate the CRC of all IEDs and the CRC of SCDs" << endl;
- cout << "2. Calculate the CRC of the specified IED" << endl;
- cout << "3. Export the CCD of the specified IED" << endl;
- cout << "Please enter the action number(1-3):" << endl;
- int iActType = -1;
- cin >> iActType;
- if (iActType == 1)
- {
- string scdPath;
- cout << "Please input the path of SCD file:" << endl;
- cin >> scdPath;
- cout << "Please wait.." << endl;
- int iCalcSize;
- char*** pszCrcMap;
- const char* pszSCDCRC = calcALLIEDCRC(&pszCrcMap, scdPath.c_str(), iCalcSize);
- cout << "SCD CRC:" << pszSCDCRC << endl;
- std::map<std::string, std::string> crcMap = charPtrToMap(pszCrcMap, iCalcSize);
- for (auto it = crcMap.begin(); it != crcMap.end(); it++) {
- cout << it->first << ":" << it->second << endl;
- }
- cout << "The CRC of SCD is:" << pszSCDCRC << endl;
-
- freeCharPtr(pszCrcMap, iCalcSize);
- delete[] pszSCDCRC;
-
- }
- else if (iActType == 2)
- {
- string scdPath;
- cout << "Please input the path of SCD file:" << endl;
- cin >> scdPath;
- string iedName;
- cout << "Please input the name of IED:" << endl;
- cin >> iedName;
- const char* crc = calcIEDCRC(scdPath.c_str(), iedName.c_str());
- cout << "The CRC of IED is:" << crc << endl;
- delete[] crc;
- }
- else if (iActType == 3)
- {
- string scdPath;
- cout << "Please input the path of SCD file:" << endl;
- cin >> scdPath;
- string iedName;
- cout << "Please input the name of IED:" << endl;
- cin >> iedName;
- string exportPath;
- cout << "Please input the path of export directory:" << endl;
- cin >> exportPath;
-
- exportCCD(scdPath.c_str(), iedName.c_str(), exportPath.c_str());
- }
- else
- {
- cout << "Please input the correct number!" << endl;
- }
- system("pause");
- return 0;
- }
|