VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
columnLogger.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include "vrfutil/vrfutilDefines.h"
12 
13 #include <boost/noncopyable.hpp>
14 
15 #include <iosfwd>
16 #include <string>
17 #include <sstream>
18 
19 #include <map>
20 #include <list>
21 #include <vector>
22 #include <boost/ptr_container/ptr_list.hpp>
23 
24 #include <tbb/spin_mutex.h>
25 #include <tbb/spin_rw_mutex.h>
26 
27 class DT_DLL_vrfutil DtColumnLogger : boost::noncopyable
28 {
29 public:
30  explicit DtColumnLogger();
31 
32  ~DtColumnLogger();
33 
34  class DT_DLL_vrfutil Column : boost::noncopyable
35  {
36  public:
38  {
39  typedef std::list<Value> List;
40 
41  unsigned line;
42  double number;
43  unsigned calls;
44  unsigned precision;
45 
46  struct Parent
47  {
48  typedef std::vector<Parent> Sequence;
49 
50  const char* group;
51  double percent;
52 
53  explicit Parent(const char* g, double p)
54  : group(g), percent(p) { }
55  };
56 
58 
59  Value& setGroup(const char* n, double percent)
60  { parents.push_back(Parent(n,percent)); return *this; }
61  Value& addCalls(unsigned c) { calls += c; return *this; }
62  Value& setPrecision(unsigned p) { precision = p; return *this; }
63 
64  std::string str() const;
65 
66  explicit Value(double number, unsigned line);
67  };
68 
69  typedef boost::ptr_list<Column> Sequence;
70 
71  explicit Column(DtColumnLogger&, const std::string& label);
72  explicit Column(Column& parent, const std::string& label);
73 
74  Column& getColumn(const std::string& label, int index = -1);
75 
76  Value& addValue(double);
77 
78  template <typename T>
79  Value& addValue(T val)
80  {
81  return addValue(double(val)).setPrecision(3);
82  }
83 
85  void reset(bool resetWidth);
86 
87  int print(std::ostream* textstream, std::ostream* csvsteram, bool headers);
88 
90  unsigned width();
91  void updateWidth(unsigned, bool onlyIfGreater=true);
92 
93  Value::List& values() { return myValues; }
94  Sequence& subColumns() { return myColumns; }
95 
96  std::string label() const { return myLabel; }
97 
98  void markAsPrinted();
99  bool hasBeenPrinted();
100 
101  private:
102  typedef tbb::spin_rw_mutex Mutex;
103 
104  mutable Mutex myMutex;
106 
107  std::string myLabel;
109 
110  unsigned myMaxWidth;
111  bool myNewFlag;
112 
114  };
115 
116  Column& getColumn(const std::string& label, int index = -1)
117  {
118  return myRootColumn.getColumn(label, index);
119  }
120 
121  Column& getColumn(const char* label, int index = -1)
122  {
123  return getColumn(std::string(label), index);
124  }
125 
126  unsigned lineNumber() const;
127  void incrementLineNumber();
128 
130  void reset(bool resetWidth = false);
131 
133  void print();
134  void printText(const std::string&);
135 
136  void setOutput(const std::string& file);
137  void setTag(const std::string& tag);
138 
139 private:
140  void initFiles();
141 
142  unsigned myCurrentLine;
144 
146  std::string myTextOutputFile;
147  std::string myCSVOutputFile;
148  std::string myTag;
149 
150  std::ostream* myTextOutput;
151  std::ostream* myCSVOutput;
152 
153 };

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)