CCOS.Dev.MouldDefine.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #pragma once
  2. #include <string>
  3. using namespace std;
  4. #include "TmplMould.tlh"
  5. #include "TmplMould.tli"
  6. #include "ResDataObject.h"
  7. namespace DIOS::Dev::Detail
  8. {
  9. namespace ValKey
  10. {
  11. static const char* UNIT = "Unit";
  12. static const char* UPPERLIMIT = "Upperlimit";
  13. static const char* LOWERLIMIT = "Lowerlimit";
  14. static const char* WARNUPPERLIMIT = "WARNUpperlimit";
  15. static const char* WARNLOWERLIMIT = "WARNLowerlimit";
  16. static const char* INITIALVALUE = "Initialvalue";
  17. static const char* ACCURACY = "Accuracy";
  18. static const char* LIST = "LIST";
  19. }
  20. //-----------------------------------------------------------------------------
  21. // IntMould
  22. //-----------------------------------------------------------------------------
  23. class IntMould : public TmplMould <int>
  24. {
  25. using super = TmplMould <int>;
  26. public:
  27. IntMould(const char* strkey, int initialvalue, int min, int max, int accuracy)
  28. :super(initialvalue, min, max, accuracy)
  29. {
  30. Key = strkey;
  31. m_Value = initialvalue;
  32. }
  33. ~IntMould() {}
  34. std::string GetDescription()
  35. {
  36. ResDataObject temp, result;
  37. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  38. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  39. temp.add(ValKey::ACCURACY, m_Accuracy);
  40. result.add(Key.c_str(), temp);
  41. return result.encode();
  42. }
  43. std::string GetAttribute()
  44. {
  45. ResDataObject temp;
  46. temp.add(Key.c_str(), (int)m_Value);
  47. return temp.encode();
  48. }
  49. //
  50. std::string JSGet()
  51. {
  52. return std::to_string(m_Value);
  53. }
  54. std::string GetKey()
  55. {
  56. return Key;
  57. }
  58. protected:
  59. std::string Key;
  60. };
  61. //-----------------------------------------------------------------------------
  62. // FloatMould
  63. //-----------------------------------------------------------------------------
  64. class FloatMould : public TmplMould <float>
  65. {
  66. using super = TmplMould <float>;
  67. public:
  68. FloatMould(const char* strkey, float initialvalue, float min, float max, float accuracy)
  69. :super(initialvalue, min, max, accuracy)
  70. {
  71. Key = strkey;
  72. m_Value = initialvalue;
  73. }
  74. ~FloatMould() {}
  75. std::string GetDescription()
  76. {
  77. ResDataObject temp, result;
  78. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  79. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  80. temp.add(ValKey::ACCURACY, m_Accuracy);
  81. result.add(Key.c_str(), temp);
  82. return result.encode();
  83. }
  84. std::string GetAttribute()
  85. {
  86. ResDataObject temp;
  87. temp.add(Key.c_str(), (int)m_Value);
  88. return temp.encode();
  89. }
  90. std::string JSGet()
  91. {
  92. return std::to_string(m_Value);
  93. }
  94. std::string GetKey()
  95. {
  96. return Key;
  97. }
  98. protected:
  99. std::string Key;
  100. };
  101. //-----------------------------------------------------------------------------
  102. // IntMould
  103. //-----------------------------------------------------------------------------
  104. class IntMouldWithWarn : public TmplMouldWithWarn <int>
  105. {
  106. using super = TmplMouldWithWarn <int>;
  107. public:
  108. IntMouldWithWarn(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax, int CalibWarnMin, int CalibWarnMax, int max, int accuracy)
  109. :super(initialvalue, min, WarnMin, WarnMax, CalibWarnMin, CalibWarnMax, max, accuracy)
  110. {
  111. Key = strkey;
  112. m_Value = initialvalue;
  113. }
  114. ~IntMouldWithWarn() {}
  115. std::string GetDescription()
  116. {
  117. ResDataObject temp, result;
  118. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  119. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  120. temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
  121. temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
  122. temp.add(ValKey::ACCURACY, m_Accuracy);
  123. result.add(Key.c_str(), temp);
  124. return result.encode();
  125. }
  126. std::string GetAttribute()
  127. {
  128. ResDataObject temp;
  129. temp.add(Key.c_str(), (int)m_Value);
  130. return temp.encode();
  131. }
  132. //
  133. std::string JSGet()
  134. {
  135. return std::to_string(m_Value);
  136. }
  137. std::string GetKey()
  138. {
  139. return Key;
  140. }
  141. protected:
  142. std::string Key;
  143. };
  144. //-----------------------------------------------------------------------------
  145. // FloatMould
  146. //-----------------------------------------------------------------------------
  147. class FloatMouldWithWarn : public TmplMouldWithWarn <float>
  148. {
  149. using super = TmplMouldWithWarn <float>;
  150. public:
  151. FloatMouldWithWarn(const char* strkey, float initialvalue, float min, float WarnMin, float WarnMax, float CalibWarnMin, float CalibWarnMax, float max, float accuracy)
  152. :super(initialvalue, min, WarnMin, WarnMax, CalibWarnMin, CalibWarnMax, max, accuracy)
  153. {
  154. Key = strkey;
  155. m_Value = initialvalue;
  156. }
  157. ~FloatMouldWithWarn() {}
  158. std::string GetDescription()
  159. {
  160. ResDataObject temp, result;
  161. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  162. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  163. temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
  164. temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
  165. temp.add(ValKey::ACCURACY, m_Accuracy);
  166. result.add(Key.c_str(), temp);
  167. return result.encode();
  168. }
  169. std::string GetAttribute()
  170. {
  171. ResDataObject temp;
  172. temp.add(Key.c_str(), (int)m_Value);
  173. return temp.encode();
  174. }
  175. std::string JSGet()
  176. {
  177. return std::to_string(m_Value);
  178. }
  179. std::string GetKey()
  180. {
  181. return Key;
  182. }
  183. protected:
  184. std::string Key;
  185. };
  186. }
  187. // ---------------------------------------------------------------------------- -
  188. // StringMould
  189. //-----------------------------------------------------------------------------
  190. class StringMould
  191. {
  192. public:
  193. StringMould(const char* strkey, std::string initialvalue)
  194. {
  195. Key = strkey;
  196. m_Value = initialvalue;
  197. }
  198. ~StringMould() {}
  199. std::string GetDescription()
  200. {
  201. ResDataObject result;
  202. result.add(Key.c_str(), "");
  203. return result.encode();
  204. }
  205. std::string GetAttribute()
  206. {
  207. ResDataObject temp;
  208. temp.add(Key.c_str(), m_Value.c_str());
  209. return temp.encode();
  210. }
  211. //
  212. std::string JSGet()
  213. {
  214. return m_Value;
  215. }
  216. std::string GetKey()
  217. {
  218. return Key;
  219. }
  220. bool Update(std::string value)
  221. {
  222. if (m_Value != value)
  223. {
  224. m_Value = value;
  225. return true;
  226. }
  227. else
  228. {
  229. return false;
  230. }
  231. }
  232. protected:
  233. std::string Key;
  234. std::string m_Value;
  235. };