Ejemplo n.º 1
0
LFFieldList::LFFieldList( const char* ptr,
                          const uint  length )
/********************************************/
        : LFLeafStruct( * ( leaf_index *) ptr )
        // assume there are no pad bytes follow as sub fields are align.
        // makesure the compiler align subfield though...
{
    leaf_index  index;
    const char* end = &ptr[length];
    LFSubField* subFieldPtr = NULL;
    ptr += WORD;    // skip leaf of fieldlist.
    while ( ptr < end ) {
        index = * ( leaf_index * ) ptr;
        subFieldPtr = _subFieldConstructorTable[ConvertIndex(index)](ptr);
        ptr += subFieldPtr -> RecordLength();
        _subFieldList.append(subFieldPtr);
    }
}
Ejemplo n.º 2
0
bool
MP4MetadataStagefright::ReadTrackIndex(FallibleTArray<Index::Indice>& aDest, mozilla::TrackID aTrackID)
{
  size_t numTracks = mMetadataExtractor->countTracks();
  int32_t trackNumber = GetTrackNumber(aTrackID);
  if (trackNumber < 0) {
    return false;
  }
  sp<MediaSource> track = mMetadataExtractor->getTrack(trackNumber);
  if (!track.get()) {
    return false;
  }
  sp<MetaData> metadata = mMetadataExtractor->getTrackMetaData(trackNumber);
  int64_t mediaTime;
  if (!metadata->findInt64(kKeyMediaTime, &mediaTime)) {
    mediaTime = 0;
  }
  bool rv = ConvertIndex(aDest, track->exportIndex(), mediaTime);

  return rv;
}
Ejemplo n.º 3
0
//draws everything to the screen
int WorldClass::Render()
{
    COORD frameCoords = ConvertIndex(frame);

    frameCoords.X++;
    frameCoords.Y++;

    bool unitTargeted = false;
    for (int i = 0; i < numOfUnits; ++i)
    {
        if (frame == _entityArray[i].unitData.position)
        {
            unitTargeted = true;
            _conBuffer.OutputScreen(unitMap, height, width, { 0, 0 }, frame, _entityArray[i]);
        }

    }
    if (!unitTargeted)
        _conBuffer.OutputScreen(worldMap, unitMap, height, width, { 0, 0 }, frame);
    _conBuffer.RenderExtraInfo(playerThreads[currentTurn], turnCounter);

    return 1;
}
Ejemplo n.º 4
0
nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsString& name, nsIFile *inFile, nsIFile *pDestination, PRUint32 *pCount)
{
  nsresult  rv;
  PRInt32    msgCount = 0;
  if (pCount)
    *pCount = 0;

  nsCOMPtr <nsIInputStream> inputStream;
  rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), inFile);
  if (NS_FAILED( rv)) return( rv);
  nsCOMPtr <nsIOutputStream> outputStream;
  rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), pDestination, -1, 0600);
  if (NS_FAILED( rv))
    return( rv);

  PRUint32 *  pIndex;
  PRUint32  indexSize;

  if (!ReadIndex( inputStream, &pIndex, &indexSize)) {
    IMPORT_LOG1( "No messages found in mailbox: %S\n", name.get());
    return( NS_OK);
  }

  char *  pBuffer = new char[kMailboxBufferSize];
  if (!(*pAbort))
    ConvertIndex( inputStream, pBuffer, pIndex, indexSize);

  PRUint32  block[4];
  PRInt32   sepLen = (PRInt32) strlen( m_pFromLineSep);
  PRUint32   written;

  /*
      Each block is:
      marker - matches file offset
      block length
      text length in block
      pointer to next block. (0 if end)

      Each message is made up of a linked list of block data.
      So what we do for each message is:
      1. Read the first block data.
      2. Write out the From message separator if the message doesn't already
      start with one.
      3. If the block of data doesn't end with CRLF then a line is broken into two blocks,
      so save the incomplete line for later process when we read the next block. Then
      write out the block excluding the partial line at the end of the block (if exists).
      4. If there's next block of data then read next data block. Otherwise we're done.
      If we found a partial line in step #3 then find the rest of the line from the
      current block and write out this line separately.
      5. Reset some of the control variables and repeat step #3.
  */

  PRUint32  didBytes = 0;
  PRUint32  next, size;
  char *pStart, *pEnd, *partialLineStart;
  nsCAutoString partialLine, tempLine;
  rv = NS_OK;

  for (PRUint32 i = 0; (i < indexSize) && !(*pAbort); i++)
  {
    if (! pIndex[i])
      continue;

    if (ReadBytes( inputStream, block, pIndex[i], 16) && (block[0] == pIndex[i]) &&
      (block[2] < kMailboxBufferSize) && (ReadBytes( inputStream, pBuffer, kDontSeek, block[2])))
    {
      // block[2] contains the chars in the buffer (ie, buf content size).
      // block[3] contains offset to the next block of data (0 means no more data).
      size = block[2];
      pStart = pBuffer;
      pEnd = pStart + size;

      // write out the from separator.
      if (IsFromLine( pBuffer, size))
      {
        char *pChar = pStart;
        while ((pChar < pEnd) && (*pChar != '\r') && (*(pChar+1) != '\n'))
          pChar++;

        if (pChar < pEnd)
        {
          // Get the "From " line so write it out.
          rv = outputStream->Write(pStart, pChar-pStart+2, &written);
          NS_ENSURE_SUCCESS(rv,rv);
          // Now buffer starts from the 2nd line.
          pStart = pChar + 2;
        }
      }
      else
      {
        // Write out the default from line since there is none in the msg.
        rv = outputStream->Write( m_pFromLineSep, sepLen, &written);
        // FIXME: Do I need to check the return value of written???
        if (NS_FAILED( rv))
          break;
      }

      char statusLine[50];
      PRUint32 msgFlags = 0; // need to convert from OE flags to mozilla flags
      PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF);
      rv = outputStream->Write(statusLine, strlen(statusLine), &written);
      NS_ENSURE_SUCCESS(rv,rv);
      PR_snprintf(statusLine, sizeof(statusLine), X_MOZILLA_STATUS2_FORMAT MSG_LINEBREAK, msgFlags & 0xFFFF0000);
      rv = outputStream->Write(statusLine, strlen(statusLine), &written);
      NS_ENSURE_SUCCESS(rv,rv);

      do
      {
        partialLine.Truncate();
        partialLineStart = pEnd;

        // If the buffer doesn't end with CRLF then a line is broken into two blocks,
        // so save the incomplete line for later process when we read the next block.
        if ( (size > 1) && !(*(pEnd - 2) == '\r' && *(pEnd - 1) == '\n') )
        {
          partialLineStart -= 2;
          while ((partialLineStart >= pStart) && (*partialLineStart != '\r') && (*(partialLineStart+1) != '\n'))
            partialLineStart--;
          if (partialLineStart != (pEnd - 2))
            partialLineStart += 2; // skip over CRLF if we find them.
          partialLine.Assign(partialLineStart, pEnd - partialLineStart);
        }

        // Now process the block of data which ends with CRLF.
        rv = EscapeFromSpaceLine(outputStream, pStart, partialLineStart);
        if (NS_FAILED(rv))
          break;

        didBytes += block[2];

        next = block[3];
        if (! next)
        {
          // OK, we're done so flush out the partial line if it's not empty.
          if (partialLine.Length())
            rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
        }
        else
          if (ReadBytes(inputStream, block, next, 16) && (block[0] == next) &&
            (block[2] < kMailboxBufferSize) && (ReadBytes(inputStream, pBuffer, kDontSeek, block[2])))
          {
            // See if we have a partial line from previous block. If so then build a complete
            // line (ie, take the remaining chars from this block) and process this line. Need
            // to adjust where data start and size in this case.
            size = block[2];
            pStart = pBuffer;
            pEnd = pStart + size;
            if (partialLine.Length())
            {
              while ((pStart < pEnd) && (*pStart != '\r') && (*(pStart+1) != '\n'))
                pStart++;
              if (pStart < pEnd)  // if we found a CRLF ..
                pStart += 2;      // .. then copy that too.
              tempLine.Assign(pBuffer, pStart - pBuffer);
              partialLine.Append(tempLine);
              rv = EscapeFromSpaceLine(outputStream, (char *)partialLine.get(), (partialLine.get()+partialLine.Length()));
              if (NS_FAILED(rv))
                break;

              // Adjust where data start and size (since some of the data has been processed).
              size -= (pStart - pBuffer);
            }
          }
          else
          {
            IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]);
            rv = outputStream->Write( "\x0D\x0A", 2, &written);
            next = 0;
          }
      } while (next);

      // Always end a msg with CRLF. This will make sure that OE msgs without body is
      // correctly recognized as msgs. Otherwise, we'll end up with the following in
      // the msg folder where the 2nd msg starts right after the headers of the 1st msg:
      //
      // From - Jan 1965 00:00:00     <<<--- 1st msg starts here
      // Subject: Test msg
      // . . . (more headers)
      // To: <*****@*****.**>
      // From - Jan 1965 00:00:00     <<<--- 2nd msg starts here
      // Subject: How are you
      // . . .(more headers)
      //
      // In this case, the 1st msg is not recognized as a msg (it's skipped)
      // when you open the folder.
      rv = outputStream->Write( "\x0D\x0A", 2, &written);

      if (NS_FAILED(rv))
        break;

      msgCount++;
      if (pCount)
        *pCount = msgCount;
      if (pBytesDone)
        *pBytesDone = didBytes;
    }
    else {
      // Error reading message, should this be logged???
      IMPORT_LOG2( "Error reading message from %S at 0x%lx\n", name.get(), pIndex[i]);
      *pAbort = PR_TRUE;
    }
  }

  delete [] pBuffer;

  if (NS_FAILED(rv))
    *pAbort = PR_TRUE;

  return( rv);
}
Ejemplo n.º 5
0
PetscErrorCode EpsPMLFull(MPI_Comm comm, Vec epspml, int Nx, int Ny, int Nz, int Npmlx, int Npmly, int Npmlz, double sigmax, double sigmay, double sigmaz, double omega, int LowerPML, int Nctrue)
{  
  PetscErrorCode ierr;
  int Nc = 3;
  int i, ns, ne;
  double sigma[3]={sigmax,sigmay,sigmaz};
  double Npml[3]={Npmlx,Npmly,Npmlz};
  int Nxyz[3]={Nx,Ny,Nz};
  int NxyzProduct = Nx*Ny*Nz; // Nxyz already taken
  
  Vec epsdummy;
  VecCreateMPI(PETSC_COMM_WORLD, PETSC_DECIDE, 6*NxyzProduct, &epsdummy);
  VecGetOwnershipRange(epsdummy, &ns, &ne);
  VecDestroy(&epsdummy);
  
  for (i = ns; i < ne; ++i) {
    if (ConvertIndex(i, NxyzProduct, Nctrue) == -1) continue; // skip calculations; row doesn't belong  	  
    int ixyz[3], ic, ir;
    int itmp;
    int cp1, cp2;
    double dic, dcp1, dcp2, epsijk;
	  
    ixyz[2] = (itmp = i) % Nz;
    ixyz[1] = (itmp /= Nz) % Ny;
    ixyz[0] = (itmp /= Ny) % Nx;
    ic = (itmp /= Nx) % Nc;
    ir = itmp / Nc;
	  
    cp1 = (ic + 1) % Nc;
    cp2 = (ic + 2) % Nc;

    int npmlic, npmlcp1, npmlcp2;

    npmlic = Npml[ic];
    npmlcp1 = Npml[cp1];
    npmlcp2 = Npml[cp2];


    if (npmlic==0)
      dic = 0;
    else
      dic =  (LowerPML)* (ixyz[ic] < Npml[ic]) * (Npml[ic]-ixyz[ic]-0.5)/npmlic 
	+ ( ixyz[ic] > (Nxyz[ic]-Npml[ic]-1-1))*(ixyz[ic]-(Nxyz[ic]-Npml[ic]-1-1) -0.5 )/npmlic ;
  /* first -1 is for the postion of E, second -1 is for C index from 0 */
    /* I had same double -1 in the implementation for mu, but did not have it here; added it Apr 20 */


    //ierr=PetscPrintf(comm,"the dic value is %f \n",dic);
    if (npmlcp1==0)
      dcp1=0;
    else
      dcp1 =  (LowerPML)* (ixyz[cp1] < Npml[cp1] ) * (Npml[cp1]-ixyz[cp1])/npmlcp1	+ ( ixyz[cp1] > (Nxyz[cp1]-Npml[cp1]-1))* (ixyz[cp1] - (Nxyz[cp1]-Npml[cp1]-1))/npmlcp1;
    
    if (npmlcp2==0)
      dcp2=0;
    else
      dcp2 =  (LowerPML)* (ixyz[cp2] < Npml[cp2] ) * (Npml[cp2]-ixyz[cp2])/npmlcp2	+ (ixyz[cp2] > (Nxyz[cp2]-Npml[cp2]-1))* (ixyz[cp2] - (Nxyz[cp2]-Npml[cp2]-1))/npmlcp2;

   

    if(ir==0) // real part of epspml[ijk], actually,same as muinv[ijk]
      {	 
	epsijk = 1 + 1/sqr(omega)* 
	  (    sigma[ic]*sigma[cp1] * sqr(dic*dcp1) 
	       +  sigma[ic]*sigma[cp2] * sqr(dic*dcp2)
	       -  sigma[cp1]*sigma[cp2] * sqr(dcp1*dcp2)
	       );
      }
    else //imaginary part of epspml[ijk], just sign difference with muinv[ijk]
      {
	epsijk =(-sigma[ic]*sqr(dic) + sigma[cp1]*sqr(dcp1) + sigma[cp2]*sqr(dcp2)
		    + sigma[ic]*sigma[cp1]*sigma[cp2]/sqr(omega) * sqr(dic*dcp1*dcp2))/omega;
      }
    /* taking care of the denominator from multipling complex conjugate */
    epsijk /= (1 + sqr(sigma[ic]/omega*sqr(dic))) ;

    //ierr=PetscPrintf(comm,"the epsijk value is %f \n", epsijk);
   int itrue = ConvertIndex(i, NxyzProduct, Nctrue);    
    VecSetValue(epspml,itrue,epsijk,INSERT_VALUES);


    }
       /*---------------------------*/
     
     ierr = VecAssemblyBegin(epspml); CHKERRQ(ierr);
     ierr = VecAssemblyEnd(epspml); CHKERRQ(ierr);

     PetscFunctionReturn(0);

}