PageRenderTime 26ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/topology/physicalNetworkStoreFactory.cpp

https://github.com/deltaforge/nebu-common-cpp
C++ | 44 lines | 33 code | 9 blank | 2 comment | 1 complexity | d03205b08c1dec24473087ebc2e80334 MD5 | raw file
 1
 2#include "nebu/topology/physicalNetworkStoreFactory.h"
 3#include "nebu/util/xmlUtil.h"
 4
 5// Using declarations - tinyxml2
 6using tinyxml2::XMLAttribute;
 7// Using declarations - standard library
 8using std::make_shared;
 9using std::shared_ptr;
10using std::string;
11
12namespace nebu
13{
14	namespace common
15	{
16		shared_ptr<PhysicalNetworkStoreFactory> PhysicalNetworkStoreFactory::instance;
17
18		const string PhysicalNetworkStoreFactory::ROOT_NAME = "store";
19		const string PhysicalNetworkStoreFactory::ATTR_ID = "id";
20
21		shared_ptr<PhysicalNetworkStoreFactory> PhysicalNetworkStoreFactory::getInstance()
22		{
23			if (!PhysicalNetworkStoreFactory::instance) {
24				PhysicalNetworkStoreFactory::setInstance(make_shared<PhysicalNetworkStoreFactory>());
25			}
26			return PhysicalNetworkStoreFactory::instance;
27		}
28		void PhysicalNetworkStoreFactory::setInstance(std::shared_ptr<PhysicalNetworkStoreFactory> instance)
29		{
30			PhysicalNetworkStoreFactory::instance = instance;
31		}
32
33		Traits<PhysicalNetworkStore>::Ptr PhysicalNetworkStoreFactory::parseXML(const tinyxml2::XMLElement *elem) const
34		{
35			XMLUtil::verifyElementName(elem, PhysicalNetworkStoreFactory::ROOT_NAME);
36
37			const XMLAttribute *idAttr = XMLUtil::findAttribute(elem, PhysicalNetworkStoreFactory::ATTR_ID, XMLUtil::MANDATORY);
38			Traits<PhysicalNetworkStore>::Ptr localStore = Traits<PhysicalNetworkStore>::MakePtr(idAttr->Value());
39
40			return localStore;
41		}
42
43	}
44}