id3_field_integer.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // The authors have released ID3Lib as Public Domain (PD) and claim no copyright,
  2. // patent or other intellectual property protection in this work. This means that
  3. // it may be modified, redistributed and used in commercial and non-commercial
  4. // software and hardware without restrictions. ID3Lib is distributed on an "AS IS"
  5. // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  6. //
  7. // The ID3Lib authors encourage improvements and optimisations to be sent to the
  8. // ID3Lib coordinator, currently Dirk Mahoney ([email protected]). Approved
  9. // submissions may be altered, and will be included and released under these terms.
  10. //
  11. // Mon Nov 23 18:34:01 1998
  12. // improved/optimized/whatever 10/30/00 JF
  13. // improved/optimized/whatEVER jan-08-2006 benski
  14. #include "id3_field.h"
  15. #if 0 // taking out operators
  16. ID3_Field& ID3_Field::operator=(luint newData)
  17. {
  18. Set(newData);
  19. return *this;
  20. }
  21. #endif
  22. void ID3_Field::Set(luint newData)
  23. {
  24. Clear();
  25. data = reinterpret_cast<uchar *>(newData);
  26. size = sizeof(luint);
  27. type = ID3FTY_INTEGER;
  28. hasChanged = true;
  29. }
  30. luint ID3_Field::Get(void)
  31. {
  32. return (luint) data;
  33. }
  34. luint ID3_Field::ParseInteger(uchar *buffer, luint posn, luint buffSize)
  35. {
  36. luint bytesUsed = 0;
  37. if(buffer && buffSize)
  38. {
  39. luint i;
  40. luint temp = 0;
  41. bytesUsed = 4;
  42. if(fixedLength != -1)
  43. bytesUsed = MIN(fixedLength, bytesUsed);
  44. for(i = 0; i < bytesUsed; i++)
  45. temp |=(buffer[ posn + i ] <<(((bytesUsed - i) - 1) * 8));
  46. Set(temp);
  47. hasChanged = false;
  48. }
  49. return bytesUsed;
  50. }
  51. luint ID3_Field::RenderInteger(uchar *buffer)
  52. {
  53. luint bytesUsed = 0;
  54. luint length = BinSize();
  55. for(luint i = 0; i < length; i++)
  56. buffer[ i ] = (uchar)((((luint) data) >>(((length - i) - 1) * 8)) & 0xFF);
  57. bytesUsed = length;
  58. hasChanged = false;
  59. return bytesUsed;
  60. }