PFUNC 1.0
Defines | Enumerations | Functions
lib/pfunc_pack.cpp File Reference

Implements pfunc_pack and pfunc_unpack functions. More...

#include <pfunc/pfunc.h>
#include <cstdarg>
#include <cstring>
#include <iostream>
#include <vector>

Defines

#define PFUNC_PACK_CODE

Enumerations

enum  {
  INVALID_TOKEN = -1, INT, UINT, LINT,
  INTP, UINTP, LINTP, INTPP,
  UINTPP, LINTPP, CHRP, UCHRP,
  CHRPP, UCHRPP, FLTP, FLTPP,
  DBL, DBLP, DBLPP, VOIDP
}

Functions

static int get_star_count (const char *&format)
static int extract_tokens (const char *format, std::vector< int > &token_array)
 Extracts tokens from the format string and populates the given vector.
int pfunc_pack (char **buffer_ptr, const char *format,...)
int pfunc_unpack (char *buffer, const char *format,...)

Detailed Description

Implements pfunc_pack and pfunc_unpack functions.

While parallelizing a program, it is desirable to keep the original function as it is and write a wrapper around it that is the parallel call. As an example, consider this:

 void serial_foo (int a, int b, int c) {
   ...
 }
 
 void parallel_foo (void* buffer) {
   int a, int b, int c;
   pfunc_unpack (buffer, "int, int, int", &a, &b, &c);
   serial_foo (a, b, c);
 }

 int main () {
   int a, b, c;
   void* buffer;
   ....
   pfunc_pack (&buffer, "int, int, int", a, b, c);
   pfunc_run (..,.., parallel_foo, buffer);
   ....
 }

Notice that the big improvement here is that we have been able to keep serial_foo as is. This is important since serial_foo might be part of a code that we cannot touch -- from another library. This is quintessential for non-intrusiveness.


Define Documentation

#define PFUNC_PACK_CODE

Enumeration Type Documentation

anonymous enum
Enumerator:
INVALID_TOKEN 

The token is not one of the expected ones

INT 

int

UINT 

unsigned int

LINT 

long int

INTP 

int*

UINTP 

unsigned int*

LINTP 

long int*

INTPP 

int**

UINTPP 

unsigned int**

LINTPP 

long int**

CHRP 

char*

UCHRP 

unsigned char*

CHRPP 

char**

UCHRPP 

unsigned char**

FLTP 

float*

FLTPP 

float**

DBL 

double

DBLP 

double*

DBLPP 

double**

VOIDP 

void*


Function Documentation

static inline int extract_tokens ( const char *  format,
std::vector< int > &  token_array 
) [inline, static]

Extracts tokens from the format string and populates the given vector.

Parameters:
formatA string that containts the desired format
token_arrayA std::vector of int's that is populated.
Returns:
The size of the buffer that needs to be allocated
INVALID_TOKEN on error
static int get_star_count ( const char *&  format) [inline, static]

static inline int get_star_count (const char*& format);

Parameters:
[out]formatThe format string from which to extract the star count
Returns:
The number of *'s found in this string till the ',' or End-Of-String
int pfunc_pack ( char **  ,
const char *  format,
  ... 
)

PFUNC_PACK_CODE Utility functions to pack and unpack the arguements into a single buffer.

int pfunc_unpack ( char *  buffer,
const char *  format,
  ... 
)