Files
scandocs/uni/masterarbeit/source/moversight/ms/PeerResources.cc
2014-06-30 13:58:10 +02:00

265 lines
7.7 KiB
C++

#include "PeerResources.h"
namespace ubeeme {
namespace moversight {
const PeerResources::ResourceValue PeerResources::MINIMUM_RESOURCE_VALUE;
const PeerResources::ResourceValue PeerResources::MAXIMUM_RESOURCE_VALUE;
/**
* @brief Creates a peer resource object. The default resource value is
* MAXIMUM_RESOURCE_VALUE.
*/
PeerResources::PeerResources() : resources(MAXIMUM_RESOURCE_VALUE) {
}
/**
* @brief Creates a peer resource object, based on the given resource
* value.
* @param rv The resource value of the peer.
*/
PeerResources::PeerResources(const ResourceValue & rv) {
setResourceValue(rv);
}
/**
* @brief Copy constructor.
* @param other The instance to copy
*/
PeerResources::PeerResources(const PeerResources & other) {
operator=(other);
}
/**
* @brief Destructor
*/
PeerResources::~PeerResources() {
}
/**
* @brief Permits access to the peer resource value.
* @return The desired resource value.
*/
PeerResources::ResourceValue
PeerResources::getResourceValue() const {
return resources;
}
/**
* @brief Sets the peer resource value.
* @param rv The resource value to set.
*/
void
PeerResources::setResourceValue(const ResourceValue & rv) {
if (rv < MINIMUM_RESOURCE_VALUE) {
resources = MINIMUM_RESOURCE_VALUE;
}
else if (rv > MAXIMUM_RESOURCE_VALUE) {
resources = MAXIMUM_RESOURCE_VALUE;
}
else {
resources = rv;
}
}
/**
* @brief Assignment operator
* @param other The instance to assign.
* @return A reference to the local object
*/
PeerResources &
PeerResources::operator=(const PeerResources & other) {
if (this != &other) {
setResourceValue(other.resources);
}
return *this;
}
/**
* @brief Less operator.
* @param rhs The operand to compare to.
* @return True, if the given operand greater or equal to the local one, false otherwise.
*/
bool
PeerResources::operator<(const PeerResources & rhs) const {
return resources < rhs.resources;
}
/**
* @brief Greate operator.
* @param rhs The operand to compare to.
* @return True, if the given operand less or equal to the local one, false otherwise.
*/
bool
PeerResources::operator>(const PeerResources & rhs) const {
return resources > rhs.resources;
}
/**
* @brief Less equal operator.
* @param rhs The operand to compare to.
* @return True, if the given operand greater as the local one, false otherwise.
*/
bool
PeerResources::operator<=(const PeerResources & rhs) const {
return resources <= rhs.resources;
}
/**
* @brief Greater equal operator.
* @param rhs The operand to compare to.
* @return True, if the given operand less as the local one, false otherwise.
*/
bool
PeerResources::operator>=(const PeerResources & rhs) const {
return resources >= rhs.resources;
}
/**
* @brief Equal operator.
* @param rhs The operand to compare to.
* @return True, if the given operand equal to the local one, false otherwise.
*/
bool
PeerResources::operator==(const PeerResources & rhs) const {
return resources == rhs.resources;
}
/**
* @brief Not equal operator.
* @param rhs The operand to compare to.
* @return True, if the given operand not equal to the local one, false otherwise.
*/
bool
PeerResources::operator!=(const PeerResources & rhs) const {
return resources != rhs.resources;
}
/**
* @brief Add and assignment operation
* @param rhs The value to add.
* @return A reference to the local object.
*/
PeerResources &
PeerResources::operator+=(const PeerResources & rhs) {
setResourceValue(resources + rhs.resources);
return *this;
}
/**
* @brief Subtract and assignment operation
* @param rhs The value to subtract.
* @return A reference to the local object.
*/
PeerResources &
PeerResources::operator-=(const PeerResources & rhs) {
setResourceValue(resources - rhs.resources);
return *this;
}
/**
* @brief Addition operation
* @param rhs The value to add.
* @return The result.
*/
PeerResources
PeerResources::operator+(const PeerResources & rhs) {
return PeerResources(resources + rhs.resources);
}
/**
* @brief Subtraction operation
* @param rhs The value to subtract.
* @return The result.
*/
PeerResources
PeerResources::operator-(const PeerResources & rhs) {
return PeerResources(resources - rhs.resources);
}
/**
* @brief Division.
* @param rhs The divisor.
* @return The result.
*/
PeerResources
PeerResources::operator/(const PeerResources & rhs) {
return PeerResources(resources / rhs.resources);
}
/**
* @brief Increment.
* @return A reference to the local instance.
*/
PeerResources &
PeerResources::operator++() {
setResourceValue(resources + 1);
return *this;
}
/**
* @brief Decrement
* @return A reference to the local instance.
*/
PeerResources &
PeerResources::operator--() {
setResourceValue(resources - 1);
return *this;
}
/**
* @brief Increment.
* @return A reference to the local instance.
*/
PeerResources
PeerResources::operator++(int) {
PeerResources result(*this);
++(*this);
return result;
}
/**
* @brief Decrement
* @return A reference to the local instance.
*/
PeerResources
PeerResources::operator--(int) {
PeerResources result(*this);
--(*this);
return result;
}
/**
* @brief Serialize / DeSerialize method.
* @param archive The archive to read/write.
*/
void
PeerResources::set(Archive & archive) {
archive(resources);
}
/**
* @brief Output operator
* @param s The stream to manipulate.
* @param pr The peer resource to output.
* @return The given stream, enhanced by a representation of the given peer resource.
*/
std::ostream & operator<<(std::ostream & s, const PeerResources & pr) {
s << pr.getResourceValue();
return s;
}
/**
* @brief Subtraction operation
* @param a The minuend
* @param b The subtrahend
* @return The result of the operation.
*/
PeerResources operator -(const PeerResources & a, const PeerResources & b) {
return PeerResources(a.getResourceValue() - b.getResourceValue());
}
}
}