DebStream.cc 21.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// (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.

#include "DebOut.hh"
#include <string>
#include <fstream>
#include <time.h>
#include <vector>
#include <iostream>
17
#include <map>
18

19
#ifdef DEB_ON
20
21
22
23
24
25
26
27
28
29
30
31
32

#define LOCAL_PROC static

LOCAL_PROC bool is_html_filename(const char * const str)  
{
  const char * dot = strchr(str, '.');
  if (dot == nullptr) return false;
  ++dot;
  return ( !strncmp(dot, "htm", 3) ) || ( !strncmp(dot,"HTM",3) ) ;
}

namespace ReForm
{
33
  class FunctionCallSequence
34
35
  {
    std::string func_name_;
36
    std::vector<DebEnter *> debs_; // These may not have sequential counts when multithreaded.
37
38

  public:
39
    FunctionCallSequence(const char * _func_name, DebEnter * _deb) 
40
41
      : func_name_(_func_name)
    {
42
      debs_.push_back(_deb);
43
44
45
    }
    ~FunctionCallSequence() {}

46
    bool add(const char * _func_name, DebEnter * _deb)
47
48
49
    {
      if (func_name_ == _func_name)
      {
50
        debs_.push_back(_deb);
51
52
53
54
55
56
57
        return true;
      }
      return false;
    }

    bool pop()
    {
58
      if (debs_.size() > 1 )
59
      {
60
        debs_.pop_back();
61
62
        return true;
      }
63
      debs_.clear();
64
65
66
67
68
69
      return false;
    }

    int number_calls() const 
    {
      if (!this) return 0;
70
      return (int)debs_.size();
71
72
73
74
75
    }

    int count(int i=0) const
    { 
      int num = number_calls();
76
      if (i < num) return debs_[num -1 - i]->count_;
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
      return -1;
    }

    const char * name() const { return func_name_.c_str();}

    // Replace interior of < > in function name with . for brevity
    void compact_name(std::string & str) const
    {
      int cnt=0;
      const char * ptr = func_name_.c_str();
      while (ptr && (*ptr != '\0'))
      {
        char c = *ptr;
        if (c=='>') --cnt;
        if (cnt==0) str.append(1, c);
        if (c=='<') 
        {
          if (cnt==0) str.append(".");
          ++cnt;
        }
        ++ptr;
      }
    }

    // Get single call stack element string
102
    void get(std::string& _str, const bool _strip_angled, bool _with_counts) const
103
    {
104
105
106
      if (_strip_angled) compact_name(_str);
      else _str.append(name());
      _str.append("[");
107
108
109
110
111
112
113
114
      if (_with_counts)
      {

        int num = number_calls();
        int prev = -2;
        int seq_cnt =0;
        for (int i=0; i < num; ++i)
        {
115
          int cnt = debs_[i]->count_;
116
117
118
119
120
121
          if (cnt != prev + 1)
          {
            char buffer[64];

            if (seq_cnt > 0)
            {
122
              _str.append("-");
123
              sprintf_s(buffer, sizeof(buffer), "%i", prev);
124
              _str.append(buffer);
125
            }
126
            if (i>0) _str.append(",");
127
            sprintf_s(buffer, sizeof(buffer), "%i", cnt);
128
            _str.append(buffer);
129
130
131
132
133
134
135
136
137
            seq_cnt=0;
          }
          else
            ++seq_cnt;
          prev = cnt;
        } // endfor i
      } // endif _with_counts
      else
      {
138
        _str.append("*");
139
      }
140
      _str.append("]");
141
142
    } // endfunc get

143
144
    void indent(std::string & _str, DebFile * _dfile, bool _is_html);

145
146
147
  }; // endclass FunctionCallSequence


148
  class CallStack
149
150
151
152
153
154
155
  {
    std::vector<FunctionCallSequence> calls_;
    int depth_;
  public:
    CallStack() : depth_(0) {}
    ~CallStack() {}

156
    void add(const char * _func_name, DebEnter * _deb)
157
    {
158
      if (calls_.empty() || !calls_.back().add(_func_name, _deb))
159
      {
160
        calls_.push_back( FunctionCallSequence(_func_name, _deb) );
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
      }
      ++depth_;
    }

    void pop()
    {
      if (!calls_.back().pop())
        calls_.pop_back();
      --depth_;
    }

    const FunctionCallSequence * call( int _up =0)
    {
      int num = (int)calls_.size();
      if (_up < num) return &calls_[num - 1 - _up];
      return nullptr;
    }

    // Read a particular call stack element
    bool read(int _up, const char*& _funcname, int & _count)
    {
      const FunctionCallSequence * fcs = call(_up);
      if (fcs != nullptr)
      {
        _funcname = fcs->name();
        _count = fcs->count(0); // Return most recent deb_enter_count
        return true;
      }
      return false;
    }

    // Get a full call stack sting.
    // returns number of call stack function elements 
    int get(std::string& _str, bool _with_counts = true) const
    {
      int num = (int)calls_.size();
      for (int i =0; i< num; ++i)
      {
        if (i>0) _str.append("->");
        calls_[i].get(_str, true, _with_counts);
      }
      return num;
    }

    int depth() const { return depth_; }

207
208
    bool indent(std::string& _str, DebFile * _dfile, const bool is_html);
}; // endclass CallStack
209
210
211
 


212
class DebFile
213
214
{
private:
215
216
217
218
219
220
221
222
223
224
225
226
227
228
  class module_stats
  {
  public:
    int lev_; // Level set for this module
    int col_; // Colour (24 bit RGB, MSB=Red) for this module's DEB_out
    module_stats(int _lev=0) : lev_(_lev), col_(0x808080) {}
    ~module_stats() {}
  };

  std::map<std::string, module_stats> module_map_;
  typedef std::map<std::string, module_stats>::iterator module_map_itr;
  typedef std::map<std::string, module_stats>::const_iterator const_module_map_itr;
  
  DebStream::StreamType type_;
229
230
  int lev_;
  int num_flush_;
231
  int priority_; // Last permission granted
232
  int indent_size_;
233
234
235
236
  std::string current_;
  std::string output_;
  std::string file_name_;
  std::fstream file_stream_;
237
  //std::string indent_string_;
238
239
240
241
242
243
244
  DebStream * deb_stream_;
  CallStack call_stack_;

public:

  CallStack& call_stack() { return call_stack_;}

245
246
247
248
  bool is_kept_open() const  { return 0 != (type_ & DebStream::StreamType::keep_open); }
  bool is_html() const  { return 0 != (type_ & DebStream::StreamType::html); }
  bool is_retained() const  { return 0 != (type_ & DebStream::StreamType::retain); }
  bool is_appended() const  { return 0 != (type_ & DebStream::StreamType::append); }
249
  // Only applies to HTML DEB_out
250
  bool is_white_on_black() const { return true; }
251
  int indent_size() { return indent_size_; }
252
253

  bool file_is_open() const { return file_stream_.is_open(); }
254
  int priority() const { return priority_; }
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

  bool fork_to_cout() { return false; }
  bool fork_to_cerr() { return true; }


  const char * file_name() const
  {
   if ( this && (!file_name_.empty()) ) return file_name_.c_str();
    return nullptr;
  }
  
  void clear()
  {
    current_.clear();
    output_.clear();
    file_name_.clear();
  }
272
  
273
274
275
276
277
278
279
  char prev_char() const
  {
    if (!current_.empty()) return current_.back();
    if (!output_.empty()) return output_.back();
    return '\0';
  }

280
281

  void indent()
282
  {
283
284
285
    std::string str;
    if (call_stack().indent(str, this,  is_html()))
      current_.append(str);
286
287
  }

288

289
  void line_break(bool _with_indent = true)
290
291
292
293
  {
    if ( is_html() ) current_.append("<br>"); // Don't bother with matching </br>
    current_.append("\n", 1);

294
    if (_with_indent) indent();
295

296
  }
297
      
298
299
  void set_level(int _lev) { lev_ = _lev; }

300
301
302
303
304
305
  void print_direct(const std::string & _s)
  {
    current_.append(_s);
  }


306
307
  void print(const char _c)
  {
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
    if (_c == '\n') 
    {
      line_break();
      return;
    }

    if ( is_html() )
    { // translate the esoteric characters used in IGM DEB_out


      if( _c == '')  // -62 
      {
        return;
      }

      if (_c == '') // 167 = -89
      {
        current_.append("&sect;");
        return;
      }

      if (_c == '') // -80
      {
        current_.append("&deg;");
        return;
      }
    }
    current_.append(&_c, 1);
336
337
338
339
340
341
342
343
344
  }

  void print(const char * const _s, bool _fork = true)
  {
    if (_s != nullptr)
    {
      for (int i=0; ;++i)
      {
        const char c = _s[i];
345
        if (c=='\0') break;
346
347
348
349
        print(c);
      }
      if (_fork)
      {
350
351
352
353
        if (fork_to_cout())
          std::cout << _s;
        if (fork_to_cerr())
          std::cerr << _s;
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
      }
    } 
  }

  void print(int _i)
  {
    char buffer[64];
    sprintf_s(buffer, sizeof(buffer), "%i", _i);
    print(buffer);
  }
  
  void print(double _d)
  {
    char buffer[64];
    sprintf_s(buffer, sizeof(buffer), "%.17g", _d);
    print(buffer);
  }

372
373
374
375
376
377
378
379
380
381
382
383
384
  void print(const DebCommand& _co)
  {
    switch(_co.com()) {
    case DebCommand::end : 
      if (is_html()) print("</FONT>", false);
      break;
    case DebCommand::end_lf :
      if (is_html()) print("</FONT>", false);
      line_break();
      break;
    }
  }

385
  DebStream & stream() { return *deb_stream_; }
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

  // Append current asctime to given string 
  bool add_time(std::string & str)
  {
    time_t rawtime;
    time ( &rawtime );
    struct tm timeinfo;
    errno_t err = localtime_s( &timeinfo, &rawtime );
    if (err == 0)
    {
      char buffer[256];
      err = asctime_s(buffer, sizeof(buffer), &timeinfo);
      if (err == 0)
      {
        str.append( buffer );
        return true;
      }
    }
    return false;
  }

407

408
#if 1
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
  bool hover(std::string & _str, const std::string & _hover, const bool _open)
  {
    if (is_html())
    {
      char buffer[1024];
      if (_open)  sprintf_s(buffer, sizeof(buffer), 
        "<span title=\"%s\">", _hover.c_str());
      else sprintf_s(buffer, sizeof(buffer), "</span>");
      _str.append(buffer);
      return true;
    }
    return false;
  }
#endif

  bool anchor(std::string & _str, const int _id, const char * _tag, const bool _open)
  {
    if (is_html())
    {
      char buffer[1024];
      if (_open)  sprintf_s(buffer, sizeof(buffer), "<A name=\"%08X_%s\">", _id, _tag);
      else sprintf_s(buffer, sizeof(buffer), "</A>");
      _str.append(buffer);
      return true;
    }
    return false;
  }

  bool link_to(std::string & _str, const int _id, const char * _tag, const std::string & _hover, const bool _open)
  {
    if (is_html())
    {
      char buffer[2048];
      if (_open)
      {
        // HTML title hover text is cropped to 64 char in Firefox but displays
        // OK in Chrome. We could use javascript to avoid this limit but HTML
        // is simpler.
        if (_hover.empty()) sprintf_s(buffer, sizeof(buffer),
          "<A href=\"#%08X_%s\">", _id, _tag);
        else sprintf_s(buffer, sizeof(buffer), 
          "<A href=\"#%08X_%s\" title=\"%s\">", _id, _tag, _hover.c_str());
      }
      else sprintf_s(buffer, sizeof(buffer), "</A>");
      _str.append(buffer);
      return true;
    }
    return false;
  }


460
461
462
463
464
465
466
467
468
469
470
471
  void header(std::string & str)
  { 
    if ( is_html() )
    {
      str.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\">");
      str.append("\n<HTML><HEAD>");
      str.append("\n<TITLE>ReForm DEB_out");
      str.append("</TITLE>");
      // javascript lib loads go here
      // stylesheet loads go here
      // within HEAD javascript goes here
      str.append("\n</HEAD>");
472
      if ( is_white_on_black() )
473
474
      {
        str.append( "\n<BODY BGCOLOR=\"#000000\" TEXT=\"#FFFFFF\" LINK=\"#%00FFFF\" VLINK=\"#FFFF00\" >");
475
        //str.append( "\n<BODY BGCOLOR=\"#000000\" TEXT=\"#FFFFFF\"  >");
476
477
478
479
      }
      else
      {
        str.append("\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" LINK=\"#%FF0000\" VLINK=\"#0000FF\" >");
480
        //str.append( "\n<BODY BGCOLOR=\"#000000\" TEXT=\"#FFFFFF\" >");
481
482
483
484
485
486
      }
      str.append("\n");
    } // endif is_html
    bool date_header = true;
    if (date_header)
    {
487
488
489
490
491
      if(!file_name_.empty())
      {
        str.append(file_name_);
        str.append(" opened ");
      }
492
      add_time(str);
493
494
495
      str.append( "[ Build: " __TIME__  " " __DATE__  "] ");
      if (is_html()) str.append("<BR>");
      str.append("\n");
496
497
498
499
500
501
502
503
    }
  }

