Logo Search packages:      
Sourcecode: lttoolbox version File versions

void Compression::multibyte_write ( unsigned int  value,
FILE *  output 
) [static]

Codifica y escribe un entero a un flujo de salida.

See also:
multibyte_read()
Parameters:
value valor a escribir.
output flujo de salida.

Definition at line 26 of file Compression.C.

Referenced by Transducer::write(), Compiler::write(), and Alphabet::write().

{
  if(value < 0x00000040)
  {
    unsigned char byte = (unsigned char) value;
    fwrite_unlocked(&byte, 1, 1, output);
  }
  else if(value < 0x00004000)
  {
    unsigned char low = (unsigned char) value;
    unsigned char up =  (unsigned char) (value >> 8);
    up = up | 0x40;
    fwrite_unlocked(&up, 1, 1, output);
    fwrite_unlocked(&low, 1, 1, output);
  }
  else if(value < 0x00400000)
  {
    unsigned char low = (unsigned char) value;
    unsigned char middle = (unsigned char) (value >> 8);
    unsigned char up = (unsigned char) (value >> 16);
    up = up | 0x80; 
    fwrite_unlocked(&up, 1, 1, output);
    fwrite_unlocked(&middle, 1, 1, output);
    fwrite_unlocked(&low, 1, 1, output);
  }
  else if(value < 0x40000000)
  {
    unsigned char low = (unsigned char) value;
    unsigned char middlelow = (unsigned char) (value >> 8);
    unsigned char middleup = (unsigned char) (value >> 16);
    unsigned char up = (unsigned char) (value >> 24);
    up = up | 0xc0; 
    fwrite_unlocked(&up, 1, 1, output);
    fwrite_unlocked(&middleup, 1, 1, output);
    fwrite_unlocked(&middlelow, 1, 1, output);
    fwrite_unlocked(&low, 1, 1, output);
  }
  else
  {
    cerr << "Out of range: " << value << endl;
    exit(EXIT_FAILURE);
  }
}


Generated by  Doxygen 1.6.0   Back to index