Skip to content

Instantly share code, notes, and snippets.

@calindotgabriel
Created June 14, 2015 11:33
Show Gist options
  • Save calindotgabriel/1a5b685f1366ab338891 to your computer and use it in GitHub Desktop.
Save calindotgabriel/1a5b685f1366ab338891 to your computer and use it in GitHub Desktop.
#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