  void footer()
  {
    bool date_footer = true;
    if (date_footer)
    {
504
505
506
      std::string str("\n");
      if(!file_name_.empty()) str.append(file_name_);
      str.append(" Closed: ");
507
508
      add_time(str);
      stream() << str << "\n";
509
510
511
512
    }

    if (is_html())
    {
513
      stream().print("\n</BODY></HTML>", false);
514
515
    }
  }
516

517
518
519
520
521
522
523
524
525
526
527
  bool is_first_flush()
  {
    return num_flush_ == 0 ;
  }
  
  int flush()
  {
    int res = 0;
    if ( !current_.empty() )
    {
      const char * fname = file_name();
528
      if ((fname != nullptr) || file_is_open() )
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
      {
        if ( !file_is_open() )
        {
          file_stream_.open( fname, 
            std::fstream::out | ( (is_appended() && !is_first_flush() ) ? 
                std::fstream::app  :  std::fstream::trunc ) );
        }

        if (file_stream_.is_open())
        {
          std::string hdr;
          if ( !is_appended() )
          { // Reoutput entire file
            header(hdr);
            output_.append(hdr);
            file_stream_ << output_;
          }
          else
          {
            if ( is_first_flush() )
            {
              header(hdr);
              if ( is_retained() )
                output_.append( hdr);
              file_stream_ << hdr;
            }
            ++num_flush_;
          }
          file_stream_ << current_;

          if ( is_retained() )
            output_.append(current_);

          current_.clear(); 
          if ( !is_kept_open() )
            file_stream_.close();
        } // endif fs.is_open
        else
        {
          res = -1;
        }
      }
    } // endif current empty
  return res;
  }  // endfunc flush

