What void operator()()
does? Found this while trying to rewrite a C++ program in python but can't even understand the functionality of this method. Its not called from anywhere in code but it is called anyway by a program and cant really understand what is this about? When is something like this called by program itself?
class MoistureSensor {
const std::chrono::seconds sleepTime;
std::mutex& mtx;
std::set<WaterDevice*> devices;
const int min = 0;
const int max = 10;
const int threshold = 3;
public:
MoistureSensor(const std::chrono::seconds sleepTime, std::mutex& mtx)
: sleepTime{ sleepTime }
, mtx{ mtx }
{
}
void subscribe(WaterDevice& device) {
devices.insert(&device);
}
void operator()(){
for (;;) {
std::cout << "this\n";
std::unique_lock<std::mutex> lock(mtx);
if (isAirTooDry())
for (auto p : devices)
p->sprinkleWater();
if (isSoilTooDry())
for (auto p : devices)
p->pourWater();
lock.unlock();
std::this_thread::sleep_for(sleepTime);
}
}
void foo();
private:
bool isAirTooDry();
bool isSoilTooDry();
int getAirMoisture();
int getSoilMoisture();
};
Is there an equivalent of something like this in Python?