source: trunk/indexers/mgpp/text/UCArray.h@ 3365

Last change on this file since 3365 was 3365, checked in by kjdon, 22 years ago

Initial revision

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
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
25// need this to avoid bizarre compiler problems under VC++ 6.0
26#if !defined (GSDL_NAMESPACE_BROKEN) && !defined (GSDL_USE_IOS_H)
27# include <iostream>
28using namespace std;
29#endif
30
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
53typedef vector<unsigned char> UCArray;
54
55// functions to manipulate UCArrays
56void SetCStr (UCArray &text, const char *cStr);
57char * GetCStr(UCArray text);
58inline void UCArrayClear (UCArray &a) {
59 a.erase (a.begin(), a.end());
60}
61
62// stream operator to print UCArray
63ostream &operator<<(ostream &s, const UCArray &a);
64
65// used for reading and writing unsigned characters
66inline bool ReadUC (FILE *f, unsigned char &c) {
67 return (fread (&c, sizeof (unsigned char), 1, f) == 1);
68}
69inline 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
74bool ReadVarLenUL (FILE *f, unsigned long &n);
75bool WriteVarLenUL (FILE *f, unsigned long n);
76
77// used for reading and writing unsigned longs
78bool ReadUL (FILE *f, unsigned long &n);
79bool WriteUL (FILE *f, unsigned long n);
80
81// used for reading and writing floats
82bool ReadF (FILE *f, float &n);
83bool WriteF (FILE *f, float n);
84
85// used for reading and writing doubles
86bool ReadD (FILE *f, double &n);
87bool WriteD (FILE *f, double n);
88
89// used for reading and writing arrays to files
90bool ReadUCArray (FILE *f, UCArray &a);
91bool WriteUCArray (FILE *f, const UCArray &a);
92
93
94// compares the two strings in dictionary order
95int DictCompare (const UCArray &a1, const UCArray &a2);
96
97struct LTUCArray {
98 bool operator()(const UCArray &a1, const UCArray &a2) const
99 { return (a1 < a2); }
100};
101
102struct DictLTUCArray {
103 bool operator() (const UCArray &a1, const UCArray &a2) const
104 { return (DictCompare (a1, a2) < 0); }
105};
106
107
108typedef set<UCArray, LTUCArray> UCArraySet;
109typedef vector<UCArray> UCArrayVector;
110
111unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
112
113// prev == NULL if no previous string
114bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
115bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
116
117
118#endif
Note: See TracBrowser for help on using the repository browser.