  void close()
  {
    footer();
    flush();
  }


  void set_file_name(const char * _name)
  {
    file_name_ = _name;
    if ( is_html_filename(_name) )
586
587
588
    {
      type_ = (DebStream::StreamType)(type_ | DebStream::StreamType::html);
    }
589
  }
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
  
  void set_module_level(const char * const _module, const int _lev)
  {
    std::pair<module_map_itr, bool> ins =  module_map_.insert(
      std::pair<std::string, module_stats>(_module, module_stats(_lev)) );
    if (!ins.second) ins.first->second.lev_ = _lev;
  }

  int get_module_level(const char * const _module) const
  {
    const_module_map_itr it = module_map_.find(std::string(_module));
    if (it == module_map_.end()) return lev_;
    return it->second.lev_;
  }


  void set_module_color(const char * const _module, const int _col)
  {
    std::pair<module_map_itr, bool> ins =  module_map_.insert(
      std::pair<std::string, module_stats>(_module, module_stats(lev_)) );
    ins.first->second.col_ = _col;
  }

  int get_module_color(const char * const _module) const
  {
    const_module_map_itr it = module_map_.find(std::string(_module));
    if (it == module_map_.end()) 
      {
        if (is_white_on_black() ) return 0xFFFFFF;
        else return 0x000000;
      }
    return it->second.col_;
  }
  
