|
Boost Users : |
From: Stephen torri (storri_at_[hidden])
Date: 2004-11-14 22:16:50
On Sun, 2004-11-14 at 18:08 -0800, Cory Nelson wrote:
> boost.variant :)
>
Possible. Let me expand my example. The Data class is really the
mechanism I want to use to pass data between Components. A Component is
a virtual class that is inherited by classes that implement the
Component interface. Each Component class performs a action (e.g. Detect
file type) when the function process() is called and returns the results
(e.g. Data<string>) when the outcome() function is called. These two
functions are called by a visitor which walks the graph of Component
objects.
A simple graph example is:
A --> B --> ...
The Component 'A' performs an action which generates a 'std::string' as
a result. When the graph visitor calls A.process() then this result is
stored in the A class object. The graph visitor takes the result via
outcome as a Data<std::string> and initializes B.init
(Data<std::string>). The visitor continues on until the end.
Here is how I am defining the Component class:
class Component
{
public:
// Boost::variant? - need to store multiple types in m_data
void init (uint32_t id, Data<...> data);
// run child class action (call process)
void run (void);
// Virtual function child class must support. Using input stored in
// m_data do some action and store the result internally.
virtual void process (void) = 0;
// get child results
// Boost::variant? - need to return the results. The return type is
// dependent on the child class's function. In 'A' the return type is
// a std::string. Call outcome() in child
Data<...> result (void);
// Virtual function child class must support. return results
virtual Data<...> outcome (void) = 0;
private:
// Boost::variant? - need to store
// multiple types of inputs maybe here depending on the child class's
// function. For example, 'A' needs a 'unsigned int' and 'std::string'
// to work.
std::list< Data<...> > m_data;
};
So input Data element types (e.g. int, std::string) depend on the output
of the previous Component in the graph connected to the present
Component. The output Data element type (e.g. int, std::string) depends
on the implementation of the child class, e.g. result of process()
retrieved by calling outcome().
I think the boost::variant might work. I want to see if this further
detailing of the example help to confirm this.
Stephen
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net