Created
July 1, 2022 16:04
-
-
Save diegopso/51e9da7fd7350c6f7706cc165d9622fa to your computer and use it in GitHub Desktop.
Static Variable Omnet++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TopologyContainer.h" | |
using namespace sdicn; | |
cTopology TopologyContainer::instance; | |
bool TopologyContainer::isInitialized = false; | |
void TopologyContainer::initialize() { | |
TopologyContainer::instance.extractByProperty("networkNode"); | |
TopologyContainer::isInitialized = true; | |
} | |
void TopologyContainer::clear() { | |
TopologyContainer::isInitialized = false; | |
} | |
cTopology& TopologyContainer::getInstance() | |
{ | |
if (!TopologyContainer::isInitialized) { | |
TopologyContainer::initialize(); | |
} | |
return TopologyContainer::instance; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <omnetpp.h> | |
using namespace omnetpp; | |
namespace sdicn { | |
class TopologyContainer { | |
public: | |
static cTopology& getInstance(); | |
static void clear(); | |
TopologyContainer(TopologyContainer &other) { | |
throw cRuntimeError("Unauthorized operation."); | |
} | |
void operator=(const TopologyContainer &) { | |
throw cRuntimeError("Unauthorized operation."); | |
} | |
protected: | |
static cTopology instance; | |
static bool isInitialized; | |
TopologyContainer() { } | |
static void initialize(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment