AI Watch A1
Multi-person 3D skeleton detection using Intel RealSense and OpenPose with Kafka support.
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
UsageManager Class Reference

UsageManager class is a utility class that helps with configuration parameters. More...

#include <UsageManager.hpp>

Public Member Functions

 UsageManager (UsageManager &other)=delete
 Disabling the possibility to clone the Singleton object. Singletons should not be cloneable. More...
 
void operator= (const UsageManager &)=delete
 Disabling the possibility to assign a Singleton object. Singletons should not be assignable. More...
 
virtual ~UsageManager ()
 Destroy the Usage Manager object. More...
 
int * get_argc (void)
 Get the argc's pointer. More...
 
char *** get_argv (void)
 Get the argv's pointer. More...
 

Static Public Member Functions

static UsageManagergetInstance (int *argc, char ***argv, const int expected_argc, const char *expectedUsageMessage)
 Get the unique class instance, given input parameters. This method should be called the first time when we want to create a reference to the object of this class. More...
 
static UsageManagergetInstance (void)
 Get the unique class instance. This methods should be called in the following scenario: when we just want to retrieve the reference to the object of this class. More...
 

Private Member Functions

const int get_expected_argc (void)
 Get the expected argc value. More...
 
const char * get_expectedUsageMessage (void)
 Get the expected usage message. More...
 
void checkUsage (void)
 Checks if the configuration parameters are valid and if they are equal to the number of the expected parameters. If not, it raises an error. More...
 
 UsageManager (int *argc=nullptr, char ***argv=nullptr, const int expected_argc=0, const char *expectedUsageMessage=nullptr)
 Construct a new UsageManager object. More...
 

Private Attributes

int * argc
 configuration parameters' number. More...
 
char *** argv
 configuration parameters. More...
 
const int expected_argc
 expected configuration parameters' number. More...
 
const char * expectedUsageMessage
 a simple message that lets the user understand how to properly run the executable. More...
 

Static Private Attributes

static UsageManagersharedInstance { nullptr }
 The field for storing the singleton instance. More...
 
static std::mutex singletonMutex
 Mutex for thread-safe access. More...
 

Detailed Description

UsageManager class is a utility class that helps with configuration parameters.

UsageManager class is a class that keeps track of configuration parameters read from a configuration file, checks if these parameters are valid, and if they are equal to the number of the expected parameters. Furthermore, it offers an on-demand service by returning the parameters read from the file to the callers.

Definition at line 27 of file UsageManager.hpp.

Constructor & Destructor Documentation

◆ UsageManager() [1/2]

UsageManager::UsageManager ( int *  argc = nullptr,
char ***  argv = nullptr,
const int  expected_argc = 0,
const char *  expectedUsageMessage = nullptr 
)
inlineprivate

Construct a new UsageManager object.

Parameters
argcconfiguration parameters' number.
argvconfiguration parameters.
expected_argcexpected configuration parameters' number.
expectedUsageMessagea simple message that lets the user understand how to properly run the executable.

Definition at line 84 of file UsageManager.hpp.

85 checkUsage();
86 }
void checkUsage(void)
Checks if the configuration parameters are valid and if they are equal to the number of the expected ...
const char * expectedUsageMessage
a simple message that lets the user understand how to properly run the executable.
int * argc
configuration parameters' number.
char *** argv
configuration parameters.
const int expected_argc
expected configuration parameters' number.

References checkUsage().

Referenced by getInstance().

◆ UsageManager() [2/2]

UsageManager::UsageManager ( UsageManager other)
delete

Disabling the possibility to clone the Singleton object. Singletons should not be cloneable.

Parameters
other

◆ ~UsageManager()

UsageManager::~UsageManager ( )
virtual

Destroy the Usage Manager object.

Definition at line 37 of file UsageManager.cpp.

37 {
38 for (unsigned int i = 0; i < * get_argc(); i++) delete [] (* get_argv())[i];
39 delete get_argc();
40 delete get_argv();
41 delete sharedInstance;
42}
int * get_argc(void)
Get the argc's pointer.
char *** get_argv(void)
Get the argv's pointer.
static UsageManager * sharedInstance
The field for storing the singleton instance.

References get_argc(), get_argv(), and sharedInstance.

Member Function Documentation

◆ checkUsage()

void UsageManager::checkUsage ( void  )
private

Checks if the configuration parameters are valid and if they are equal to the number of the expected parameters. If not, it raises an error.

Definition at line 20 of file UsageManager.cpp.

20 {
21 if (* get_argc() != get_expected_argc()) {
22 std::string buffer = "Usage: ./" + std::string((* get_argv())[programNameOffset]) + std::string(get_expectedUsageMessage()) + " -- " + std::string(CHECK_USAGE_SCOPE);
23 CV_Error(CHECK_USAGE_ERROR, buffer);
24 }
25}
const char * get_expectedUsageMessage(void)
Get the expected usage message.
const int get_expected_argc(void)
Get the expected argc value.
static const char * CHECK_USAGE_SCOPE
Definition: constants.hpp:18
static const short int programNameOffset
Definition: constants.hpp:61
static const short int CHECK_USAGE_ERROR
Definition: constants.hpp:17

References CHECK_USAGE_ERROR, CHECK_USAGE_SCOPE, get_argc(), get_argv(), get_expected_argc(), get_expectedUsageMessage(), and programNameOffset.

Referenced by UsageManager().

◆ get_argc()

