CLAM-Development  1.4.0
ControlTrace.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  * Copyright (c) 2007 Superlucidity Services, LLC and Zachary T Welch
5  *
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 
23 #ifndef CONTROL_TRACE_HXX
24 #define CONTROL_TRACE_HXX
25 
26 #include "Processing.hxx"
27 #include "ProcessingConfig.hxx"
28 #include "InControlArray.hxx"
29 #include "OutControlArray.hxx"
30 #include "Filename.hxx"
31 #include <vector>
32 
33 namespace CLAM
34 {
35 
36 class ControlTraceEvent : public Component {
37 public:
38  typedef std::vector<TControlData> ValueArray;
39 
41  ControlTraceEvent(const InControlArray &inputs);
44  virtual ~ControlTraceEvent() { }
45 
46  const char *GetClassName() const { return "ControlTraceEvent"; }
47 
48  void LoadFrom( Storage& storage);
49  void StoreOn( Storage& storage ) const;
50 
51  void WasRepeated() { mRepeats++; }
52  unsigned int Repeats() const { return mRepeats; }
53 
54  size_t Size() const { return mValues.size(); }
55 
56  void UpdateControls(OutControlArray &array) const;
57 
58  bool ValuesEqual(const ControlTraceEvent &rhs) const;
59 
60 private:
61  unsigned int mRepeats;
62  ValueArray mValues;
63 };
64 
65 class ControlTraceData : public Component {
66  static const unsigned int DumpVersion;
67 public:
68  typedef std::list<ControlTraceEvent> EventList;
69  virtual ~ControlTraceData() { }
70 
73 
74  const char *GetClassName() const { return "ControlTraceData"; }
75 
76  unsigned int GetVersion() const { return mVersion; }
77 
78  void LoadFrom( Storage& storage);
79  void StoreOn( Storage& storage ) const;
80 
81  size_t GetNumberOfControls() const { return mEvents.front().Size(); }
82 
83  void Append(const ControlTraceEvent &data);
84 
85  EventList::iterator Begin() { return mEvents.begin(); }
86  EventList::iterator End() { return mEvents.end(); }
87 
88  void Clear() { mEvents.clear(); }
89 
90 private:
91  unsigned int mVersion;
92  EventList mEvents;
93 };
94 
95 
97 {
98 public:
99  ControlTraceInFilename(const std::string & s="") : InFilename(s) {}
100  ControlTraceInFilename(const char * s) : InFilename(s) {}
101  const char* TypeFamily() const;
102  const Filter * Filters() const;
103 };
104 CLAM_TYPEINFOGROUP(BasicCTypeInfo, ControlTraceInFilename);
105 
107  DYNAMIC_TYPE_USING_INTERFACE
109 
110  DYN_ATTRIBUTE( 0, public, ControlTraceInFilename, TraceFile );
111 
112 protected:
113  void DefaultInit();
114 };
115 
117 {
118 public:
120  ControlTraceReader( const ProcessingConfig& cfg );
121  virtual ~ControlTraceReader();
122 
123  const char* GetClassName() const { return "ControlTraceReader"; }
124  const ProcessingConfig& GetConfig() const { return mConfig; }
125 
126  bool Do();
127 
128 protected: // methods
129  bool ConcreteConfigure( const ProcessingConfig& cfgObject );
130  bool ConcreteStart();
131  void RemoveOldControls();
132 
133 protected: // attributes
136  ControlTraceData::EventList::iterator mIterator;
137  unsigned int mRepeatCounter;
139 };
140 
141 
143 {
144 public:
145  ControlTraceOutFilename(const std::string & s="") : OutFilename(s) {}
146  ControlTraceOutFilename(const char * s) : OutFilename(s) {}
147  const char* TypeFamily() const;
148  const Filter * Filters() const;
149 };
150 CLAM_TYPEINFOGROUP(BasicCTypeInfo, ControlTraceOutFilename);
151 
153  DYNAMIC_TYPE_USING_INTERFACE
155 
156  DYN_ATTRIBUTE( 0, public, ControlTraceOutFilename, TraceFile );
157  DYN_ATTRIBUTE( 1, public, TData, NumberOfInputs );
158 
159 protected:
160  void DefaultInit();
161 };
162 
164 {
165 public:
167  ControlTraceWriter( const ProcessingConfig& cfg );
168  virtual ~ControlTraceWriter();
169 
170  const char* GetClassName() const { return "ControlTraceWriter"; }
171  const ProcessingConfig& GetConfig() const { return mConfig; }
172 
173  bool Do();
174 
175 protected: // methods
176  bool ConcreteConfigure( const ProcessingConfig& cfgObject );
177  bool ConcreteStop();
178  void RemoveOldControls();
179 
180 protected: // attributes
184 };
185 
186 } // CLAM namespace
187 
188 #endif