dynamic-graph  4.1.0-8-gdab7-dirty
Dynamic graph library
tracer.h
1 // -*- mode: c++ -*-
2 // Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3 // JRL, CNRS/AIST.
4 //
5 
6 #ifndef DYNAMIC_GRAPH_TRACER_H
7 #define DYNAMIC_GRAPH_TRACER_H
8 #include <boost/function.hpp>
9 #include <list>
10 #include <string>
11 
12 #include <dynamic-graph/entity.h>
13 #include <dynamic-graph/exception-traces.h>
14 #include <dynamic-graph/signal-base.h>
15 #include <dynamic-graph/signal-time-dependent.h>
16 #include <dynamic-graph/time-dependency.h>
17 
18 #include <dynamic-graph/config-tracer.hh>
19 
20 namespace dynamicgraph {
24 class DG_TRACER_DLLAPI Tracer : public Entity {
25  DYNAMIC_GRAPH_ENTITY_DECL();
26 
27 protected:
28  typedef std::list<const SignalBase<int> *> SignalList;
29  SignalList toTraceSignals;
30 
31 public:
32  enum TraceStyle {
33  WHEN_SAID
35  ,
36  EACH_TIME
38  ,
39  FREQUENTLY
41  };
42  TraceStyle traceStyle;
43  static const TraceStyle TRACE_STYLE_DEFAULT = EACH_TIME;
44  double frequency;
45 
46  std::string basename;
47  std::string suffix;
48  std::string rootdir;
49  bool namesSet;
50  typedef std::list<std::ostream *> FileList;
51  FileList files;
52  typedef std::list<std::string> NameList;
53  NameList names;
54  bool play;
55  int timeStart;
56 
57 public:
58  Tracer(const std::string n);
59  virtual ~Tracer() { closeFiles(); }
60 
61  void addSignalToTrace(const SignalBase<int> &sig,
62  const std::string &filename = "");
63  void addSignalToTraceByName(const std::string &signame,
64  const std::string &filename = "");
65  void clearSignalToTrace();
66  // void parasite( SignalBase<int>& sig );
67  void openFiles(const std::string &rootdir, const std::string &basename,
68  const std::string &suffix);
69  virtual void closeFiles();
70 
71 protected:
72  virtual void openFile(const SignalBase<int> &sig,
73  const std::string &filename);
74 
75 public:
76  void setTraceStyle(const TraceStyle &style) { traceStyle = style; }
77  TraceStyle getTraceStyle() { return traceStyle; }
78 
79  void setFrenquency(const double &frqu) { frequency = frqu; }
80  double getFrequency() { return frequency; }
81 
82  void record();
83  virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig);
84  int &recordTrigger(int &dummy, const int &time);
85 
86  virtual void trace();
87  void start() { play = true; }
88  void stop() { play = false; }
89 
90 public:
91  // SignalTrigerer<int> triger;
93 
94  /* --- DISPLAY --------------------------------------------------------- */
95  DG_TRACER_DLLAPI friend std::ostream &operator<<(std::ostream &os,
96  const Tracer &t);
97 
98  /* --- PARAMS --- */
99  void display(std::ostream &os) const;
100 };
101 
102 } // end of namespace dynamicgraph
103 
104 #endif
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: entity.h:53
Tracer plug-in main class.
Definition: tracer.h:24