Re: Throwing constructor for wrong type of objects
 
Vladimir Jovic wrote:
Victor Bazarov wrote:
Vladimir Jovic wrote:
Victor Bazarov wrote:
Vladimir Jovic wrote:
[..]
Buffers (except for the source and destination) can be created in a 
vector, list, or queue (different container objects for different 
base buffer classes).
Where do those live and what is the relationship between buffers of 
different types (instance of different templates) and the queue (one 
object) which is going to "connect buffers"?
Buffers are created on the heap, and are completely independent.
They can't be independent if they are put in a queue.
Not sure I understand. Why they wouldn't be independent?
 > The
requirements are that the first has to be the source buffer type, 
which somehow gets input data (doesn't matter how), and the last has 
to be the destination buffer type, where the resulting data is stored.
Data is of fixed size, which is known in front.
All filter objects will be stored in one container, and the data 
will be processed in one run.
OK, let's proceed with a simplified model.  Let's have a queue of 
two filters, and make it create all the "buffers" for those and 
process the input to get to the output.
struct Filter
{
   virtual void setFrom(???);
   virtual void setTo(???);
   virtual void process(??, ??);
};
It is actually simpler :
struct Filter
{
  Filter( const BufferType1 &b1, BufferType2 &b2 );
  virtual void Process();
};
or as you wrote it:
struct Filter
{
  void SetFrom( const BufferType1 &b1 );
  void SetTo( BufferType1 &b1 );
  virtual void Process();
};
Only one combination of BufferType1/BufferType2 are valid for any 
Filter type.
The Process() method reads data from the input buffer, process it, 
and store the result in the output buffer.
// now, is this queue generic or does it know how many filters
// it has and what is the sequence of types it processes?
The queue is generic, and can be changed during the program 
execution. It can contain any number of filters.
If it was static, I would not have this problem.
struct FilterQueue
{
    typedef std::list<Filter*> list;
    typedef list::iterator iterator;
    list filters;
    void append(Filter* pf) { filters.push_back(pf); }
    void createBuffers(???) {
        // the filters are added in 'append', here we need to add
        // all the buffers between the filters
        for (iterator it = filters.begin(); it != filters.end; ++it)
        {
           // it would seem that the buffers have to be *ALSO*
           // storable in some kind of container, no?  Otherwise
           // how do you move from 'createBuffers' to 'process'?
        }
    }
    void process(???) {
        for (iterator it = filters.begin(); it != filters.end; ++it)
            it->process(??,??);
    }
};
I can only see more questions that haven't yet been answered.  Do 
you have any answers?
There are actually two classes:
class BufferQueue
{
  typedef std::list<Filter*> list;
                      ^^^^^^
Really?
Typo. Should have been Buffer*
So, what's a Buffer?  Below you say it's a template.  It can't be a 
template if you are going to put it in a common BufferQueue.  Or is it 
not a common BufferQueue, but itself a template?  Then you can't pass a 
reference to it to a single function in FilterQueue either...
  typedef list::iterator iterator;
  void CreateBuffers( ConfigType & )
  {
    list.push( sourceBuffer);
What is 'sourceBuffer'?  What type does it have?  Is it convertible to 
'Filter*'?
It is not. The source and destination buffers are declared like this:
class SourceBuffer : public BufferBase< unsigned short >;
class DestinationBuffer : public BufferBase< unsigned char >;
    // create all intermediate buffers
    list.push( destBuffer);
  }
  list buffers;
};
Actually, since I got 3 base types (BufferBase is a template), there 
should be 3 queues for each buffer type.
I am not sure I understand.  3 base types : BufferBase<unsigned char>, 
BufferBase<unsigned short>, BufferBase<unsigned long>?  Or something 
else?  So, do you have 3 queues which are also instantiations of some 
class template?  Consider spelling it out, don't expect me to pull it 
out of you with pliers.
The idea is to have dump Buffer classes, which holds array as 
intermediate data points, and to use Filter classes to transfer and 
transform data from one point to another (from the source to the 
destination/sink)
struct FilterQueue
{
    typedef std::list<Filter*> list;
    typedef list::iterator iterator;
    list filters;
  void CreateFilters( ConfigType &, BufferQueue & )
  {
    // read configuration
    // create filters (types are defined in the configuration)
    // connect buffers to each filter
  }
    void process() {
        for (iterator it = filters.begin(); it != filters.end; ++it)
            it->process();
    }
};
Seems like you got a few things to figure out, still.
Looked simple and straight-forward on the paper :/
Start writing code.  And start from the *use* of your classes, so you 
can figure out the interfaces.  Then try declaring the interfaces. 
Forget about linking, try making it compile.  Then add implementations 
to some of your interfaces.
It's an iterative process.  It looks very clean and straightforward in 
one's head, sometimes on paper, but as soon as you try coding it, the 
cleanliness and straightforwardness is usually gone (at least 
temporarily until you figure it all out).
I recommend trying to get as much done as you can and repost when you 
have more questions.  Post real compilable (or almost compilable) code 
at that time.
V
-- 
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask