Created
June 14, 2015 13:03
-
-
Save calindotgabriel/a527088ac97b6d0d6ef1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ProductRepo::_load(){ | |
// ****** {id}, {name} ****** | |
if (getFileNameIdName().empty()) { | |
return; | |
} | |
std::ifstream loaderIdNameProducts(getFileNameIdName()); | |
if (!loaderIdNameProducts) { | |
std::cout << "Can't read first file\n"; | |
return; | |
} | |
bool stillReading = true; | |
while (stillReading) { | |
Product* p = new Product; | |
int id; | |
std::string name; | |
if (loaderIdNameProducts >> id >> name) { | |
p->setId(id); | |
p->setName(name); | |
products.push_back(*p); | |
} else { | |
stillReading = false; | |
} | |
} | |
loaderIdNameProducts.close(); | |
// ****** {id}, {qty} ******** | |
if (getFileNameIdQty().empty()) { | |
return; | |
} | |
std::ifstream loaderIdQtyProducts(getFileNameIdQty()); | |
if (!loaderIdQtyProducts) { | |
std::cout << "Can't read first file\n"; | |
return; | |
} | |
stillReading = true; | |
while (stillReading) { | |
int id; | |
long qty; | |
if (loaderIdQtyProducts >> id >> qty) { | |
try { | |
Product& p = findByID(id); | |
std::cout << "Found " << p.getName() <<"\n" ; | |
p.setQty(qty); | |
} catch (std::exception e) { | |
std::cout << "No product with id: " << id <<"\n"; | |
} | |
} else { | |
stillReading = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment