aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bufferstore.h
diff options
context:
space:
mode:
authorFritz Elfert <felfert@to.com>2000-07-31 03:12:38 +0000
committerFritz Elfert <felfert@to.com>2000-07-31 03:12:38 +0000
commit7fb94ed43a814788cda019c1e77314abc1626339 (patch)
tree50b86a44e2809e6fbcdcd080f2a2dc4dbc37042e /lib/bufferstore.h
parentfbb17061d3c622f0786a5d9ad41e8ccd95ef706c (diff)
downloadplptools-7fb94ed43a814788cda019c1e77314abc1626339.tar.gz
plptools-7fb94ed43a814788cda019c1e77314abc1626339.tar.bz2
plptools-7fb94ed43a814788cda019c1e77314abc1626339.zip
Applied mjg-0.6 patch.
Started adding kdoc compliant documentation comments. Added PsiTime
Diffstat (limited to 'lib/bufferstore.h')
-rw-r--r--lib/bufferstore.h223
1 files changed, 190 insertions, 33 deletions
diff --git a/lib/bufferstore.h b/lib/bufferstore.h
index df216c0..cad32fa 100644
--- a/lib/bufferstore.h
+++ b/lib/bufferstore.h
@@ -4,48 +4,205 @@
#include "bool.h"
class ostream;
+/**
+ * A generic container for an array of bytes.
+ *
+ * bufferStore provides an array of bytes which
+ * can be accessed using various types.
+ */
class bufferStore {
public:
- bufferStore();
- bufferStore(const unsigned char *, long);
- ~bufferStore();
- bufferStore(const bufferStore &);
- bufferStore &operator =(const bufferStore &);
-
- // Reading Utils
- unsigned long getLen() const;
- unsigned char getByte(long pos) const;
- unsigned int getWord(long pos) const;
- unsigned int getDWord(long pos) const;
- const char* getString(long pos=0) const;
- void discardFirstBytes(int);
- friend ostream &operator<<(ostream &, const bufferStore &);
- bool empty() const;
-
- // Writing utils
- void init();
- void init(const unsigned char*, long);
- void addByte(unsigned char);
- void addWord(int);
- void addDWord(long);
- void addString(const char*);
- void addStringT(const char*);
- void addBytes(const unsigned char*, int);
- void addBuff(const bufferStore &, long maxLen=-1);
+ /**
+ * Constructs a new bufferStore.
+ */
+ bufferStore();
+
+ /**
+ * Constructs a new bufferStore and
+ * initializes its content.
+ *
+ * @param buf Pointer to data for initialization.
+ * @param len Length of data for initialization.
+ */
+ bufferStore(const unsigned char *, long);
+
+ /**
+ * Destroys a bufferStore instance.
+ */
+ ~bufferStore();
+
+ /**
+ * Constructs a new bufferStore and
+ * initializes its content.
+ *
+ * @param b A bufferStore, whose content is
+ * used for initialization.
+ */
+ bufferStore(const bufferStore &);
+
+ /**
+ * Copies a bufferStore.
+ */
+ bufferStore &operator =(const bufferStore &);
+
+ /**
+ * Retrieves the length of a bufferStore.
+ *
+ * @returns The current length of the contents
+ * in bytes.
+ */
+ unsigned long getLen() const;
+
+ /**
+ * Retrieves the byte at index <em>pos</em>.
+ *
+ * @param pos The index of the byte to retrieve.
+ *
+ * @returns The value of the byte at index <em>pos</em>
+ */
+ unsigned char getByte(long pos) const;
+
+ /**
+ * Retrieves the word at index <em>pos</em>.
+ *
+ * @param pos The index of the word to retrieve.
+ *
+ * @returns The value of the word at index <em>pos</em>
+ */
+ unsigned int getWord(long pos) const;
+
+ /**
+ * Retrieves the dword at index <em>pos</em>.
+ *
+ * @param pos The index of the dword to retrieve.
+ *
+ * @returns The value of the dword at index <em>pos</em>
+ */
+ unsigned int getDWord(long pos) const;
+
+ /**
+ * Retrieves the characters at index <em>pos</em>.
+ *
+ * @param pos The index of the characters to retrieve.
+ *
+ * @returns A pointer to characters at index <em>pos</em>
+ */
+ const char* getString(long pos=0) const;
+
+ /**
+ * Removes bytes from the start of the buffer.
+ *
+ * @param len Number of bytes to remove.
+ */
+ void discardFirstBytes(int);
+
+ /**
+ * Prints a dump of the content.
+ *
+ * Mainly used for debugging purposes.
+ *
+ * @param s The stream to write to.
+ * @param b The bufferStore do be dumped.
+ *
+ * @returns The stream.
+ */
+ friend ostream &operator<<(ostream &, const bufferStore &);
+
+ /**
+ * Tests if the bufferStore is empty.
+ *
+ * @returns true, if the bufferStore is empty.
+ * false, if it contains data.
+ */
+ bool empty() const;
+
+ /**
+ * Initializes the bufferStore.
+ *
+ * All data is removed, the length is
+ * reset to 0.
+ */
+ void init();
+
+ /**
+ * Initializes the bufferStore with
+ * a given data.
+ *
+ * @param buf Pointer to data to initialize from.
+ * @param len Length of data.
+ */
+ void init(const unsigned char*, long);
+
+ /**
+ * Appends a byte to the content of this instance.
+ *
+ * @param c The byte to append.
+ */
+ void addByte(unsigned char);
+
+ /**
+ * Appends a word to the content of this instance.
+ *
+ * @param w The word to append.
+ */
+ void addWord(int);
+
+ /**
+ * Appends a dword to the content of this instance.
+ *
+ * @param dw The dword to append.
+ */
+ void addDWord(long);
+
+ /**
+ * Appends a string to the content of this instance.
+ *
+ * The trailing zero byte is <em>not</em> copied
+ * to the content.
+ *
+ * @param s The string to append.
+ */
+ void addString(const char*);
+
+ /**
+ * Appends a string to the content of this instance.
+ *
+ * The trailing zero byte <em>is</em> copied
+ * to the content.
+ *
+ * @param s The string to append.
+ */
+ void addStringT(const char*);
+
+ /**
+ * Appends data to the content of this instance.
+ *
+ * @param buf The data to append.
+ * @param len Length of data.
+ */
+ void addBytes(const unsigned char*, int);
+
+ /**
+ * Appends data to the content of this instance.
+ *
+ * @param b The bufferStore whose content to append.
+ * @param maxLen Length of content.
+ */
+ void addBuff(const bufferStore &, long maxLen=-1);
private:
- void checkAllocd(long newLen);
+ void checkAllocd(long newLen);
- long len;
- long lenAllocd;
- long start;
- unsigned char* buff;
+ long len;
+ long lenAllocd;
+ long start;
+ unsigned char* buff;
- enum c { MIN_LEN = 300 };
+ enum c { MIN_LEN = 300 };
};
inline bool bufferStore::empty() const {
- return (len-start) == 0;
+ return (len-start) == 0;
}
#endif