aboutsummaryrefslogtreecommitdiffstats
path: root/libbuf/buf.h
diff options
context:
space:
mode:
Diffstat (limited to 'libbuf/buf.h')
-rw-r--r--libbuf/buf.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/libbuf/buf.h b/libbuf/buf.h
new file mode 100644
index 0000000..ba5c7e7
--- /dev/null
+++ b/libbuf/buf.h
@@ -0,0 +1,89 @@
+#ifndef __BUF_H
+#define __BUF_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+/*
+typedef struct bbuf {
+ int size; //total size
+ int buf_size; //used size
+ char *buf;
+} bbuf;
+*/
+
+//operations on plain buffers also operations on bufer to buffer should be
+//supoorted
+
+/*
+//create new buffer without content
+bbuf* bbuf_new(int size);
+
+//set buffer value
+int bbuf_set(bbuf *a, char *val, int size);
+//get copy of buffer
+bbuf *bbuf_copy(bbuf *buf);
+//get buffer from buffer
+int bbuf_get(bbuf *buf, char **val, int *size);
+//resize buffer
+int bbuf_realloc(bbuf *buf, int size);
+//set to minimal size
+int bbuf_reduce(bbuf *buf);
+//increase buffer for size
+int bbuf_inc(bbuf *a, char *b, int size);
+//decrease buffer for size
+int bbuf_dec(bbuf *a, char *b, int size);
+//free buffer
+int bbuf_set_max(bbuf *buf);
+int bbuf_memset(bbuf *buf, char c);
+
+int bbuf_concat(bbuf *a, bbuf *b);
+
+int bbuf_size(bbuf *a);
+
+int bbuf_print(bbuf *a);
+
+void bbuf_free(bbuf *buf);
+*/
+
+class Buf
+{
+private:
+ int cur_size;
+ int buf_size;
+ char *buf;
+public:
+ Buf(int size);
+ ~Buf();
+
+ int set(char *val, int size);
+ int set(char *val);
+ Buf* copy();
+ int get_ptr(char **val, int *size);
+ int realloc(int size);
+ int reduce();
+ int inc(int size);
+ int dec(int size);
+
+ int set_max();
+ int memset(char c);
+ int concat(Buf *b);
+ int size();
+ int cursize();
+ int print();
+ int setc(int idx, char c);
+ int pushc(char c);
+ int getc(int idx, char *c);
+ int findc(char c, int *idx);
+ int popsubstring(int sz, char **val, int *size);
+ int shiftleft(int n);
+ int zero();
+ bool isempty();
+ int empty();
+ int set_size(int size);
+};
+
+#endif \ No newline at end of file