1
0

SWFParameters.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "SWFParameters.h"
  2. #include "../xml/obj_xml.h"
  3. #include <locale.h>
  4. /*
  5. example:
  6. <invoke name="Benski" returntype="xml">
  7. <arguments>
  8. </arguments>
  9. </invoke>
  10. */
  11. SWFParameters::SWFParameters(obj_xml *_parser)
  12. {
  13. parser = _parser;
  14. parser->xmlreader_setCaseSensitive();
  15. parser->xmlreader_registerCallback(L"invoke", this);
  16. parser->xmlreader_registerCallback(L"invoke\farguments\f*", this);
  17. parser->xmlreader_registerCallback(L"invoke\farguments\f*", &currentParameter);
  18. functionName=0;
  19. C_locale = _create_locale(LC_NUMERIC, "C");
  20. }
  21. SWFParameters::~SWFParameters()
  22. {
  23. for (ArgumentList::iterator itr=arguments.begin();itr!=arguments.end();itr++)
  24. {
  25. SWFArgument *argument = *itr;
  26. free(argument->type);
  27. free(argument->value);
  28. free(argument);
  29. }
  30. arguments.clear();
  31. parser->xmlreader_unregisterCallback(this);
  32. parser->xmlreader_unregisterCallback(&currentParameter);
  33. }
  34. void SWFParameters::StartTag(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
  35. {
  36. if (!wcscmp(xmlpath, L"invoke"))
  37. {
  38. const wchar_t *name = params->getItemValue(L"name");
  39. if (name)
  40. functionName = _wcsdup(name);
  41. }
  42. }
  43. void SWFParameters::EndTag(const wchar_t *xmlpath, const wchar_t *xmltag)
  44. {
  45. if (!wcsncmp(xmlpath, L"invoke\farguments\f", 6 /*invoke*/+ 1/*\f*/ + 9/*arguments*/ + 1/*\f*/))
  46. {
  47. SWFArgument *argument = new SWFArgument;
  48. argument->type = _wcsdup(xmltag);
  49. const wchar_t *value = currentParameter.GetString();
  50. if (value)
  51. argument->value = _wcsdup(value);
  52. else
  53. argument->value = 0;
  54. arguments.push_back(argument);
  55. }
  56. }
  57. bool SWFParameters::GetUnsigned(size_t index, unsigned int *value)
  58. {
  59. if (index < arguments.size())
  60. {
  61. SWFArgument *argument = arguments[index];
  62. if (argument && argument->type && !wcscmp(argument->type, L"number"))
  63. {
  64. const wchar_t *val = argument->value;
  65. if (val)
  66. {
  67. *value = wcstoul(val, 0, 10);
  68. return true;
  69. }
  70. }
  71. }
  72. return false;
  73. }
  74. bool SWFParameters::GetDouble(size_t index, double *value)
  75. {
  76. if (index < arguments.size())
  77. {
  78. SWFArgument *argument = arguments[index];
  79. if (argument && argument->type && !wcscmp(argument->type, L"number"))
  80. {
  81. const wchar_t *val = argument->value;
  82. if (val)
  83. {
  84. *value = _wtof_l(val, C_locale);
  85. return true;
  86. }
  87. }
  88. }
  89. return false;
  90. }
  91. #define CBCLASS SWFParameters
  92. START_DISPATCH;
  93. VCB(ONSTARTELEMENT, StartTag)
  94. VCB(ONENDELEMENT, EndTag)
  95. END_DISPATCH;
  96. #undef CBCLASS