|
2 | 2 | * @file Model.cpp |
3 | 3 | * |
4 | 4 | * @ingroup Simulator/Core |
5 | | - * |
| 5 | + * |
6 | 6 | * @brief Implementation of Model for the graph-based networks. |
7 | 7 | * |
8 | 8 | * The network is composed of 3 superimposed 2-d arrays: vertices, edges, and |
9 | 9 | * summation points. |
10 | 10 | * |
11 | 11 | * Edges in the edge map are located at the coordinates of the vertex |
12 | 12 | * from which they receive output. Each edge stores a pointer into a |
13 | | - * summation point. |
| 13 | + * summation point. |
14 | 14 | */ |
15 | 15 |
|
16 | 16 | #include "Model.h" |
|
23 | 23 | /// Constructor |
24 | 24 | Model::Model() |
25 | 25 | { |
| 26 | + // Get a copy of the console logger to use in the case of errors |
| 27 | + log4cplus::Logger consoleLogger = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("console")); |
| 28 | + |
26 | 29 | // Reference variable used to get class type from ParameterManager. |
27 | 30 | string type; |
28 | 31 |
|
29 | 32 | // Create Layout class using type definition from configuration file. |
30 | 33 | ParameterManager::getInstance().getStringByXpath("//LayoutParams/@class", type); |
31 | 34 | layout_ = Factory<Layout>::getInstance().createType(type); |
32 | 35 |
|
| 36 | + // If the factory returns an error (nullptr), exit |
| 37 | + if (layout_ == nullptr) { |
| 38 | + LOG4CPLUS_INFO(consoleLogger, "INVALID CLASS: " + type); |
| 39 | + exit(EXIT_FAILURE); |
| 40 | + } |
| 41 | + |
33 | 42 | // Create Connections class using type definition from configuration file. |
34 | 43 | ParameterManager::getInstance().getStringByXpath("//ConnectionsParams/@class", type); |
35 | 44 | connections_ = Factory<Connections>::getInstance().createType(type); |
36 | 45 |
|
| 46 | + // If the factory returns an error (nullptr), exit |
| 47 | + if (connections_ == nullptr) { |
| 48 | + LOG4CPLUS_INFO(consoleLogger, "INVALID CLASS: " + type); |
| 49 | + exit(EXIT_FAILURE); |
| 50 | + } |
| 51 | + |
37 | 52 | // Create Recorder class using type definition from configuration file. |
38 | 53 | ParameterManager::getInstance().getStringByXpath("//RecorderParams/@class", type); |
39 | 54 | recorder_ = Factory<Recorder>::getInstance().createType(type); |
40 | 55 |
|
| 56 | + // If the factory returns an error (nullptr), exit |
| 57 | + if (recorder_ == nullptr) { |
| 58 | + LOG4CPLUS_INFO(consoleLogger, "INVALID CLASS: " + type); |
| 59 | + exit(EXIT_FAILURE); |
| 60 | + } |
| 61 | + |
41 | 62 | // Get a copy of the file logger to use log4cplus macros |
42 | 63 | fileLogger_ = log4cplus::Logger::getInstance(LOG4CPLUS_TEXT("file")); |
43 | 64 | } |
|
0 commit comments