ClassFlow.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "ClassFlow.h"
  2. #include <fstream>
  3. #include <string>
  4. #include <iostream>
  5. #include <string.h>
  6. #include "esp_log.h"
  7. static const char *TAG = "FLOW CLASS";
  8. void ClassFlow::SetInitialParameter(void)
  9. {
  10. ListFlowControll = NULL;
  11. previousElement = NULL;
  12. disabled = false;
  13. }
  14. std::vector<string> ClassFlow::ZerlegeZeile(std::string input, std::string delimiter)
  15. {
  16. std::vector<string> Output;
  17. input = trim(input, delimiter);
  18. size_t pos = findDelimiterPos(input, delimiter);
  19. std::string token;
  20. while (pos != std::string::npos) {
  21. token = input.substr(0, pos);
  22. token = trim(token, delimiter);
  23. Output.push_back(token);
  24. input.erase(0, pos + 1);
  25. input = trim(input, delimiter);
  26. pos = findDelimiterPos(input, delimiter);
  27. }
  28. Output.push_back(input);
  29. return Output;
  30. }
  31. bool ClassFlow::isNewParagraph(string input)
  32. {
  33. if ((input[0] == '[') || ((input[0] == ';') && (input[1] == '[')))
  34. {
  35. return true;
  36. }
  37. return false;
  38. }
  39. bool ClassFlow::GetNextParagraph(FILE* pfile, string& aktparamgraph)
  40. {
  41. while (getNextLine(pfile, &aktparamgraph) && !isNewParagraph(aktparamgraph));
  42. if (isNewParagraph(aktparamgraph))
  43. return true;
  44. return false;
  45. }
  46. ClassFlow::ClassFlow(void)
  47. {
  48. SetInitialParameter();
  49. }
  50. ClassFlow::ClassFlow(std::vector<ClassFlow*> * lfc)
  51. {
  52. SetInitialParameter();
  53. ListFlowControll = lfc;
  54. }
  55. ClassFlow::ClassFlow(std::vector<ClassFlow*> * lfc, ClassFlow *_prev)
  56. {
  57. SetInitialParameter();
  58. ListFlowControll = lfc;
  59. previousElement = _prev;
  60. }
  61. bool ClassFlow::ReadParameter(FILE* pfile, string &aktparamgraph)
  62. {
  63. return false;
  64. }
  65. bool ClassFlow::doFlow(string time)
  66. {
  67. return false;
  68. }
  69. string ClassFlow::getHTMLSingleStep(string host){
  70. return "";
  71. }
  72. string ClassFlow::getReadout()
  73. {
  74. return string();
  75. }
  76. std::string ClassFlow::GetParameterName(std::string _input)
  77. {
  78. string _param;
  79. int _pospunkt = _input.find_first_of(".");
  80. if (_pospunkt > -1)
  81. {
  82. _param = _input.substr(_pospunkt+1, _input.length() - _pospunkt - 1);
  83. }
  84. else
  85. {
  86. _param = _input;
  87. }
  88. // ESP_LOGD(TAG, "Parameter: %s, Pospunkt: %d", _param.c_str(), _pospunkt);
  89. return _param;
  90. }
  91. bool ClassFlow::getNextLine(FILE* pfile, string *rt)
  92. {
  93. char zw[1024];
  94. if (pfile == NULL)
  95. {
  96. *rt = "";
  97. return false;
  98. }
  99. if (!fgets(zw, 1024, pfile))
  100. {
  101. *rt = "";
  102. ESP_LOGD(TAG, "END OF FILE");
  103. return false;
  104. }
  105. ESP_LOGD(TAG, "%s", zw);
  106. *rt = zw;
  107. *rt = trim(*rt);
  108. while ((zw[0] == ';' || zw[0] == '#' || (rt->size() == 0)) && !(zw[1] == '[')) // Kommentarzeilen (; oder #) und Leerzeilen überspringen, es sei denn es ist ein neuer auskommentierter Paragraph
  109. {
  110. *rt = "";
  111. if (!fgets(zw, 1024, pfile))
  112. return false;
  113. ESP_LOGD(TAG, "%s", zw);
  114. *rt = zw;
  115. *rt = trim(*rt);
  116. }
  117. return true;
  118. }