Go to the documentation of this file.00001
00002
00003
00004
00005 #include <iostream>
00006 #include <istream>
00007 #include <sstream>
00008 #include <fstream>
00009
00010 #include <rmol/field/FldYieldRange.hpp>
00011 #include <rmol/field/FldDistributionParameters.hpp>
00012 #include <rmol/bom/Demand.hpp>
00013 #include <rmol/bom/Bucket.hpp>
00014 #include <rmol/bom/BucketHolder.hpp>
00015 #include <rmol/factory/FacDemand.hpp>
00016 #include <rmol/factory/FacBucket.hpp>
00017 #include <rmol/factory/FacBucketHolder.hpp>
00018 #include <rmol/command/FileMgr.hpp>
00019 #include <rmol/service/Logger.hpp>
00020
00021 namespace RMOL {
00022
00023
00024 void FileMgr::readAndProcessInputFile (const std::string& iInputFileName,
00025 BucketHolder& ioBucketHolder) {
00026
00027
00028 std::ifstream inputFile (iInputFileName.c_str());
00029 if (! inputFile) {
00030 RMOL_LOG_ERROR ("Can not open input file \"" << iInputFileName << "\"");
00031 throw new FileNotFoundException();
00032 }
00033
00034 char buffer[80];
00035 double dval;
00036 short i = 1;
00037 bool hasAllPArams = true;
00038 FldYieldRange aYieldRange;
00039 FldDistributionParameters aDistribParams;
00040
00041 while (inputFile.getline (buffer, sizeof (buffer), ';')) {
00042 std::istringstream iStringStr (buffer);
00043
00044 if (i == 1) {
00045 hasAllPArams = true;
00046 }
00047
00048 if (iStringStr >> dval) {
00049 if (i == 1) {
00050 aYieldRange.setUpperYield (dval);
00051 aYieldRange.setAverageYield (dval);
00052
00053
00054 } else if (i == 2) {
00055 aDistribParams.setMean (dval);
00056
00057
00058 } else if (i == 3) {
00059 aDistribParams.setStandardDeviation (dval);
00060
00061 i = 0;
00062 }
00063 i++;
00064
00065 } else {
00066 hasAllPArams = false;
00067 }
00068
00069 if (hasAllPArams && i == 1) {
00070 Demand& aDemand =
00071 FacDemand::instance().create (aDistribParams, aYieldRange);
00072 Bucket& aBucket = FacBucket::instance().create (aYieldRange, aDemand);
00073 FacBucketHolder::instance().addBucket (ioBucketHolder, aBucket);
00074 }
00075
00076 }
00077
00078 if (!inputFile.eof()) {
00079 std::cerr << "Problem when reading input file \"" << iInputFileName
00080 << "\"" << std::endl;
00081 } else {
00082 if (i == 2) {
00083
00084
00085 Bucket& aBucket = FacBucket::instance().create (aYieldRange);
00086 FacBucketHolder::instance().addBucket (ioBucketHolder, aBucket);
00087 }
00088 }
00089
00090 }
00091
00092 }