  int permission(const int _lev, const int _warn, const char * const _module)
  {
    _warn;
    int lev = get_module_level(_module);
    lev -= _lev;
    if (lev <0) lev = 0;
    if (lev > 0) priority_ = lev;
    return lev;
  }
633
634
  
  bool is_at_line_start() 
635
636
637
638
639
640
641
642
643
644
645
646
647
  {
    char prev = prev_char();
    return (prev=='\n') || (prev=='\0');
  }


  DebFile(
    DebStream* _deb_stream,
    DebStream::StreamType _type = (DebStream::StreamType) (DebStream::append | DebStream::retain), 
    const char * _file_name = nullptr) :
  type_(_type), lev_(5), deb_stream_(_deb_stream), num_flush_(0)
  {
    set_file_name(_file_name);
648
649
650
    indent_size_ = 3;
    //    indent_string_ = ".";
    set_module_color("PARA", 0xFF8000);
651
652
    set_module_color("SOLV", 0x00FF00);
    set_module_color("NSLV", 0xFFFF00);
653
    set_module_color("FELD", 0x0080FF);
654
    set_module_color("CURV", 0x00FFFF);
655
656
    set_module_color("QMGN", 0xFF00FF);
    // Don't set a TEST module colour here because Test is not part of Reform
657
658
659
660
661
662
  }

