danicoin/src/P2p/P2pContextOwner.cpp

35 lines
993 B
C++
Raw Normal View History

// Copyright (c) 2011-2016 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2015-05-27 12:08:46 +00:00
2015-07-30 15:22:07 +00:00
#include "P2pContextOwner.h"
2015-05-27 12:08:46 +00:00
#include <cassert>
2015-07-30 15:22:07 +00:00
#include "P2pContext.h"
2015-05-27 12:08:46 +00:00
namespace CryptoNote {
2015-07-30 15:22:07 +00:00
P2pContextOwner::P2pContextOwner(P2pContext* ctx, ContextList& contextList) : contextList(contextList) {
contextIterator = contextList.insert(contextList.end(), ContextList::value_type(ctx));
2015-05-27 12:08:46 +00:00
}
2015-07-30 15:22:07 +00:00
P2pContextOwner::P2pContextOwner(P2pContextOwner&& other) : contextList(other.contextList), contextIterator(other.contextIterator) {
other.contextIterator = contextList.end();
2015-05-27 12:08:46 +00:00
}
2015-07-30 15:22:07 +00:00
P2pContextOwner::~P2pContextOwner() {
if (contextIterator != contextList.end()) {
contextList.erase(contextIterator);
}
2015-05-27 12:08:46 +00:00
}
2015-07-30 15:22:07 +00:00
P2pContext& P2pContextOwner::get() {
assert(contextIterator != contextList.end());
return *contextIterator->get();
2015-05-27 12:08:46 +00:00
}
2015-07-30 15:22:07 +00:00
P2pContext* P2pContextOwner::operator -> () {
return &get();
2015-05-27 12:08:46 +00:00
}
}