Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
ApplicationTools.h
Go to the documentation of this file.
1//! @file ApplicationTools.h
2//! @brief A set of function to initialize the SDK, and define the running context.
3//!
4///////////////////////////////////////////////////////////////////////////////////
5
6#ifndef APPLICATION_TOOLS_H
7#define APPLICATION_TOOLS_H
8
9BEGIN_MOOTOOLS_NAMESPACE
10
11#ifdef __cplusplus
13 {
14 MOOTOOLS_APPLICATION_NONE = 0x00,
15 MOOTOOLS_APPLICATION_REGISTER_FILES = 0x01, //!< Register built in file format so there extension will be recognized and parsed
16 MOOTOOLS_APPLICATION_CATCH_EXCEPTION = 0x02, //!< Release mode only. Set Mootools signal handler
17 MOOTOOLS_APPLICATION_ERROR_HANDLERS = 0x04, //!< windows only: _set_invalid_parameter_handler
18 MOOTOOLS_APPLICATION_DISABLE_LEAKS_CHECK = 0x08, //!< Debug only: disables memory leaks checks. Checking memory leaks slow down the application. This settings has no effect in release mode has memory leaks are never checked.
19 MOOTOOLS_APPLICATION_CLEAN_MEMORY = 0x010, //!< Clean memory from any preallocated structs and release any service launched (ie socket servive)
20 MOOTOOLS_APPLICATION_REGISTER_PLUGINS = 0x020, //!< Load plugins if any. Plugin directory can be set using SetPluginsDirectory
21 MOOTOOLS_APPLICATION_DEFAULT = -1,
23
24 DLL_TOOLSFUNCTION void InitMootoolsApplication(const char *licenseKey, LPCTSTR applicationPath = NULL, unsigned int flags = MOOTOOLS_APPLICATION_DEFAULT, LPCTSTR logFilePath = NULL); //!< By default applicationPath is the executable application path. Many internal features use applicationPath to load or save extra information (plugins, preferences...)
25 DLL_TOOLSFUNCTION void CloseMootoolsApplication(unsigned int flags = MOOTOOLS_APPLICATION_DEFAULT);
26
27#define EXITCALLBACK_CALL_LAST ((unsigned int)(-2)) //!< Maximum order to make the callback being call lastly
28#define EXITCALLBACK_IN_PLUGIN ((unsigned int)(-1)) //!< Add application callback from an external plugin. This will be called before unloading plugins
29 typedef void(*exitCallback)(void);
30 DLL_TOOLSFUNCTION void RemoveApplicationExitCallback(exitCallback callback, unsigned int order = 0); //!< Add a callback for specific cleaning operation that occurs when CloseMootoolsApplication is call
31 DLL_TOOLSFUNCTION void AddApplicationExitCallback(exitCallback callback, unsigned int order = 0); //!< Add a callback for specific cleaning operation that occurs when CloseMootoolsApplication is call. Large order are destroyed first. APPLICATION_PLUGIN_CALLBACK are destroyed before releasing plugins
32#endif
33
34extern "C"
35{
36 // Useful to call it from C code
37 // General cancel operations
38 DLL_TOOLSFUNCTION void SetCancelThread(bool cancel, xThreadID threadID = 0); //!< Any call to SetCancelThread(TRUE must have a pending call to SetCancelThread(FALSE when thread exit. SetCancelThread(FALSE can be called if you know that thread exit
39 DLL_TOOLSFUNCTION bool ShouldCancelThread(xThreadID threadID = 0);
40 DLL_TOOLSFUNCTION xThreadID GetApplicationMainThreadID();
41
42 // General silent operations
43 DLL_TOOLSFUNCTION void SetSilentThread(bool silent, xThreadID threadID = 0); //!< Any call to SetSilentThread(TRUE must have a pending call to SetSilentThread(FALSE when thread exit. SetSilentThread(FALSE can be called if you know that thread exit
44 DLL_TOOLSFUNCTION bool IsSilentThread(xThreadID threadID = 0);
45
46 // Allow to attach a thread to another one, which is useful when using some mechanism such OpenMP through a CXThread object
47 DLL_TOOLSFUNCTION void AttachThread(xThreadID newThreadID, xThreadID parentThreadID); //!< newThreadID is attached to parentThreadID and get the silent and cancel status
48 DLL_TOOLSFUNCTION void DetachThread(xThreadID threadID); //!< Any call to AttachThread must have a pending call to detach, but DetachThread can be call if you know that the thread exit
49 DLL_TOOLSFUNCTION unsigned int GetChildThreads(xThreadID refparentThreadID, CXArray<xThreadID>& childTheads); //!< Retrieve threads attached to a given parent. Return the number of found threads.
50
51 DLL_TOOLSFUNCTION void OMPSetMaxThreadCount(unsigned int maxThreadCount); //!< Set OMP max thread count
52 DLL_TOOLSFUNCTION unsigned int OMPGetMaxThreadCount(); //!< Get OMP max thread count, which is set to
53 DLL_TOOLSFUNCTION unsigned int OMPGetScheduleChunkSize(unsigned int iterationCount); //!< Return an interesting OMP schedule value, depending on the number of iteration and maximum number of thread
54}
55
56#ifdef __cplusplus
57 #define UNDEFINED_VERSION_NUMBER -1
58
59 // The internal product name is the name used to created some directories ("3DBrowser") used by the software
60 // This is not the front user name (ie "3DBrowser for 3D Users", "3DBrowser Light Edition") as these different products share the same preferences folders
61 DLL_TOOLSFUNCTION void SetInternalProductName(const CXString& nameWithoutVersion, int version, bool resetPreferencesPath = false);
62 DLL_TOOLSFUNCTION CXString GetInternalProductName(bool nameWithVersion = true);
63 DLL_TOOLSFUNCTION void SetUserPreferencesPath(const CXString& path);
64 DLL_TOOLSFUNCTION CXString GetUserPreferencesPath(bool create = true); //!< The returned path integrates the version
65 DLL_TOOLSFUNCTION CXString GetCommonPreferencesPath(bool create = true); //!< The returned path integrates the version
66 DLL_TOOLSFUNCTION CXString GetPreferencesFile();
67 DLL_TOOLSFUNCTION void SetApplicationPath(const CXString& path);
68 DLL_TOOLSFUNCTION CXString GetApplicationPath(bool pathWithoutApplicationName); //!< Return the exe path and filename of the running application
69 DLL_TOOLSFUNCTION CXString GetApplicationName(bool nameWithoutExtension);
70 DLL_TOOLSFUNCTION CXString GetCommonApplicationDataPath(bool commonToAllVersion = false, LPCTSTR alternateName = NULL); //!< The SDK version returns GetUserPreferencesPath(), whatever commonToAllVersion value. Otherwise, the returned path integrates the version if commonToAllVersion = false, otherwise it returns a path that can be shared by all version of the application
71 DLL_TOOLSFUNCTION CXString GetUserApplicationDataPath(bool commonToAllVersion = false, LPCTSTR alternateName = NULL); //!< The SDK version returns GetUserPreferencesPath(), whatever commonToAllVersion value. The returned path integrates the version if commonToAllVersion = false, otherwise it returns a path that can be shared by all version of the application
72
73 DLL_TOOLSFUNCTION void EnablePreferencesSaving(bool enable); //!< Preferences saving is disabled by default
74 DLL_TOOLSFUNCTION bool IsPreferencesSavingEnabled(); //!< Preferences saving is disabled by default
75 DLL_TOOLSFUNCTION bool CopyFileFromPreviousVersionIfMissing(const CXString& targetPath); //!< Copy a file from a previous version if it is missing from the current version
76
77 typedef enum LogFileMode
78 {
79 LOGFILE_REPLACE_EXISTING = 0,
80 LOGFILE_ADD_TO_EXISTING,
81 LOGFILE_PREVENT_REPLACE
82 } LogFileMode;
83
84 #define LOG_ENABLE_ALL ((unsigned int)(-1))
85 #define LOG_IS_DISABLED ((unsigned int)(-2))
86
87 //! @name Log functions
88 //! @brief Convenient functions to log information to an output file.
89 //! @details Cf. @ref LOGMACRO for convenient log macros
90 //! @{
91 DLL_TOOLSFUNCTION bool SetLogFile(const CXString& filename, LogFileMode mode, unsigned int filterLevel = LOG_ENABLE_ALL); //!< a filename for loggin some events. Log is written in the user application data path. The file is automatically closed
92 DLL_TOOLSFUNCTION bool CloseLogFile();
93 DLL_TOOLSFUNCTION unsigned int SetLogLevel(unsigned int level); //!< Set level to LOG_ENABLE_ALL to enable all log message or LOG_IS_DISABLED
94 DLL_TOOLSFUNCTION bool IsLogFileEnabled(); //!< return true if log is enabled
95 DLL_TOOLSFUNCTION unsigned int LogFileAddTab(bool addTab); //!< add/remove tabulation for LogFile
96 DLL_TOOLSFUNCTION void LogLock(bool lock); //!< Allow lock until write several lines
97 DLL_TOOLSFUNCTION void WriteToLogFile(const char *lpszFormat, ...);
98 DLL_TOOLSFUNCTION void WriteToLogFile(const wchar_t *lpszFormat, ...);
99
100 //! @}
101 //!
102 //! @name Useful macro for log files
103 //! @anchor LOGMACRO
104 //! @brief Convenient macro for writing information in the log file.
105 //! @{
106 #define XLOG(a, ...) \
107 { \
108 if (IsLogFileEnabled()) \
109 WriteToLogFile(a, __VA_ARGS__); \
110 }
111
112 #define XLOG_INC_TAB(a) \
113 { \
114 LogFileAddTab(a); \
115 }
116
117 #define XLOG_INC(a, ...) \
118 { \
119 WriteToLogFile(a, __VA_ARGS__); \
120 LogFileAddTab(true); \
121 }
122
123 #define XLOG_DEC(a, ...) \
124 { \
125 LogFileAddTab(false); \
126 WriteToLogFile(a, __VA_ARGS__); \
127 }
128
129 #define XLOG_IF(cond, ...) \
130 { \
131 if (cond) \
132 XLOG(__VA_ARGS__); \
133 }
134
135 #define XLOG_LOCK(lock) \
136 { \
137 LogLock(lock); \
138 }
139
140 //! @}
141
142 #if defined(MOOTOOLS_MFC_PRODUCT_BUILD) && !defined(MOOTOOLS_MINIMAL_BUILD)
143 // Log events
144 DLL_TOOLSFUNCTION void LogEvents();
145 DLL_TOOLSFUNCTION void UnlogEvents();
146
147 CXString GetVersionInformation(const CXString& version);
148 #ifdef _DEBUG
149 DLL_TOOLSFUNCTION void RemoveFirstLaunch();
150 #endif
151
152 DLL_TOOLSFUNCTION bool IsFirstLaunch(CWinApp *theApp, bool removeIfVersionLower, bool getFromPrefsFile, int *prevVersMajor = NULL, int *prevVersMinor = NULL);
153 DLL_TOOLSFUNCTION void SetCommonPreferencesPath(const CXString& path);
154 DLL_TOOLSFUNCTION void SetThreadLanguage(LANGID langid);
155
156 #endif // !MOOTOOLS_MFC_PRODUCT_BUILD
157#endif //#ifdef __cplusplus
158
159 END_MOOTOOLS_NAMESPACE
160
161#endif // APPLICATION_TOOLS_H
DLL_TOOLSFUNCTION CXString GetUserApplicationDataPath(bool commonToAllVersion=false, LPCTSTR alternateName=NULL)
The SDK version returns GetUserPreferencesPath(), whatever commonToAllVersion value....
DLL_TOOLSFUNCTION unsigned int LogFileAddTab(bool addTab)
add/remove tabulation for LogFile
DLL_TOOLSFUNCTION void AddApplicationExitCallback(exitCallback callback, unsigned int order=0)
Add a callback for specific cleaning operation that occurs when CloseMootoolsApplication is call....
DLL_TOOLSFUNCTION void InitMootoolsApplication(const char *licenseKey, LPCTSTR applicationPath=NULL, unsigned int flags=MOOTOOLS_APPLICATION_DEFAULT, LPCTSTR logFilePath=NULL)
By default applicationPath is the executable application path. Many internal features use application...
DLL_TOOLSFUNCTION void LogLock(bool lock)
Allow lock until write several lines.
DLL_TOOLSFUNCTION bool SetLogFile(const CXString &filename, LogFileMode mode, unsigned int filterLevel=LOG_ENABLE_ALL)
a filename for loggin some events. Log is written in the user application data path....
DLL_TOOLSFUNCTION unsigned int OMPGetScheduleChunkSize(unsigned int iterationCount)
Return an interesting OMP schedule value, depending on the number of iteration and maximum number of ...
DLL_TOOLSFUNCTION void DetachThread(xThreadID threadID)
Any call to AttachThread must have a pending call to detach, but DetachThread can be call if you know...
DLL_TOOLSFUNCTION void EnablePreferencesSaving(bool enable)
Preferences saving is disabled by default.
DLL_TOOLSFUNCTION CXString GetUserPreferencesPath(bool create=true)
The returned path integrates the version.
DLL_TOOLSFUNCTION CXString GetCommonApplicationDataPath(bool commonToAllVersion=false, LPCTSTR alternateName=NULL)
The SDK version returns GetUserPreferencesPath(), whatever commonToAllVersion value....
DLL_TOOLSFUNCTION CXString GetCommonPreferencesPath(bool create=true)
The returned path integrates the version.
_MOOTOOLS_APPLICATION_FLAGS
Definition ApplicationTools.h:13
@ MOOTOOLS_APPLICATION_CLEAN_MEMORY
Clean memory from any preallocated structs and release any service launched (ie socket servive)
Definition ApplicationTools.h:19
@ MOOTOOLS_APPLICATION_CATCH_EXCEPTION
Release mode only. Set Mootools signal handler.
Definition ApplicationTools.h:16
@ MOOTOOLS_APPLICATION_REGISTER_PLUGINS
Load plugins if any. Plugin directory can be set using SetPluginsDirectory.
Definition ApplicationTools.h:20
@ MOOTOOLS_APPLICATION_REGISTER_FILES
Register built in file format so there extension will be recognized and parsed.
Definition ApplicationTools.h:15
@ MOOTOOLS_APPLICATION_ERROR_HANDLERS
windows only: _set_invalid_parameter_handler
Definition ApplicationTools.h:17
@ MOOTOOLS_APPLICATION_DISABLE_LEAKS_CHECK
Debug only: disables memory leaks checks. Checking memory leaks slow down the application....
Definition ApplicationTools.h:18
DLL_TOOLSFUNCTION bool IsPreferencesSavingEnabled()
Preferences saving is disabled by default.
DLL_TOOLSFUNCTION void SetSilentThread(bool silent, xThreadID threadID=0)
Any call to SetSilentThread(TRUE must have a pending call to SetSilentThread(FALSE when thread exit....
DLL_TOOLSFUNCTION void OMPSetMaxThreadCount(unsigned int maxThreadCount)
Set OMP max thread count.
DLL_TOOLSFUNCTION unsigned int SetLogLevel(unsigned int level)
Set level to LOG_ENABLE_ALL to enable all log message or LOG_IS_DISABLED.
DLL_TOOLSFUNCTION void SetCancelThread(bool cancel, xThreadID threadID=0)
Any call to SetCancelThread(TRUE must have a pending call to SetCancelThread(FALSE when thread exit....
DLL_TOOLSFUNCTION unsigned int OMPGetMaxThreadCount()
Get OMP max thread count, which is set to.
DLL_TOOLSFUNCTION bool IsLogFileEnabled()
return true if log is enabled
DLL_TOOLSFUNCTION void RemoveApplicationExitCallback(exitCallback callback, unsigned int order=0)
Add a callback for specific cleaning operation that occurs when CloseMootoolsApplication is call.
DLL_TOOLSFUNCTION unsigned int GetChildThreads(xThreadID refparentThreadID, CXArray< xThreadID > &childTheads)
Retrieve threads attached to a given parent. Return the number of found threads.
DLL_TOOLSFUNCTION bool CopyFileFromPreviousVersionIfMissing(const CXString &targetPath)
Copy a file from a previous version if it is missing from the current version.
DLL_TOOLSFUNCTION void AttachThread(xThreadID newThreadID, xThreadID parentThreadID)
newThreadID is attached to parentThreadID and get the silent and cancel status
DLL_TOOLSFUNCTION CXString GetApplicationPath(bool pathWithoutApplicationName)
Return the exe path and filename of the running application.
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27