int * UsageManager::get_argc ( void  )

Get the argc's pointer.

Returns
int*

Definition at line 56 of file UsageManager.cpp.

56 {
57 return this->argc;
58}

References argc.

Referenced by checkUsage(), and ~UsageManager().

◆ get_argv()

char *** UsageManager::get_argv ( void  )

Get the argv's pointer.

Returns
char ***

Definition at line 60 of file UsageManager.cpp.

60 {
61 std::stringstream openPoseTerminalCommand;
62 UsageManager * usageManagerInstance = UsageManager::getInstance();
63 if (usageManagerInstance == nullptr) CV_Error(USAGE_MANAGER_NULLPTR_ERROR, USAGE_MANAGER_NULLPTR_SCOPE);
64 return usageManagerInstance->argv;
65}
UsageManager class is a utility class that helps with configuration parameters.
static UsageManager * getInstance(void)
Get the unique class instance. This methods should be called in the following scenario: when we just ...
static const short int USAGE_MANAGER_NULLPTR_ERROR
Definition: constants.hpp:35
static const char * USAGE_MANAGER_NULLPTR_SCOPE
Definition: constants.hpp:36

References argv, getInstance(), USAGE_MANAGER_NULLPTR_ERROR, and USAGE_MANAGER_NULLPTR_SCOPE.

Referenced by checkUsage(), OpenCV_Manager::getVideoFramesCV(), FacadeSingleton::sendData(), CleanCommand::setCommand(), OpenPoseCommand::setCommand(), MoveCommand::setCommand(), OpenCV_Manager::showSkeletonsCV(), and ~UsageManager().

◆ get_expected_argc()

const int UsageManager::get_expected_argc ( void  )
private

Get the expected argc value.

Returns
const int

Definition at line 27 of file UsageManager.cpp.

27 {
28 return this->expected_argc;
29}

References expected_argc.

Referenced by checkUsage().

◆ get_expectedUsageMessage()

const char * UsageManager::get_expectedUsageMessage ( void  )
private

Get the expected usage message.

Returns
const char *

Definition at line 31 of file UsageManager.cpp.

31 {
32 return this->expectedUsageMessage;
33}

References expectedUsageMessage.

Referenced by checkUsage().

◆ getInstance() [1/2]

UsageManager * UsageManager::getInstance ( int *  argc,
char ***  argv,
const int  expected_argc,
const char *  expectedUsageMessage 
)
static

Get the unique class instance, given input parameters. This method should be called the first time when we want to create a reference to the object of this class.

Parameters
argcconfiguration parameters' number.
argvconfiguration parameters.
expected_argcexpected configuration parameters' number.
expectedUsageMessagea simple message that lets the user understand how to properly run the executable.
Returns
UsageManager *

Definition at line 44 of file UsageManager.cpp.

44 {
45 std::lock_guard <std::mutex> lock(singletonMutex);
47 return sharedInstance;
48}
static std::mutex singletonMutex
Mutex for thread-safe access.
UsageManager(int *argc=nullptr, char ***argv=nullptr, const int expected_argc=0, const char *expectedUsageMessage=nullptr)
Construct a new UsageManager object.

References argc, argv, expected_argc, expectedUsageMessage, sharedInstance, singletonMutex, and UsageManager().

◆ getInstance() [2/2]

UsageManager * UsageManager::getInstance ( void  )
static

Get the unique class instance. This methods should be called in the following scenario: when we just want to retrieve the reference to the object of this class.

Returns
UsageManager*

Definition at line 50 of file UsageManager.cpp.

50 {
51 std::lock_guard <std::mutex> lock(singletonMutex);
52 if (sharedInstance == nullptr) return nullptr;
53 return sharedInstance;
54}

References sharedInstance, and singletonMutex.

Referenced by FacadeSingleton::FacadeSingleton(), get_argv(), OpenCV_Manager::getVideoFramesCV(), CleanCommand::setCommand(), OpenPoseCommand::setCommand(), and MoveCommand::setCommand().

◆ operator=()

void UsageManager::operator= ( const UsageManager )
delete

Disabling the possibility to assign a Singleton object. Singletons should not be assignable.

Member Data Documentation

◆ argc

int* UsageManager::argc
private

configuration parameters' number.

Definition at line 43 of file UsageManager.hpp.

Referenced by get_argc(), and getInstance().

◆ argv

char*** UsageManager::argv
private

configuration parameters.

Definition at line 47 of file UsageManager.hpp.

Referenced by get_argv(), and getInstance().

◆ expected_argc

const int UsageManager::expected_argc
private

expected configuration parameters' number.

Definition at line 51 of file UsageManager.hpp.

Referenced by get_expected_argc(), and getInstance().

◆ expectedUsageMessage

const char* UsageManager::expectedUsageMessage
private

a simple message that lets the user understand how to properly run the executable.

Definition at line 55 of file UsageManager.hpp.

Referenced by get_expectedUsageMessage(), and getInstance().

◆ sharedInstance

UsageManager * UsageManager::sharedInstance { nullptr }
staticprivate

The field for storing the singleton instance.

Definition at line 32 of file UsageManager.hpp.

Referenced by getInstance(), and ~UsageManager().

◆ singletonMutex

std::mutex UsageManager::singletonMutex
staticprivate

Mutex for thread-safe access.

Definition at line 36 of file UsageManager.hpp.

Referenced by getInstance().


The documentation for this class was generated from the following files: