HiveBrain v1.2.0
Get Started
← Back to all entries
patterncppMinor

Debug log wrapper

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
debugwrapperlog

Problem

I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I build it further. I know documentation is probably a bit sparse but, you know how it is. If you feel anything significantly warrants documentation, let me know. I know I understand the code; I don't know about others.

Please review code correctness, best practices, design and code formatting.

```
//File debug.h
//Release 1.2.0.0
//Copyright Michael Mercer

/* Include code
#ifdef NDEBUG
#include
#else
#undef OBJECT_NAME
#define OBJECT_NAME debugDefault //Name object by file or project
#include
using namespace debug_1_2_0; //Required to debug main() and NDEBUG ForwardCall
debug OBJECT_NAME; //debug OBJECT_NAME(std::initializer_list); to set ostreams
#endif

DEBUG_MAIN //Wrap main with debug diagnostics
{
//DEBUG(Args...);
//DEBUG_FUNC("Function name", function, function args...);
//DEBUG_FUNC(function, function args...);
return 0;
}
*/

#ifdef NDEBUG

#undef DEBUG
#undef DEBUG_FUNC
#undef DEBUG_MAIN
#define DEBUG(...)
#define DEBUG_FUNC ForwardCall
#define DEBUG_MAIN int main(int argc, char argv, char envp)

#else

#undef DEBUG
#undef DEBUG_FUNC
#undef DEBUG_MAIN
#define DEBUG OBJECT_NAME.debugOutput
#define DEBUG_FUNC DEBUG

#define DEBUG_MAIN \
int main(int argc, char argv, char envp) \
{ \
OBJECT_NAME.debugDiagnostics(argc, argv, envp); \
} \
int debug::main(int argc, char argv, char envp)

#endif

#ifndef DEBUG_H //Include guard
#define DEBUG_H

#include //for std::exception
#include //for std::ostream
#include //for std::logic_error
#include //for GetStdHandle etc
#include //for std::forward_list
namespace debug_1_2_

Solution

I didn't quite get the whole picture of your code without a usage example, but there are a few aspects I can comment on. In order of appearance:

-
main() with the extra envp parameter is not standard, though that format is accepted by the main compilers out there. Your code has a few Windows-specific portions, so I don't think portability is your concern anyway. You can read more about the signature of main in this SO question.

-
namespace debug_1_2_0: It doesn't strike me as a good idea encoding the version number of a library in the names of things. When the version changes, what will you do?

-
What you are trying to achieve with the several instances of static_cast() through the code is what std::forward does. You should use the latter since it is a clearer and standard way of doing it.

-
Consider replacing the Visual Studio specific __int64 with the standard std::int64_t, found in the ` header. There is no advantage in using a compiler extension when a standard version of the same feature is also available.

-
These two constants:

const char* const enterRoutine = "Enter ";
const char* const exitRoutine =  "Exit  ";


Could be
static, to ensure no data is duplicated if more than one class instance is created.

-
Empty destructor in
~debug(){}; is really not necessary.

-
Minor point, but you are using a somewhat unusual naming convention for your class types.
camelCase methods are usually combined with PascalCase class names, so I would expect your classes to be Debug and OStreams`.

Code Snippets

const char* const enterRoutine = "Enter ";
const char* const exitRoutine =  "Exit  ";

Context

StackExchange Code Review Q#56953, answer score: 3

Revisions (0)

No revisions yet.