/********************************************************************
*
* File: fsShareCompletions.h
*
* Purpose: Share results can arrive on any thread (Java, WinRT, UIKit);
* they are queued and handed out from update().
*
*********************************************************************/
#ifndef fsShareCompletionshdr
#define fsShareCompletionshdr
#include "../../fsShareSheetService.h"
#include <mutex>
#include <utility>
#include <vector>
class fsShareCompletions
{
public:
void push(fsShareSheetService::DoneCallback done, fsShareResult result, std::string detail = std::string())
{
std::lock_guard<std::mutex> lock(mMutex);
mPending.push_back({std::move(done), result, std::move(detail)});
}
void deliver()
{
std::vector<Pending> pending;
{
std::lock_guard<std::mutex> lock(mMutex);
pending.swap(mPending);
}
for (auto& item : pending)
{
if (item.done)
{
item.done(item.result, item.detail);
}
}
}
private:
struct Pending
{
fsShareSheetService::DoneCallback done;
fsShareResult result;<--- Member variable 'Pending::result' has no initializer. [+]Member variable 'Pending::result' has no initializer. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.
std::string detail;
};
std::mutex mMutex;
std::vector<Pending> mPending;
};
#endif