  ~DebFile() {}

 
}; // endclass DebFile
663
664
665
666
667

// =====================================
//      DebEnter member funcs
// =====================================

668
DebEnter::DebEnter(const char * const _funcname, const int _count, const char * const _module) 
669
{
670
671
672
  // TODO: this might have to be atomic
  static int id_cnt=0;
  module_ = _module;
673
  deb_outs_ = 0;
674
  deb_lines_ = 0;
675
  id_ = ++id_cnt;
676
677
  count_ = _count;
  stream(0, false).dfile()->call_stack().add(_funcname, this);
678
679
680
681
}

DebEnter::~DebEnter() 
{
682
683
  DebFile * impl = stream(0, false).dfile();
  impl->call_stack().pop();
684

685
  std::string str;
686
  if ( ((deb_outs_ > 0) || (deb_lines_ >0)) && impl->anchor(str, id_, "exit", true))
687
  {
688
    impl->anchor(str, id_, "exit", false);  
689
690
    impl->print_direct(str);
  }
691
692
}

693
DebStream& DebEnter::stream(const int _warn, const bool _print)
694
695
{
  DebStream & ds = ReForm::DebStream::get_global(_warn);
696
697
698
  DebFile * impl = ds.dfile();

  if ( _print)
699
  {
700
701
702
703
704
705
706
707
708
    if (impl->is_html())
    {
      int col = impl->get_module_color(module_);
      char buffer[256];
      sprintf_s(buffer, sizeof(buffer),"<FONT COLOR=\"#%06X\" SIZE=%i>", 
        col, impl->priority()+1 );
      ds.print(buffer, false);
    }

709
710
711
    if ( deb_outs_ < 1)
    {
      // First DEB_out in this function so output callstack, and flush.
712
713
714
715
      std::string str;
      bool is_html = impl->is_html();
      if (is_html)
      {
716
717
        str.append("<FONT SIZE=2><u>");
        impl->anchor(str, id_,"enter", true);
718
      }
719
720
721
722
723
      else
      {  // .txt call stack lead in
        str.append("****>");
      }

724
      impl->call_stack().get(str);
725
      if (is_html) str.append("</u></FONT>");
726
727
      str.append("\n");
      ds.print(str.c_str(), false); // Don't fork callstack to cerr etc.
728
      ds.dfile()->flush();
729
730
731
    }
    else
    {
732
      if ( impl->is_at_line_start() )
733
      {
734
        impl->indent();
735
736
737
738
739
740
741
742
      }
    }
    ++deb_outs_;
  }

  return ds;
}

743
int DebEnter::permission(const int _lev, const int _warn)
744
{ 
745
746
  int res = ReForm::DebStream::get_global().dfile()->permission(_lev, _warn, module_);
  return res;
747
748
}

749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816

