Created
June 14, 2015 11:33
-
-
Save calindotgabriel/1a5b685f1366ab338891 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
#include "productrepo.h" | |
#include <iostream> | |
#include <fstream> | |
ProductRepo::ProductRepo() | |
{ | |
} | |
ProductRepo::ProductRepo(std::string fIdName, | |
std::string fNameQty) | |
: fIdName(fIdName), fNameQty(fNameQty) | |
{ | |
_load(); | |
} | |
std::string& ProductRepo::getFileNameIdName() { | |
return fIdName; | |
} | |
std::vector<Product> ProductRepo::getProducts() { | |
return products; | |
} | |
void ProductRepo::_load(){ | |
if (getFileNameIdName().empty()) { | |
return; | |
} | |
std::ifstream loaderProducts(getFileNameIdName()); | |
if (!loaderProducts) { | |
std::cout << "loaderProducts null\n"; | |
return; | |
} | |
bool stillReading = true; | |
while (stillReading) { | |
Product* p = new Product; | |
int id; | |
std::string name; | |
if (loaderProducts >> id >> name) { | |
p->setId(id); | |
p->setName(name); | |
products.push_back(*p); | |
} else { | |
stillReading = false; | |
} | |
} | |
loaderProducts.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment