- 在cocoa中使用C++STL 链表
- 1>.把“*.m”文件重命名为“*.mm”。
- 2>.在.mm文件中包含头文件:
- #include <list>
- using namespace std;
- 3>.定义结构
- typedef struct MSUsb_mountInfo
- {
- char cVolumePath[MAX_CHARLEN];
- uint32_t cVolumeByteLen;
- char cDiskID[MAX_CHARLEN];
- uint32_t cDiskIDLen;
- }mountInfo;
- //usb pid, vid, mount disk information
- typedef struct MStorageDeviceInfo // __MS_USBInformation
- {
- uintptr_t VendorID; //vendor id
- uintptr_t ProductID; //product id
- uintptr_t bcdDevice; //device version number
- uintptr_t nMountNumber; //挂载分区的个数
- mountInfo szMount[40]; //最多挂载20个分区
- /* bool operator == (const MStorageDeviceInfo & rhs)
- {
- if(VendorID==rhs.VendorID && ProductID==rhs.ProductID && bcdDevice == rhs.bcdDevice)
- {
- return true;
- }
- else
- return false;
- }*/
- };
- 4>.使用链表:
- //使用c++ 炼表
- typedef list<MStorageDeviceInfo> ListMStorageDeviceInfo;
- ListMStorageDeviceInfo g_msListDev;
- ListMStorageDeviceInfo g_interListDev;
- 5>.添加节点:
- MStorageDeviceInfo dev;
- dev.nMountNumber = 0;
- g_msListDev.insert(g_msListDev.end(), dev);
- 6>.删除节点:
- int ms_DeleteListNoDiffRecorded(
- long vendorID,
- long productID,
- long versionNumber,
- void *param
- )
- {
- ListMStorageDeviceInfo *plist= (ListMStorageDeviceInfo*)param;
- if(plist->empty())
- {
- //ps is empty
- return 0;
- }
- ListMStorageDeviceInfo::iterator ites;
- for(ites = plist->begin(); ites != plist->end();)
- {
- if((*ites).VendorID == vendorID
- (*ites).ProductID == productID
- (*ites).bcdDevice == versionNumber)
- {
- ites = plist->erase(ites); //删除节点
- continue;
- }
- ites ++;
- }
- return 0;
- }
在cocoa中使用C++STL 链表
最新推荐文章于 2024-04-28 04:13:15 发布