Skip to content
Snippets Groups Projects
Commit 06be8a21 authored by Steven Murray's avatar Steven Murray
Browse files

Added StorageClassAndUsageCount

parent 5a3f273f
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ set (CLIENT_LIB_SRC_FILES
MockClientAPI.cpp
SecurityIdentity.cpp
StorageClass.cpp
StorageClassAndUsageCount.cpp
UserIdentity.cpp)
add_library (ctaclient SHARED
......
#define __STDC_LIMIT_MACROS
#include "StorageClassAndUsageCount.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::StorageClassAndUsageCount::StorageClassAndUsageCount():
m_usageCount(0) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::StorageClassAndUsageCount::StorageClassAndUsageCount(
const StorageClass &storageClass):
m_storageClass(storageClass),
m_usageCount(0) {
}
//------------------------------------------------------------------------------
// getStorageClass
//------------------------------------------------------------------------------
const cta::StorageClass &cta::StorageClassAndUsageCount::getStorageClass()
const throw() {
return m_storageClass;
}
//------------------------------------------------------------------------------
// getUsageCount
//------------------------------------------------------------------------------
uint64_t cta::StorageClassAndUsageCount::getUsageCount() const throw() {
return m_usageCount;
}
//------------------------------------------------------------------------------
// incUsageCount
//------------------------------------------------------------------------------
void cta::StorageClassAndUsageCount::incUsageCount() {
if(UINT64_MAX == m_usageCount) {
std::ostringstream message;
message << "Cannot increment usage count of storage class " <<
m_storageClass.name << " because its maximum value of UINT64_MAX has "
"already been reached";
throw Exception(message.str());
}
m_usageCount++;
}
//------------------------------------------------------------------------------
// decUsageCount
//------------------------------------------------------------------------------
void cta::StorageClassAndUsageCount::decUsageCount() {
if(0 == m_usageCount) {
std::ostringstream message;
message << "Cannot decrement usage count of storage class " <<
m_storageClass.name << " because it is already at zero";
throw Exception(message.str());
}
m_usageCount--;
}
#pragma once
#include "Exception.hpp"
#include "StorageClass.hpp"
#include <sstream>
namespace cta {
/**
* Class used to store a storage class and it usage count.
*/
class StorageClassAndUsageCount {
public:
/**
* Constructor.
*
* Initialisez the usage count to 0.
*/
StorageClassAndUsageCount();
/**
* Constructor.
*
* Initialisez the usage count to 0.
*/
StorageClassAndUsageCount(const StorageClass &storageClass);
/**
* Returns the storage class.
*/
const StorageClass &getStorageClass() const throw();
/**
* Returns the usage count.
*/
uint64_t getUsageCount() const throw();
/**
* Increments the usage count by 1.
*/
void incUsageCount();
/**
* Decrements the usage count by 1.
*/
void decUsageCount();
private:
/**
* The storage class.
*/
StorageClass m_storageClass;
/**
* The usage count.
*/
uint64_t m_usageCount;
}; // class StorageClassAndUsageCount
} // namespace cta
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment