/[svn]/libgig/trunk/src/RIFF.cpp
ViewVC logotype

Diff of /libgig/trunk/src/RIFF.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1050 by schoenebeck, Fri Mar 2 01:04:45 2007 UTC revision 1184 by persson, Sun May 13 13:24:22 2007 UTC
# Line 29  Line 29 
29    
30  namespace RIFF {  namespace RIFF {
31    
32    // *************** Internal functions **************
33    // *
34    
35        /// Returns a human readable path of the given chunk.
36        String __resolveChunkPath(Chunk* pCk) {
37            String sPath;
38            for (Chunk* pChunk = pCk; pChunk; pChunk = pChunk->GetParent()) {
39                if (pChunk->GetChunkID() == CHUNK_ID_LIST) {
40                    List* pList = (List*) pChunk;
41                    sPath = "->'" + pList->GetListTypeString() + "'" + sPath;
42                } else {
43                    sPath = "->'" + pChunk->GetChunkIDString() + "'" + sPath;
44                }
45            }
46            return sPath;
47        }
48    
49    
50    
51  // *************** Chunk **************  // *************** Chunk **************
52  // *  // *
53    
# Line 70  namespace RIFF { Line 89  namespace RIFF {
89      }      }
90    
91      Chunk::~Chunk() {      Chunk::~Chunk() {
92            if (CurrentChunkSize != NewChunkSize) pFile->UnlogResized(this);
93          if (pChunkData) delete[] pChunkData;          if (pChunkData) delete[] pChunkData;
94      }      }
95    
# Line 774  namespace RIFF { Line 794  namespace RIFF {
794       * @see File::Save()       * @see File::Save()
795       */       */
796      void Chunk::Resize(int iNewSize) {      void Chunk::Resize(int iNewSize) {
797          if (iNewSize <= 0) throw Exception("Chunk size must be at least one byte");          if (iNewSize <= 0)
798                throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(this));
799          if (NewChunkSize == iNewSize) return;          if (NewChunkSize == iNewSize) return;
800          NewChunkSize = iNewSize;          NewChunkSize = iNewSize;
801          pFile->LogAsResized(this);          pFile->LogAsResized(this);
# Line 1134  namespace RIFF { Line 1155  namespace RIFF {
1155          return pNewChunk;          return pNewChunk;
1156      }      }
1157    
1158        /** @brief Moves a sub chunk.
1159         *
1160         * Moves a sub chunk from one position in a list to another
1161         * position in the same list. The pSrc chunk is placed before the
1162         * pDst chunk.
1163         *
1164         * @param pSrc - sub chunk to be moved
1165         * @param pDst - the position to move to. pSrc will be placed
1166         *               before pDst. If pDst is 0, pSrc will be placed
1167         *               last in list.
1168         */
1169        void List::MoveSubChunk(Chunk* pSrc, Chunk* pDst) {
1170            if (!pSubChunks) LoadSubChunks();
1171            pSubChunks->remove(pSrc);
1172            ChunkList::iterator iter = find(pSubChunks->begin(), pSubChunks->end(), pDst);
1173            pSubChunks->insert(iter, pSrc);
1174        }
1175    
1176      /** @brief Creates a new list sub chunk.      /** @brief Creates a new list sub chunk.
1177       *       *
1178       * Creates and adds a new list sub chunk to this list chunk. Note that       * Creates and adds a new list sub chunk to this list chunk. Note that
# Line 1155  namespace RIFF { Line 1194  namespace RIFF {
1194       *       *
1195       * Removes the sub chunk given by \a pSubChunk from this list and frees       * Removes the sub chunk given by \a pSubChunk from this list and frees
1196       * it completely from RAM. The given chunk can either be a normal sub       * it completely from RAM. The given chunk can either be a normal sub
1197       * chunk or a list sub chunk. You should call File::Save() to make this       * chunk or a list sub chunk. In case the given chunk is a list chunk,
1198       * change persistent at any time.       * all its subchunks (if any) will be removed recursively as well. You
1199         * should call File::Save() to make this change persistent at any time.
1200       *       *
1201       * @param pSubChunk - sub chunk or sub list chunk to be removed       * @param pSubChunk - sub chunk or sub list chunk to be removed
1202       */       */
# Line 1487  namespace RIFF { Line 1527  namespace RIFF {
1527          return false;          return false;
1528      }      }
1529    
1530        /** @brief Set the byte order to be used when saving.
1531         *
1532         * Set the byte order to be used in the file. A value of
1533         * endian_little will create a RIFF file, endian_big a RIFX file
1534         * and endian_native will create a RIFF file on little-endian
1535         * machines and RIFX on big-endian machines.
1536         *
1537         * @param Endian - endianess to use when file is saved.
1538         */
1539        void File::SetByteOrder(endian_t Endian) {
1540            #if WORDS_BIGENDIAN
1541            bEndianNative = Endian != endian_little;
1542            #else
1543            bEndianNative = Endian != endian_big;
1544            #endif
1545        }
1546    
1547      /** @brief Save changes to same file.      /** @brief Save changes to same file.
1548       *       *
1549       * Make all changes of all chunks persistent by writing them to the       * Make all changes of all chunks persistent by writing them to the
# Line 1514  namespace RIFF { Line 1571  namespace RIFF {
1571          // first we sum up all positive chunk size changes (and skip all negative ones)          // first we sum up all positive chunk size changes (and skip all negative ones)
1572          unsigned long ulPositiveSizeDiff = 0;          unsigned long ulPositiveSizeDiff = 0;
1573          for (ChunkList::iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) {          for (ChunkList::iterator iter = ResizedChunks.begin(), end = ResizedChunks.end(); iter != end; ++iter) {
1574              if ((*iter)->GetNewSize() == 0) throw Exception("There is at least one empty chunk (zero size)");              if ((*iter)->GetNewSize() == 0) {
1575                    throw Exception("There is at least one empty chunk (zero size): " + __resolveChunkPath(*iter));
1576                }
1577              if ((*iter)->GetNewSize() + 1L > (*iter)->GetSize()) {              if ((*iter)->GetNewSize() + 1L > (*iter)->GetSize()) {
1578                  unsigned long ulDiff = (*iter)->GetNewSize() - (*iter)->GetSize() + 1L; // +1 in case we have to add a pad byte                  unsigned long ulDiff = (*iter)->GetNewSize() - (*iter)->GetSize() + 1L; // +1 in case we have to add a pad byte
1579                  ulPositiveSizeDiff += ulDiff;                  ulPositiveSizeDiff += ulDiff;
# Line 1675  namespace RIFF { Line 1734  namespace RIFF {
1734          ResizedChunks.push_back(pResizedChunk);          ResizedChunks.push_back(pResizedChunk);
1735      }      }
1736    
1737        void File::UnlogResized(Chunk* pResizedChunk) {
1738            ResizedChunks.remove(pResizedChunk);
1739        }
1740    
1741      unsigned long File::GetFileSize() {      unsigned long File::GetFileSize() {
1742          return __GetFileSize(hFileRead);          return __GetFileSize(hFileRead);
1743      }      }
# Line 1688  namespace RIFF { Line 1751  namespace RIFF {
1751      }      }
1752      #elif defined(WIN32)      #elif defined(WIN32)
1753      unsigned long File::__GetFileSize(HANDLE hFile) {      unsigned long File::__GetFileSize(HANDLE hFile) {
1754          LARGE_INTEGER size;          DWORD dwSize = ::GetFileSize(hFile, NULL /*32bit*/);
1755          GetFileSizeEx(hFile, &size);          if (dwSize == INVALID_FILE_SIZE)
1756          return size.LowPart;              throw Exception("Windows FS error: could not determine file size");
1757            return dwSize;
1758      }      }
1759      #else // standard C functions      #else // standard C functions
1760      unsigned long File::__GetFileSize(FILE* hFile) {      unsigned long File::__GetFileSize(FILE* hFile) {

Legend:
Removed from v.1050  
changed lines
  Added in v.1184

  ViewVC Help
Powered by ViewVC