[Clam-devel] PATCH: revised ControlTrace{Reader,Writer} classes
Zach Welch
zach-clam-devel at splitstring.com
Wed Apr 18 01:42:07 PDT 2007
Zach Welch wrote:
[snip]
> I have attached a new patch that accomplishes almost everything you ask;
> I think the Load is better performed in the Configure step, since errors
> can be detected at that point and reported as a misconfiguration. Other
> than that, I think it's all there... and then some. I added a "repeats"
> storage optimization that gives run length encoding of the value sets,
> which can help shrink (and annotate) traces whose inputs change
> relatively infrequently (e.g. GUI controls).
[snip]
After writing up the improvements in the ControlTrace components, I
realized there was a need to clean up the new "repeats" code such that
its value reflected the meaning of its name. This minor patch applies on
top of the last patch and fixes this conceptual problem, changing the
internal "steps" logic to "repeats". The resulting code reads much
better; these changes should have been part of the revised patch.
Cheers,
Zach
-------------- next part --------------
diff -u CLAM/src/Processing/Controls/ControlTrace.cxx CLAM/src/Processing/Controls/ControlTrace.cxx
--- CLAM/src/Processing/Controls/ControlTrace.cxx (revision 0)
+++ CLAM/src/Processing/Controls/ControlTrace.cxx (revision 0)
@@ -33,16 +33,16 @@
{
ControlTraceEvent::ControlTraceEvent()
- : mSteps(1)
+ : mRepeats(0)
{
}
ControlTraceEvent::ControlTraceEvent(const ControlTraceEvent &obj)
- : mSteps(obj.mSteps)
+ : mRepeats(obj.mRepeats)
, mValues(obj.mValues)
{
}
ControlTraceEvent::ControlTraceEvent(const InControlArray &inputs)
- : mSteps(1)
+ : mRepeats(0)
{
mValues.resize(inputs.Size());
for (int i = 0; i < inputs.Size(); i++)
@@ -60,7 +60,7 @@
XMLIterableAdapter<ValueArray> vAdapter(mValues, "x", "controls", true);
storage.Load(vAdapter);
- XMLAdapter<unsigned int> sAdapter(mSteps, "repeats", true);
+ XMLAdapter<unsigned int> sAdapter(mRepeats, "repeats", true);
storage.Load(sAdapter);
}
@@ -69,9 +69,9 @@
XMLIterableAdapter<ValueArray> vAdapter(mValues, "x", "controls", true);
storage.Store(vAdapter);
- if (mSteps > 1)
+ if (mRepeats)
{
- XMLAdapter<unsigned int> sAdapter(mSteps, "repeats", true);
+ XMLAdapter<unsigned int> sAdapter(mRepeats, "repeats", true);
storage.Store(sAdapter);
}
}
@@ -137,7 +137,7 @@
{
ControlTraceEvent &prev = mEvents.back();
if (prev.ValuesEqual(data))
- prev.AddStep();
+ prev.WasRepeated();
else
mEvents.push_back(data);
}
@@ -300,7 +300,7 @@
bool ControlTraceReader::ConcreteStart()
{
mIterator = mTrace.Begin();
- mStepCounter = 0;
+ mRepeatCounter = 0;
return true;
}
@@ -312,14 +312,15 @@
const ControlTraceEvent &event = *mIterator;
// if this is the zeroth (first) step, update the controls
- if (!mStepCounter)
+ if (!mRepeatCounter)
event.UpdateControls(mOutputs);
// if this step completes the current event, advance and reset counter
- if (++mStepCounter == event.Steps()) {
+ if (mRepeatCounter++ == event.Repeats()) {
mIterator++;
- mStepCounter = 0;
+ mRepeatCounter = 0;
}
+
return true;
}
diff -u CLAM/src/Processing/Controls/ControlTrace.hxx CLAM/src/Processing/Controls/ControlTrace.hxx
--- CLAM/src/Processing/Controls/ControlTrace.hxx (revision 0)
+++ CLAM/src/Processing/Controls/ControlTrace.hxx (revision 0)
@@ -52,8 +52,9 @@
void LoadFrom( Storage& storage);
void StoreOn( Storage& storage ) const;
- void AddStep() { mSteps++; }
- unsigned int Steps() const { return mSteps; }
+ void WasRepeated() { mRepeats++; }
+ unsigned int Repeats() const { return mRepeats; }
+
size_t Size() const { return mValues.size(); }
void UpdateControls(OutControlArray &array) const;
@@ -61,7 +62,7 @@
bool ValuesEqual(const ControlTraceEvent &rhs) const;
private:
- unsigned int mSteps;
+ unsigned int mRepeats;
ValueArray mValues;
};
@@ -137,7 +138,7 @@
ControlTraceReaderConfig mConfig;
ControlTraceData mTrace;
ControlTraceData::EventList::iterator mIterator;
- unsigned int mStepCounter;
+ unsigned int mRepeatCounter;
OutControlArray mOutputs;
};
More information about the clam-devel
mailing list