Blame view

src/dcxmlmodelmapping.cpp 4.49 KB
30448f62   Peter M. Groen   Replace Qt with s...
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  #include "dcxmlmodelmapping.h"
  #include "dcxmlconfig.h"
  
  using namespace osdev::components;
  
  // The only instance of the singleton Modelmapper Config Parser.
  std::unique_ptr<DcXmlModelMapping> DcXmlModelMapping::s_instance(nullptr);
  
  DcXmlModelMapping& DcXmlModelMapping::Instance()
  {
      if (nullptr == s_instance) {
          s_instance = std::unique_ptr<DcXmlModelMapping>(new DcXmlModelMapping());
      }
  
      return *s_instance;
  }
  
  DcXmlModelMapping::DcXmlModelMapping()
      : m_services(nullptr)
      , m_networks()
  {
  }
  
  DcXmlModelMapping::~DcXmlModelMapping()
  {
      this->cleanInternals();
  }
  
  bool DcXmlModelMapping::loadConfiguration(const QString& configDir, const QString& fileName)
  {
      // Check if the internal service parser is instantiated. If not, do so.
      // The network parsers will be parsed "on the way".
      if (nullptr != m_services || !m_networks.isEmpty()) {
          // clean up the internal structures.. We obviously want to (re)load the configuration.
          cleanInternals();
      }
  
      // Start the services configuration...
      m_services = QSharedPointer<DcXmlEtlServices>(new DcXmlEtlServices(configDir + "/" + fileName));
      for (const QString& serviceName : m_services->getServiceNames()) {
          QSharedPointer<DcXmlEtlNetwork> pNetwork = QSharedPointer<DcXmlEtlNetwork>(new DcXmlEtlNetwork(configDir + "/" + m_services->getServiceConfigByName(serviceName)));
  
          if (nullptr != pNetwork) {
              m_networks.insert(serviceName, pNetwork);
          }
      }
  
      return true;
  }
  
  bool DcXmlModelMapping::loadConfiguration(const QString& fileName)
  {
      return loadConfiguration(DCXmlConfig::Instance().getConfigPath(), fileName);
  }
  
  QStringList DcXmlModelMapping::getServices() const
  {
      return QStringList(m_networks.keys());
  }
  
  QString DcXmlModelMapping::getServiceId(const QString& _serviceName) const
  {
      return m_services->getServiceIdByName(_serviceName);
  }
  
  QStringList DcXmlModelMapping::getNetworksOfService(const QString& _serviceName) const
  {
      return m_networks.value(_serviceName)->getNetworkNames();
  }
  
  QList<QSharedPointer<ObjectData>> DcXmlModelMapping::getObjectsOfNetwork(const QString& _networkName) const
  {
      // Find the network pointer containing the networkName.
      QSharedPointer<DcXmlEtlNetwork> pNetwork = findNetworkByName(_networkName);
      if (nullptr != pNetwork) {
          return pNetwork->getObjectsOfNetwork(_networkName);
      }
      return QList<QSharedPointer<ObjectData>>();
  }
  
  Connections DcXmlModelMapping::getConnectionsOfNetwork(const QString& _networkName) const
  {
      // Find the network pointer containing the networkName.
      QSharedPointer<DcXmlEtlNetwork> pNetwork = findNetworkByName(_networkName);
      if (nullptr != pNetwork) {
          return pNetwork->getConnectionsOfNetwork(_networkName);
      }
      return Connections();
  }
  
  QStringList DcXmlModelMapping::getInputVariables(const QString& _networkName) const
  {
      // Find the network pointer containing the networkName.
      QSharedPointer<DcXmlEtlNetwork> pNetwork = findNetworkByName(_networkName);
      if (nullptr != pNetwork) {
          return pNetwork->getInputVariables(_networkName);
      }
      return QStringList();
  }
  
  QStringList DcXmlModelMapping::getOutputVariables(const QString& _networkName) const
  {
      QSharedPointer<DcXmlEtlNetwork> pNetwork = findNetworkByName(_networkName);
      if (nullptr != pNetwork) {
          return pNetwork->getOutputVariables(_networkName);
      }
      return QStringList();
  }
  
  QThread::Priority DcXmlModelMapping::getPrioByNetworkName(const QString& _networkName) const
  {
      // Find the network pointer containing the networkName.
      QSharedPointer<DcXmlEtlNetwork> pNetwork = findNetworkByName(_networkName);
      if (nullptr != pNetwork) {
          return pNetwork->getPrioByNetworkName(_networkName);
      }
      return QThread::NormalPriority;
  }
  
  void DcXmlModelMapping::cleanInternals()
  {
      // Retrieve every network object and destroy it...
      if (!m_networks.isEmpty()) {
          for (const QString& serviceName : QStringList(m_networks.keys())) {
              // Clear the reference. If it was the last (only) reference
              // the pointer wil be deleted.
              m_networks.take(serviceName).clear();
          }
      }
  
      m_services.clear();
  }
  
  QSharedPointer<DcXmlEtlNetwork> DcXmlModelMapping::findNetworkByName(const QString& networkName) const
  {
      for (QSharedPointer<DcXmlEtlNetwork> pNetwork : m_networks.values()) {
          if (pNetwork->getNetworkNames().contains(networkName)) {
              return pNetwork;
          }
      }
      return QSharedPointer<DcXmlEtlNetwork>();
  }