Skip to content
Snippets Groups Projects
toolbox.cpp 1.4 KiB
Newer Older
Jan Reher's avatar
Jan Reher committed
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
Jan Reher's avatar
Jan Reher committed
#include <algorithm>
Jan Reher's avatar
Jan Reher committed

#include "ProdDbAccess.h"
#include "BulkDbAccess.h"

Jan Reher's avatar
Jan Reher committed
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;
Jan Reher's avatar
Jan Reher committed
        line.erase(std::remove_if(line.begin(), line.end(), [](char c) {return !std::isdigit(c); }), line.end());
        while (line.length() < 10) {
            line = "0" + line;
        }
Jan Reher's avatar
Jan Reher committed
        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)
Jan Reher's avatar
Jan Reher committed
      std::cout << "Initializing ProdDbAccess, since only a few APDs are being queried...";
    result = new ProdDbAccess();
  }
  return result;
}