home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 March / VPR0303A.ISO / AIBO / MoNet / common / libODA / ODA.cc < prev   
C/C++ Source or Header  |  2002-12-19  |  3KB  |  130 lines

  1. //
  2. // Copyright 2002 Sony Corporation 
  3. //
  4. // Permission to use, copy, modify, and redistribute this software for
  5. // non-commercial use is hereby granted.
  6. //
  7. // This software is provided "as is" without warranty of any kind,
  8. // either expressed or implied, including but not limited to the
  9. // implied warranties of fitness for a particular purpose.
  10. //
  11.  
  12. #include <string.h>
  13. #include <ODA.h>
  14.  
  15. ODA::ODA() : toc(0)
  16. {
  17. }
  18.  
  19. ODA::ODA(byte* oda)
  20. {
  21.     Set(oda);
  22. }
  23.  
  24. void
  25. ODA::Set(byte* oda)
  26. {
  27.     toc = (ODATOC*)oda;
  28. }
  29.  
  30. int
  31. ODA::Find(char* name) const
  32. {
  33.     if (toc == 0) return -1;
  34.     if (toc->info.magic != ODA_MAGIC_ODAR) return -1;
  35.  
  36.     for (int i = 0; i < toc->info.numFiles; i++) {
  37.         if (strcmp(name, toc->entry[i].name) == 0) return i;
  38.     }
  39.  
  40.     return -1;
  41. }
  42.  
  43. int
  44. ODA::Find(ODAMagic magic, char* name) const
  45. {
  46.     if (toc == 0) return -1;
  47.     if (toc->info.magic != ODA_MAGIC_ODAR) return -1;
  48.     
  49.     if (magic == ODA_MAGIC_OSND) {
  50.  
  51.         for (int i = 0; i < toc->info.numFiles; i++) {
  52.             if (toc->entry[i].magic == ODA_MAGIC_WAVE &&
  53.                 strcmp(name, toc->entry[i].name) == 0) return i;
  54.         }
  55.  
  56.         for (int i = 0; i < toc->info.numFiles; i++) {
  57.             if (toc->entry[i].magic == ODA_MAGIC_MIDI &&
  58.                 strcmp(name, toc->entry[i].name) == 0) return i;
  59.         }
  60.  
  61.     } else {
  62.  
  63.         for (int i = 0; i < toc->info.numFiles; i++) {
  64.             if (toc->entry[i].magic == magic &&
  65.                 strcmp(name, toc->entry[i].name) == 0) return i;
  66.         }
  67.     }
  68.  
  69.     return -1;
  70. }
  71.  
  72. int
  73. ODA::GetNumFiles() const
  74. {
  75.     if (toc == 0) return -1;
  76.     if (toc->info.magic != ODA_MAGIC_ODAR) return -1;
  77.     return toc->info.numFiles;
  78. }
  79.  
  80. ODAMagic
  81. ODA::GetMagic(int index) const
  82. {
  83.     if (toc == 0) return ODA_MAGIC_UNDEF;
  84.     if (toc->info.magic != ODA_MAGIC_ODAR) return ODA_MAGIC_UNDEF;
  85.     if (index >= toc->info.numFiles) return ODA_MAGIC_UNDEF;
  86.  
  87.     return toc->entry[index].magic;
  88. }
  89.  
  90. char* 
  91. ODA::GetName(int index) const
  92. {
  93.     if (toc == 0) return 0;
  94.     if (toc->info.magic != ODA_MAGIC_ODAR) return 0;
  95.     if (index >= toc->info.numFiles) return 0;
  96.  
  97.     return toc->entry[index].name;
  98. }
  99.  
  100. int
  101. ODA::GetSize(int index) const
  102. {
  103.     if (toc == 0) return -1;
  104.     if (toc->info.magic != ODA_MAGIC_ODAR) return -1;
  105.     if (index >= toc->info.numFiles) return -1;
  106.  
  107.     return toc->entry[index].size;
  108. }
  109.  
  110. byte*
  111. ODA::GetData(int index) const
  112. {
  113.     if (toc == 0) return 0;
  114.     if (toc->info.magic != ODA_MAGIC_ODAR) return 0;
  115.     if (index >= toc->info.numFiles) return 0;
  116.  
  117.     byte* ptr = (byte*)toc;
  118.     return ptr + toc->entry[index].offset;
  119. }
  120.  
  121. int
  122. ODA::GetOffset(int index) const
  123. {
  124.     if (toc == 0) return -1;
  125.     if (toc->info.magic != ODA_MAGIC_ODAR) return -1;
  126.     if (index >= toc->info.numFiles) return -1;
  127.  
  128.     return toc->entry[index].offset;
  129. }
  130.