FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTObject.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTobject_Hm_included
9#define FMTobject_Hm_included
10
11#ifndef NOMINMAX
12 #define NOMINMAX
13#endif // !NOMINMAX
14
15#include <boost/serialization/unique_ptr.hpp>
16#include <boost/serialization/nvp.hpp>
17#include <boost/serialization/export.hpp>
18#include "FMTException.h"
19#include <memory>
20#include <chrono>
21#include <vector>
22
23#if defined _MSC_VER || __MINGW64__ || __CYGWIN__
24
25#else
26 #include <boost/dll/runtime_symbol_info.h>
27#endif
28
29namespace Exception
30{
31 class FMTExceptionHandler;
32}
33
34namespace Logging
35{
36 class FMTLogger;
37}
38
39
40
41namespace Core
42{
43// DocString: FMTObject
49 {
50 public:
51 // DocString: FMTObject::getLogger
57 // DocString: FMTObject::getExceptionHandler
63 // DocString: FMTObject::getRuntimeLocation
68 static std::string getRuntimeLocation();
69 // DocString: FMTObject::getAvailableMemory
74 static unsigned long long getAvailableMemory();
75 // DocString: FMTObject()
80 // DocString: ~FMTObject()
84 virtual ~FMTObject();
85 // DocString: FMTObject(const std::unique_ptr<Exception::FMTExceptionHandler>)
90 FMTObject(const std::unique_ptr<Exception::FMTExceptionHandler> exhandler);
91 // DocString: FMTObject(const FMTObject&)
96 FMTObject(const FMTObject& rhs);
97 // DocString: FMTObject::operator=
103 FMTObject& operator = (const FMTObject& rhs);
104 // DocString: FMTObject::passInLogger
109 virtual void passInLogger(const std::unique_ptr<Logging::FMTLogger>& logger);
110 // DocString: FMTObject::passInExceptionHandler
115 void passInExceptionHandler(const std::unique_ptr<Exception::FMTExceptionHandler>& exhandler);
116 // DocString: FMTObject::redirectLogToFile
121 void redirectLogToFile(const std::string& location);
122 // DocString: FMTObject::setDefaultLogger
126 virtual void setDefaultLogger();
127 // DocString: FMTObject::setQuietLogger
131 virtual void setQuietLogger();
132 // DocString: FMTObject::setTaskLogger
136 virtual void setTaskLogger();
137 // DocString: FMTObject::setDebugLogger
141 virtual void setDebugLogger();
142 // DocString: FMTObject::setDefaultExceptionHandler
147 // DocString: FMTObject::setQuietExceptionHandler
152 // DocString: FMTObject::setDebugExceptionHandler
157 // DocString: FMTObject::setFreeExceptionHandler
162 // DocString: FMTObject::disableNestedExceptions
167 // DocString: FMTObject::enableNestedExceptions
172 // DocString: FMTObject::setErrorsToWarnings
177 void setErrorsToWarnings(const std::vector<Exception::FMTexc>& errors);
178 // DocString: FMTObject::setMaxWarningsBeforeSilenced
183 void setMaxWarningsBeforeSilenced(const size_t& maxwarningcount);
184 // DocString: FMTExceptionHandler::setTerminateStack
188 static void setTerminateStack();
189 // DocString: FMTExceptionHandler::setAbortStack
193 static void setAbortStack();
194 // DocString: FMTObject::serialize
201 friend class boost::serialization::access;
202 template<class Archive>
203 void serialize(Archive& ar, const unsigned int version)
204 {
205 //ar & BOOST_SERIALIZATION_NVP(_exhandler);
206 //ar & BOOST_SERIALIZATION_NVP(_logger);
207 //ar & BOOST_SERIALIZATION_NVP(m_section);
208 }
209 protected:
210 // DocString: FMTObject::_exhandler
212 static std::unique_ptr<Exception::FMTExceptionHandler> _exhandler;
213 // DocString: FMTObject::_logger
215 static std::unique_ptr<Logging::FMTLogger> _logger;
216 // DocString: FMTObject:: forceSave
223 template<class Archive>
224 void forceSave(Archive& ar, const unsigned int version) const
225 {
226 //ar & BOOST_SERIALIZATION_NVP(_exhandler);
227 //ar & BOOST_SERIALIZATION_NVP(_logger);
228 //ar & BOOST_SERIALIZATION_NVP(m_section);
229 }
230 // DocString: FMTObject:: forceLoad
237 template<class Archive>
238 void forceLoad(Archive& ar, const unsigned int version)
239 {
240 //ar & BOOST_SERIALIZATION_NVP(_exhandler);
241 //ar & BOOST_SERIALIZATION_NVP(_logger);
242 setDefaultLogger();
243 setDefaultExceptionHandler();
244 //ar & BOOST_SERIALIZATION_NVP(m_section);
245 }
246 // DocString: FMTObject::checkSignals
250 void checkSignals() const;
251 // DocString: FMTObject::setCplHandler
256 // DocString: FMTObject::getClock
261 static std::chrono::time_point<std::chrono::high_resolution_clock> getClock();
262 // DocString: FMTObject::getDuration
269 template<class chrono>
270 static double getDuration(const std::chrono::time_point<std::chrono::high_resolution_clock>& startclock);
271 // DocString: FMTObject::getDurationInSeconds
277 static std::string getDurationInSeconds(const std::chrono::time_point<std::chrono::high_resolution_clock>& startclock);
278 // DocString: FMTExceptionHandler::_logStack
282 static void _logStack();
283 // DocString: FMTExceptionHandler::_terminate
287 static void _terminate();
288 // DocString: FMTExceptionHandler::_abort
293 static void _abort(int p_signal);
294
295
296 };
297}
298BOOST_SERIALIZATION_ASSUME_ABSTRACT(Core::FMTObject)
299BOOST_CLASS_TRACKING(Core::FMTObject, boost::serialization::track_always)
300BOOST_CLASS_EXPORT_KEY(Core::FMTObject)
301
302#endif
303
#define FMTEXPORT
Definition: FMTutility.h:125
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
static std::string getDurationInSeconds(const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
Return the time elapsed since a start clock in seconds as a string.
void setQuietExceptionHandler()
Create and set a quiet exception handler to the FMTObject.
static Logging::FMTLogger * getLogger()
get a pointer to the actual logger.
void forceSave(Archive &ar, const unsigned int version) const
Force the serialization to save useful information, which the default FMTObject serialization does no...
Definition: FMTObject.h:224
static Exception::FMTExceptionHandler * getExceptionHandler()
get a pointer to the actual exception handler.
virtual void setDebugLogger()
Create and set a debug logger to the FMTObject.
void forceLoad(Archive &ar, const unsigned int version)
Force the serialization to load useful information, which the default FMTObject serialization does no...
Definition: FMTObject.h:238
static std::unique_ptr< Logging::FMTLogger > _logger
A shared pointer to the logger.
Definition: FMTObject.h:215
void passInExceptionHandler(const std::unique_ptr< Exception::FMTExceptionHandler > &exhandler)
Pass in the exception handler of another FMTObject.
void setCplHandler()
Pass the FMT exception handler to the GDAL exception handler (GDAL only).
static std::unique_ptr< Exception::FMTExceptionHandler > _exhandler
A shared pointer to the exception handler.
Definition: FMTObject.h:212
void setFreeExceptionHandler()
Create and set a free exception handler to the FMTObject.
void enableNestedExceptions()
Enable the nested exception throw of the exception handler.
FMTObject()
Default constructor for FMTObject.
virtual void setDefaultLogger()
Create and set a default logger to the FMTObject.
void redirectLogToFile(const std::string &location)
Redirect the log to a specific file, appending to it.
static std::chrono::time_point< std::chrono::high_resolution_clock > getClock()
Return a clock of the current time.
virtual void setTaskLogger()
Create and set a task logger to the FMTObject.
FMTObject(const FMTObject &rhs)
Copy constructor for FMTObject.
void checkSignals() const
Check if the user has sent a ctrl-c signal using boost::python to FMT.
static std::string getRuntimeLocation()
Return the location of the FMT shared library.
static double getDuration(const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
Return the time elapsed since a start clock as a double.
static unsigned long long getAvailableMemory()
Return the available memory in bytes.
FMTObject(const std::unique_ptr< Exception::FMTExceptionHandler > exhandler)
Construct a FMTObject passing in the exception handler of another FMTObject.
void setDefaultExceptionHandler()
Create and set a default exception handler to the FMTObject.
static void _terminate()
Raise an error with the boost stacktrace.
virtual ~FMTObject()
Default virtual destructor for FMTObject.
void serialize(Archive &ar, const unsigned int version)
Definition: FMTObject.h:203
static void _logStack()
Log the stack trace...
static void setAbortStack()
will write the stack in the log when abort called with SIGABRT and raise a function failed.
void setErrorsToWarnings(const std::vector< Exception::FMTexc > &errors)
Set a list of errors to be cast to warnings on the exception handler.
static void _abort(int p_signal)
Raise an error with the boost stacktrace on abort.
virtual void setQuietLogger()
Create and set a quiet logger to the FMTObject.
void disableNestedExceptions()
Disable the nested exception throw of the exception handler.
virtual void passInLogger(const std::unique_ptr< Logging::FMTLogger > &logger)
Pass in the logger of another FMTObject.
static void setTerminateStack()
will write the stack in the log when terminate called and raise a function failed.
void setMaxWarningsBeforeSilenced(const size_t &maxwarningcount)
Set the number of warnings raised before being silenced.
void setDebugExceptionHandler()
Create and set a debug exception handler to the FMTObject.
Base class used to handle errors thrown in FMT.
Definition: FMTExceptionHandler.h:34
Base class handling the level of information printed by FMT.
Definition: FMTLogger.h:37
The Core namespace provides classes for simulating stands/strata growth/harvest through time.
Definition: FMTAction.h:34
Namespace for exceptions and exceptions handling (warnings and errors) thrown by FMT and all exceptio...
Definition: FMTAggregateRedefinition.h:11
Namespace for the log management, provides different log handlers.
Definition: FMTDebugLogger.h:14