#include <fstream> #include <iostream> #include <string> #include <vector> #include <algorithm> #include "ProdDbAccess.h" #include "BulkDbAccess.h" using namespace std; vector<string> loadSerialsFromFileName(string m_fileName, bool m_debug = false) { ifstream in(m_fileName.c_str()); if (!in.good()) { cerr << "Could not load serials. Does the input file exist?" << endl; exit(0); } vector<string> result; result.clear(); string line = ""; while (in.good()) { getline(in,line); if (line.length() == 0 || !isdigit(line[0])) continue; line.erase(std::remove_if(line.begin(), line.end(), [](char c) {return !std::isdigit(c); }), line.end()); while (line.length() < 10) { line = "0" + line; } result.push_back(line); if (m_debug) cout << "Found serial: " << line << endl; } cerr << "Found " << result.size() << " APDs" << endl; return result; } AbsDbAccess *suitedDbAccess(size_t nAPDs, bool debug = false) { AbsDbAccess *result; if (nAPDs > 30) { if (debug) std::cout << "Initializing BulkDbAccess which becomes efficient for many queries. Patience, this might take a minute..."; result = new BulkDbAccess(); } else { if (debug) std::cout << "Initializing ProdDbAccess, since only a few APDs are being queried..."; result = new ProdDbAccess(); } return result; }