저는 Qt에 대해 매우 잘 알고 있습니다. 여기에 MOC 부분이 없기 때문에 유사한 신택스를 사용할 수 없다는 것을 알고 있습니다. 그러나 신호 생성 및 신호 클래스의 연결을 간단하게하기 위해 신호 생성 관리를 시도하고 있습니다. 내가 "를 해결 수 있다고 생각 (대문자 = 된 부분)사용자 등급의 다중 서명 신호 관리
class SignalManager
{
public:
typedef boost::unrodered_map<std::string, GENERIC_SIGNAL *> MapSignal;
public:
template <typename Sig>
bool connect(const std::string& strSignalName, boost::signal<Sig>::slot_type slot)
{
// simplyfied... :
(*m_mapSignal.find(strSignalName))->connect(slot);
}
template <typename Sig>
bool disconnect(const std::string& strSignalName, boost::signal<Sig>::slot_type slot)
{
// simplyfied... :
(*m_mapSignal.find(strSignalName))->disconnect(slot);
}
protected:
bool call(const std::string& strSignalName, SIGNAL_ARGS)
{
(*m_mapSignal.find(strSignalName))(SIGNAL_ARGS);
}
template <typename Sig>
void delareSignal(const std::string& strSignalName)
{
m_mapSignals.insert(MapSignal::value_type(strSignalName, new boost::signal<Sig>()));
}
void destroySignal(const std::string& strSignalName)
{
// simplyfied... :
auto it = m_mapSignal.find(strSignalName);
delete *it;
m_mapSignal.erase(it);
}
private:
MapSignal m_mapSignals;
};
class Foo : public SignalManager
{
public:
Foo(void)
{
this->declareSignal<void(int)>("Move");
this->declareSignal<void(double)>("Rotate");
}
};
class Other : public boost::signals::trackable
{
public:
Other(Foo *p)
{
p->connect("Move", &Other::onMove);
p->connect("Rotate", &Other::onRotate);
}
void onMove(int i)
{
/* ... */
}
void onRotate(double d)
{
/* ... */
}
};
이
내가 지금
class Foo
{
public:
void connectMove(boost::signal<void(int)>::slot_type slot)
void connectRotate(boost::signal<void(double)>::slot_type slot)
private:
boost::signal<void(int)> m_signalMove;
boost::signal<void(double)> m_signalRotate;
};
을 뭘하는지 schematicly이며, 이것은 내가하고 싶은 것이 basicaly입니다 SIGNAL_ARGS "부분에 boost :: functions_traits <>가 있지만 추상적 인 신호 유형을 어떻게 처리해야할지 모르겠다.
1/내가 원하는 것도 가능합니까?
2 /이 방법이 좋은 방법입니까? (나는이 -> 호출 ("signalname", ...)을 사용할 때 essordly unordered_map.find로 인해 약간의 오버 헤드를 가질 것이라는 것을 알고 있지만 너무 중요해서는 안된다고 생각한다.)
3/이것이 가능하지 않거나 좋은 방법이 아니라면 다른 제안이 있습니까?