NCCLOUD  0.1
Defines | Functions
common.h File Reference

Implements various convenience functions (e.g., error reporting) More...

#include <cstdio>
#include <cstdlib>
#include <errno.h>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Defines

#define show_error(call)
 Print error details with perror() and exit.
#define show_file_error(call, filename, fp)
 Print error details with perror(), close specified file (if any) and exit.

Functions

void print (std::ostream &s)
 cout for use in multi-threaded environments
void print_error (std::ostream &s)
 cerr for use in multi-threaded environments
template<typename T >
void reset_array (T **array, unsigned int size=0)
 deallocate an array and reallocate if needed
void write_file (std::string dst, char *data, size_t size)

Detailed Description

Implements various convenience functions (e.g., error reporting)

Author:
Henry Chen (chchen@cse.cuhk.edu.hk)

Define Documentation

#define show_error (   call)
Value:
do { \
    fprintf(stderr, "%c[1;31;40m", 0x1B); \
    fprintf(stderr, "%s(%d) in %s:: ", __FILE__, __LINE__, __func__); \
    perror(call); \
    fprintf(stderr, "%c[0m", 0x1B); \
    exit(-1); } while (0)

Print error details with perror() and exit.

#define show_file_error (   call,
  filename,
  fp 
)
Value:
do { \
    fprintf(stderr, "%c[1;31;40m", 0x1B); \
    fprintf(stderr, "%s(%d) in %s:: ", __FILE__, __LINE__, __func__); \
    perror(call); \
    fprintf(stderr, "\twhen working with file: %s\n", filename); \
    fprintf(stderr, "%c[0m", 0x1B); \
    if (fp) { fclose(fp); } \
    exit(-1); } while (0)

Print error details with perror(), close specified file (if any) and exit.


Function Documentation

void print ( std::ostream &  s) [inline]

cout for use in multi-threaded environments

void print_error ( std::ostream &  s) [inline]

cerr for use in multi-threaded environments

template<typename T >
void reset_array ( T **  array,
unsigned int  size = 0 
)

deallocate an array and reallocate if needed

void write_file ( std::string  dst,
char *  data,
size_t  size 
) [inline]
 All Data Structures Files Functions Variables Enumerations Enumerator Defines