1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/*
STRINGLIB
Ulli Meybohm's C++ String Library
Copyright (C) 2000 Ulli Meybohm, www.meybohm.de (ulli@meybohm.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef binary_H
#define binary_H
/*
Bytevector-Class , Storage for Strings or binary data
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <vector>
#ifdef STRINGLIB_USE_GLIBC
#include <fnmatch.h>
#include <wordexp.h>
#include <regex.h>
#endif
#ifndef BYTEVECTOR_CFGSEPERATOR
#define BYTEVECTOR_CFGSEPERATOR "="
#endif
class VectorIndexList : public std::vector<int> {
};
class Bytevector{
private:
void create(int newsize);
public:
int size; //data size
char* data;
/*Container for binary/string data
data automatically terminates with Zero at data[size]
First Item is data[0] , Last Item is data[size-1] !
Bytevector.data is public for speed advantage, so don't
play with it and only use read-only access!!
Manual free(data), data=XY or other pointer arithmethic operations
will surely cause a segmentation fault!
*/
Bytevector();
Bytevector(Bytevector &b);
Bytevector(const Bytevector &b);
Bytevector(int n);
Bytevector(const char* pchar);
Bytevector(char* pchar);
~Bytevector();
void copyFromString(char* pchar);
void copyFromString(const char* pchar);
void copyFromBytevector(Bytevector &source, int start, int len);
void copyFromBytevector(const Bytevector &source, int start, int len);
void resize(int newsize);
int find(char c, int startpos);
int find(Bytevector &b, int startpos);
VectorIndexList findall(Bytevector b);
bool freadln(int file,char seperator); // returns false when eof
bool freadln(int file); // returns false when eof
void freadeof(int file);
void fwrite(int file);
void fwriteln(int file);
bool readfile(Bytevector file);
void replace(Bytevector from, Bytevector to);
void append(Bytevector &source);
void append(const Bytevector &source);
void override(Bytevector &source, int overridepos);
void override(const Bytevector &source, int overridepos);
Bytevector copy(int start, int len);
Bytevector copyRange(int indexA, int indexB);
int toInt();
bool toBool();
//For config-files id=value
Bytevector id();
Bytevector value();
void setValue(Bytevector &value);
void setValue(const Bytevector &value);
void setValue(const char *c);
void setValue(int n);
void setValue(bool b);
#ifdef STRINGLIB_USE_GLIBC
bool fnmatch(Bytevector filenamepattern);
bool getstdout(Bytevector shellcommand);
bool regexmatch(Bytevector regex);
//SET/GET Environmentvariables
void setEnv(Bytevector varname);
void getEnv(Bytevector varname);
void cfg2env(); //= setenv(id(),value());
#endif
Bytevector* clone();
char* clonePCHAR();
// Note: The memory, which is occupied by the cloned data
// WILL NOT be released when Bytevector-Object is deleted
// use delete(Bytevector*) or free(pchar)
char& operator[](int i);
//slow! Use Bytevector.data[i] for high speed access
char* operator*();
//returns Bytevector.data
Bytevector operator+(Bytevector b);
Bytevector& operator+=(Bytevector &b);
Bytevector& operator+=(const Bytevector &b);
Bytevector& operator+=(const char *c);
Bytevector& operator+=(char *c);
Bytevector& operator=(Bytevector &b);
Bytevector& operator=(int n);
Bytevector& operator=(const Bytevector &b);
Bytevector& operator=(const char* pchar);
Bytevector& operator=(char* pchar);
bool operator==(Bytevector &b);
bool operator!=(Bytevector &b);
/* friend ifstream& operator >> (ifstream& s, Configuration& c);
friend ofstream& operator << (ofstream& s, Configuration& c);
friend ostream& operator << (ostream& s, Configuration& c);
friend istream& operator >> (istream& s, Configuration& c);*/
};
#endif
|