forked from sstsimulator/sst-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlConfigOutput.cc
More file actions
85 lines (65 loc) · 2.96 KB
/
xmlConfigOutput.cc
File metadata and controls
85 lines (65 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2009-2025 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2025, NTESS
// All rights reserved.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
//
#include "sst_config.h"
#include "xmlConfigOutput.h"
#include "sst/core/configGraphOutput.h"
#include "sst/core/warnmacros.h"
using namespace SST::Core;
XMLConfigGraphOutput::XMLConfigGraphOutput(const char* path) : ConfigGraphOutput(path) {}
void
XMLConfigGraphOutput::generate(const Config* UNUSED(cfg), ConfigGraph* graph)
{
if ( nullptr == outputFile ) { throw ConfigGraphOutputException("Output file is not open for writing"); }
fprintf(outputFile, "<?xml version=\"1.0\" ?>\n");
fprintf(outputFile, "<component id=\"root\" name=\"root\">\n");
fprintf(outputFile, " <component id=\"system\" name=\"system\">\n");
const auto compMap = graph->getComponentMap();
const auto linkMap = graph->getLinkMap();
for ( auto compItr = compMap.begin(); compItr != compMap.end(); compItr++ ) {
generateXML(" ", (*compItr), linkMap);
}
for ( auto linkItr = linkMap.begin(); linkItr != linkMap.end(); linkItr++ ) {
generateXML(" ", (*linkItr), compMap);
}
fprintf(outputFile, " </component>\n");
fprintf(outputFile, "</component>\n");
}
void
XMLConfigGraphOutput::generateXML(
const std::string& indent, const ConfigComponent* comp, const ConfigLinkMap_t& UNUSED(linkMap)) const
{
fprintf(
outputFile, "%s<component id=\"system.%s\" name=\"%s\" type=\"%s\">\n", indent.c_str(), comp->name.c_str(),
comp->name.c_str(), comp->type.c_str());
// for(auto paramsItr = comp->params.begin(); paramsItr != comp->params.end(); paramsItr++) {
auto keys = comp->params.getKeys();
for ( auto paramsItr = keys.begin(); paramsItr != keys.end(); paramsItr++ ) {
std::string paramName = *paramsItr;
std::string paramValue = comp->params.find<std::string>(*paramsItr);
fprintf(
outputFile, "%s%s<param name=\"%s\" value=\"%s\"/>\n", indent.c_str(), " ", paramName.c_str(),
paramValue.c_str());
}
fprintf(outputFile, "%s</component>\n", indent.c_str());
}
void
XMLConfigGraphOutput::generateXML(
const std::string& indent, const ConfigLink* link, const ConfigComponentMap_t& compMap) const
{
const ConfigComponent* link_left = compMap[link->component[0]];
const ConfigComponent* link_right = compMap[link->component[1]];
fprintf(
outputFile,
"%s<link id=\"%s\" name=\"%s\"\n%s%sleft=\"%s\" right=\"%s\"\n%s%sleftport=\"%s\" rightport=\"%s\"/>\n",
indent.c_str(), link->name.c_str(), link->name.c_str(), indent.c_str(), " ", link_left->name.c_str(),
link_right->name.c_str(), indent.c_str(), " ", link->port[0].c_str(), link->port[1].c_str());
}