Go to the documentation of this file.00001
00002
00003
00004
00005 #include <sstream>
00006 #include <fstream>
00007 #include <cassert>
00008
00009 #include <stdair/stdair_inventory_types.hpp>
00010 #include <stdair/stdair_maths_types.hpp>
00011 #include <stdair/stdair_exceptions.hpp>
00012 #include <stdair/basic/BasConst_DefaultObject.hpp>
00013 #include <stdair/basic/BasConst_Inventory.hpp>
00014 #include <stdair/basic/BasFileMgr.hpp>
00015 #include <stdair/bom/BomRetriever.hpp>
00016 #include <stdair/bom/BomManager.hpp>
00017 #include <stdair/bom/BomRoot.hpp>
00018 #include <stdair/bom/Inventory.hpp>
00019 #include <stdair/bom/FlightDate.hpp>
00020 #include <stdair/bom/SegmentDate.hpp>
00021 #include <stdair/bom/SegmentCabin.hpp>
00022 #include <stdair/bom/LegDate.hpp>
00023 #include <stdair/bom/LegCabin.hpp>
00024 #include <stdair/bom/BookingClass.hpp>
00025 #include <stdair/bom/VirtualClassStruct.hpp>
00026 #include <stdair/factory/FacBom.hpp>
00027 #include <stdair/factory/FacBomManager.hpp>
00028 #include <stdair/service/Logger.hpp>
00029
00030 #include <rmol/command/InventoryParser.hpp>
00031
00032 namespace RMOL {
00033
00034
00035 bool InventoryParser::
00036 parseInputFileAndBuildBom (const std::string& iInputFileName,
00037 stdair::BomRoot& ioBomRoot) {
00038 bool hasReadBeenSuccessful = false;
00039
00040
00041 const bool doesExistAndIsReadable =
00042 stdair::BasFileMgr::doesExistAndIsReadable (iInputFileName);
00043 if (doesExistAndIsReadable == false) {
00044 std::ostringstream oMessage;
00045 oMessage << "The input file, '" << iInputFileName
00046 << "', can not be retrieved on the file-system";
00047 throw stdair::FileNotFoundException (oMessage.str());
00048 }
00049
00050
00051 stdair::LegCabin& lLegCabin =
00052 stdair::BomRetriever::retrieveDummyLegCabin (ioBomRoot);
00053
00054
00055 stdair::SegmentCabin& lSegmentCabin =
00056 stdair::BomRetriever::retrieveDummySegmentCabin (ioBomRoot);
00057
00058
00059 std::ifstream inputFile (iInputFileName.c_str());
00060 if (! inputFile) {
00061 STDAIR_LOG_ERROR ("Can not open input file '" << iInputFileName << "'");
00062 throw new stdair::FileNotFoundException ("Can not open input file '"
00063 + iInputFileName + "'");
00064 }
00065
00066 char buffer[80];
00067 double dval;
00068 short i = 1;
00069 bool hasAllPArams = true;
00070 stdair::Yield_T lYield;
00071 stdair::MeanValue_T lMean;
00072 stdair::StdDevValue_T lStdDev;
00073 stdair::BookingClassKey lBCKey (stdair::DEFAULT_CLASS_CODE);
00074
00075 while (inputFile.getline (buffer, sizeof (buffer), ';')) {
00076 std::istringstream iStringStr (buffer);
00077
00078 if (i == 1) {
00079 hasAllPArams = true;
00080 }
00081
00082 if (iStringStr >> dval) {
00083 if (i == 1) {
00084 lYield = dval;
00085
00086
00087 } else if (i == 2) {
00088 lMean = dval;
00089
00090
00091 } else if (i == 3) {
00092 lStdDev = dval;
00093
00094 i = 0;
00095 }
00096 i++;
00097
00098 } else {
00099 hasAllPArams = false;
00100 }
00101
00102 if (hasAllPArams && i == 1) {
00103 stdair::BookingClass& lBookingClass =
00104 stdair::FacBom<stdair::BookingClass>::instance().create (lBCKey);
00105 stdair::FacBomManager::addToList (lSegmentCabin, lBookingClass);
00106 lBookingClass.setYield (lYield);
00107 lBookingClass.setMean (lMean);
00108 lBookingClass.setStdDev (lStdDev);
00109
00110 stdair::VirtualClassStruct lVirtualClass (lBookingClass);
00111 lVirtualClass.setYield (lYield);
00112 lVirtualClass.setMean (lMean);
00113 lVirtualClass.setStdDev (lStdDev);
00114 lLegCabin.addVirtualClass (lVirtualClass);
00115 }
00116 }
00117
00118
00119 if (!inputFile.eof()) {
00120 STDAIR_LOG_ERROR ("Problem when reading input file '" << iInputFileName
00121 << "'");
00122 return hasReadBeenSuccessful;
00123 }
00124
00125
00126 hasReadBeenSuccessful = true;
00127 return hasReadBeenSuccessful;
00128 }
00129
00130 }