ArithmeticCoding  0.0.0a
Arithmetic coding in C
Defines | Typedefs | Functions
C:/Users/clackn/Desktop/src/arithcode/src/stream.c File Reference
#include "stream.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define ENDL   "\n"
#define TRY(e)
#define SAFE_FREE(e)   if(e) { free(e); (e)=NULL; }
#define DEFN_PUSH(T)
#define DEFN_POP(T)
#define MAX_TYPE(T)   static const T max_##T = (T)(-1)
#define DEFN_CARRY(T)

Typedefs

typedef uint8_t u8
typedef uint16_t u16
typedef uint32_t u32
typedef uint64_t u64
typedef int8_t i8
typedef int16_t i16
typedef int32_t i32
typedef int64_t i64

Functions

static void maybe_init (stream_t *self)
void attach (stream_t *self, void *d, size_t n)
void detach (stream_t *self, void **d, size_t *n)
static void maybe_resize (stream_t *s)
 DEFN_PUSH (u8)
 DEFN_PUSH (u32)
 DEFN_PUSH (u64)
 DEFN_PUSH (i8)
 DEFN_PUSH (i16)
 DEFN_PUSH (i32)
 DEFN_PUSH (i64)
void push_u1 (stream_t *self, u8 v)
void push_u4 (stream_t *self, u8 v)
 DEFN_POP (u8)
 DEFN_POP (u32)
 DEFN_POP (u64)
 DEFN_POP (i8)
 DEFN_POP (i16)
 DEFN_POP (i32)
 DEFN_POP (i64)
u8 pop_u1 (stream_t *self)
u8 pop_u4 (stream_t *self)
 MAX_TYPE (u8)
 MAX_TYPE (u32)
 MAX_TYPE (u64)
 DEFN_CARRY (u8)
 DEFN_CARRY (u32)
 DEFN_CARRY (u64)
void carry_u1 (stream_t *self)
void carry_u4 (stream_t *self)

Define Documentation

#define DEFN_CARRY (   T)
Value:
void carry_##T(stream_t *self)          \
{ size_t n = (self->ibyte-1)/sizeof(T); \
  while( ((T*)(self->d))[n]==max_##T )  \
    ((T*)(self->d))[n--]=0;             \
  ((T*)(self->d))[n]++;                 \
}

Definition at line 166 of file stream.c.

#define DEFN_POP (   T)
Value:
T pop_##T(stream_t *self) \
  { T v; \
    if(self->ibyte>=self->nbytes) return 0; \
    v = *(T*)(self->d+self->ibyte); \
    self->ibyte+=sizeof(T); \
    return v; \
  }

Definition at line 114 of file stream.c.

#define DEFN_PUSH (   T)
Value:
void push_##T(stream_t *self, T v) \
  { *(T*)(self->d+self->ibyte) = v;  \
    self->ibyte+=sizeof(T);          \
    maybe_resize(self);              \
  }

Definition at line 62 of file stream.c.

#define ENDL   "\n"

Definition at line 17 of file stream.c.

#define MAX_TYPE (   T)    static const T max_##T = (T)(-1)

Definition at line 160 of file stream.c.

#define SAFE_FREE (   e)    if(e) { free(e); (e)=NULL; }

Definition at line 25 of file stream.c.

#define TRY (   e)
Value:
do{ if(!(e)) {\
    printf("%s(%d):"ENDL "\t%s"ENDL "\tExpression evaluated as false."ENDL, \
        __FILE__,__LINE__,#e); \
    goto Error; \
  }} while(0)

Definition at line 18 of file stream.c.


Typedef Documentation

typedef int16_t i16

Definition at line 13 of file stream.c.

typedef int32_t i32

Definition at line 14 of file stream.c.

typedef int64_t i64

Definition at line 15 of file stream.c.

typedef int8_t i8

Definition at line 12 of file stream.c.

typedef uint16_t u16

Definition at line 9 of file stream.c.

typedef uint32_t u32

Definition at line 10 of file stream.c.

typedef uint64_t u64

Definition at line 11 of file stream.c.

typedef uint8_t u8

Definition at line 8 of file stream.c.


Function Documentation

void attach ( stream_t self,
void *  d,
size_t  n 
)

Definition at line 38 of file stream.c.

void carry_u1 ( stream_t self)

Definition at line 178 of file stream.c.

void carry_u4 ( stream_t self)

Definition at line 192 of file stream.c.

DEFN_CARRY ( u8  )
DEFN_CARRY ( u32  )
DEFN_CARRY ( u64  )
DEFN_POP ( u8  )
DEFN_POP ( u32  )
DEFN_POP ( u64  )
DEFN_POP ( i8  )
DEFN_POP ( i16  )
DEFN_POP ( i32  )
DEFN_POP ( i64  )
DEFN_PUSH ( u8  )
DEFN_PUSH ( u32  )
DEFN_PUSH ( u64  )
DEFN_PUSH ( i8  )
DEFN_PUSH ( i16  )
DEFN_PUSH ( i32  )
DEFN_PUSH ( i64  )
void detach ( stream_t self,
void **  d,
size_t *  n 
)

Definition at line 46 of file stream.c.

MAX_TYPE ( u8  )
MAX_TYPE ( u32  )
MAX_TYPE ( u64  )
static void maybe_init ( stream_t self) [static]

Definition at line 27 of file stream.c.

static void maybe_resize ( stream_t s) [static]

Definition at line 52 of file stream.c.

u8 pop_u1 ( stream_t self)

Definition at line 131 of file stream.c.

u8 pop_u4 ( stream_t self)

Definition at line 145 of file stream.c.

void push_u1 ( stream_t self,
u8  v 
)

Definition at line 77 of file stream.c.

void push_u4 ( stream_t self,
u8  v 
)

Definition at line 95 of file stream.c.

 All Classes Files Functions Variables Typedefs Defines