/[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 2543 by schoenebeck, Sat May 10 02:06:58 2014 UTC revision 2675 by schoenebeck, Sun Sep 14 16:07:34 2014 UTC
# Line 29  Line 29 
29    
30  #include "helper.h"  #include "helper.h"
31    
32    #if POSIX
33    # include <errno.h>
34    #endif
35    
36  namespace RIFF {  namespace RIFF {
37    
38  // *************** Internal functions **************  // *************** Internal functions **************
# Line 1191  namespace RIFF { Line 1195  namespace RIFF {
1195          return pNewChunk;          return pNewChunk;
1196      }      }
1197    
1198      /** @brief Moves a sub chunk.      /** @brief Moves a sub chunk witin this list.
1199       *       *
1200       * Moves a sub chunk from one position in a list to another       * Moves a sub chunk from one position in this list to another
1201       * position in the same list. The pSrc chunk is placed before the       * position in the same list. The pSrc chunk is placed before the
1202       * pDst chunk.       * pDst chunk.
1203       *       *
# Line 1209  namespace RIFF { Line 1213  namespace RIFF {
1213          pSubChunks->insert(iter, pSrc);          pSubChunks->insert(iter, pSrc);
1214      }      }
1215    
1216        /** @brief Moves a sub chunk from this list to another list.
1217         *
1218         * Moves a sub chunk from this list list to the end of another
1219         * list.
1220         *
1221         * @param pSrc - sub chunk to be moved
1222         * @param pDst - destination list where the chunk shall be moved to
1223         */
1224        void List::MoveSubChunk(Chunk* pSrc, List* pNewParent) {
1225            if (pNewParent == this || !pNewParent) return;
1226            if (!pSubChunks) LoadSubChunks();
1227            if (!pNewParent->pSubChunks) pNewParent->LoadSubChunks();
1228            pSubChunks->remove(pSrc);
1229            pNewParent->pSubChunks->push_back(pSrc);
1230            // update chunk id map of this List
1231            if ((*pSubChunksMap)[pSrc->GetChunkID()] == pSrc) {
1232                pSubChunksMap->erase(pSrc->GetChunkID());
1233                // try to find another chunk of the same chunk ID
1234                ChunkList::iterator iter = pSubChunks->begin();
1235                ChunkList::iterator end  = pSubChunks->end();
1236                for (; iter != end; ++iter) {
1237                    if ((*iter)->GetChunkID() == pSrc->GetChunkID()) {
1238                        (*pSubChunksMap)[pSrc->GetChunkID()] = *iter;
1239                        break; // we're done, stop search
1240                    }
1241                }
1242            }
1243            // update chunk id map of other list
1244            if (!(*pNewParent->pSubChunksMap)[pSrc->GetChunkID()])
1245                (*pNewParent->pSubChunksMap)[pSrc->GetChunkID()] = pSrc;
1246        }
1247    
1248      /** @brief Creates a new list sub chunk.      /** @brief Creates a new list sub chunk.
1249       *       *
1250       * 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 1515  namespace RIFF { Line 1551  namespace RIFF {
1551          ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));          ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>));
1552          #if POSIX          #if POSIX
1553          hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);          hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK);
1554          if (hFileRead <= 0) {          if (hFileRead == -1) {
1555              hFileRead = hFileWrite = 0;              hFileRead = hFileWrite = 0;
1556              throw RIFF::Exception("Can't open \"" + path + "\"");              String sError = strerror(errno);
1557                throw RIFF::Exception("Can't open \"" + path + "\": " + sError);
1558          }          }
1559          #elif defined(WIN32)          #elif defined(WIN32)
1560          hFileRead = hFileWrite = CreateFile(          hFileRead = hFileWrite = CreateFile(
# Line 1594  namespace RIFF { Line 1631  namespace RIFF {
1631                      #if POSIX                      #if POSIX
1632                      if (hFileRead) close(hFileRead);                      if (hFileRead) close(hFileRead);
1633                      hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK);                      hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK);
1634                      if (hFileRead < 0) {                      if (hFileRead == -1) {
1635                          hFileRead = hFileWrite = 0;                          hFileRead = hFileWrite = 0;
1636                          throw Exception("Could not (re)open file \"" + Filename + "\" in read mode");                          String sError = strerror(errno);
1637                            throw Exception("Could not (re)open file \"" + Filename + "\" in read mode: " + sError);
1638                      }                      }
1639                      #elif defined(WIN32)                      #elif defined(WIN32)
1640                      if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);                      if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);
# Line 1623  namespace RIFF { Line 1661  namespace RIFF {
1661                      #if POSIX                      #if POSIX
1662                      if (hFileRead) close(hFileRead);                      if (hFileRead) close(hFileRead);
1663                      hFileRead = hFileWrite = open(Filename.c_str(), O_RDWR | O_NONBLOCK);                      hFileRead = hFileWrite = open(Filename.c_str(), O_RDWR | O_NONBLOCK);
1664                      if (hFileRead < 0) {                      if (hFileRead == -1) {
1665                          hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK);                          hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK);
1666                          throw Exception("Could not open file \"" + Filename + "\" in read+write mode");                          String sError = strerror(errno);
1667                            throw Exception("Could not open file \"" + Filename + "\" in read+write mode: " + sError);
1668                      }                      }
1669                      #elif defined(WIN32)                      #elif defined(WIN32)
1670                      if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);                      if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead);
# Line 1815  namespace RIFF { Line 1854  namespace RIFF {
1854          // open the other (new) file for writing and truncate it to zero size          // open the other (new) file for writing and truncate it to zero size
1855          #if POSIX          #if POSIX
1856          hFileWrite = open(path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP);          hFileWrite = open(path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP);
1857          if (hFileWrite < 0) {          if (hFileWrite == -1) {
1858              hFileWrite = hFileRead;              hFileWrite = hFileRead;
1859              throw Exception("Could not open file \"" + path + "\" for writing");              String sError = strerror(errno);
1860                throw Exception("Could not open file \"" + path + "\" for writing: " + sError);
1861          }          }
1862          #elif defined(WIN32)          #elif defined(WIN32)
1863          hFileWrite = CreateFile(          hFileWrite = CreateFile(

Legend:
Removed from v.2543  
changed lines
  Added in v.2675

  ViewVC Help
Powered by ViewVC