Exemplo n.º 1
0
void CustomerData::update(const std::string& customer, const EntryList& entries)
{
    std::lock_guard<std::mutex> lock(mutex_);
    if (!data_.unique())
    {
        MapPtr newData(new Map(*data_));
        data_.swap(newData);
    }
    assert(data_.unique());
    (*data_)[customer] = entries;

}
Exemplo n.º 2
0
void CustomerData::updateMap(const std::string& customer, const std::string& stock, int value)
{

    std::lock_guard<std::mutex> lock(mutex_);
    if (!data_.unique())
    {
        MapPtr newData(new Map(*data_));
        data_.swap(newData);
    }
    EntryList::iterator it = (*data_)[customer].begin();
    while (it != (*data_)[customer].end())
    {
        if (it->first == stock)
        {
            it->second = value;
            return;
        }
        ++it;
    }
    (*data_)[customer].push_back(std::pair<std::string, int>(stock, value));
    std::cout << "CustomerData::updateMap: " << customer << ", " << stock << ", " << value << std::endl;

}