#ifndef DATA_MANAGER_H #define DATA_MANAGER_H #include #include #include #include "DataPipe.h" // 假设 DataPipe 类定义在这个头文件中 #include "DataPackage.h" // 假设 DataPackage 类定义在这个头文件中 #include "../DataBuffer/DataBuffer.h" class DataManager { public: static DataManager &getInstance() { static DataManager instance; return instance; } // add data pipe template void addDataPipe(std::string name); // erase data pipe void eraseDataPipe(std::string name); // get data pipe by name template std::shared_ptr> getDataPipe(std::string name); // push data to the data pipe template void pushData(std::string name, T *data); // pop data from the data pipe template bool popData(std::string name, T *&data); template MemoryPool *getDataBuffer(); // get a data buffer from the memory pool template T *acquireDataBuffer(); // release a data buffer to the memory pool template void releaseDataBuffer(T *buffer); private: DataManager() = default; ~DataManager() = default; DataManager(const DataManager &) = delete; DataManager &operator=(const DataManager &) = delete; private: std::unordered_map> m_dataPipes; int width{3840}; int height{2160}; }; template void DataManager::addDataPipe(std::string name) { // Check if the data pipe already exists if (m_dataPipes.find(name) != m_dataPipes.end()) { return; } auto dataPipe = std::make_shared>(); m_dataPipes[name] = dataPipe; } template std::shared_ptr> DataManager::getDataPipe(std::string name) { auto it = m_dataPipes.find(name); if (it != m_dataPipes.end()) { return std::static_pointer_cast>(it->second); } return nullptr; } template void DataManager::pushData(std::string name, T *data) { auto dataPipe = getDataPipe(name); if (dataPipe) { dataPipe->pushData(data); } } template bool DataManager::popData(std::string name, T *&data) { auto dataPipe = getDataPipe(name); if (dataPipe) { return dataPipe->popData(data); } return false; } template MemoryPool *DataManager::getDataBuffer() { static MemoryPool memoryPool(BUFFER_SIZE, width, height); return &memoryPool; } template T *DataManager::acquireDataBuffer() { // static MemoryPool memoryPool(BUFFER_SIZE, width, height); return getDataBuffer()->acquire(); } template void DataManager::releaseDataBuffer(T *buffer) { // static MemoryPool memoryPool(BUFFER_SIZE, width, height); getDataBuffer()->release(buffer); } #endif // DATA_MANAGER_H