#include "calccrc.hpp" #include // 使用extern "C"来定义接口函数 #ifdef __cplusplus extern "C" { #endif char*** map_to_char(const std::map& m) { // Allocate memory for the char*** int size = m.size(); char*** array = new char** [size]; // Iterate over the map and copy each key and value to the char*** int i = 0; for (const auto& p : m) { // Allocate memory for each key and value pair array[i] = new char* [2]; // Copy the key int key_len = p.first.length(); array[i][0] = new char[key_len + 1]; strcpy(array[i][0], p.first.c_str()); // Copy the value int val_len = p.second.length(); array[i][1] = new char[val_len + 1]; strcpy(array[i][1], p.second.c_str()); i++; } return array; } const char* get_string(string str) { const char* pszSTR = str.data(); char* new_str = new char[strlen(pszSTR) + 1]; strcpy(new_str, pszSTR); return new_str; } const char* calcALLIEDCRC(char**** iedCrcMap, const char* pszSCDFile, int& iSize) { iSize = 0; map iedCRCMap = CCalCRC::getIedCrc(pszSCDFile); iSize = iedCRCMap.size(); *iedCrcMap = map_to_char(iedCRCMap); string strSCDCRC = CCalCRC::getScdCRC(iedCRCMap).c_str(); return get_string(strSCDCRC); } const char* calcIEDCRC(const char* pszSCDFile, const char* pszIEDName) { string crcValue = CCalCRC::getIedCrc(pszSCDFile, pszIEDName).data(); return get_string(crcValue); } const char* calcCRCForBytes(const char* pszBytes, int nLen) { int crc = 0xffffffff; string serial(pszBytes, nLen); crc = CCalCRC::crcbyTable(crc, serial); string crcValue = CCalCRC::dec2hex(crc); for (size_t i = crcValue.size(); i < 8; i++) crcValue.insert(0, "0"); return get_string(crcValue); } void exportCCD(const char* pszSCDFile, const char* pszIEDName, const char* pszDirName) { CCalCRC::exportIedCCD(pszSCDFile, pszIEDName, pszDirName); } #ifdef __cplusplus } #endif