Antares Simulator
Power System Simulator
sets.hxx
1 /*
2  * Copyright 2007-2025, RTE (https://www.rte-france.com)
3  * See AUTHORS.txt
4  * SPDX-License-Identifier: MPL-2.0
5  * This file is part of Antares-Simulator,
6  * Adequacy and Performance assessment for interconnected energy networks.
7  *
8  * Antares_Simulator is free software: you can redistribute it and/or modify
9  * it under the terms of the Mozilla Public Licence 2.0 as published by
10  * the Mozilla Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Antares_Simulator is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * Mozilla Public Licence 2.0 for more details.
17  *
18  * You should have received a copy of the Mozilla Public Licence 2.0
19  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20  */
21 #ifndef __LIBS_STUDY_SCENARIO_BUILDER_SETS_HXX__
22 #define __LIBS_STUDY_SCENARIO_BUILDER_SETS_HXX__
23 
24 namespace Antares::Data::ScenarioBuilder
25 {
26 inline uint Sets::size() const
27 {
28  return (uint)pMap.size();
29 }
30 
31 inline bool Sets::empty() const
32 {
33  return pMap.empty();
34 }
35 
36 inline Sets::iterator Sets::begin()
37 {
38  return pMap.begin();
39 }
40 
41 inline Sets::const_iterator Sets::begin() const
42 {
43  return pMap.begin();
44 }
45 
46 inline Sets::iterator Sets::end()
47 {
48  return pMap.end();
49 }
50 
51 inline Sets::const_iterator Sets::end() const
52 {
53  return pMap.end();
54 }
55 
56 inline bool Sets::exists(const RulesScenarioName& lname) const
57 {
58  return pMap.find(lname) != pMap.end();
59 }
60 
61 inline Rules::Ptr Sets::find(const RulesScenarioName& lname) const
62 {
63  using namespace Yuni;
64  const_iterator i = pMap.find(lname);
65  if (i != pMap.end())
66  {
67  return i->second;
68  }
69  return nullptr;
70 }
71 
72 #ifdef BUILD_UI
73 template<class StringT>
74 inline bool Sets::saveToINIFile(const StringT& filename)
75 {
76  const AnyString adapter(filename);
77  return internalSaveToIniFile(adapter);
78 }
79 #endif
80 
81 template<class StringT>
82 bool Sets::loadFromINIFile(const StringT& filename)
83 {
84  // If the source code below is changed, please change it in loadFromStudy too
85  const AnyString adapter(filename);
86  bool r = internalLoadFromINIFile(adapter);
87  if (!r)
88  {
89  pMap.clear();
90  }
91  if (pMap.empty())
92  {
93  createNew("Default Ruleset");
94  }
95  return r;
96 }
97 
98 } // namespace Antares::Data::ScenarioBuilder
99 
100 #endif // __LIBS_STUDY_SCENARIO_BUILDER_SETS_H__
std::shared_ptr< Rules > Ptr
Smart pointer.
Definition: rules.h:53
Rules::Ptr createNew(const RulesScenarioName &name)
Create a new set.
Definition: sets.cpp:83
bool empty() const
Get if empty.
Definition: sets.hxx:31
bool loadFromINIFile(const StringT &filename)
Load all rulesets from an INI file.
Definition: sets.hxx:82
Rules::Map::iterator iterator
Iterator.
Definition: sets.h:37
Rules::Ptr find(const RulesScenarioName &lname) const
Find a rule set.
Definition: sets.hxx:61
bool exists(const RulesScenarioName &lname) const
Test if a rules set exist.
Definition: sets.hxx:56
Rules::Map::const_iterator const_iterator
Const iterator.
Definition: sets.h:39
uint size() const
Get the number of available sets.
Definition: sets.hxx:26
MapType::const_iterator const_iterator
Standard iterators from the STL (const)
Definition: sets.h:58