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

Last change on this file since 879 was 855, checked in by sjboddie, 24 years ago

Rodgers new C++ mg

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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 855 2000-01-14 02:17:52Z sjboddie $
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);
53inline void UCArrayClear (UCArray &a) {
54 a.erase (a.begin(), a.end());
55}
56
57// stream operator to print UCArray
58ostream &operator<<(ostream &s, const UCArray &a);
59
60// used for reading and writing unsigned characters
61inline bool ReadUC (FILE *f, unsigned char &c) {
62 return (fread (&c, sizeof (unsigned char), 1, f) == 1);
63}
64inline bool WriteUC (FILE *f, unsigned char c) {
65 return (fwrite (&c, sizeof (unsigned char), 1, f) == 1);
66}
67
68// used for reading and writing variable length unsigned longs
69bool ReadVarLenUL (FILE *f, unsigned long &n);
70bool WriteVarLenUL (FILE *f, unsigned long n);
71
72// used for reading and writing unsigned longs
73bool ReadUL (FILE *f, unsigned long &n);
74bool WriteUL (FILE *f, unsigned long n);
75
76// used for reading and writing floats
77bool ReadF (FILE *f, float &n);
78bool WriteF (FILE *f, float n);
79
80// used for reading and writing doubles
81bool ReadD (FILE *f, double &n);
82bool WriteD (FILE *f, double n);
83
84// used for reading and writing arrays to files
85bool ReadUCArray (FILE *f, UCArray &a);
86bool WriteUCArray (FILE *f, const UCArray &a);
87
88
89// compares the two strings in dictionary order
90int DictCompare (const UCArray &a1, const UCArray &a2);
91
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;
105
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
Note: See TracBrowser for help on using the repository browser.