parameters.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "parameters.h"
  2. parameters::parameters()
  3. {
  4. int loop;
  5. for(loop=0;loop<parameters::MAX_PARAMETERS;loop++) {
  6. long_parameters[loop] = 0;
  7. }
  8. parameter_count = 0;
  9. }
  10. int64_t parameters::get_long_parameter(datastring &input,bool &success)
  11. {
  12. int64_t output = 0;
  13. char ch;
  14. while (input.length > 0) {
  15. ch = input.data[0];
  16. input.remove_bytes_from_front(1);
  17. if ((ch >='0') && (ch <= '9')) {
  18. output = output * 10 + ch - '0';
  19. continue;
  20. }
  21. if (ch == ',') {
  22. break;
  23. }
  24. success = false;
  25. break;
  26. }
  27. return output;
  28. }
  29. datastring parameters::get_string_parameter(datastring &input,bool &success)
  30. {
  31. int64_t length;
  32. datastring output;
  33. // Get the length. The string looks like 4,test6,number
  34. length = get_long_parameter(input,success);
  35. if (length > input.length) {
  36. success = false;
  37. }
  38. if (success) {
  39. output = input.substr(0,(int)length);
  40. input.remove_bytes_from_front((int)length);
  41. }
  42. return output;
  43. }
  44. void parameters::string_parameter(datastring &input,bool &success)
  45. {
  46. if (success) {
  47. string_parameters[parameter_count++] = get_string_parameter(input,success);
  48. }
  49. return;
  50. }
  51. void parameters::long_parameter(datastring &input,bool &success)
  52. {
  53. if (success) {
  54. long_parameters[parameter_count++] = get_long_parameter(input,success);
  55. }
  56. return;
  57. }