152 lines
3.2 KiB
C++
152 lines
3.2 KiB
C++
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (C) 2003 Intel Corporation
|
|
//
|
|
// File: flexbuf.h
|
|
//
|
|
// Contents: A class which manages a string-like entity with advanced
|
|
// features such as file I/O.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
#ifndef _FLEX_BUF
|
|
#define _FLEX_BUF
|
|
|
|
#include <strstream>
|
|
|
|
using namespace std;
|
|
|
|
class flexbuf : protected strstreambuf
|
|
{
|
|
public:
|
|
|
|
bool m_error;
|
|
|
|
/*
|
|
* Constructor - creates a flexbuf instance
|
|
* Arguments:
|
|
* none
|
|
*/
|
|
flexbuf();
|
|
/*
|
|
* Constructor - creates a flexbuf instance
|
|
* Arguments:
|
|
* n - Initial size of buffer
|
|
*/
|
|
flexbuf(int n);
|
|
/*
|
|
* Adds array of characters of size n to the end of the buffer
|
|
* Arguments:
|
|
* b - pointer to character array
|
|
* n - number of characters to insert
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void addbuf(const unsigned char *b,
|
|
int n);
|
|
/*
|
|
* Adds array of characters of size n to the end of the buffer
|
|
* Arguments:
|
|
* b - pointer to character array
|
|
* n - number of characters to insert
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void addbuf(const char *b,
|
|
int n);
|
|
/*
|
|
* Adds null terminating string to end of buffer
|
|
* Arguments:
|
|
* b - pointer to null terminating string
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void addbuf(const char *b);
|
|
/*
|
|
* Returns the current size of the buffer
|
|
* Arguments:
|
|
* none
|
|
* Return Value:
|
|
* size of the buffer (in bytes)
|
|
*/
|
|
int size() const;
|
|
|
|
/*
|
|
* Returns a regular pointer to the buffer's data
|
|
* Arguments:
|
|
* none
|
|
* Return Value:
|
|
* pointer to buffer's data
|
|
*/
|
|
char * buffer();
|
|
/*
|
|
* Concatenates a buffer to this buffer
|
|
* Arguments:
|
|
* f - buffer to concatenate to this buffer
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void operator<< (flexbuf &f);
|
|
/*
|
|
* Adds a single character to the end of the buffer
|
|
* Arguments:
|
|
* c - character to add
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void operator<< (const unsigned char c);
|
|
/*
|
|
* Adds a short integer to the end of the buffer
|
|
* Arguments:
|
|
* s - short value to add
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void operator<< (const unsigned short s);
|
|
/*
|
|
* Adds a long integer to the end of the buffer
|
|
* Arguments:
|
|
* l - long value to add
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void operator<< (const unsigned long l);
|
|
/*
|
|
* Adds an integer to the end of the buffer
|
|
* Arguments:
|
|
* i - int value to add
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void operator<< (const unsigned int i);
|
|
/*
|
|
* Prints the contents of the buffer for debug purposes
|
|
* Arguments:
|
|
* none
|
|
* Return Value:
|
|
* none
|
|
*/
|
|
void trace();
|
|
/*
|
|
* Adds the contents of a file to the buffer
|
|
* Arguments:
|
|
* filename - name of the input file
|
|
* Return Value:
|
|
* 0 - on success
|
|
* -1/err - on failure
|
|
*/
|
|
int file_in(char *filename);
|
|
/*
|
|
* Writes the contents of the buffer to a file
|
|
* Arguments:
|
|
* filename - name of the output file
|
|
* Return Value:
|
|
* 0 - on success
|
|
* -1 - on failure
|
|
*/
|
|
int file_out(char *filename);
|
|
|
|
};
|
|
|
|
#endif
|