DataPipe Class Reference

[libgfc Index] [libgfc Hierarchy] [Headers]


DataPipe maintains an extensible in-memory binary data stream More...

#include <src/gdatapipe.h>

Public Members


Detailed Description

DataPipe maintains an extensible in-memory binary data stream.

This class can be used as a dynamic array or a pipeline

stream for serializing classes' persistent data members.

The central information about the pipe is the 'cursor', which

indicates the current position where subsequent methods such as

append , and fetch will start. Such methods

will reposition the cursor accordingly upon the completion of

the operation. Other important data members of DataPipe includes

the "size" of the data in the pipe and the "ptr" to the location

wehre the data is stored in memory.

Every ADT in GFC defines at least two methods to store/retrive persistent

member data into and out of a pipe. They are the store

method and the load method. Additionaly there are two

global operators "DataPipe<<" and "DataPipe>>" for each ADT which can

be used handy when pumping several ADT objects into the same pipe.

Some sample use:

GPolygon poly1;

GRect rect1;

... do some thing on poly1 and rect1 ...

DataPipe p;

p << poly1 <<rect1;

db.create_record(p.ptr(), p.size()); //store into the database

DataPipe also accepts standard built-in types such as int, float,

char* etc. Here is another example:

DataPipe p1;

int x=100, y=200;

float dist = 1000;

char *name = "Pittsburgh";

p1 <<x << y << dist << name;

DataPipe p2 (p);

p2 >> x2 >> y2 >> dist2 >> name2;

...

TODO

Make DataPipe be able to redirect to i/o streams.


enum seek_dir (BEGIN=0, END=1, CURRENT=2) [public]

seek directions

DataPipe& operator=(const DataPipe& a) [public virtual]

asignment operator

Result append(const char* data, int length) [public]

This method appends data to the pipe. append new data to the end of the existing data buffer and advance cursor. The buffer in the pipe get automatically expanded if length is greater than available space in pipe.

Parameters:
data is the data to be add to the pipe length the size of the new data

Result insert(const char* data, int length) [public]

insert a chunk of data at the beginning of the pipe. New data is always put in the position 0 of the internal buffer. Existing data gets shifted to the tail by "length".

Result fetch(char* dest, int length) [public]

copy a chunk of data starting at cursor into 'dest'; the cursor in the pipe is advanced accordingly

Result attach(void* p, int space) [public]

attach this pipe to a pointer

Result detach(void) [public]

detach the previously attached pointer

Result extendTo(int new_capacity) [public]

extend the capacity for the pipe to the 'new_capacity'. Old contents are preserved.

Result seek(int off, int dir=BEGIN) [public]

move the cursor to the specified position

int pos(void) [public]

return the position (beginning with 0) of the cursor

inline char* cursor(void) const [public]

return the pointer at cursor

inline void recycle() [public]

memset all data to zeros; keep the capacity intact; reset cursor to 0

inline char* ptr(void) const [public]

return the pointer to the beginning of the data

operator char* ()() [public]

type conversiion operator;

operator const char*() [public]

const char* conversion

inline bool eop(void) const [public]

return true if reached end of pipe (eop)

inline int size(void) const [public]

return the data size

inline int capacity(void) [public]

return the capacity

inline int remainder(void) const [public]

reutrn free space in the array

friend ostream& operator<<(ostream& s, const DataPipe& p) [public]

print the data pipe


Documentation generated by lqian@lqian-sun on Wed Jul 14 09:36:10 EDT 1999
Kdoc