- Installation
- MarsTech Compiler Header
- MarsTech Objects Headers
- Usage Example
- Source code documentation
- License
MarsTech Headers is C++ project which contains headers usefull in MarsTech projects. There will usually be macros definitions used in MarsTech projects.
MHEADERS is header only project/library - there is no static or dynamic library. You can download repository and include header files to your project.
No configuration is needed - just include MHEADERS header files to your project.
Contains implementations and all definitions for compiler settings (e.g. macros to disable or enable warnings). Please see source code documentation for more information. Example:
#include "mheaders/MsvCompiler.h"
MSV_DISABLE_ALL_WARNINGS
//include 3rdParty library which generates or can generate warnings
#include "spdlog/spdlog.h"
MSV_ENABLE_WARNINGS
Contains MarsTech objects implementations. They are base classes which implements basic methods. Please see source code documentation for more information.
Loggable object implements logger member and its initialization in constructors. Just inherit from this class and your class is ready for logging.
Example:
#include "MsvLoggable.h"
class LoggingClass:
public MsvLoggable
{
public:
LoggingClass(std::shared_ptr<MsvLogger> spLogger):
MsvLoggable(spLogger)
{
//logger is already initialized -> just set it and use it
}
LoggingClass(std::shared_ptr<IMsvLoggerProvider> spLoggerProvider:
MsvLoggable(spLoggerProvider, "MyLoggerName")
{
//logger is not initialized -> get logger from logger provider
}
void SomeMethodWhichLogs()
{
//m_spLogger is inherited from MsvLoggable
MSV_LOG_INFO(m_spLogger, "Some log message.");
}
};
Lockable object implements lock member and its initialization in constructors. Just inherit from this class and your class is ready for locking (thread synchronization).
Example:
#include "MsvLockable.h"
class LockingClass:
public MsvLockable
{
public:
LockingClass():
MsvLockable()
{
//m_lock is created
}
void SomeMethodWhichLocks()
{
//m_lock is inherited from MsvLockable
std::lock_guard<std::recursive_mutex> lock(m_lock);
}
};
Initiable object inherits from lockable object and implements initialized flag, which is set to false in its constructor and initialize flag check method. Just inherit from this class and your class is ready for locking and initializing (Initialize and Unitialize methods should be implemented by a child).
Example:
#include "MsvInitiliable.h"
class InitiliableClass:
public MsvInitiliable<InitiliableClassInterface>
{
public:
InitiliableClass():
MsvInitiliable<InitiliableClassInterface>()
{
//m_lock is created
//m_initialized is set to false
}
void SomeMethodWhichLocksAndChecksIntializeFlag()
{
//m_lock is inherited from MsvLockable (through MsvInitiliable)
std::lock_guard<std::recursive_mutex> lock(m_lock);
//Initialized (and m_initialized) are inherited from MsvInitiliable
if (Initialized())
{
return;
}
}
};
Runnable object inherits from initialiable object and implements running flag, which is set to false in its constructor and running flag check method. Just inherit from this class and your class is ready for locking, initializing and starting/stopping (Start and Stop methods should be implemented by a child).
Example:
#include "MsvRunnable.h"
class RunnableClass:
public MsvRunnable<RunnableClassInterface>
{
public:
RunnableClass():
MsvRunnable<RunnableClassInterface>()
{
//m_lock is created
//m_initialized is set to false
//m_running is set to false
}
void SomeMethodWhichLocksChecksIntializeAndRunningFlag()
{
//m_lock is inherited from MsvLockable (through MsvInitiliable)
std::lock_guard<std::recursive_mutex> lock(m_lock);
//Initialized (and m_initialized) are inherited from MsvInitiliable (through MsvRunnable)
if (Initialized())
{
return;
}
//Running (and m_running) are inherited from MsvRunnable
if (Running())
{
return;
}
}
};
MarsTech object inherits from runnable object and loggable object. Just inherit from this class and your class is ready for logging, locking, initializing and starting/stopping (Initialize, Unitialize, Start and Stop methods should be implemented by a child).
Example:
#include "MsvObject.h"
class ObjectClass:
public MsvObject<ObjectClassInterface>
{
public:
ObjectClass(std::shared_ptr<MsvLogger> spLogger):
MsvObject<ObjectClassInterface>(spLogger)
{
//logger is already initialized -> just set it and use it
//m_lock is created
//m_initialized is set to false
//m_running is set to false
}
ObjectClass(std::shared_ptr<IMsvLoggerProvider> spLoggerProvider:
MsvObject<ObjectClassInterface>(spLoggerProvider, "MyLoggerName")
{
//logger is not initialized -> get logger from logger provider
//m_lock is created
//m_initialized is set to false
//m_running is set to false
}
void SomeMethodWhichLocksChecksIntializeAndRunningFlagAndLogs()
{
//m_lock is inherited from MsvLockable (through MsvObject)
std::lock_guard<std::recursive_mutex> lock(m_lock);
//Initialized (and m_initialized) are inherited from MsvInitiliable (through MsvObject)
if (Initialized())
{
return;
}
//Running (and m_running) are inherited from MsvRunnable (through MsvObject)
if (Running())
{
return;
}
//m_spLogger is inherited from MsvLoggable (through MsvObject)
MSV_LOG_INFO(m_spLogger, "Some log message.");
}
};
There is also an usage example which uses the most of MarsTech projects and libraries. Its source codes and readme can be found at:
You can find generated source code documentation at https://www.marstech.cz/projects/mheaders/1.0.1/doc.
This project is released under GNU General Public License version 3. If you can not or do not want to accept GNU GPLv3 license and you would like to use this project under another license, please contact me on info@marstech.cz or visit www.marstech.cz.