1 #ifndef ENHANCE_CPP_GROUP
2 #define ENHANCE_CPP_GROUP
4 /*****************************************************************************\
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1996-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/definitions.h>
22 //! Provides missing language features in C++.
24 The most noticeable missing thing in C++ when trying to build debugging
25 and tracking subsystems with it is *reflection*. This header attempts to
26 ameliorate some of the worst missing parts, such as the fact that a function
27 cannot get its own name, and other really helpful features.
30 //hmmm: temporary to hide missing code.
31 #define frame_tracking_instance
32 #define __trail_of_function(a, b, c, d, e)
34 class enhance_cpp : public virtual root_object
37 // this class is an encapsulator; any macros are not actual members.
41 //! Defines the name of a class by providing a couple standard methods.
42 /*! This provides a virtual function functionality slice for the class name,
43 as well as a static version that can be used when no instances of the
45 #define DEFINE_CLASS_NAME(objname) \
46 static const char *static_class_name() { return (objname); } \
47 virtual const char *class_name() const { return static_class_name(); }
51 //! FUNCDEF sets the name of a function (and plugs it into the callstack).
52 /*! This macro establishes the function name and should be used at the top
53 of functions that wish to participate in class based logged as well as the
54 callstack tracing capability of hoople. A new variable is created on the
55 stack to track the function's presence until the function exits, at which
56 time the stack will no longer show it as active. */
57 #define FUNCDEF(func_in) \
58 const char *func = (const char *)func_in; \
59 frame_tracking_instance __trail_of_function(static_class_name(), func, \
60 __FILE__, __LINE__, true)
64 //! A macro used within the FUNCTION macro to do most of the work.
65 #define BASE_FUNCTION(func) astring just_function = astring(func); \
66 astring function_name = static_class_name(); \
67 function_name += astring("::") + just_function
68 //! This macro sets up a descriptive variable called "function_name".
69 /*! The variable includes the object's name (static_class_name() must be
70 implemented for the current object) and the current function's name within
71 that object (the macro "func" must be defined with that name). */
72 #define FUNCTION(func) BASE_FUNCTION(func); \
73 function_name += ": "; \
74 update_current_stack_frame_line_number(__LINE__)
76 //! A macro used within the INSTANCE_FUNCTION macro.
77 #define BASE_INSTANCE_FUNCTION(func) astring just_function = astring(func); \
78 astring function_name = instance_name(); \
79 function_name += astring("::") + just_function
80 //! A function macro that contains more information.
81 /*! This macro is similar to FUNCTION but it uses the class's instance_name()
82 method (see root_object). The instance function usually will provide more
83 information about the class. */
84 #define INSTANCE_FUNCTION(func) BASE_INSTANCE_FUNCTION(func); \
85 function_name += ": "; \
86 update_current_stack_frame_line_number(__LINE__)
90 //! __WHERE__ is a macro that combines the file and line number macros.
91 /*! These are available to most compilers as automatically updated macros
92 called __FILE__ and __LINE__. This macro can be used anywhere an astring can
93 be used and reports the current file name and line number. */
94 #define __WHERE__ basis::a_sprintf("%s [line %d]", __FILE__, __LINE__)