DebOut.hh 5.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
// (C) Copyright 2014 by Autodesk, Inc.
//
// The information contained herein is confidential, proprietary
// to Autodesk,  Inc.,  and considered a trade secret as defined
// in section 499C of the penal code of the State of California.
// Use of  this information  by  anyone  other  than  authorized
// employees of Autodesk, Inc.  is granted  only under a written
// non-disclosure agreement,  expressly  prescribing  the  scope
// and manner of such use.

#ifndef REFORM_DEBUG_OUT_HH_INCLUDED
#define REFORM_DEBUG_OUT_HH_INCLUDED

14
// DEB_ON is defined, or not, in Cmakelists.txt for primary project
15

16
#ifndef DEB_ON
17

18
#define DEB_module(SS) 
19
20
#define DEB_enter_func 
#define DEB_only( CC )
21
22
23
24
25
#define DEB_out(LL, AA ) {}
#define DEB_out_if( CC, LL, AA ) {} 
#define DEB_warning( LL, AA ) {}
#define DEB_warning_if( CC, LL, AA ) {} 
#define DEB_mesh_if( CC, LL, FF, MM ) {} 
26

27
28
#define DEB_error(AA) {}
#define DEB_error_if(CC, AA) {}
29

30
#else // DEB_ON
31
32
33
34
35

#include <string>

namespace ReForm {}

36
37
#define DEB_module(SS) static const char * l_g_module = SS;

38
39
40
/* TODO: This should use an atomic thread safe static int 
*/
#define DEB_enter_func static int deb_enter_count =0; \
41
  ReForm::DebEnter deb(__FUNCTION__, deb_enter_count++, l_g_module);
42
43
44

#define DEB_only( CC )  CC

45
46
#define DEB_out(LL, AA ) { if (deb.permission(LL)) \
{ deb.stream() << AA << deb.end(); } }
47

48
49
#define DEB_out_if( CC, LL, AA ) { if (deb.permission(LL) && (CC)) \
{ deb.stream() << AA << deb.end(); } }
50

51
52
#define DEB_warning(LL, AA ) { if (deb.permission(LL, 1)) \
{ deb.stream(1) << AA << deb.end_lf(); } }
53
54

#define DEB_warning_if( CC, LL, AA ) { if (deb.permission(LL, 1) && (CC)) \
55
{ deb.stream(1) << AA << deb.end_lf(); } }
56

57
#define DEB_mesh_out_if( CC, LL, FF, MM ){ if (deb.permission(LL, 2) && (CC)) \
58
59
60
61
{ deb.stream(2) << deb.mesh(FF, MM) ; } }
// TODO: implement Deb.mesh() filename and mesh holding class and assocated
// DebStream streamer

62
63
#define DEB_error(AA) { if (deb.permission(0, 1) )\
{ deb.stream(1) << "Error:" << AA << deb.end_lf(); } }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

#define DEB_error_if(CC, AA) if (CC) DEB_error(AA) 


// DebStream does not fulfill ostream. If you want to exploit an existing
// ostream streamer to DEB_out a class as text without exploiting any 
// numeric processing or custom DebStream streamers then use this macro thus
// DEB_out(1, "my_class is " << DEB_os_str(my_c) )
#define DEB_os_str(AA) dynamic_cast<std::ostringstream &>((std::ostringstream() << AA )).str()

namespace ReForm
{
  
class DebStream;

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class DebCommand
{
public:
  enum CommandType
  {
    end    = 0x01,
    end_lf = 0x03
  };
  CommandType com_;
  CommandType com() const { return com_; }
  DebCommand(CommandType _com) : com_(_com) {}
  ~DebCommand() {};
};


94
95
  // Class used to maintain DebStream's CallStack
  // This does not currently contain a pointer to the file streamer used
96
  // but might do in future. 
97
98
99
  class DebEnter
  {
  public:
100
101
    int id_;       /*!< Unique identifier for this DebEnter (used in ANCHORS) */
    int count_;    /*!< deb_enter_count for this function. */
102
103
104
    int deb_outs_; /*!< Number of DEB_outs encountered within this function
                    determining whether a given DEB_out should include or omit
                    a call stack or exit trace. */
105
    int deb_lines_; /*!< Number of call stack indents including this call. */
106
    const char * module_; /*!< Module name for this DEB_enter. */
107

108
    DebEnter(const char * const _funcname, const int _count,const char * const _module);
109
    ~DebEnter();
110
111
112
113
114
    DebStream& stream(const int _warn = 0, const bool _print = true);
    int permission(const int _lev, const int _warn=0);

    DebCommand end() { return DebCommand(DebCommand::CommandType::end); }
    DebCommand end_lf() { return DebCommand(DebCommand::CommandType::end_lf); }
115
116
  };

117
118
119
 
  class DebFile;

120
121
122
123
124
125
126
127
128
129
130
131
  class DebStream
  {
  public:
    enum StreamType
    {
      append    = 0x01,
      html      = 0x02,
      retain    = 0x04,
      keep_open = 0x08
    };

  private:
132
    DebFile * dfile_;
133
  public:
134
    DebFile * dfile() const { return dfile_;}
135
136
137
138
139
140
141
142
143
144
145
    //! Constructor.
    DebStream(
      const char * _file_name = nullptr,  //!< [in] File name if file based. 
      const StreamType _type = append    //!< [in] bitsfield enum type identifier
      ) ;
    ~DebStream();

    DebStream& print(const int);
    DebStream& print(const double);
    DebStream& print(const char * const, bool fork = true);
    DebStream& print(const char);
146
    DebStream& print(const DebCommand &);
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

    //! Get the currently active DebStream
    static DebStream& get_global(int _warn=0);

  };

DebStream& operator<<(DebStream& ds, const int i );
DebStream& operator<<(DebStream& ds, const double d );

DebStream& operator<<(DebStream& ds, const size_t i );
DebStream& operator<<(DebStream& ds, const unsigned int i );
DebStream& operator<<(DebStream& ds, const float d );

DebStream& operator<<(DebStream& ds, const char c);
DebStream& operator<<(DebStream& ds, const char* const s );
DebStream& operator<<(DebStream& ds, const std::string& s );
163
164
165

DebStream& operator<<(DebStream& ds, const DebCommand& co );

166
167
168
169
170
171
172
// A std::stream streamer might be useful here. Add when needed.

}//namespace 

#endif // DEB_out_INCLUDED

#endif // REFORM_DEBUG_OUT_HH_INCLUDED