void FunctionCallSequence::indent(std::string & _str, DebFile * _dfile, bool _is_html)
{
  int num = number_calls();
  for (int i=0; i<num; ++i) 
  { 
    DebEnter * deb = debs_[i];
    if (_is_html)
    {
      /* HTML indent element is <L> with span title the name and count
      of the function and with < linking to the entry anchor (if present) and
      > linking to the exit anchor (will be present).
      L is the first letter of the module name */
      char hovert[1024];
      sprintf_s(hovert, sizeof(hovert), "%s[%i]", func_name_.c_str(), deb->count_);
      int col = _dfile->get_module_color(deb->module_);
      char buffer[1024];
      sprintf_s(buffer, sizeof(buffer), "<FONT COLOR=\"#%06X\">.", col);

      _dfile->hover(_str, std::string(hovert), true);

      _str.append(buffer);
      std::string cstk;
      //impl->call_stack().get(cstk);
      if ((deb->deb_outs_>0) && _dfile->link_to(_str, deb->id_, "enter", cstk, true))
      {
        _str.append("&lt;");
        _dfile->link_to(_str, deb->id_, "enter", cstk,  false);
      }
      else _str.append("&lt;");

      _str.append(deb->module_, 1);

      if (_dfile->link_to(_str, deb->id_, "exit", cstk, true))
      {
        _str.append("&gt;");
        _dfile->link_to(_str, deb->id_, "exit", cstk,  false);
        ++deb->deb_lines_;
      }

      _dfile->hover(_str, std::string(hovert), false);

      _str.append("</FONT>");
    } // endif html
    else _str.append("  ");
  }
}

bool CallStack::indent(std::string& _str, DebFile * _dfile, const bool is_html)
{

  if (_dfile->indent_size() == 0) return false;
  if (is_html)
  {
    char buffer[64];
    sprintf_s(buffer, sizeof(buffer), "<FONT SIZE=%i>", _dfile->indent_size());
    _str.append(buffer);
  }
  int num = (int)calls_.size();
  for (int i =0; i< num; ++i)
  {
    calls_[i].indent(_str, _dfile,  is_html);
  }
  if (is_html) _str.append(":&nbsp;</FONT>\n");
  return true;
}


817
818
819
820
821
822
823
824
// =====================================
//        DebStream member funcs
// =====================================


DebStream::DebStream(const char * _file_name, StreamType _type)
{
  // NB. disable DEB_out over this new if new contains DEB_out
825
  dfile_ = new DebFile(this, _type, _file_name);
826
827
828
829
}

DebStream::~DebStream()
{
830
  if ( dfile_ != nullptr)
831
  {
832
833
    dfile()->close();
    dfile()->clear();
834
    // NB. disable DEB_out over this delete if delete contains DEB_out
835
836
    delete dfile_;
    dfile_ = nullptr;
837
838
839
840
841
  }
}

DebStream& DebStream::print(const int _i)
{
842
  dfile_->print(_i);
843
844
845
846
847
  return *this;
};

DebStream& DebStream::print(const double _d)
{
848
  dfile_->print(_d);
849
850
851
852
853
  return *this;
};

DebStream& DebStream::print(const char * _s, bool _fork)
{
854
  dfile_->print(_s, _fork);
855
856
857
858
859
  return *this;
};

DebStream& DebStream::print(const char _c)
{
860
861
862
863
864
865
866
  dfile_->print(_c);
  return *this;
};

DebStream& DebStream::print(const DebCommand & _co)
{
  dfile_->print(_co);
867
868
869
870
871
872
873
874
  return *this;
};

DebStream & DebStream::get_global(int _warn)
{
  _warn; 
  // TODO: Replace with a Singleton?? ThreadArray??
  static DebStream g_ds__("reform_deb_out.txt");
875
  //static DebStream g_ds__("reform_deb_out.htm");
876
877
878
879
880
881
882
883
884
885
886
887
888
  return g_ds__;
}

DebStream& operator<<(DebStream& ds, const int i ) { return ds.print(i);}
DebStream& operator<<(DebStream& ds, const double d ) { return ds.print(d);}
DebStream& operator<<(DebStream& ds, const char * const s ) { return ds.print(s);}
DebStream& operator<<(DebStream& ds, const char c) { return ds.print(c);}

DebStream& operator<<(DebStream& ds, const size_t i ) { return ds.print((int)i);}
DebStream& operator<<(DebStream& ds, const unsigned int i ) { return ds.print((int)i);}
DebStream& operator<<(DebStream& ds, const float f ) { return ds.print((double)f);}
DebStream& operator<<(DebStream& ds, const std::string& s ) { return ds.print(s.c_str());}

889
890
891
DebStream& operator<<(DebStream& ds, const DebCommand& co ) { return ds.print(co); }


892
893
894
}//namespace


895
#endif // DEB_ON