Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

A First Example

This is almost the smallest complete AxPipe program possible, sort of the equivalent of the standard 'Hello World' first program.

It does nothing, except move data from one source, through a pipe section, to a destination. But even so, it's probably a fair performing file copier, since the source and destination are memory mapped files, and execute in different threads in this example. What will happen is that the source file is mapped into memory, section by section, and a pointer to that memory mapping is passed to the destination, where it is copied into the correspondingly mapped section of the destination file. Thus, the file copy is reduced to one more more memcpy() calls + actually mapping them to memory.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "AxPipe.h"                         // The base AxPipe declarations
#include "CFileMap.h"                       // Additional for file I/O via memory map

class CPipeDoNothing : public AxPipe::CPipe {
    void Out(AxPipe::CSeg *pSeg) {
        // Insert your code here and do things with pSeg...

_tmain(int argc, _TCHAR* argv[]) {
    AxPipe::CGlobalInit axpipeInit;         // It just has to be there to initialize global things.
    AxPipe::CSourceMemFile sourceFile;      // The source is a memory mapped file

    sourceFile.Init(argv[1]);               // Set the source file name
    // Append a stage, in it's own thread, just to demonstrate how easy it is ;-)
    sourceFile.Append(new AxPipe::CThread<CPipeDoNothing>);
    // Continue to append a sink to accept the output, set the destination file name too.
    sourceFile.Append((new AxPipe::CSinkMemFile)->Init(argv[2]));

    // Initialize, Process the data, End and Finalize, Get the Error Code if any
    int iError = sourceFile.Open()->Drain()->Close()->Plug()->GetErrorCode();

    // Check for any errors in any parts...
    if (iError) {
        // Print a clear text representation of the problem
        fprintf(stderr, sourceFile.GetErrorMsg());

    return 0;

See also:
Introduction, Installation, A First Example, A Second Examle, Definitions of Terms, Stock Transformations, Utilities and Overrides

Generated on Mon Feb 2 13:19:21 2004 for AxPipe by doxygen 1.3.5