/
Zero_Fly
/
parall
Обзор
Документация
Войти
/
Zero_Fly
/
parall
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/parallel-executor/deviceA.h
50 строк
1 KB
akulyanin
add random string
22 янв 2025, 15:33
22 янв 2025, 15:33
4c9eefb
Код
Авторство
О чём код?
#include"device.h" #include<string> #include<memory> #include<vector> #include<thread> using namespace std; class ReadA: public Read{ shared_ptr<string> read(string msg) override{ std::this_thread::sleep_for(1000ms); return make_shared<string>(msg); } }; class DeviceA: public Device{ public: DeviceA(){ this->reader = new ReadA(); } DeviceA(int _lifeTime): Device(_lifeTime){ this->reader = new ReadA(); } DeviceA(int _lifeTime, Read* rd): Device(_lifeTime, rd){} shared_ptr<string> getDataAsString() override{ if(lifeTime == 0) return nullptr; else { decLife(); int len = random() % 501; return reader->read(gen_random(len)); } } string getName() override{ return "A";} private: string gen_random(const int len) { static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; std::string tmp_s; tmp_s.reserve(len); for (int i = 0; i < len; ++i) { tmp_s += alphanum[rand() % (sizeof(alphanum) - 1)]; } return tmp_s; } };