|
-
February 7th, 2010, 05:03 AM
#13
Re: static factory...
 Originally Posted by mop65715
This has become silly
It's your responsability to explain clearly what's your problem. Your code it's not clear and it's full of inconcistencies that make very hard to understand exactly what's your real intent.
As far as I could read from your code snippets you have two class hyerarchies P and D, a mechanism describing a set of fixed connections between pairs of P's and D's, a function (update_p_msg) issuing a message to some P and a function (process) notifing the message to the correspondingly connected D's. Am I right ?
If this is the case,
Code:
typedef int Message;
typedef boost::shared_ptr<P> PPtr;
typedef boost::shared_ptr<D> DPtr;
typedef std::pair<PPtr,DPtr> PDConn;
void Process( P& p, Message msg );
void Process( D& d, Message msg );
class ProcessConnection: std::unary_function<const PDConn&,void>
{
public:
ProcessConnection( Message msg )
: msg_(msg) {}
void operator()( const PDConn& connection) const
{
Process( *connection.first, msg_ );
Process( *connection.second, msg_ );
}
private:
Message msg_;
};
int main()
{
std::vector<PPtr> vector_of_Ps;
std::vector<DPtr> vector_of_Ds;
std::multi_map<PPtr,DPtr> connections;
// pupulate vectors
vector_of_Ps.push_back( ... );
vector_of_Ds.push_back( ... );
// pupulate connections
connections.insert( PDConn( vector_of_Ps.front(), vector_of_Ds.back() ) );
// "send" a message
Message some_message = 1;
std::for_each( connections.begin(), connections.end(),
ProcessConnection( some_message ) );
}
ps.: I've not compiled nor tested the code...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|