Digitalisierte Elektroverteilung zur permanenten Verbraucherüberwachung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataModel.h 1.2KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <memory>
  3. #include <vector>
  4. #include <map>
  5. #include <chrono>
  6. #include <optional>
  7. #include <regex>
  8. #include <atomic>
  9. #include "PublisherData.h"
  10. constexpr auto READ_BUFFER_SIZE = 4096;
  11. typedef std::map<unsigned int, std::vector<PublisherData>> data_key_map;
  12. using namespace std::chrono;
  13. class DataModel
  14. {
  15. public:
  16. //Sigleton Methods
  17. static std::unique_ptr<DataModel>& Instance();
  18. static void Destroy();
  19. static void Create();
  20. void savePublishedData(PublisherData data);
  21. data_key_map& getSavedPublishedData() { return savedPublishedData; };
  22. //saves collected data after a certain amount of time points
  23. void checkIfToFlush(bool keepDataLocally = false);
  24. private:
  25. //static instance which can be accessed by calling DataModel::Instance()
  26. static std::unique_ptr<DataModel> instance;
  27. //Data from publishers, one elemt in outer vector for one id
  28. //Each id consists of a vector of PublisherData (use map to make the id become a unique key)
  29. data_key_map savedPublishedData;
  30. //ostream operators (read and write dataModel data from streams)
  31. friend std::ostream& operator<<(std::ostream& os, DataModel& dataModel);
  32. friend std::istream& operator>>(std::istream& is, DataModel& dataModel);
  33. };