Hey, da nun Visual Studio 2013 im RTM stand ist, habe ich mal mein signal/slots lib angepasst.
Es ist unabhängig von irgendwelchen 3rd party libs (z.B. boost) und sollte sich problemlos auf jedem C++11 fähigen Compiler, der variadische Templates unterstützt benutzen lassen.
Das Library besteht aus einer einzigen Headerdatei, die ihr nur fix in euer Projekt einbinden braucht. Es unterstützt connection-objekte, mit denen man den Status einer Verbindung abfragen bzw. den Slot vom Signal disconnecten kann. ScopedConnection wird die Verbindung trennen, wenn das Connection-Objekt zerstört wird.
Zusätzlich lässt sich über custom-compare Funktionen ganz einfach das minimale/maximale Ergebins eines Aufrufs ermitteln. Slots können auch während eines Aufrufs ohne Probleme disconnected werden.
Source: [Only registered and activated users can see links. Click Here To Register...]
Beispiel:
Es ist unabhängig von irgendwelchen 3rd party libs (z.B. boost) und sollte sich problemlos auf jedem C++11 fähigen Compiler, der variadische Templates unterstützt benutzen lassen.
Das Library besteht aus einer einzigen Headerdatei, die ihr nur fix in euer Projekt einbinden braucht. Es unterstützt connection-objekte, mit denen man den Status einer Verbindung abfragen bzw. den Slot vom Signal disconnecten kann. ScopedConnection wird die Verbindung trennen, wenn das Connection-Objekt zerstört wird.
Zusätzlich lässt sich über custom-compare Funktionen ganz einfach das minimale/maximale Ergebins eines Aufrufs ermitteln. Slots können auch während eines Aufrufs ohne Probleme disconnected werden.
Source: [Only registered and activated users can see links. Click Here To Register...]
Beispiel:
Code:
int main(int argc, const char* argv[])
{
try {
// create some signal, return value float - arguments: int, float
SimpleSig::Signal<float(int, float)> someSignal;
// connect a slot and get a default connection
auto someSlot = someSignal.connect([](int a1, float a2) {
return a1 / a2;
});
if (someSlot)
std::cout << "someSlot is connected!" << std::endl;
// connect a sig with +=
someSignal += [](int a1, float a2) {
return a1 * a2;
};
{ // connect a sig and get a scoped connection
SimpleSig::ScopedConnection<float(int, float)> g =
someSignal.connect([](int a1, float a2) {
return a1 + a2;
});
// print all results
std::cout << "printing all " << someSignal.size() << " results..." << std::endl;
for (auto result : someSignal.invoke_getall(5, 7.1f))
std::cout << result << std::endl;
} // ~g, disconnects the slot
// get the minimum of all returned results...
// invoke and operator() return a proxy class which can be used to check if anything was returned
std::cout << "getting minimum value..." << std::endl;
std::cout << *someSignal.invoke<SimpleSig::Minimum>(5, 7.1f) << std::endl;
// how many slots are left? (should be 2)
std::cout << "there are still " << someSignal.size() << " slots connected!" << std::endl;
// use default compare
std::cout << "getting default value..." << std::endl;
std::cout << *someSignal(5, 7.1f) << std::endl;
someSignal.clear();
if (!someSlot)
std::cout << "someSlot is disconnected!" << std::endl;
// should throw an exception: attempt to access empty return value...
std::cout << *someSignal(1, 2.9f) << std::endl;
}
catch (SimpleSig::Error &e) {
std::cout << e.what() << std::endl;
}
std::cin.get();
return 0;
}