[855] | 1 | /**************************************************************************
|
---|
| 2 | *
|
---|
| 3 | * UCArray.h -- vector based string class
|
---|
| 4 | * Copyright (C) 1999 Rodger McNab
|
---|
| 5 | *
|
---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
---|
| 7 | * it under the terms of the GNU General Public License as published by
|
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | * (at your option) any later version.
|
---|
| 10 | *
|
---|
| 11 | * This program is distributed in the hope that it will be useful,
|
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | * GNU General Public License for more details.
|
---|
| 15 | *
|
---|
| 16 | * You should have received a copy of the GNU General Public License
|
---|
| 17 | * along with this program; if not, write to the Free Software
|
---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 19 | *
|
---|
| 20 | **************************************************************************/
|
---|
| 21 |
|
---|
| 22 | #ifndef UCARRAY_H
|
---|
| 23 | #define UCARRAY_H
|
---|
| 24 |
|
---|
[2468] | 25 | // need this to avoid bizarre compiler problems under VC++ 6.0
|
---|
| 26 | #if defined (__WIN32__) && !defined (GSDL_USE_IOS_H)
|
---|
| 27 | # include <iostream>
|
---|
| 28 | using namespace std;
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
[855] | 31 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 32 | # include <ospace\std\vector>
|
---|
| 33 | # include <ospace\std\set>
|
---|
| 34 | #elif defined(GSDL_USE_STL_H)
|
---|
| 35 | # include <vector.h>
|
---|
| 36 | # include <set.h>
|
---|
| 37 | #else
|
---|
| 38 | # include <vector>
|
---|
| 39 | # include <set>
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 43 | # include <ospace\std\iostream>
|
---|
| 44 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 45 | # include <iostream.h>
|
---|
| 46 | #else
|
---|
| 47 | # include <iostream>
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | #include <stdio.h>
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | typedef vector<unsigned char> UCArray;
|
---|
| 54 |
|
---|
| 55 | // functions to manipulate UCArrays
|
---|
| 56 | void SetCStr (UCArray &text, const char *cStr);
|
---|
[1125] | 57 | char * GetCStr(UCArray text);
|
---|
[855] | 58 | inline void UCArrayClear (UCArray &a) {
|
---|
| 59 | a.erase (a.begin(), a.end());
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | // stream operator to print UCArray
|
---|
| 63 | ostream &operator<<(ostream &s, const UCArray &a);
|
---|
| 64 |
|
---|
| 65 | // used for reading and writing unsigned characters
|
---|
| 66 | inline bool ReadUC (FILE *f, unsigned char &c) {
|
---|
| 67 | return (fread (&c, sizeof (unsigned char), 1, f) == 1);
|
---|
| 68 | }
|
---|
| 69 | inline bool WriteUC (FILE *f, unsigned char c) {
|
---|
| 70 | return (fwrite (&c, sizeof (unsigned char), 1, f) == 1);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | // used for reading and writing variable length unsigned longs
|
---|
| 74 | bool ReadVarLenUL (FILE *f, unsigned long &n);
|
---|
| 75 | bool WriteVarLenUL (FILE *f, unsigned long n);
|
---|
| 76 |
|
---|
| 77 | // used for reading and writing unsigned longs
|
---|
| 78 | bool ReadUL (FILE *f, unsigned long &n);
|
---|
| 79 | bool WriteUL (FILE *f, unsigned long n);
|
---|
| 80 |
|
---|
| 81 | // used for reading and writing floats
|
---|
| 82 | bool ReadF (FILE *f, float &n);
|
---|
| 83 | bool WriteF (FILE *f, float n);
|
---|
| 84 |
|
---|
| 85 | // used for reading and writing doubles
|
---|
| 86 | bool ReadD (FILE *f, double &n);
|
---|
| 87 | bool WriteD (FILE *f, double n);
|
---|
| 88 |
|
---|
| 89 | // used for reading and writing arrays to files
|
---|
| 90 | bool ReadUCArray (FILE *f, UCArray &a);
|
---|
| 91 | bool WriteUCArray (FILE *f, const UCArray &a);
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | // compares the two strings in dictionary order
|
---|
| 95 | int DictCompare (const UCArray &a1, const UCArray &a2);
|
---|
| 96 |
|
---|
| 97 | struct LTUCArray {
|
---|
| 98 | bool operator()(const UCArray &a1, const UCArray &a2) const
|
---|
| 99 | { return (a1 < a2); }
|
---|
| 100 | };
|
---|
| 101 |
|
---|
| 102 | struct DictLTUCArray {
|
---|
| 103 | bool operator() (const UCArray &a1, const UCArray &a2) const
|
---|
| 104 | { return (DictCompare (a1, a2) < 0); }
|
---|
| 105 | };
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | typedef set<UCArray, LTUCArray> UCArraySet;
|
---|
[1297] | 109 | typedef vector<UCArray> UCArrayVector;
|
---|
[855] | 110 |
|
---|
| 111 | unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
|
---|
| 112 |
|
---|
| 113 | // prev == NULL if no previous string
|
---|
| 114 | bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
|
---|
| 115 | bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | #endif
|
---|