source: trunk/gsdl/src/mgpp/text/UCArray.h@ 1297

Last change on this file since 1297 was 1297, checked in by kjm18, 24 years ago

removed BrowseCompare(), added UCArrayVector type

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 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 * $Id: UCArray.h 1297 2000-07-24 02:15:17Z kjm18 $
21 *
22 **************************************************************************/
23
24#ifndef UCARRAY_H
25#define UCARRAY_H
26
27#if defined(GSDL_USE_OBJECTSPACE)
28# include <ospace\std\vector>
29# include <ospace\std\set>
30#elif defined(GSDL_USE_STL_H)
31# include <vector.h>
32# include <set.h>
33#else
34# include <vector>
35# include <set>
36#endif
37
38#if defined(GSDL_USE_OBJECTSPACE)
39# include <ospace\std\iostream>
40#elif defined(GSDL_USE_IOS_H)
41# include <iostream.h>
42#else
43# include <iostream>
44#endif
45
46#include <stdio.h>
47
48
49typedef vector<unsigned char> UCArray;
50
51// functions to manipulate UCArrays
52void SetCStr (UCArray &text, const char *cStr);
53char * GetCStr(UCArray text);
54inline void UCArrayClear (UCArray &a) {
55 a.erase (a.begin(), a.end());
56}
57
58// stream operator to print UCArray
59ostream &operator<<(ostream &s, const UCArray &a);
60
61// used for reading and writing unsigned characters
62inline bool ReadUC (FILE *f, unsigned char &c) {
63 return (fread (&c, sizeof (unsigned char), 1, f) == 1);
64}
65inline bool WriteUC (FILE *f, unsigned char c) {
66 return (fwrite (&c, sizeof (unsigned char), 1, f) == 1);
67}
68
69// used for reading and writing variable length unsigned longs
70bool ReadVarLenUL (FILE *f, unsigned long &n);
71bool WriteVarLenUL (FILE *f, unsigned long n);
72
73// used for reading and writing unsigned longs
74bool ReadUL (FILE *f, unsigned long &n);
75bool WriteUL (FILE *f, unsigned long n);
76
77// used for reading and writing floats
78bool ReadF (FILE *f, float &n);
79bool WriteF (FILE *f, float n);
80
81// used for reading and writing doubles
82bool ReadD (FILE *f, double &n);
83bool WriteD (FILE *f, double n);
84
85// used for reading and writing arrays to files
86bool ReadUCArray (FILE *f, UCArray &a);
87bool WriteUCArray (FILE *f, const UCArray &a);
88
89
90// compares the two strings in dictionary order
91int DictCompare (const UCArray &a1, const UCArray &a2);
92
93struct LTUCArray {
94 bool operator()(const UCArray &a1, const UCArray &a2) const
95 { return (a1 < a2); }
96};
97
98struct DictLTUCArray {
99 bool operator() (const UCArray &a1, const UCArray &a2) const
100 { return (DictCompare (a1, a2) < 0); }
101};
102
103
104typedef set<UCArray, LTUCArray> UCArraySet;
105typedef vector<UCArray> UCArrayVector;
106
107unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
108
109// prev == NULL if no previous string
110bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
111bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
112
113
114#endif
115
116
117
118
119
Note: See TracBrowser for help on using the repository browser.