Added a simple RTF::Worker class that can be subclassed in order to work

with the RTF document step by step.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10568 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2005-01-03 10:10:46 +00:00
parent 9932029846
commit 63c6a88ba0
2 changed files with 113 additions and 0 deletions

View File

@ -746,3 +746,92 @@ Iterator::Next()
return element;
}
// #pragma mark -
Worker::Worker(RTF::Header &start)
:
fStart(start)
{
}
Worker::~Worker()
{
}
void
Worker::Dispatch(Element *element)
{
if (RTF::Group *group = dynamic_cast<RTF::Group *>(element)) {
fSkip = false;
Group(group);
if (fSkip)
return;
for (int32 i = 0; (element = group->ElementAt(i)) != NULL; i++)
Dispatch(element);
GroupEnd(group);
} else if (RTF::Command *command = dynamic_cast<RTF::Command *>(element)) {
Command(command);
} else if (RTF::Text *text = dynamic_cast<RTF::Text *>(element)) {
Text(text);
}
}
void
Worker::Work() throw (status_t)
{
Dispatch(&fStart);
}
void
Worker::Group(RTF::Group *group)
{
}
void
Worker::GroupEnd(RTF::Group *group)
{
}
void
Worker::Command(RTF::Command *command)
{
}
void
Worker::Text(RTF::Text *text)
{
}
RTF::Header &
Worker::Start()
{
return fStart;
}
void
Worker::Skip()
{
fSkip = true;
}
void
Worker::Abort(status_t status)
{
throw status;
}

View File

@ -158,6 +158,30 @@ class Iterator {
group_destination fDestination;
};
class Worker {
public:
Worker(RTF::Header &start);
virtual ~Worker();
void Work() throw (status_t);
protected:
virtual void Group(RTF::Group *group);
virtual void GroupEnd(RTF::Group *group);
virtual void Command(RTF::Command *command);
virtual void Text(RTF::Text *text);
RTF::Header &Start();
void Skip();
void Abort(status_t status);
private:
void Dispatch(RTF::Element *element);
RTF::Header &fStart;
bool fSkip;
};
} // namespace RTF
#endif /* RTF_H */