54 struct Map: std::map<std::string, T> {
55 typename std::map<std::string, T>::iterator
find(
const std::string& key) {
56 std::string name = key;
57 std::replace(name.begin(), name.end(),
'-',
'_');
58 return std::map<std::string, T>::find(name);
61 typename std::map<std::string, T>::const_iterator
find(
const std::string& key)
const {
62 std::string name = key;
63 std::replace(name.begin(), name.end(),
'-',
'_');
64 return std::map<std::string, T>::find(name);
70 throw Exception(
"can't load section \"{0}\" from \"{1}\". Loading from external sources is not supported or disallowed.",
section,
url); }
84 bool hasCircularRef(boost::filesystem::path& fileName,
const std::string& section) {
85 if (!currentSection.empty() || currentSection != section)
return false;
86 if (fileName == originalFileName)
return true;
103 const std::string& currentSection = std::string(),
105 : originalFileName(originalFileName), currentSection(currentSection), prev(prev) {}
107 void operator()(
Manager& manager,
const std::string& url,
const std::string& section);
114 std::map<std::string, std::map<std::string, std::string>> global_solver_names;
117 static bool acceptAllSections(
const std::string&) {
return true; }
126 typedef std::function<
void(Manager&,
const std::string&,
const std::string&)> LoadFunCallbackT;
135 bool tryLoadFromExternal(XMLReader& reader,
const LoadFunCallbackT&
load_from);
145 virtual shared_ptr<Solver> loadSolver(
const std::string& category,
const std::string&
lib,
const std::string& solver_name,
const std::string& name);
152 void loadMaterialLib(XMLReader& reader);
158 virtual void loadMaterial(XMLReader& reader);
162 static constexpr const char* TAG_NAME_ROOT =
"plask";
163 static constexpr const char* TAG_NAME_DEFINES =
"defines";
164 static constexpr const char* TAG_NAME_MATERIALS =
"materials";
165 static constexpr const char* TAG_NAME_GEOMETRY =
"geometry";
166 static constexpr const char* TAG_NAME_GRIDS =
"grids";
167 static constexpr const char* TAG_NAME_SOLVERS =
"solvers";
168 static constexpr const char* TAG_NAME_CONNECTS =
"connects";
169 static constexpr const char* TAG_NAME_SCRIPT =
"script";
171 static constexpr const char* XML_AXES_ATTR =
"axes";
177 std::vector<shared_ptr<Geometry>>
roots;
205 std::deque<std::pair<int,std::string>>
errors;
213 errors.push_back(std::make_pair(line,
mesg));
222 pushError(
error.what(), line);
231 if (line == -1) line =
error.line;
232 pushError(
error.what(), line);
240 template <
typename ErrorType>
242 if (!draft)
throw error;
243 else pushError(
error, line);
307 explicit Manager(
bool draft =
false): scriptline(0), axisNames(&
AxisNames::axisNamesRegister.get(
"long, tran, vert")), draft(draft) {}
354 template <
typename RequiredObjectType>
373 template <
typename RequiredObjectType>
395 template <
typename RequiredCalcSpaceType>
403 template <
typename RequiredCalcSpaceType>
414 virtual void loadDefines(
XMLReader& reader);
426 virtual void loadMaterials(
XMLReader& reader);
432 virtual void loadGrids(
XMLReader& reader);
438 virtual void loadSolvers(
XMLReader& reader);
444 virtual void loadConnects(
XMLReader& reader);
451 virtual void loadScript(
XMLReader& reader);
467 void loadFromStream(std::unique_ptr<std::istream>&& input,
const LoadFunCallbackT&
load_from_cb = &disallowExternalSources);
475 void loadFromXMLString(
const std::string &
input_XML_str,
const LoadFunCallbackT&
load_from_cb = &disallowExternalSources);
491 void loadFromFile(
const std::string&
fileName);
499 void loadFromFILE(
FILE* file,
const LoadFunCallbackT&
load_from_cb = &disallowExternalSources);
508 template <
typename Boundary>
510 auto p = this->boundaries.
find(name);
511 if (p == this->boundaries.end())
512 throw XMLException(reader, format(
"can't find boundary (place) with given name \"{0}\".", name));
513 return boost::any_cast<Boundary>(p->second);
521 void storeBoundary(
const std::string& name, boost::any&& boundary) {
522 if (!this->boundaries.insert(std::make_pair(name, std::move(boundary))).second)
523 throw NamesConflictException(
"place (boundary)", name);
531 template <
typename Boundary>
532 Boundary readBoundary(XMLReader& reader);
561 template <
typename Boundary,
typename ConditionT>
572 const LoadFunCallbackT&
load_from_cb = &disallowExternalSources,
583 const LoadFunCallbackT&
load_from_cb = &disallowExternalSources) {
596 void validatePositions(
const std::function<
void(
const Geometry*,
const Geometry*, std::vector<const GeometryObject*>&&,
const std::map<const GeometryObject*, const char*>&)>&
callback)
const;
604 void validatePositions()
const;