Salome HOME
Auto-formatting according to the defined code standard.
[modules/shaper.git] / src / Config / Config_ModuleReader.cpp
1 /*
2  * Config_ModuleReader.cpp
3  *
4  *  Created on: Mar 20, 2014
5  *      Author: sbh
6  */
7
8 #include <Config_ModuleReader.h>
9 #include <Config_FeatureReader.h>
10
11 #include <libxml\parser.h>
12 #include <libxml\tree.h>
13
14 #ifdef _DEBUG
15 #include <iostream>
16 #endif
17
18 //Hardcoded xml entities
19 // * Nodes
20 const static char* NODE_PLUGIN = "plugin";
21 const static char* NODE_PLUGINS = "plugins";
22
23 // * Properties
24 const static char* PLUGINS_MODULE = "module";
25 const static char* PLUGIN_CONFIG = "configuration";
26 const static char* PLUGIN_LIBRARY = "library";
27
28 Config_ModuleReader::Config_ModuleReader()
29     : Config_XMLReader("plugins.xml"), m_isAutoImport(false)
30 {
31 }
32
33 Config_ModuleReader::~Config_ModuleReader()
34 {
35 }
36
37 /*
38  * Get module name from plugins.xml
39  * (property "module")
40  */
41 std::string Config_ModuleReader::getModuleName()
42 {
43   xmlNodePtr aRoot = findRoot();
44   return getProperty(aRoot, PLUGINS_MODULE);
45 }
46
47 /*
48  *
49  */
50 void Config_ModuleReader::processNode(xmlNodePtr theNode)
51 {
52   if (isNode(theNode, NODE_PLUGIN, NULL)) {
53     std::string aPluginName = getProperty(theNode, PLUGIN_CONFIG);
54     if (m_isAutoImport)
55       importPlugin(aPluginName);
56     m_pluginsList.push_back(aPluginName);
57   }
58 }
59
60 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
61 {
62   return isNode(theNode, NODE_PLUGINS, NULL);
63 }
64
65 void Config_ModuleReader::importPlugin(const std::string& thePluginName)
66 {
67   Config_FeatureReader aReader(thePluginName);
68   aReader.readAll();
69 }
70
71 void Config_ModuleReader::setAutoImport(bool enabled)
72 {
73   m_isAutoImport = enabled;
74 }
75
76 const std::list<std::string>& Config_ModuleReader::pluginsList() const
77 {
78   return m_pluginsList;
79 }