source: branches/New_Config_Format-branch/gsdl/src/mgpp/text/UCArray.h@ 1279

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

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 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 1279 2000-07-12 22:21:53Z 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);
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// compares the two strings, case independent, a match (ie 0) is
93// if one string is a prefix of the other
94int BrowseCompare (const UCArray &a1, const UCArray &a2);
95
96struct LTUCArray {
97 bool operator()(const UCArray &a1, const UCArray &a2) const
98 { return (a1 < a2); }
99};
100
101struct DictLTUCArray {
102 bool operator() (const UCArray &a1, const UCArray &a2) const
103 { return (DictCompare (a1, a2) < 0); }
104};
105
106
107typedef set<UCArray, LTUCArray> UCArraySet;
108
109
110unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
111
112// prev == NULL if no previous string
113bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
114bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
115
116
117#endif
118
119
120
121
122
Note: See TracBrowser for help on using the repository browser.