Slim numerical data compression 1.0
slim_file.cpp File Reference

Implements the classes slim_compressor_t and slim_expander_t. More...

#include <iostream>
#include <iomanip>
#include <cassert>
#include <climits>
#include <stdexcept>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>
#include "slim.h"
#include "bitstream.h"

Enumerations

enum  section_foot_markers_t { NOT_LAST_SECTION = 0x8 , LAST_SECTION = 0xf , BITS_SECTION_FOOT = 4 }
 Markers at the end of sections to tell whether more follow. More...
 

Functions

static void verify_twos_complement ()
 Fail an assertion if this is NOT a TWOS-COMPLEMENT machine.
 
int alter_mtime (const char *filename, time_t mtime)
 Alter the access and modification time on a closed file.
 

Detailed Description

Implements the classes slim_compressor_t and slim_expander_t.

They are used respectively for compressing raw data (from memory to file) and restoring it from compressed (slim) form (file to memory).

Enumeration Type Documentation

◆ section_foot_markers_t

Markers at the end of sections to tell whether more follow.

Enumerator
NOT_LAST_SECTION 

Marker for all non-final sections in file.

LAST_SECTION 

Marker for the last section in a file.

BITS_SECTION_FOOT 

Number of bits to write for sect. foot markers.

Function Documentation

◆ alter_mtime()

int alter_mtime ( const char * filename,
time_t mtime )
inline

Alter the access and modification time on a closed file.

Parameters
filenameThe file to alter.
mtimeThe new value for filename's atime and mtime.
Returns
Returns 0 on success or -1 on error (and errno is set).

◆ verify_twos_complement()

static void verify_twos_complement ( )
inlinestatic

Fail an assertion if this is NOT a TWOS-COMPLEMENT machine.

The program assumes throughout that it's on a twos-complement machine. Failing these assertions means that this is NOT. It might either be a ones-complement machine (recogize when i and ~i are negatives of each other) or a sign-bit machine (recognize when i and -i differ only in the highest bit).