diff --git a/src/analyzer/atsp/cache.cpp b/src/analyzer/atsp/cache.cpp index 07ecd37803..dbc4d1132c 100644 --- a/src/analyzer/atsp/cache.cpp +++ b/src/analyzer/atsp/cache.cpp @@ -21,10 +21,6 @@ #include "atsp.h" -using namespace Yuni; - -#define SEP Yuni::Core::IO::Separator - namespace Antares { void ATSP::cacheCreate() diff --git a/src/libs/antares/memory/memory.cpp b/src/libs/antares/memory/memory.cpp index 3819cc8036..5d368137bc 100644 --- a/src/libs/antares/memory/memory.cpp +++ b/src/libs/antares/memory/memory.cpp @@ -47,8 +47,6 @@ using namespace Yuni; -#define SEP Yuni::IO::Separator - namespace Antares { /*extern*/ diff --git a/src/libs/antares/paths/include/antares/paths/list.h b/src/libs/antares/paths/include/antares/paths/list.h index 135a18ff95..4aa03124f7 100644 --- a/src/libs/antares/paths/include/antares/paths/list.h +++ b/src/libs/antares/paths/include/antares/paths/list.h @@ -178,17 +178,6 @@ class PathList return item.empty(); } - template - size_t sizeOnDisk(const StringT& sourceFolder) const - { - if (item.empty()) - { - return 0; - } - pTmp = sourceFolder; - return (!pTmp) ? 0 : internalSizeOnDisk(); - } - size_t totalSizeInBytes() const; template diff --git a/src/libs/antares/paths/list.cpp b/src/libs/antares/paths/list.cpp index 5369e24513..ad5efa1a33 100644 --- a/src/libs/antares/paths/list.cpp +++ b/src/libs/antares/paths/list.cpp @@ -41,23 +41,6 @@ void PathList::clear() item.clear(); } -size_t PathList::internalSizeOnDisk() const -{ - size_t size = 0; - Clob buffer; - - const ItemList::const_iterator end = item.end(); - for (ItemList::const_iterator i = item.begin(); i != end; ++i) - { - if (!(i->second.options & pathListOptFolder)) - { - buffer.clear() << pTmp << SEP << i->first; - size += (size_t)IO::File::Size(pTmp); - } - } - return size; -} - size_t PathList::totalSizeInBytes() const { size_t size = 0; @@ -70,6 +53,7 @@ size_t PathList::totalSizeInBytes() const return size; } +// TODO VP: remove with tools uint PathList::internalDeleteAllEmptyFolders() { if (!pTmp || item.empty()) diff --git a/src/libs/antares/series/series.cpp b/src/libs/antares/series/series.cpp index 4c0cca690e..2f0dcd9111 100644 --- a/src/libs/antares/series/series.cpp +++ b/src/libs/antares/series/series.cpp @@ -31,10 +31,6 @@ #include -using namespace Yuni; - -#define SEP IO::Separator - namespace Antares::Data { void TimeSeriesNumbers::registerSeries(const TimeSeries* s, std::string label) @@ -135,8 +131,8 @@ int TimeSeries::saveToFolder(const std::string& areaID, const std::string& folder, const std::string& prefix) const { - Clob buffer; - buffer.clear() << folder << SEP << prefix << areaID << ".txt"; + Yuni::Clob buffer; + buffer.clear() << folder << Yuni::IO::Separator << prefix << areaID << ".txt"; return timeSeries.saveToCSVFile(buffer, 0); } diff --git a/src/libs/antares/study/area/links.cpp b/src/libs/antares/study/area/links.cpp index 97668638e0..767808693a 100644 --- a/src/libs/antares/study/area/links.cpp +++ b/src/libs/antares/study/area/links.cpp @@ -38,11 +38,6 @@ namespace fs = std::filesystem; #define SEP (IO::Separator) -namespace -{ -const YString DIRECTORY_NAME_FOR_TRANSMISSION_CAPACITIES = "ntc"; -} - namespace Antares { namespace Data @@ -78,15 +73,14 @@ AreaLink::~AreaLink() { } -bool AreaLink::linkLoadTimeSeries_for_version_below_810(const AnyString& folder) +bool AreaLink::linkLoadTimeSeries_for_version_below_810(const fs::path& folder) { - String buffer; - buffer.clear() << folder << SEP << with->id << ".txt"; + fs::path path = folder / static_cast(with->id + ".txt"); // Load link's data Matrix<> tmpMatrix; const uint matrixWidth = 8; - if (!tmpMatrix.loadFromCSVFile(buffer, + if (!tmpMatrix.loadFromCSVFile(path.string(), matrixWidth, HOURS_PER_YEAR, Matrix<>::optFixedSize | Matrix<>::optImmediate)) @@ -110,26 +104,28 @@ bool AreaLink::linkLoadTimeSeries_for_version_below_810(const AnyString& folder) return true; } -bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const AnyString& folder) +bool AreaLink::linkLoadTimeSeries_for_version_820_and_later(const fs::path& folder) { - String capacitiesFolder; - capacitiesFolder << folder << SEP << "capacities"; - - String filename; bool success = true; // Read link's parameters times series - filename.clear() << folder << SEP << with->id << "_parameters.txt"; - success = parameters.loadFromCSVFile(filename, fhlMax, HOURS_PER_YEAR, Matrix<>::optFixedSize) + std::string paramId = with->id + "_parameters.txt"; + fs::path path = folder / paramId; + success = parameters.loadFromCSVFile(path.string(), + fhlMax, + HOURS_PER_YEAR, + Matrix<>::optFixedSize) && success; + fs::path capacitiesFolder = folder / "capacities"; + // Read link's direct capacities time series - filename.clear() << capacitiesFolder << SEP << with->id << "_direct.txt"; - success = directCapacities.loadFromFile(filename.c_str(), false) && success; + path = capacitiesFolder / static_cast(with->id + "_direct.txt"); + success = directCapacities.loadFromFile(path, false) && success; // Read link's indirect capacities time series - filename.clear() << capacitiesFolder << SEP << with->id << "_indirect.txt"; - success = indirectCapacities.loadFromFile(filename.c_str(), false) && success; + path = capacitiesFolder / static_cast(with->id + "_indirect.txt"); + success = indirectCapacities.loadFromFile(path, false) && success; return success; } @@ -173,7 +169,7 @@ void AreaLink::overrideTransmissionCapacityAccordingToGlobalParameter( } } -bool AreaLink::loadTimeSeries(const StudyVersion& version, const AnyString& folder) +bool AreaLink::loadTimeSeries(const StudyVersion& version, const fs::path& folder) { if (version < StudyVersion(8, 2)) { @@ -187,14 +183,12 @@ bool AreaLink::loadTimeSeries(const StudyVersion& version, const AnyString& fold void AreaLink::storeTimeseriesNumbers(Solver::IResultWriter& writer) const { - Clob path; - std::string buffer; - - path << "ts-numbers" << SEP << DIRECTORY_NAME_FOR_TRANSMISSION_CAPACITIES << SEP << from->id - << SEP << with->id << ".txt"; + std::string filename = with->id + ".txt"; + fs::path path = fs::path("ts-numbers") / "ntc" / from->id.to() / filename; + std::string buffer; timeseriesNumbers.saveToBuffer(buffer); - writer.addEntryFromBuffer(path.c_str(), buffer); + writer.addEntryFromBuffer(path, buffer); } void AreaLink::detach() @@ -527,7 +521,7 @@ bool AreaLinksLoadFromFolder(Study& study, AreaList* areaList, Area* area, const link.comments.clear(); link.displayComments = true; - ret = link.loadTimeSeries(study.header.version, folder.string()) && ret; + ret = link.loadTimeSeries(study.header.version, folder) && ret; // Checks on loaded link's data if (study.usedByTheSolver) diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 0f95023f33..1439e36198 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -44,7 +44,7 @@ namespace Antares::Data { namespace // anonymous { -static bool AreaListLoadThermalDataFromFile(AreaList& list, const Clob& filename) +static bool AreaListLoadThermalDataFromFile(AreaList& list, const fs::path& filename) { // Reset to 0 list.each( @@ -776,38 +776,39 @@ bool AreaList::saveToFolder(const AnyString& folder) const return ret; } -template -static void readAdqPatchMode(Study& study, Area& area, StringT& buffer) +static void readAdqPatchMode(Study& study, Area& area) { - if (study.header.version >= StudyVersion(8, 3)) + if (study.header.version < StudyVersion(8, 3)) + { + return; + } + + fs::path adqPath = study.folderInput / "areas" / area.id.to() + / "adequacy_patch.ini"; + IniFile ini; + if (ini.open(adqPath)) { - buffer.clear() << study.folderInput << SEP << "areas" << SEP << area.id << SEP - << "adequacy_patch.ini"; - IniFile ini; - if (ini.open(buffer)) + auto* section = ini.find("adequacy-patch"); + for (auto* p = section->firstProperty; p; p = p->next) { - auto* section = ini.find("adequacy-patch"); - for (auto* p = section->firstProperty; p; p = p->next) + CString<30, false> tmp; + tmp = p->key; + tmp.toLower(); + if (tmp == "adequacy-patch-mode") { - CString<30, false> tmp; - tmp = p->key; - tmp.toLower(); - if (tmp == "adequacy-patch-mode") - { - auto value = (p->value).toLower(); + auto value = (p->value).toLower(); - if (value == "virtual") - { - area.adequacyPatchMode = Data::AdequacyPatch::virtualArea; - } - else if (value == "inside") - { - area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaInsideAdqPatch; - } - else - { - area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaOutsideAdqPatch; - } + if (value == "virtual") + { + area.adequacyPatchMode = Data::AdequacyPatch::virtualArea; + } + else if (value == "inside") + { + area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaInsideAdqPatch; + } + else + { + area.adequacyPatchMode = Data::AdequacyPatch::physicalAreaOutsideAdqPatch; } } } @@ -899,7 +900,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { // if changes are required, please update reloadXCastData() fs::path loadPath = study.folderInput / "load" / "prepro" / area.id.to(); - ret = area.load.prepro->loadFromFolder(loadPath.string()) && ret; + ret = area.load.prepro->loadFromFolder(loadPath) && ret; } if (!options.loadOnlyNeeded || !area.load.prepro) // Series { @@ -916,7 +917,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { // if changes are required, please update reloadXCastData() fs::path solarPath = study.folderInput / "solar" / "prepro" / area.id.to(); - ret = area.solar.prepro->loadFromFolder(solarPath.string()) && ret; + ret = area.solar.prepro->loadFromFolder(solarPath) && ret; } if (!options.loadOnlyNeeded || !area.solar.prepro) // Series { @@ -940,7 +941,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { // if changes are required, please update reloadXCastData() fs::path hydroPrepro = pathHydro / "prepro"; - ret = area.hydro.prepro->loadFromFolder(study, area.id, hydroPrepro.string()) && ret; + ret = area.hydro.prepro->loadFromFolder(study, area.id, hydroPrepro) && ret; ret = area.hydro.prepro->validate(area.id) && ret; } @@ -972,7 +973,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, { // if changes are required, please update reloadXCastData() fs::path windPath = study.folderInput / "wind" / "prepro" / area.id.to(); - ret = area.wind.prepro->loadFromFolder(windPath.string()) && ret; + ret = area.wind.prepro->loadFromFolder(windPath) && ret; } if (!options.loadOnlyNeeded || !area.wind.prepro) // Series { @@ -1016,7 +1017,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study, } // Adequacy patch - readAdqPatchMode(study, area, buffer); + readAdqPatchMode(study, area); // Nodal Optimization fs::path nodalPath = study.folderInput / "areas" / area.id.to() @@ -1160,21 +1161,18 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options) // Thermal data, specific to areas { logs.info() << "Loading thermal clusters..."; - buffer.clear() << pStudy.folderInput << SEP << "thermal" << SEP << "areas.ini"; - ret = AreaListLoadThermalDataFromFile(*this, buffer) && ret; + fs::path thermalPath = pStudy.folderInput / "thermal"; + fs::path areaIniPath = thermalPath / "areas.ini"; + ret = AreaListLoadThermalDataFromFile(*this, areaIniPath) && ret; - // The cluster list must be loaded before the method - // ensureDataIsInitialized is called + // The cluster list must be loaded before the method ensureDataIsInitialized is called // in order to allocate data with all thermal clusters. - CString<30, false> thermalPlant; - thermalPlant << SEP << "thermal" << SEP << "clusters" << SEP; - auto end = areas.end(); for (auto i = areas.begin(); i != end; ++i) { Area& area = *(i->second); - buffer.clear() << pStudy.folderInput << thermalPlant << area.id; - ret = area.thermal.list.loadFromFolder(pStudy, buffer.c_str(), &area) && ret; + fs::path areaPath = thermalPath / "clusters" / area.id.to(); + ret = area.thermal.list.loadFromFolder(pStudy, areaPath, &area) && ret; ret = area.thermal.list.validateClusters(pStudy.parameters) && ret; } } @@ -1203,18 +1201,16 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options) // Renewable data, specific to areas if (studyVersion >= StudyVersion(8, 1)) { - // The cluster list must be loaded before the method - // ensureDataIsInitialized is called + // The cluster list must be loaded before the method ensureDataIsInitialized is called // in order to allocate data with all renewable clusters. - CString<30, false> renewablePlant; - renewablePlant << SEP << "renewables" << SEP << "clusters" << SEP; + fs::path renewClusterPath = pStudy.folderInput / "renewables" / "clusters"; auto end = areas.end(); for (auto i = areas.begin(); i != end; ++i) { Area& area = *(i->second); - buffer.clear() << pStudy.folderInput << renewablePlant << area.id; - ret = area.renewable.list.loadFromFolder(buffer.c_str(), &area) && ret; + fs::path areaPath = renewClusterPath / area.id.to(); + ret = area.renewable.list.loadFromFolder(areaPath, &area) && ret; ret = area.renewable.list.validateClusters() && ret; } } diff --git a/src/libs/antares/study/area/store-timeseries-numbers.cpp b/src/libs/antares/study/area/store-timeseries-numbers.cpp index 9619206239..daa3a250c8 100644 --- a/src/libs/antares/study/area/store-timeseries-numbers.cpp +++ b/src/libs/antares/study/area/store-timeseries-numbers.cpp @@ -25,24 +25,22 @@ #include #include -using namespace Yuni; - -#define SEP IO::Separator +namespace fs = std::filesystem; namespace Antares::Data { static void storeTSnumbers(Solver::IResultWriter& writer, const TimeSeriesNumbers& timeseriesNumbers, - const String& id, - const String& directory) + const std::string& id, + const fs::path& directory) { - Clob path; - path << "ts-numbers" << SEP << directory << SEP << id << ".txt"; + std::string fullId = id + ".txt"; + fs::path path = "ts-numbers" / directory / fullId; std::string buffer; timeseriesNumbers.saveToBuffer(buffer); - writer.addEntryFromBuffer(path.c_str(), buffer); + writer.addEntryFromBuffer(path, buffer); } void storeTimeseriesNumbersForLoad(Solver::IResultWriter& writer, const Area& area) diff --git a/src/libs/antares/study/binding_constraint/BindingConstraint.cpp b/src/libs/antares/study/binding_constraint/BindingConstraint.cpp index abdce0befb..ef94fed123 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraint.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraint.cpp @@ -34,8 +34,6 @@ using namespace Antares; -#define SEP IO::Separator - #ifdef _MSC_VER #define SNPRINTF sprintf_s #else diff --git a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp index e68c97d15c..991a79a0f1 100644 --- a/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp +++ b/src/libs/antares/study/binding_constraint/BindingConstraintsRepository.cpp @@ -177,7 +177,7 @@ bool BindingConstraintsRepository::rename(BindingConstraint* bc, const AnyString bool BindingConstraintsRepository::loadFromFolder(Study& study, const StudyLoadOptions& options, - const AnyString& folder) + const std::filesystem::path& folder) { // Log entries logs.info(); // space for beauty @@ -203,7 +203,7 @@ bool BindingConstraintsRepository::loadFromFolder(Study& study, EnvForLoading env(study.areas, study.header.version); env.folder = folder; - env.iniFilename << env.folder << Yuni::IO::Separator << "bindingconstraints.ini"; + env.iniFilename = folder / "bindingconstraints.ini"; IniFile ini; if (!ini.open(env.iniFilename)) { diff --git a/src/libs/antares/study/include/antares/study/area/links.h b/src/libs/antares/study/include/antares/study/area/links.h index fd4b8e69d8..ef17bc5e40 100644 --- a/src/libs/antares/study/include/antares/study/area/links.h +++ b/src/libs/antares/study/include/antares/study/area/links.h @@ -69,7 +69,7 @@ class AreaLink final: public Yuni::NonCopyable ~AreaLink(); //@} - bool loadTimeSeries(const StudyVersion& version, const AnyString& folder); + bool loadTimeSeries(const StudyVersion& version, const std::filesystem::path& folder); void storeTimeseriesNumbers(Solver::IResultWriter& writer) const; @@ -121,8 +121,8 @@ class AreaLink final: public Yuni::NonCopyable void overrideTransmissionCapacityAccordingToGlobalParameter(GlobalTransmissionCapacities tc); private: - bool linkLoadTimeSeries_for_version_below_810(const AnyString& folder); - bool linkLoadTimeSeries_for_version_820_and_later(const AnyString& folder); + bool linkLoadTimeSeries_for_version_below_810(const std::filesystem::path& folder); + bool linkLoadTimeSeries_for_version_820_and_later(const std::filesystem::path& folder); NamePair getNamePair() const; public: diff --git a/src/libs/antares/study/include/antares/study/binding_constraint/BindingConstraintsRepository.h b/src/libs/antares/study/include/antares/study/binding_constraint/BindingConstraintsRepository.h index 25809de754..67fd346a1b 100644 --- a/src/libs/antares/study/include/antares/study/binding_constraint/BindingConstraintsRepository.h +++ b/src/libs/antares/study/include/antares/study/binding_constraint/BindingConstraintsRepository.h @@ -112,7 +112,7 @@ class BindingConstraintsRepository final: public Yuni::NonCopyable #include #include @@ -51,7 +52,7 @@ class LayerData protected: bool saveLayers(const AnyString& filename); - void loadLayers(const AnyString& filename); + void loadLayers(const std::filesystem::path& filename); }; } // namespace Antares::Data diff --git a/src/libs/antares/study/include/antares/study/output.h b/src/libs/antares/study/include/antares/study/output.h index 38846330bd..ffebc06d90 100644 --- a/src/libs/antares/study/include/antares/study/output.h +++ b/src/libs/antares/study/include/antares/study/output.h @@ -34,6 +34,8 @@ namespace Antares { namespace Data { + +// TODO VP: remove with GUI class Output final { public: diff --git a/src/libs/antares/study/include/antares/study/parameters.h b/src/libs/antares/study/include/antares/study/parameters.h index 1b2ce027d9..540cf5fc67 100644 --- a/src/libs/antares/study/include/antares/study/parameters.h +++ b/src/libs/antares/study/include/antares/study/parameters.h @@ -75,7 +75,7 @@ class Parameters final ** \param version Current study version ** \return True if the settings have been loaded, false if at least one error has occured */ - bool loadFromFile(const AnyString& filename, const StudyVersion& version); + bool loadFromFile(const std::filesystem::path& filename, const StudyVersion& version); /*! ** \brief Prepare all settings for a simulation diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/container.h b/src/libs/antares/study/include/antares/study/parts/hydro/container.h index 1da5ab6023..91b668ba6a 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/container.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/container.h @@ -114,7 +114,7 @@ class PartHydro ** \param folder The targer folder ** \return A non-zero value if the operation succeeded, 0 otherwise */ - static bool LoadFromFolder(Study& study, const AnyString& folder); + static bool LoadFromFolder(Study& study, const std::filesystem::path& folder); /*! ** \brief Check and validate the loaded datas @@ -157,7 +157,7 @@ class PartHydro /*! ** \brief Load daily max energy */ - bool LoadDailyMaxEnergy(const AnyString& folder, const AnyString& areaid); + bool LoadDailyMaxEnergy(const std::filesystem::path& folder, const std::string& areaid); bool CheckDailyMaxEnergy(const AnyString& areaName); diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/prepro.h b/src/libs/antares/study/include/antares/study/parts/hydro/prepro.h index b35798f862..d85e803686 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/prepro.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/prepro.h @@ -95,7 +95,7 @@ class PreproHydro ** \param folder The source folder (ex: `input/hydro/prepro`) ** \return A non-zero value if the operation succeeded, 0 otherwise */ - bool loadFromFolder(Study& s, const AreaName& areaID, const std::string& folder); + bool loadFromFolder(Study& s, const std::string& areaID, const std::filesystem::path& folder); bool validate(const std::string& areaID); /*! diff --git a/src/libs/antares/study/include/antares/study/parts/hydro/series.h b/src/libs/antares/study/include/antares/study/parts/hydro/series.h index 343e49e266..e8fae00e36 100644 --- a/src/libs/antares/study/include/antares/study/parts/hydro/series.h +++ b/src/libs/antares/study/include/antares/study/parts/hydro/series.h @@ -76,7 +76,7 @@ class DataSeriesHydro StudyVersion version); // Loading hydro max generation and mqx pumping TS's - bool LoadMaxPower(const AreaName& areaID, const std::filesystem::path& folder); + bool LoadMaxPower(const std::string& areaID, const std::filesystem::path& folder); void buildHourlyMaxPowerFromDailyTS(const Matrix::ColumnType& DailyMaxGenPower, const Matrix::ColumnType& DailyMaxPumpPower); diff --git a/src/libs/antares/study/include/antares/study/parts/load/prepro.h b/src/libs/antares/study/include/antares/study/parts/load/prepro.h index bbe3c7a008..9f3f037e4e 100644 --- a/src/libs/antares/study/include/antares/study/parts/load/prepro.h +++ b/src/libs/antares/study/include/antares/study/parts/load/prepro.h @@ -52,7 +52,7 @@ class Prepro /*! ** \brief Load data from a folder */ - bool loadFromFolder(const AnyString& folder); + bool loadFromFolder(const std::filesystem::path& folder); /*! ** \brief Save data to a folder diff --git a/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h b/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h index 275d495020..d596384cc4 100644 --- a/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h +++ b/src/libs/antares/study/include/antares/study/parts/renewable/cluster_list.h @@ -22,6 +22,8 @@ #ifndef __ANTARES_LIBS_STUDY_PARTS_RENEWABLE_CLUSTER_LIST_H__ #define __ANTARES_LIBS_STUDY_PARTS_RENEWABLE_CLUSTER_LIST_H__ +#include + #include "../../fwd.h" #include "../common/cluster_list.h" #include "cluster.h" @@ -38,7 +40,7 @@ class RenewableClusterList: public ClusterList std::string typeID() const override; uint64_t memoryUsage() const override; - bool loadFromFolder(const AnyString& folder, Area* area); + bool loadFromFolder(const std::filesystem::path& folder, Area* area); bool validateClusters() const; bool saveToFolder(const AnyString& folder) const override; diff --git a/src/libs/antares/study/include/antares/study/parts/solar/prepro.h b/src/libs/antares/study/include/antares/study/parts/solar/prepro.h index 4365c0c6cf..e6f15d1d42 100644 --- a/src/libs/antares/study/include/antares/study/parts/solar/prepro.h +++ b/src/libs/antares/study/include/antares/study/parts/solar/prepro.h @@ -52,7 +52,7 @@ class Prepro /*! ** \brief Solar data from a folder */ - bool loadFromFolder(const AnyString& folder); + bool loadFromFolder(const std::filesystem::path& folder); /*! ** \brief Save data to a folder diff --git a/src/libs/antares/study/include/antares/study/parts/wind/prepro.h b/src/libs/antares/study/include/antares/study/parts/wind/prepro.h index 1d0ed8722e..c62669d0a6 100644 --- a/src/libs/antares/study/include/antares/study/parts/wind/prepro.h +++ b/src/libs/antares/study/include/antares/study/parts/wind/prepro.h @@ -49,7 +49,7 @@ class Prepro /*! ** \brief Load data from a folder */ - bool loadFromFolder(const AnyString& folder); + bool loadFromFolder(const std::filesystem::path& folder); /*! ** \brief Save data to a folder diff --git a/src/libs/antares/study/include/antares/study/simulation.h b/src/libs/antares/study/include/antares/study/simulation.h index b3ca6addd8..2a34d9c343 100644 --- a/src/libs/antares/study/include/antares/study/simulation.h +++ b/src/libs/antares/study/include/antares/study/simulation.h @@ -34,6 +34,8 @@ namespace Data /*! ** \brief Set of settings for a simulation */ + +// TODO VP: remove with GUI class SimulationComments final { public: diff --git a/src/libs/antares/study/include/antares/study/study.h b/src/libs/antares/study/include/antares/study/study.h index 9b348a28f5..6ed7ce9b5c 100644 --- a/src/libs/antares/study/include/antares/study/study.h +++ b/src/libs/antares/study/include/antares/study/study.h @@ -467,6 +467,7 @@ class Study: public Yuni::NonCopyable, public LayerData //! \name Simulation //@{ //! The current Simulation + // TODO VP: remove with GUI SimulationComments simulationComments; int64_t pStartTime; diff --git a/src/libs/antares/study/include/antares/study/xcast/xcast.h b/src/libs/antares/study/include/antares/study/xcast/xcast.h index cc7e281763..a8b5eebe7a 100644 --- a/src/libs/antares/study/include/antares/study/xcast/xcast.h +++ b/src/libs/antares/study/include/antares/study/xcast/xcast.h @@ -140,7 +140,7 @@ class XCast final: private Yuni::NonCopyable /*! ** \brief Load data from a folder */ - bool loadFromFolder(const AnyString& folder); + bool loadFromFolder(const std::filesystem::path& folder); /*! ** \brief Save data to a folder diff --git a/src/libs/antares/study/layerdata.cpp b/src/libs/antares/study/layerdata.cpp index 781a807037..cd8606dbaf 100644 --- a/src/libs/antares/study/layerdata.cpp +++ b/src/libs/antares/study/layerdata.cpp @@ -33,7 +33,7 @@ using namespace Yuni; namespace Antares::Data { -void LayerData::loadLayers(const AnyString& filename) +void LayerData::loadLayers(const std::filesystem::path& filename) { IniFile ini; if (std::ifstream(filename.c_str()).good() && ini.open(filename)) // check if file exists diff --git a/src/libs/antares/study/load.cpp b/src/libs/antares/study/load.cpp index c6b61a6e61..3a756333f3 100644 --- a/src/libs/antares/study/load.cpp +++ b/src/libs/antares/study/load.cpp @@ -26,16 +26,9 @@ #include "antares/study/ui-runtimeinfos.h" #include "antares/study/version.h" -using namespace Yuni; -using Antares::Constants::nbHoursInAWeek; - namespace fs = std::filesystem; -#define SEP IO::Separator - -namespace Antares -{ -namespace Data +namespace Antares::Data { bool Study::internalLoadHeader(const fs::path& path) { @@ -82,8 +75,8 @@ bool Study::internalLoadIni(const fs::path& path, const StudyLoadOptions& option } } // Load the general data - buffer.clear() << folderSettings << SEP << "generaldata.ini"; - bool errorWhileLoading = !parameters.loadFromFile(buffer, header.version); + fs::path generalDataPath = folderSettings / "generaldata.ini"; + bool errorWhileLoading = !parameters.loadFromFile(generalDataPath, header.version); parameters.validateOptions(options); @@ -98,8 +91,8 @@ bool Study::internalLoadIni(const fs::path& path, const StudyLoadOptions& option } // Load the layer data - buffer.clear() << path << SEP << "layers" << SEP << "layers.ini"; - loadLayers(buffer); + fs::path layersPath = path / "layers" / "layers.ini"; + loadLayers(layersPath); return true; } @@ -238,40 +231,32 @@ bool Study::internalLoadCorrelationMatrices(const StudyLoadOptions& options) if (!options.loadOnlyNeeded || timeSeriesLoad & parameters.timeSeriesToRefresh || timeSeriesLoad & parameters.timeSeriesToGenerate) { - buffer.clear() << folderInput << SEP << "load" << SEP << "prepro" << SEP - << "correlation.ini"; - preproLoadCorrelation.loadFromFile(*this, buffer); + fs::path loadPath = folderInput / "load" / "prepro" / "correlation.ini"; + preproLoadCorrelation.loadFromFile(*this, loadPath.string()); } // Solar if (!options.loadOnlyNeeded || timeSeriesSolar & parameters.timeSeriesToRefresh || timeSeriesSolar & parameters.timeSeriesToGenerate) { - buffer.clear() << folderInput << SEP << "solar" << SEP << "prepro" << SEP - << "correlation.ini"; - preproSolarCorrelation.loadFromFile(*this, buffer); + fs::path solarPath = folderInput / "solar" / "prepro" / "correlation.ini"; + preproSolarCorrelation.loadFromFile(*this, solarPath.string()); } // Wind + if (!options.loadOnlyNeeded || timeSeriesWind & parameters.timeSeriesToRefresh + || timeSeriesWind & parameters.timeSeriesToGenerate) { - if (!options.loadOnlyNeeded || timeSeriesWind & parameters.timeSeriesToRefresh - || timeSeriesWind & parameters.timeSeriesToGenerate) - { - buffer.clear() << folderInput << SEP << "wind" << SEP << "prepro" << SEP - << "correlation.ini"; - preproWindCorrelation.loadFromFile(*this, buffer); - } + fs::path windPath = folderInput / "wind" / "prepro" / "correlation.ini"; + preproWindCorrelation.loadFromFile(*this, windPath.string()); } // Hydro + if (!options.loadOnlyNeeded || (timeSeriesHydro & parameters.timeSeriesToRefresh) + || (timeSeriesHydro & parameters.timeSeriesToGenerate)) { - if (!options.loadOnlyNeeded || (timeSeriesHydro & parameters.timeSeriesToRefresh) - || (timeSeriesHydro & parameters.timeSeriesToGenerate)) - { - buffer.clear() << folderInput << SEP << "hydro" << SEP << "prepro" << SEP - << "correlation.ini"; - preproHydroCorrelation.loadFromFile(*this, buffer); - } + fs::path hydroPath = folderInput / "hydro" / "prepro" / "correlation.ini"; + preproHydroCorrelation.loadFromFile(*this, hydroPath.string()); } return true; } @@ -280,8 +265,8 @@ bool Study::internalLoadBindingConstraints(const StudyLoadOptions& options) { // All checks are performed in 'loadFromFolder' // (actually internalLoadFromFolder) - buffer.clear() << folderInput << SEP << "bindingconstraints"; - bool r = bindingConstraints.loadFromFolder(*this, options, buffer); + fs::path constraintPath = folderInput / "bindingconstraints"; + bool r = bindingConstraints.loadFromFolder(*this, options, constraintPath); if (r) { r &= bindingConstraintsGroups.buildFrom(bindingConstraints); @@ -291,16 +276,15 @@ bool Study::internalLoadBindingConstraints(const StudyLoadOptions& options) bool Study::internalLoadSets() { - const fs::path path = fs::path(folderInput.c_str()) / "areas" / "sets.ini"; // Set of areas logs.info(); logs.info() << "Loading sets of areas..."; // filename - buffer.clear() << folderInput << SEP << "areas" << SEP << "sets.ini"; + const fs::path setPath = folderInput / "areas" / "sets.ini"; // Load the rules - if (setsOfAreas.loadFromFile(path)) + if (setsOfAreas.loadFromFile(setPath)) { // Apply the rules SetHandlerAreas handler(areas); @@ -321,6 +305,7 @@ void Study::reloadCorrelation() internalLoadCorrelationMatrices(options); } +// TODO remove with GUI bool Study::reloadXCastData() { // if changes are required, please update AreaListLoadFromFolderSingleArea() @@ -333,17 +318,16 @@ bool Study::reloadXCastData() assert(area.wind.prepro); // Load - buffer.clear() << folderInput << SEP << "load" << SEP << "prepro" << SEP << area.id; - ret = area.load.prepro->loadFromFolder(buffer) && ret; + fs::path loadPath = folderInput / "load" / "prepro" / area.id.to(); + ret = area.load.prepro->loadFromFolder(loadPath.string()) && ret; // Solar - buffer.clear() << folderInput << SEP << "solar" << SEP << "prepro" << SEP << area.id; - ret = area.solar.prepro->loadFromFolder(buffer) && ret; + fs::path solarPath = folderInput / "solar" / "prepro" / area.id.to(); + ret = area.solar.prepro->loadFromFolder(solarPath.string()) && ret; // Wind - buffer.clear() << folderInput << SEP << "wind" << SEP << "prepro" << SEP << area.id; - ret = area.wind.prepro->loadFromFolder(buffer) && ret; + fs::path windPath = folderInput / "wind" / "prepro" / area.id.to(); + ret = area.wind.prepro->loadFromFolder(windPath.string()) && ret; }); return ret; } -} // namespace Data -} // namespace Antares +} // namespace Antares::Data diff --git a/src/libs/antares/study/output.cpp b/src/libs/antares/study/output.cpp index 0409f2bb6e..c28a1c95a2 100644 --- a/src/libs/antares/study/output.cpp +++ b/src/libs/antares/study/output.cpp @@ -35,6 +35,8 @@ namespace Antares::Data { namespace // anonymous { + +// TODO VP: remove with GUI class OutputFolderIterator: public IO::Directory::IIterator { public: @@ -189,6 +191,7 @@ bool Output::loadFromFolder(const AnyString& folder) return true; } +// TODO VP: remove with GUI void Output::RetrieveListFromStudy(List& out, const Study& study) { out.clear(); diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index 72be2dd7b4..9db123b5d8 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -1980,7 +1980,7 @@ void Parameters::saveToINI(IniFile& ini) const } } -bool Parameters::loadFromFile(const AnyString& filename, const StudyVersion& version) +bool Parameters::loadFromFile(const std::filesystem::path& filename, const StudyVersion& version) { // Loading the INI file IniFile ini; diff --git a/src/libs/antares/study/parts/common/cluster_list.cpp b/src/libs/antares/study/parts/common/cluster_list.cpp index b8e16c5081..0feee3a77f 100644 --- a/src/libs/antares/study/parts/common/cluster_list.cpp +++ b/src/libs/antares/study/parts/common/cluster_list.cpp @@ -28,7 +28,7 @@ #include #include "antares/study/study.h" -using namespace Yuni; +namespace fs = std::filesystem; namespace Antares::Data { @@ -88,21 +88,20 @@ void ClusterList::resizeAllTimeseriesNumbers(uint n) const } } -#define SEP IO::Separator - template void ClusterList::storeTimeseriesNumbers(Solver::IResultWriter& writer) const { - Clob path; std::string ts_content; + fs::path basePath = fs::path("ts-numbers") / typeID(); for (auto& cluster: each_enabled()) { - path.clear() << "ts-numbers" << SEP << typeID() << SEP << cluster->parentArea->id << SEP - << cluster->id() << ".txt"; + fs::path path = fs::path(cluster->parentArea->id.c_str()) + / std::string(cluster->id() + ".txt"); + ts_content.clear(); // We must clear ts_content here, since saveToBuffer does not do it. cluster->series.timeseriesNumbers.saveToBuffer(ts_content); - writer.addEntryFromBuffer(path.c_str(), ts_content); + writer.addEntryFromBuffer(path, ts_content); } } diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index 336595b95b..6ee131b4f3 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -25,10 +25,9 @@ #include "antares/study/parts/hydro/hydromaxtimeseriesreader.h" #include "antares/study/study.h" -using namespace Antares; -using namespace Yuni; +namespace fs = std::filesystem; -#define SEP IO::Separator +#define SEP Yuni::IO::Separator namespace Antares::Data { @@ -102,7 +101,7 @@ void PartHydro::reset() template static bool loadProperties(Study& study, IniFile::Property* property, - const std::string& filename, + const fs::path& filename, T PartHydro::*ptr) { if (!property) @@ -132,14 +131,13 @@ static bool loadProperties(Study& study, return ret; } -bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) +bool PartHydro::LoadFromFolder(Study& study, const fs::path& folder) { - auto& buffer = study.bufferLoadingTS; bool ret = true; // Initialize all alpha values to 0 study.areas.each( - [&ret, &buffer, &study, &folder](Data::Area& area) + [&ret, &study, &folder](Data::Area& area) { area.hydro.interDailyBreakdown = 1.; area.hydro.intraDailyModulation = 24.; @@ -174,7 +172,7 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) enabledModeIsChanged = true; } - ret = area.hydro.LoadDailyMaxEnergy(folder, area.id) && ret; + ret = area.hydro.LoadDailyMaxEnergy(folder.string(), area.id) && ret; if (enabledModeIsChanged) { @@ -183,7 +181,7 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) } else { - ret = area.hydro.LoadDailyMaxEnergy(folder, area.id) && ret; + ret = area.hydro.LoadDailyMaxEnergy(folder.string(), area.id) && ret; // Check is moved here, because in case of old study // dailyNbHoursAtGenPmax and dailyNbHoursAtPumpPmax are not yet initialized. @@ -192,36 +190,38 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) } } - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "creditmodulations_" << area.id << '.' << study.inputExtension; - ret = area.hydro.creditModulation.loadFromCSVFile(buffer, + fs::path capacityPath = folder / "common" / "capacity"; + + std::string creditId = "creditmodulations_" + area.id + ".txt"; + fs::path creditPath = capacityPath / creditId; + ret = area.hydro.creditModulation.loadFromCSVFile(creditPath.string(), 101, 2, Matrix<>::optFixedSize, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "reservoir_" - << area.id << '.' << study.inputExtension; - ret = area.hydro.reservoirLevel.loadFromCSVFile(buffer, + std::string reservoirId = "reservoir_" + area.id + ".txt"; + fs::path reservoirPath = capacityPath / reservoirId; + ret = area.hydro.reservoirLevel.loadFromCSVFile(reservoirPath.string(), 3, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP << "waterValues_" - << area.id << '.' << study.inputExtension; - ret = area.hydro.waterValues.loadFromCSVFile(buffer, + std::string waterValueId = "waterValues_" + area.id + ".txt"; + fs::path waterValuePath = capacityPath / waterValueId; + ret = area.hydro.waterValues.loadFromCSVFile(waterValuePath.string(), 101, DAYS_PER_YEAR, Matrix<>::optFixedSize, &study.dataBuffer) && ret; - buffer.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "inflowPattern_" << area.id << '.' << study.inputExtension; - ret = area.hydro.inflowPattern.loadFromCSVFile(buffer, + std::string inflowId = "inflowPattern_" + area.id + ".txt"; + fs::path inflowPath = capacityPath / inflowId; + ret = area.hydro.inflowPattern.loadFromCSVFile(inflowPath.string(), 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, @@ -230,103 +230,96 @@ bool PartHydro::LoadFromFolder(Study& study, const AnyString& folder) }); IniFile ini; - if (not ini.open(buffer.clear() << folder << SEP << "hydro.ini")) + auto path = folder / "hydro.ini"; + if (not ini.open(path)) { return false; } if (IniFile::Section* section = ini.find("inter-daily-breakdown")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::interDailyBreakdown) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::interDailyBreakdown) && ret; } if (IniFile::Section* section = ini.find("intra-daily-modulation")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::intraDailyModulation) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::intraDailyModulation) && ret; } if (IniFile::Section* section = ini.find("reservoir")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirManagement) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::reservoirManagement) && ret; } if (IniFile::Section* section = ini.find("reservoir capacity")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::reservoirCapacity) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::reservoirCapacity) && ret; } if (IniFile::Section* section = ini.find("follow load")) { - ret = loadProperties(study, - section->firstProperty, - buffer, - &PartHydro::followLoadModulations) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::followLoadModulations) && ret; } if (IniFile::Section* section = ini.find("use water")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useWaterValue) - && ret; + ret = loadProperties(study, section->firstProperty, path, &PartHydro::useWaterValue) && ret; } if (IniFile::Section* section = ini.find("hard bounds")) { ret = loadProperties(study, section->firstProperty, - buffer, + path, &PartHydro::hardBoundsOnRuleCurves) && ret; } if (IniFile::Section* section = ini.find("use heuristic")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useHeuristicTarget) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::useHeuristicTarget) && ret; } if (IniFile::Section* section = ini.find("power to level")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::powerToLevel) - && ret; + ret = loadProperties(study, section->firstProperty, path, &PartHydro::powerToLevel) && ret; } if (IniFile::Section* section = ini.find("initialize reservoir date")) { ret = loadProperties(study, section->firstProperty, - buffer, + path, &PartHydro::initializeReservoirLevelDate) && ret; } if (IniFile::Section* section = ini.find("use leeway")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::useLeeway) && ret; + ret = loadProperties(study, section->firstProperty, path, &PartHydro::useLeeway) && ret; } if (IniFile::Section* section = ini.find("leeway low")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayLowerBound) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::leewayLowerBound) && ret; } if (IniFile::Section* section = ini.find("leeway up")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::leewayUpperBound) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::leewayUpperBound) && ret; } if (IniFile::Section* section = ini.find("pumping efficiency")) { - ret = loadProperties(study, section->firstProperty, buffer, &PartHydro::pumpingEfficiency) + ret = loadProperties(study, section->firstProperty, path, &PartHydro::pumpingEfficiency) && ret; } @@ -480,7 +473,7 @@ bool PartHydro::SaveToFolder(const AreaList& areas, const AnyString& folder) return false; } - String buffer; + Yuni::String buffer; buffer.clear() << folder << SEP << "common" << SEP << "capacity"; struct AllSections @@ -704,26 +697,21 @@ void PartHydro::copyFrom(const PartHydro& rhs) } } -bool PartHydro::LoadDailyMaxEnergy(const AnyString& folder, const AnyString& areaid) +bool PartHydro::LoadDailyMaxEnergy(const fs::path& folder, const std::string& areaid) { - YString filePath; Matrix<>::BufferType fileContent; bool ret = true; - filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyGenEnergy_" << areaid << ".txt"; - - ret = dailyNbHoursAtGenPmax.loadFromCSVFile(filePath, + fs::path genPath = folder / "common" / "capacity" / ("maxDailyGenEnergy_" + areaid + ".txt"); + ret = dailyNbHoursAtGenPmax.loadFromCSVFile(genPath.string(), 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, &fileContent) && ret; - filePath.clear() << folder << SEP << "common" << SEP << "capacity" << SEP - << "maxDailyPumpEnergy_" << areaid << ".txt"; - - ret = dailyNbHoursAtPumpPmax.loadFromCSVFile(filePath, + fs::path pumpPath = folder / "common" / "capacity" / ("maxDailyPumpEnergy_" + areaid + ".txt"); + ret = dailyNbHoursAtPumpPmax.loadFromCSVFile(pumpPath.string(), 1, DAYS_PER_YEAR, Matrix<>::optFixedSize, diff --git a/src/libs/antares/study/parts/hydro/prepro.cpp b/src/libs/antares/study/parts/hydro/prepro.cpp index 13711759f4..945b65cf23 100644 --- a/src/libs/antares/study/parts/hydro/prepro.cpp +++ b/src/libs/antares/study/parts/hydro/prepro.cpp @@ -32,6 +32,8 @@ using namespace Antares; using namespace Yuni; +namespace fs = std::filesystem; + #define SEP IO::Separator namespace Antares @@ -46,7 +48,7 @@ static bool PreproHydroSaveSettings(PreproHydro* h, const char* filename) return ini.save(filename); } -static bool PreproHydroLoadSettings(PreproHydro* h, const std::string& filename) +static bool PreproHydroLoadSettings(PreproHydro* h, const fs::path& filename) { IniFile ini; IniFile::Section* s; @@ -145,7 +147,7 @@ bool PreproHydro::saveToFolder(const AreaName& areaID, const char* folder) return false; } -bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::string& folder) +bool PreproHydro::loadFromFolder(Study& s, const std::string& areaID, const fs::path& folder) { enum { @@ -153,15 +155,17 @@ bool PreproHydro::loadFromFolder(Study& s, const AreaName& areaID, const std::st }; constexpr int maxNbOfLineToLoad = 12; - data.resize(hydroPreproMax, 12, true); - String& buffer = s.bufferLoadingTS; - buffer.clear() << folder << SEP << areaID << SEP << "prepro.ini"; - bool ret = PreproHydroLoadSettings(this, buffer); + fs::path preproPath = folder / areaID / "prepro.ini"; + bool ret = PreproHydroLoadSettings(this, preproPath); - buffer.clear() << folder << SEP << areaID << SEP << "energy.txt"; - ret = data.loadFromCSVFile(buffer, hydroPreproMax, maxNbOfLineToLoad, mtrxOption, &s.dataBuffer) + fs::path energyPath = folder / areaID / "energy.txt"; + ret = data.loadFromCSVFile(energyPath.string(), + hydroPreproMax, + maxNbOfLineToLoad, + mtrxOption, + &s.dataBuffer) && ret; return ret; diff --git a/src/libs/antares/study/parts/hydro/series.cpp b/src/libs/antares/study/parts/hydro/series.cpp index 52a087b975..818fef9dc2 100644 --- a/src/libs/antares/study/parts/hydro/series.cpp +++ b/src/libs/antares/study/parts/hydro/series.cpp @@ -40,15 +40,14 @@ namespace Antares::Data { static bool loadTSfromFile(Matrix& ts, - const AreaName& areaID, + const std::string& areaID, const fs::path& folder, const std::string& filename, unsigned int height) { - YString filePath; + fs::path filePath = folder / areaID / filename; Matrix<>::BufferType fileContent; - filePath.clear() << folder << SEP << areaID << SEP << filename; - return ts.loadFromCSVFile(filePath, 1, height, &fileContent); + return ts.loadFromCSVFile(filePath.string(), 1, height, &fileContent); } static void ConvertDailyTSintoHourlyTS(const Matrix::ColumnType& dailyColumn, @@ -157,18 +156,23 @@ bool DataSeriesHydro::loadGenerationTS(const AreaName& areaID, return ret; } -bool DataSeriesHydro::LoadMaxPower(const AreaName& areaID, const fs::path& folder) +bool DataSeriesHydro::LoadMaxPower(const std::string& areaID, const fs::path& folder) { bool ret = true; - YString filepath; Matrix<>::BufferType fileContent; - filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyGenPower.txt"; - ret = maxHourlyGenPower.timeSeries.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) + fs::path filePath = folder / areaID / "maxHourlyGenPower.txt"; + ret = maxHourlyGenPower.timeSeries.loadFromCSVFile(filePath.string(), + 1, + HOURS_PER_YEAR, + &fileContent) && ret; - filepath.clear() << folder << SEP << areaID << SEP << "maxHourlyPumpPower.txt"; - ret = maxHourlyPumpPower.timeSeries.loadFromCSVFile(filepath, 1, HOURS_PER_YEAR, &fileContent) + filePath = folder / areaID / "maxHourlyPumpPower.txt"; + ret = maxHourlyPumpPower.timeSeries.loadFromCSVFile(filePath.string(), + 1, + HOURS_PER_YEAR, + &fileContent) && ret; return ret; diff --git a/src/libs/antares/study/parts/load/prepro.cpp b/src/libs/antares/study/parts/load/prepro.cpp index 68ae63a322..b5a5342c82 100644 --- a/src/libs/antares/study/parts/load/prepro.cpp +++ b/src/libs/antares/study/parts/load/prepro.cpp @@ -38,7 +38,7 @@ Prepro::~Prepro() { } -bool Prepro::loadFromFolder(const AnyString& folder) +bool Prepro::loadFromFolder(const std::filesystem::path& folder) { return xcast.loadFromFolder(folder); } diff --git a/src/libs/antares/study/parts/renewable/cluster.cpp b/src/libs/antares/study/parts/renewable/cluster.cpp index 749ed53a57..0d87c28776 100644 --- a/src/libs/antares/study/parts/renewable/cluster.cpp +++ b/src/libs/antares/study/parts/renewable/cluster.cpp @@ -38,8 +38,6 @@ using namespace Yuni; using namespace Antares; -#define SEP IO::Separator - namespace Antares::Data { Data::RenewableCluster::RenewableCluster(Area* parent): diff --git a/src/libs/antares/study/parts/renewable/cluster_list.cpp b/src/libs/antares/study/parts/renewable/cluster_list.cpp index aa1c915a75..5c8429d046 100644 --- a/src/libs/antares/study/parts/renewable/cluster_list.cpp +++ b/src/libs/antares/study/parts/renewable/cluster_list.cpp @@ -28,6 +28,8 @@ using namespace Yuni; +namespace fs = std::filesystem; + namespace Antares::Data { @@ -143,7 +145,7 @@ static bool ClusterLoadFromProperty(RenewableCluster& cluster, const IniFile::Pr return false; } -static bool ClusterLoadFromSection(const AnyString& filename, +static bool clusterLoadFromSection(const fs::path& filename, RenewableCluster& cluster, const IniFile::Section& section) { @@ -176,7 +178,7 @@ static bool ClusterLoadFromSection(const AnyString& filename, return true; } -bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) +bool RenewableClusterList::loadFromFolder(const fs::path& folder, Area* area) { assert(area and "A parent area is required"); @@ -184,11 +186,10 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) logs.info() << "Loading renewable configuration for the area " << area->name; // Open the ini file - YString buffer; - buffer << folder << SEP << "list.ini"; + fs::path filename = folder / "list.ini"; IniFile ini; - if (ini.open(buffer, false)) + if (ini.open(filename, false)) { bool ret = true; @@ -204,7 +205,7 @@ bool RenewableClusterList::loadFromFolder(const AnyString& folder, Area* area) auto cluster = std::make_shared(area); // Load data of a renewable cluster from a ini file section - if (!ClusterLoadFromSection(buffer, *cluster, *section)) + if (!clusterLoadFromSection(filename, *cluster, *section)) { continue; } diff --git a/src/libs/antares/study/parts/short-term-storage/properties.cpp b/src/libs/antares/study/parts/short-term-storage/properties.cpp index b4592105fe..28d6afe9a8 100644 --- a/src/libs/antares/study/parts/short-term-storage/properties.cpp +++ b/src/libs/antares/study/parts/short-term-storage/properties.cpp @@ -27,8 +27,6 @@ #include -#define SEP Yuni::IO::Separator - namespace Antares::Data::ShortTermStorage { diff --git a/src/libs/antares/study/parts/solar/prepro.cpp b/src/libs/antares/study/parts/solar/prepro.cpp index e11b4e00ea..0e3af8f016 100644 --- a/src/libs/antares/study/parts/solar/prepro.cpp +++ b/src/libs/antares/study/parts/solar/prepro.cpp @@ -43,7 +43,7 @@ Prepro::~Prepro() { } -bool Prepro::loadFromFolder(const AnyString& folder) +bool Prepro::loadFromFolder(const std::filesystem::path& folder) { return xcast.loadFromFolder(folder); } diff --git a/src/libs/antares/study/parts/thermal/cluster.cpp b/src/libs/antares/study/parts/thermal/cluster.cpp index 9198bc1ec6..3070518f05 100644 --- a/src/libs/antares/study/parts/thermal/cluster.cpp +++ b/src/libs/antares/study/parts/thermal/cluster.cpp @@ -42,8 +42,6 @@ using namespace Antares; #define THERMALAGGREGATELIST_INITIAL_CAPACITY 10 -#define SEP IO::Separator - namespace Yuni::Extension::CString { bool Into::Perform(AnyString string, TargetType& out) diff --git a/src/libs/antares/study/parts/wind/prepro.cpp b/src/libs/antares/study/parts/wind/prepro.cpp index f631a5db81..fd449e61a1 100644 --- a/src/libs/antares/study/parts/wind/prepro.cpp +++ b/src/libs/antares/study/parts/wind/prepro.cpp @@ -21,17 +21,9 @@ #include "antares/study/parts/wind/prepro.h" -#include -#include - #include #include "antares/study/study.h" -using namespace Yuni; -using namespace Antares; - -#define SEP IO::Separator - namespace Antares::Data::Wind { Prepro::Prepro(): @@ -43,7 +35,7 @@ Prepro::~Prepro() { } -bool Prepro::loadFromFolder(const AnyString& folder) +bool Prepro::loadFromFolder(const std::filesystem::path& folder) { return xcast.loadFromFolder(folder); } diff --git a/src/libs/antares/study/scenario-builder/sets.cpp b/src/libs/antares/study/scenario-builder/sets.cpp index 76dbcb9166..78cdffb3d9 100644 --- a/src/libs/antares/study/scenario-builder/sets.cpp +++ b/src/libs/antares/study/scenario-builder/sets.cpp @@ -26,8 +26,6 @@ using namespace Yuni; -#define SEP IO::Separator - namespace Antares::Data::ScenarioBuilder { Sets::Sets(): diff --git a/src/libs/antares/study/study.cpp b/src/libs/antares/study/study.cpp index 1b5493e750..cd20e14348 100644 --- a/src/libs/antares/study/study.cpp +++ b/src/libs/antares/study/study.cpp @@ -655,6 +655,7 @@ Area* Study::areaAdd(const AreaName& name, bool updateMode) return area; } +// TODO VP: delete with GUI bool Study::areaDelete(Area* area) { if (not area) @@ -702,6 +703,7 @@ bool Study::areaDelete(Area* area) return true; } +// TODO VP: delete with GUI void Study::areaDelete(Area::Vector& arealist) { if (arealist.empty()) @@ -764,6 +766,7 @@ void Study::areaDelete(Area::Vector& arealist) } } +// TODO VP: delete with GUI bool Study::linkDelete(AreaLink* lnk) { // Impossible to find the attached area @@ -789,6 +792,7 @@ bool Study::linkDelete(AreaLink* lnk) return true; } +// TODO VP: delete with GUI bool Study::areaRename(Area* area, AreaName newName) { // A name must not be empty @@ -871,6 +875,7 @@ bool Study::areaRename(Area* area, AreaName newName) return ret; } +// TODO VP: delete with GUI bool Study::clusterRename(Cluster* cluster, ClusterName newName) { // A name must not be empty diff --git a/src/libs/antares/study/study.importprepro.cpp b/src/libs/antares/study/study.importprepro.cpp index 69a0fe058b..3cf520c5eb 100644 --- a/src/libs/antares/study/study.importprepro.cpp +++ b/src/libs/antares/study/study.importprepro.cpp @@ -29,6 +29,8 @@ using namespace Yuni; namespace Antares::Data { + +// TODO VP: remove with time series TS generation before solver execution bool Study::importTimeseriesIntoInput() { // Special case: some thermal clusters may force TS generation diff --git a/src/libs/antares/study/xcast/xcast.cpp b/src/libs/antares/study/xcast/xcast.cpp index 0f2e05956b..d8f055775a 100644 --- a/src/libs/antares/study/xcast/xcast.cpp +++ b/src/libs/antares/study/xcast/xcast.cpp @@ -30,6 +30,8 @@ using namespace Yuni; +namespace fs = std::filesystem; + #define SEP IO::Separator namespace Antares::Data @@ -181,7 +183,7 @@ void XCast::resetToDefaultValues() useTranslation = tsTranslationNone; } -bool XCast::loadFromFolder(const AnyString& folder) +bool XCast::loadFromFolder(const fs::path& folder) { // reset distribution = dtBeta; @@ -196,13 +198,13 @@ bool XCast::loadFromFolder(const AnyString& folder) // Return value bool ret = true; // Settings - buffer.clear() << folder << SEP << "settings.ini"; + fs::path settingsPath = folder / "settings.ini"; IniFile ini; - if (ini.open(buffer)) + if (ini.open(settingsPath)) { ini.each( - [this, &buffer](const IniFile::Section& section) + [this, &settingsPath](const IniFile::Section& section) { // For each property if (section.name == "general") @@ -217,7 +219,7 @@ bool XCast::loadFromFolder(const AnyString& folder) distribution = StringToDistribution(p->value); if (distribution == dtNone) { - logs.warning() << buffer + logs.warning() << settingsPath << ": Invalid probability distribution. The beta " "distribution will be used"; distribution = dtBeta; @@ -230,7 +232,7 @@ bool XCast::loadFromFolder(const AnyString& folder) if (capacity < 0.) { logs.warning() - << buffer << ": The capacity can not be a negative value"; + << settingsPath << ": The capacity can not be a negative value"; capacity = 0.; } continue; @@ -246,18 +248,18 @@ bool XCast::loadFromFolder(const AnyString& folder) continue; } - logs.warning() << buffer << ": Unknown property '" << p->key << "'"; + logs.warning() << settingsPath << ": Unknown property '" << p->key << "'"; } } else { - logs.warning() << buffer << ": unknown section '" << section.name << "'"; + logs.warning() << settingsPath << ": unknown section '" << section.name << "'"; } }); } else { - logs.error() << "I/O Error: unable to open '" << buffer << "'"; + logs.error() << "I/O Error: unable to open '" << settingsPath << "'"; ret = false; } @@ -265,22 +267,22 @@ bool XCast::loadFromFolder(const AnyString& folder) // fix invalid data // Coefficients - buffer.clear() << folder << SEP << "data.txt"; + fs::path p = folder / "data.txt"; // Performing normal loading - ret = data.loadFromCSVFile(buffer, (uint)dataMax, 12, Matrix<>::optFixedSize, &readBuffer) + ret = data.loadFromCSVFile(p.string(), (uint)dataMax, 12, Matrix<>::optFixedSize, &readBuffer) && ret; // K - buffer.clear() << folder << SEP << "k.txt"; - ret = K.loadFromCSVFile(buffer, 12, 24, Matrix<>::optFixedSize, &readBuffer) && ret; + p = folder / "k.txt"; + ret = K.loadFromCSVFile(p.string(), 12, 24, Matrix<>::optFixedSize, &readBuffer) && ret; uint opts = Matrix<>::optNone; // Time-series translation - buffer.clear() << folder << SEP << "translation.txt"; + p = folder / "translation.txt"; - ret = translation.loadFromCSVFile(buffer, 1, HOURS_PER_YEAR, opts, &readBuffer) && ret; + ret = translation.loadFromCSVFile(p.string(), 1, HOURS_PER_YEAR, opts, &readBuffer) && ret; if (!JIT::usedFromGUI) { if (translation.empty()) @@ -303,8 +305,9 @@ bool XCast::loadFromFolder(const AnyString& folder) opts = Matrix<>::optNone; // Transfer function - buffer.clear() << folder << SEP << "conversion.txt"; - ret = conversion.loadFromCSVFile(buffer, 3, 2, opts, &readBuffer) && ret; + p = folder / "conversion.txt"; + + ret = conversion.loadFromCSVFile(p.string(), 3, 2, opts, &readBuffer) && ret; if (not JIT::enabled) { if (conversion.width >= 3 && conversion.width <= conversionMaxPoints) @@ -318,7 +321,7 @@ bool XCast::loadFromFolder(const AnyString& folder) { if (conversion[x][0] <= -1.0e+19 || conversion[x][0] >= +1.0e+19) { - logs.error() << "TS-Generator: Conversion: Invalid range: " << buffer; + logs.error() << "TS-Generator: Conversion: Invalid range: " << p; } } conversion[conversion.width - 1][0] @@ -327,7 +330,7 @@ bool XCast::loadFromFolder(const AnyString& folder) } else { - logs.warning() << "Invalid transfer function: '" << buffer << "'"; + logs.warning() << "Invalid transfer function: '" << p << "'"; resetTransferFunction(); useConversion = false; } diff --git a/src/libs/antares/writer/immediate_file_writer.cpp b/src/libs/antares/writer/immediate_file_writer.cpp index 3554598de3..40a90ec067 100644 --- a/src/libs/antares/writer/immediate_file_writer.cpp +++ b/src/libs/antares/writer/immediate_file_writer.cpp @@ -68,7 +68,7 @@ void ImmediateFileResultWriter::addEntryFromBuffer(const std::string& entryPath, } // Write to file immediately, creating directories if needed -void ImmediateFileResultWriter::addEntryFromBuffer(const std::string& entryPath, +void ImmediateFileResultWriter::addEntryFromBuffer(const fs::path& entryPath, std::string& entryContent) { fs::path output; @@ -121,7 +121,7 @@ void NullResultWriter::addEntryFromBuffer(const std::string&, Yuni::Clob&) { } -void NullResultWriter::addEntryFromBuffer(const std::string&, std::string&) +void NullResultWriter::addEntryFromBuffer(const fs::path&, std::string&) { } diff --git a/src/libs/antares/writer/in_memory_writer.cpp b/src/libs/antares/writer/in_memory_writer.cpp index 182fee1927..2c5e282fcb 100644 --- a/src/libs/antares/writer/in_memory_writer.cpp +++ b/src/libs/antares/writer/in_memory_writer.cpp @@ -75,9 +75,9 @@ void InMemoryWriter::addEntryFromBuffer(const std::string& entryPath, Yuni::Clob addToMap(pEntries, entryPath, entryContent, pMapMutex, pDurationCollector); } -void InMemoryWriter::addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) +void InMemoryWriter::addEntryFromBuffer(const fs::path& entryPath, std::string& entryContent) { - addToMap(pEntries, entryPath, entryContent, pMapMutex, pDurationCollector); + addToMap(pEntries, entryPath.string(), entryContent, pMapMutex, pDurationCollector); } void InMemoryWriter::addEntryFromFile(const fs::path& entryPath, const fs::path& filePath) diff --git a/src/libs/antares/writer/include/antares/writer/i_writer.h b/src/libs/antares/writer/include/antares/writer/i_writer.h index 40fd3799ee..473ae6daa4 100644 --- a/src/libs/antares/writer/include/antares/writer/i_writer.h +++ b/src/libs/antares/writer/include/antares/writer/i_writer.h @@ -35,7 +35,9 @@ class IResultWriter public: using Ptr = std::shared_ptr; virtual void addEntryFromBuffer(const std::string& entryPath, Yuni::Clob& entryContent) = 0; - virtual void addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) = 0; + virtual void addEntryFromBuffer(const std::filesystem::path& entryPath, + std::string& entryContent) + = 0; virtual void addEntryFromFile(const std::filesystem::path& entryPath, const std::filesystem::path& filePath) = 0; @@ -52,7 +54,7 @@ class IResultWriter class NullResultWriter: public Solver::IResultWriter { void addEntryFromBuffer(const std::string&, Yuni::Clob&) override; - void addEntryFromBuffer(const std::string&, std::string&) override; + void addEntryFromBuffer(const std::filesystem::path&, std::string&) override; void addEntryFromFile(const std::filesystem::path&, const std::filesystem::path&) override; void flush() override; bool needsTheJobQueue() const override; diff --git a/src/libs/antares/writer/include/antares/writer/in_memory_writer.h b/src/libs/antares/writer/include/antares/writer/in_memory_writer.h index 9fc465a83f..e5be52be24 100644 --- a/src/libs/antares/writer/include/antares/writer/in_memory_writer.h +++ b/src/libs/antares/writer/include/antares/writer/in_memory_writer.h @@ -38,7 +38,8 @@ class InMemoryWriter: public IResultWriter explicit InMemoryWriter(Benchmarking::DurationCollector& duration_collector); virtual ~InMemoryWriter(); void addEntryFromBuffer(const std::string& entryPath, Yuni::Clob& entryContent) override; - void addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) override; + void addEntryFromBuffer(const std::filesystem::path& entryPath, + std::string& entryContent) override; void addEntryFromFile(const std::filesystem::path& entryPath, const std::filesystem::path& filePath) override; void flush() override; diff --git a/src/libs/antares/writer/private/immediate_file_writer.h b/src/libs/antares/writer/private/immediate_file_writer.h index 1711bbfe96..1c340ee066 100644 --- a/src/libs/antares/writer/private/immediate_file_writer.h +++ b/src/libs/antares/writer/private/immediate_file_writer.h @@ -36,7 +36,8 @@ class ImmediateFileResultWriter: public IResultWriter virtual ~ImmediateFileResultWriter(); // Write to file immediately, creating directories if needed void addEntryFromBuffer(const std::string& entryPath, Yuni::Clob& entryContent) override; - void addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) override; + void addEntryFromBuffer(const std::filesystem::path& entryPath, + std::string& entryContent) override; void addEntryFromFile(const std::filesystem::path& entryPath, const std::filesystem::path& filePath) override; void flush() override; diff --git a/src/libs/antares/writer/private/zip_writer.h b/src/libs/antares/writer/private/zip_writer.h index f24c353018..948c3aaa04 100644 --- a/src/libs/antares/writer/private/zip_writer.h +++ b/src/libs/antares/writer/private/zip_writer.h @@ -82,7 +82,8 @@ class ZipWriter: public IResultWriter Benchmarking::DurationCollector& duration_collector); virtual ~ZipWriter(); void addEntryFromBuffer(const std::string& entryPath, Yuni::Clob& entryContent) override; - void addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) override; + void addEntryFromBuffer(const std::filesystem::path& entryPath, + std::string& entryContent) override; void addEntryFromFile(const std::filesystem::path& entryPath, const std::filesystem::path& filePath) override; void flush() override; @@ -109,7 +110,8 @@ class ZipWriter: public IResultWriter private: template - void addEntryFromBufferHelper(const std::string& entryPath, ContentType& entryContent); + void addEntryFromBufferHelper(const std::filesystem::path& entryPath, + ContentType& entryContent); }; } // namespace Antares::Solver diff --git a/src/libs/antares/writer/private/zip_writer.hxx b/src/libs/antares/writer/private/zip_writer.hxx index a435768b5a..2bc13ff316 100644 --- a/src/libs/antares/writer/private/zip_writer.hxx +++ b/src/libs/antares/writer/private/zip_writer.hxx @@ -27,7 +27,8 @@ namespace Antares::Solver { template -void ZipWriter::addEntryFromBufferHelper(const std::string& entryPath, ContentType& entryContent) +void ZipWriter::addEntryFromBufferHelper(const std::filesystem::path& entryPath, + ContentType& entryContent) { if (pState != ZipState::can_receive_data) { @@ -37,7 +38,7 @@ void ZipWriter::addEntryFromBufferHelper(const std::string& entryPath, ContentTy EnsureQueueStartedIfNeeded ensureQueue(this, pQueueService); pendingTasks_.add(Concurrency::AddTask( *pQueueService, - ZipWriteJob(*this, entryPath, entryContent, pDurationCollector), + ZipWriteJob(*this, entryPath.string(), entryContent, pDurationCollector), Yuni::Job::priorityLow)); } diff --git a/src/libs/antares/writer/zip_writer.cpp b/src/libs/antares/writer/zip_writer.cpp index 007524377a..008f7fdd9c 100644 --- a/src/libs/antares/writer/zip_writer.cpp +++ b/src/libs/antares/writer/zip_writer.cpp @@ -157,7 +157,7 @@ void ZipWriter::addEntryFromBuffer(const std::string& entryPath, Yuni::Clob& ent addEntryFromBufferHelper(entryPath, entryContent); } -void ZipWriter::addEntryFromBuffer(const std::string& entryPath, std::string& entryContent) +void ZipWriter::addEntryFromBuffer(const fs::path& entryPath, std::string& entryContent) { addEntryFromBufferHelper(entryPath, entryContent); } diff --git a/src/solver/constraints-builder/load.cpp b/src/solver/constraints-builder/load.cpp index 73beec49c1..36868da082 100644 --- a/src/solver/constraints-builder/load.cpp +++ b/src/solver/constraints-builder/load.cpp @@ -18,17 +18,10 @@ * You should have received a copy of the Mozilla Public Licence 2.0 * along with Antares_Simulator. If not, see . */ -#include - -#include #include "antares/config/config.h" #include "antares/solver/constraints-builder/cbuilder.h" #include "antares/study/area/constants.h" -using namespace Yuni; - -#define SEP Yuni::IO::Separator - namespace Antares { bool CBuilder::completeFromStudy() diff --git a/src/solver/hydro/management/daily.cpp b/src/solver/hydro/management/daily.cpp index 8bf59df763..ee11407f1f 100644 --- a/src/solver/hydro/management/daily.cpp +++ b/src/solver/hydro/management/daily.cpp @@ -141,7 +141,7 @@ struct DebugData buffer << '\n'; } auto buffer_str = buffer.str(); - pWriter.addEntryFromBuffer(path.string(), buffer_str); + pWriter.addEntryFromBuffer(path, buffer_str); } void writeDailyDebugData(const Date::Calendar& calendar, @@ -210,7 +210,7 @@ struct DebugData } } auto buffer_str = buffer.str(); - pWriter.addEntryFromBuffer(path.string(), buffer_str); + pWriter.addEntryFromBuffer(path, buffer_str); } }; diff --git a/src/solver/hydro/management/monthly.cpp b/src/solver/hydro/management/monthly.cpp index 62658e277d..0b004a11ef 100644 --- a/src/solver/hydro/management/monthly.cpp +++ b/src/solver/hydro/management/monthly.cpp @@ -304,7 +304,7 @@ void HydroManagement::prepareMonthlyOptimalGenerations(const double* random_rese buffer << '\n'; } auto content = buffer.str(); - resultWriter_.addEntryFromBuffer(path.string(), content); + resultWriter_.addEntryFromBuffer(path, content); } indexArea++; }); diff --git a/src/solver/main.cpp b/src/solver/main.cpp index a0f012a9ef..3840446c73 100644 --- a/src/solver/main.cpp +++ b/src/solver/main.cpp @@ -28,9 +28,6 @@ #include "antares/application/application.h" using namespace Antares; -using namespace Yuni; - -#define SEP Yuni::IO::Separator namespace { diff --git a/src/solver/simulation/TimeSeriesNumbersWriter.cpp b/src/solver/simulation/TimeSeriesNumbersWriter.cpp index 09122c32e0..d35dd5fdc5 100644 --- a/src/solver/simulation/TimeSeriesNumbersWriter.cpp +++ b/src/solver/simulation/TimeSeriesNumbersWriter.cpp @@ -48,7 +48,7 @@ static void genericStoreTimeseriesNumbers(Solver::IResultWriter& writer, std::string buffer; timeseriesNumbers.saveToBuffer(buffer); - writer.addEntryFromBuffer(path.string(), buffer); + writer.addEntryFromBuffer(path, buffer); } void BindingConstraintsTimeSeriesNumbersWriter::write( diff --git a/src/solver/simulation/opt_time_writer.cpp b/src/solver/simulation/opt_time_writer.cpp index a09f3feaa8..8ea4091a26 100644 --- a/src/solver/simulation/opt_time_writer.cpp +++ b/src/solver/simulation/opt_time_writer.cpp @@ -47,5 +47,5 @@ void OptimizationStatisticsWriter::finalize() const path filename = path("optimization") / "week-by-week" / ("year_" + std::to_string(pYear) + ".txt"); std::string s = pBuffer.str(); - pWriter.addEntryFromBuffer(filename.string(), s); + pWriter.addEntryFromBuffer(filename, s); } diff --git a/src/solver/simulation/solver_utils.cpp b/src/solver/simulation/solver_utils.cpp index 76f5fc0ce3..401aa3db68 100644 --- a/src/solver/simulation/solver_utils.cpp +++ b/src/solver/simulation/solver_utils.cpp @@ -22,21 +22,18 @@ #include "antares/solver/simulation/solver_utils.h" #include +#include #include #include #include #include -#include - -#define SEP Yuni::IO::Separator +namespace fs = std::filesystem; static const std::string systemCostFilename = "annualSystemCost.txt"; static const std::string criterionsCostsFilename = "checkIntegrity.txt"; -static const std::string optimizationTimeFilename = std::string("optimization") + SEP - + "solve-durations.txt"; -static const std::string updateTimeFilename = std::string("optimization") + SEP - + "update-durations.txt"; +static const fs::path optimizationTimeFilename = fs::path("optimization") / "solve-durations.txt"; +static const fs::path updateTimeFilename = fs::path("optimization") / "update-durations.txt"; static std::ostream& toScientific(std::ostream& os) { diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index dd5af1a25e..966625aa81 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -30,7 +30,7 @@ using namespace Antares; -#define SEP Yuni::IO::Separator +namespace fs = std::filesystem; #define EPSILON ((double)1.0e-9) @@ -281,26 +281,22 @@ bool GenerateHydroTimeSeries(Data::Study& study, uint currentYear, Solver::IResu { logs.info() << "Archiving the hydro time-series"; study.areas.each( - [&study, ¤tYear, &writer, &progression](const Data::Area& area) + [¤tYear, &writer, &progression](const Data::Area& area) { const int precision = 0; - Yuni::String output; - study.buffer.clear() << "ts-generator" << SEP << "hydro" << SEP << "mc-" - << currentYear << SEP << area.id; - - { - std::string buffer; - area.hydro.series->ror.timeSeries.saveToBuffer(buffer, precision); - output.clear() << study.buffer << SEP << "ror.txt"; - writer.addEntryFromBuffer(output.c_str(), buffer); - } - - { - std::string buffer; - area.hydro.series->storage.timeSeries.saveToBuffer(buffer, precision); - output.clear() << study.buffer << SEP << "storage.txt"; - writer.addEntryFromBuffer(output.c_str(), buffer); - } + std::string mcYear = "mc-" + currentYear; + fs::path outputFolder = fs::path("ts-generator") / "hydro" / mcYear + / area.id.to(); + + std::string buffer; + area.hydro.series->ror.timeSeries.saveToBuffer(buffer, precision); + fs::path outputFile = outputFolder / "ror.txt"; + writer.addEntryFromBuffer(outputFile, buffer); + + area.hydro.series->storage.timeSeries.saveToBuffer(buffer, precision); + outputFile = outputFolder / "storage.txt"; + writer.addEntryFromBuffer(outputFile, buffer); + ++progression; }); } diff --git a/src/solver/ts-generator/prepro.cpp b/src/solver/ts-generator/prepro.cpp index b26faefb50..04cc371b8a 100644 --- a/src/solver/ts-generator/prepro.cpp +++ b/src/solver/ts-generator/prepro.cpp @@ -20,18 +20,11 @@ */ #include -#include -#include -#include #include #include #include "antares/study/study.h" -using namespace Yuni; - -#define SEP IO::Separator - namespace Antares::Data { PreproAvailability::PreproAvailability(const YString& id, unsigned int unitCount): @@ -50,10 +43,10 @@ void PreproAvailability::copyFrom(const PreproAvailability& rhs) bool PreproAvailability::saveToFolder(const AnyString& folder) const { - if (IO::Directory::Create(folder)) + if (Yuni::IO::Directory::Create(folder)) { - String buffer; - buffer.clear() << folder << SEP << "data.txt"; + Yuni::String buffer; + buffer.clear() << folder << Yuni::IO::Separator << "data.txt"; return data.saveToCSVFile(buffer, /*decimal*/ 6); } return false; diff --git a/src/solver/ts-generator/xcast/xcast.cpp b/src/solver/ts-generator/xcast/xcast.cpp index 3f42862cb5..7af0d35da5 100644 --- a/src/solver/ts-generator/xcast/xcast.cpp +++ b/src/solver/ts-generator/xcast/xcast.cpp @@ -25,16 +25,12 @@ #include #include -#include - #include #include #include #include "antares/solver/ts-generator/xcast/predicate.hxx" -using namespace Yuni; - -#define SEP (IO::Separator) +namespace fs = std::filesystem; namespace Antares::TSGenerator::XCast { @@ -71,20 +67,18 @@ void XCast::exportTimeSeriesToTheOutput(Progression::Task& progression, Predicat logs.info() << "Exporting " << predicate.timeSeriesName() << " time-series into the output (year:" << year << ')'; - String output; - String filename; - - output << "ts-generator" << SEP << predicate.timeSeriesName() << SEP << "mc-" << year; - filename.reserve(output.size() + 80); + fs::path output = "ts-generator"; + output /= fs::path(predicate.timeSeriesName()) / std::string("mc-" + year); study.areas.each( - [this, &filename, &progression, &predicate, &output](Data::Area& area) + [this, &progression, &predicate, &output](Data::Area& area) { - filename.clear() << output << SEP << area.id << ".txt"; + std::string areaId = area.id + "txt"; + fs::path filename = output / areaId; std::string buffer; predicate.matrix(area).saveToBuffer(buffer); - pWriter.addEntryFromBuffer(filename.c_str(), buffer); + pWriter.addEntryFromBuffer(filename, buffer); ++progression; }); diff --git a/src/solver/variable/include/antares/solver/variable/container.hxx b/src/solver/variable/include/antares/solver/variable/container.hxx index 0f9559b3a2..fe62b761f9 100644 --- a/src/solver/variable/include/antares/solver/variable/container.hxx +++ b/src/solver/variable/include/antares/solver/variable/container.hxx @@ -23,13 +23,10 @@ #include -#include #include #include "antares/solver/variable/surveyresults/reportbuilder.hxx" -#define SEP Yuni::IO::Separator - namespace Antares { namespace Solver @@ -254,7 +251,8 @@ void List::buildSurveyReport(SurveyResults& results, // The new filename results.data.filename.clear(); - results.data.filename << results.data.output << SEP; + results.data.filename << std::filesystem::path(static_cast(results.data.output)) + / ""; Category::FileLevelToStream(results.data.filename, fileLevel); results.data.filename << '-'; Category::PrecisionLevelToStream(results.data.filename, precision); @@ -283,7 +281,8 @@ void List::buildAnnualSurveyReport(SurveyResults& results, // The new filename results.data.filename.clear(); - results.data.filename << results.data.output << SEP; + results.data.filename << std::filesystem::path(static_cast(results.data.output)) + / ""; Category::FileLevelToStream(results.data.filename, fileLevel); results.data.filename << '-'; Category::PrecisionLevelToStream(results.data.filename, precision); diff --git a/src/solver/variable/include/antares/solver/variable/surveyresults/reportbuilder.hxx b/src/solver/variable/include/antares/solver/variable/surveyresults/reportbuilder.hxx index 6354169b96..11a9277dab 100644 --- a/src/solver/variable/include/antares/solver/variable/surveyresults/reportbuilder.hxx +++ b/src/solver/variable/include/antares/solver/variable/surveyresults/reportbuilder.hxx @@ -36,8 +36,6 @@ #include "../info.h" #include "../surveyresults.h" -#define SEP Yuni::IO::Separator - namespace Antares { namespace Solver @@ -272,8 +270,10 @@ public: } // THIS FILE IS DEPRECATED !!! YString digestFileName; - digestFileName << results.data.originalOutput << SEP << "grid" << SEP << "digest.txt"; - writer.addEntryFromBuffer(digestFileName.c_str(), digestBuffer); + std::filesystem::path path = static_cast(results.data.originalOutput); + path /= "grid"; + path /= "digest.txt"; + writer.addEntryFromBuffer(path, digestBuffer); } private: @@ -320,9 +320,11 @@ private: { logs.info() << "Exporting results : " << area.name; // The new output - results.data.output.clear(); - results.data.output << results.data.originalOutput << SEP << "areas" << SEP - << area.id; + std::filesystem::path path = static_cast(results.data.originalOutput); + path /= "areas"; + path /= area.id.to(); + + results.data.output = path.string(); SurveyReportBuilderFile::Run(list, results, numSpace); } @@ -354,9 +356,11 @@ private: logs.info() << "Exporting results : " << area.name << " :: " << cluster->name(); // The new output - results.data.output.clear(); - results.data.output << results.data.originalOutput << SEP << "areas" << SEP - << area.id << SEP << "thermal" << SEP << cluster->id(); + std::filesystem::path path = static_cast(results.data.originalOutput); + path /= std::filesystem::path("areas") / area.id.to() / "thermal" + / cluster->id(); + + results.data.output = path.string(); SurveyReportBuilderFile::Run(list, results, numSpace); } @@ -405,9 +409,14 @@ private: Antares::logs.info() << "Exporting results : " << area.name << " - " << results.data.link->with->name; // The new output - results.data.output.clear(); - results.data.output << results.data.originalOutput << SEP << "links" << SEP - << area.id << " - " << results.data.link->with->id; + std::filesystem::path path = static_cast( + results.data.originalOutput); + std::string areaId = static_cast(area.id) + " - " + + results.data.link->with->id; + path /= std::filesystem::path("links") / areaId; + + results.data.output = path.string(); + SurveyReportBuilderFile::Run(list, results, numSpace); @@ -449,11 +458,13 @@ private: logs.info() << "Exporting results : " << sets.caption(i); // The new output - results.data.output.clear(); - results.data.output << results.data.originalOutput << SEP << "areas" << SEP << "@ " - << sets.nameByIndex(i); + std::filesystem::path path = static_cast(results.data.originalOutput); + std::string setId = "@ " + sets.nameByIndex(i); + path /= std::filesystem::path("areas") / setId; + results.data.output = path.string(); results.data.setOfAreasIndex = indx++; + SurveyReportBuilderFile::Run(list, results, numSpace); } } @@ -469,8 +480,10 @@ private: { logs.info() << "Exporting results : binding constraints"; // The new output - results.data.output.clear(); - results.data.output << results.data.originalOutput << SEP << "binding_constraints"; + std::filesystem::path path = static_cast(results.data.originalOutput); + path /= "binding_constraints"; + + results.data.output = path.string(); SurveyReportBuilderFile::Run(list, results, numSpace); } } @@ -496,7 +509,4 @@ public: } // namespace Solver } // namespace Antares -// cleanup -#undef SEP - #endif // __SOLVER_VARIABLE_SURVEYRESULTS_REPORT_BUILDER_HXX__ diff --git a/src/solver/variable/surveyresults/surveyresults.cpp b/src/solver/variable/surveyresults/surveyresults.cpp index 8df87678e4..6a89d2cb14 100644 --- a/src/solver/variable/surveyresults/surveyresults.cpp +++ b/src/solver/variable/surveyresults/surveyresults.cpp @@ -31,11 +31,8 @@ #include #include -using namespace Yuni; using namespace Antares; -#define SEP IO::Separator - namespace Antares::Solver::Variable::Private { void InternalExportDigestLinksMatrix(const Data::Study& study, @@ -114,12 +111,12 @@ void InternalExportDigestLinksMatrix(const Data::Study& study, } static void ExportGridInfosAreas(const Data::Study& study, - const Yuni::String& originalOutput, + const std::string& originalOutput, IResultWriter& writer) { - Clob out; - Clob outLinks; - Clob outThermal; + Yuni::Clob out; + Yuni::Clob outLinks; + Yuni::Clob outThermal; out << "id\tname\n"; outLinks << "upstream\tdownstream\n"; @@ -164,11 +161,12 @@ static void ExportGridInfosAreas(const Data::Study& study, } // each thermal cluster }); // each area - auto add = [&writer, &originalOutput](const YString& filename, Clob&& buffer) + auto add = [&writer, &originalOutput](const std::string& filename, Yuni::Clob&& buffer) { - YString path; - path << originalOutput << SEP << "grid" << SEP << filename; - writer.addEntryFromBuffer(path.c_str(), buffer); + std::filesystem::path path = originalOutput; + path /= "grid"; + path /= filename; + writer.addEntryFromBuffer(path.string(), buffer); }; add("areas.txt", std::move(out)); @@ -176,7 +174,7 @@ static void ExportGridInfosAreas(const Data::Study& study, add("thermal.txt", std::move(outThermal)); } -SurveyResultsData::SurveyResultsData(const Data::Study& s, const String& o): +SurveyResultsData::SurveyResultsData(const Data::Study& s, const Yuni::String& o): columnIndex((uint)-1), thermalCluster(nullptr), area(nullptr), @@ -511,7 +509,7 @@ static inline void WriteIndexHeaderToFileDescriptor(int precisionLevel, s += '\n'; } -SurveyResults::SurveyResults(const Data::Study& s, const String& o, IResultWriter& writer): +SurveyResults::SurveyResults(const Data::Study& s, const Yuni::String& o, IResultWriter& writer): data(s, o), yearByYearResults(false), isCurrentVarNA(nullptr), diff --git a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp index d7de940912..427eeadb73 100644 --- a/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp +++ b/src/tests/src/libs/antares/study/short-term-storage-input/short-term-storage-input-output.cpp @@ -31,17 +31,16 @@ #include "antares/study/parts/short-term-storage/container.h" -#define SEP Yuni::IO::Separator - using namespace std; using namespace Antares::Data; +namespace fs = std::filesystem; + namespace { -std::string getFolder() +fs::path getFolder() { - std::filesystem::path tmpDir = std::filesystem::temp_directory_path(); - return tmpDir.string(); + return fs::temp_directory_path(); } void resizeFillVectors(ShortTermStorage::Series& series, double value, unsigned int size) @@ -57,7 +56,7 @@ void resizeFillVectors(ShortTermStorage::Series& series, double value, unsigned series.costLevel.resize(size, value); } -void createIndividualFileSeries(const std::string& path, double value, unsigned int size) +void createIndividualFileSeries(const fs::path& path, double value, unsigned int size) { std::ofstream outfile(path); @@ -69,7 +68,7 @@ void createIndividualFileSeries(const std::string& path, double value, unsigned outfile.close(); } -void createIndividualFileSeries(const std::string& path, unsigned int size) +void createIndividualFileSeries(const fs::path& path, unsigned int size) { std::ofstream outfile; outfile.open(path, std::ofstream::out | std::ofstream::trunc); @@ -85,40 +84,40 @@ void createIndividualFileSeries(const std::string& path, unsigned int size) void createFileSeries(double value, unsigned int size) { - std::string folder = getFolder(); + fs::path folder = getFolder(); - createIndividualFileSeries(folder + SEP + "PMAX-injection.txt", value, size); - createIndividualFileSeries(folder + SEP + "PMAX-withdrawal.txt", value, size); - createIndividualFileSeries(folder + SEP + "inflows.txt", value, size); - createIndividualFileSeries(folder + SEP + "lower-rule-curve.txt", value, size); - createIndividualFileSeries(folder + SEP + "upper-rule-curve.txt", value, size); + createIndividualFileSeries(folder / "PMAX-injection.txt", value, size); + createIndividualFileSeries(folder / "PMAX-withdrawal.txt", value, size); + createIndividualFileSeries(folder / "inflows.txt", value, size); + createIndividualFileSeries(folder / "lower-rule-curve.txt", value, size); + createIndividualFileSeries(folder / "upper-rule-curve.txt", value, size); - createIndividualFileSeries(folder + SEP + "cost-injection.txt", value, size); - createIndividualFileSeries(folder + SEP + "cost-withdrawal.txt", value, size); - createIndividualFileSeries(folder + SEP + "cost-level.txt", value, size); + createIndividualFileSeries(folder / "cost-injection.txt", value, size); + createIndividualFileSeries(folder / "cost-withdrawal.txt", value, size); + createIndividualFileSeries(folder / "cost-level.txt", value, size); } void createFileSeries(unsigned int size) { - std::string folder = getFolder(); + fs::path folder = getFolder(); - createIndividualFileSeries(folder + SEP + "PMAX-injection.txt", size); - createIndividualFileSeries(folder + SEP + "PMAX-withdrawal.txt", size); - createIndividualFileSeries(folder + SEP + "inflows.txt", size); - createIndividualFileSeries(folder + SEP + "lower-rule-curve.txt", size); - createIndividualFileSeries(folder + SEP + "upper-rule-curve.txt", size); + createIndividualFileSeries(folder / "PMAX-injection.txt", size); + createIndividualFileSeries(folder / "PMAX-withdrawal.txt", size); + createIndividualFileSeries(folder / "inflows.txt", size); + createIndividualFileSeries(folder / "lower-rule-curve.txt", size); + createIndividualFileSeries(folder / "upper-rule-curve.txt", size); - createIndividualFileSeries(folder + SEP + "cost-injection.txt", size); - createIndividualFileSeries(folder + SEP + "cost-withdrawal.txt", size); - createIndividualFileSeries(folder + SEP + "cost-level.txt", size); + createIndividualFileSeries(folder / "cost-injection.txt", size); + createIndividualFileSeries(folder / "cost-withdrawal.txt", size); + createIndividualFileSeries(folder / "cost-level.txt", size); } void createIniFile(bool enabled) { - std::string folder = getFolder(); + fs::path folder = getFolder(); std::ofstream outfile; - outfile.open(folder + SEP + "list.ini", std::ofstream::out | std::ofstream::trunc); + outfile.open(folder / "list.ini", std::ofstream::out | std::ofstream::trunc); outfile << "[area]" << std::endl; outfile << "name = area" << std::endl; @@ -135,10 +134,10 @@ void createIniFile(bool enabled) void createIniFileWrongValue() { - std::string folder = getFolder(); + fs::path folder = getFolder(); std::ofstream outfile; - outfile.open(folder + SEP + "list.ini", std::ofstream::out | std::ofstream::trunc); + outfile.open(folder / "list.ini", std::ofstream::out | std::ofstream::trunc); outfile << "[area]" << std::endl; outfile << "name = area" << std::endl; @@ -155,18 +154,17 @@ void createIniFileWrongValue() void createEmptyIniFile() { - std::string folder = getFolder(); + fs::path folder = getFolder(); std::ofstream outfile; - outfile.open(folder + SEP + "list.ini", std::ofstream::out | std::ofstream::trunc); + outfile.open(folder / "list.ini", std::ofstream::out | std::ofstream::trunc); outfile.close(); } void removeIniFile() { - std::string folder = getFolder(); - std::filesystem::remove(folder + SEP + "list.ini"); + fs::remove(getFolder() / "list.ini"); } } // namespace @@ -183,18 +181,18 @@ struct Fixture ~Fixture() { - std::filesystem::remove(folder + SEP + "PMAX-injection.txt"); - std::filesystem::remove(folder + SEP + "PMAX-withdrawal.txt"); - std::filesystem::remove(folder + SEP + "inflows.txt"); - std::filesystem::remove(folder + SEP + "lower-rule-curve.txt"); - std::filesystem::remove(folder + SEP + "upper-rule-curve.txt"); - - std::filesystem::remove(folder + SEP + "cost-injection.txt"); - std::filesystem::remove(folder + SEP + "cost-withdrawal.txt"); - std::filesystem::remove(folder + SEP + "cost-level.txt"); + fs::remove(folder / "PMAX-injection.txt"); + fs::remove(folder / "PMAX-withdrawal.txt"); + fs::remove(folder / "inflows.txt"); + fs::remove(folder / "lower-rule-curve.txt"); + fs::remove(folder / "upper-rule-curve.txt"); + + fs::remove(folder / "cost-injection.txt"); + fs::remove(folder / "cost-withdrawal.txt"); + fs::remove(folder / "cost-level.txt"); } - std::string folder = getFolder(); + fs::path folder = getFolder(); ShortTermStorage::Series series; ShortTermStorage::Properties properties; @@ -345,7 +343,7 @@ BOOST_FIXTURE_TEST_CASE(check_file_save, Fixture) removeIniFile(); - BOOST_CHECK(container.saveToFolder(folder)); + BOOST_CHECK(container.saveToFolder(folder.string())); BOOST_CHECK(container.createSTStorageClustersFromIniFile(folder)); @@ -356,7 +354,7 @@ BOOST_FIXTURE_TEST_CASE(check_series_save, Fixture) { resizeFillVectors(series, 0.123456789, 8760); - BOOST_CHECK(series.saveToFolder(folder)); + BOOST_CHECK(series.saveToFolder(folder.string())); resizeFillVectors(series, 0, 0); BOOST_CHECK(series.loadFromFolder(folder));