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

Last change on this file since 18717 was 18717, checked in by oranfry, 15 years ago

being more explicit about libraries for the sake of newer compilers

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.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 **************************************************************************/
21
22#ifndef UCARRAY_H
23#define UCARRAY_H
24
25#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
26#pragma warning(disable:4786)
27#endif
28
29// need this to avoid bizarre compiler problems under VC++ 6.0
30#if !defined (GSDL_NAMESPACE_BROKEN) && !defined (GSDL_USE_IOS_H)
31# include <iostream>
32using namespace std;
33#endif
34
35#if defined(GSDL_USE_OBJECTSPACE)
36# include <ospace\std\vector>
37# include <ospace\std\set>
38#elif defined(GSDL_USE_STL_H)
39# include <vector.h>
40# include <set.h>
41#else
42# include <vector>
43# include <set>
44#endif
45
46#if defined(GSDL_USE_OBJECTSPACE)
47# include <ospace\std\iostream>
48#elif defined(GSDL_USE_IOS_H)
49# include <iostream.h>
50#else
51# include <iostream>
52#endif
53
54#include <stdio.h>
55#include <cstring>
56
57
58typedef vector<unsigned char> UCArray;
59
60// functions to manipulate UCArrays
61void SetCStr (UCArray &text, const char *cStr);
62// same as SetCStr but first tries to allocate nSizeHint space (only if needed)
63void SetCStr (UCArray &text, const char *cStr, size_t nSizeHint);
64char * GetCStr(const UCArray& text);
65inline void UCArrayClear (UCArray &a) {
66 a.erase (a.begin(), a.end());
67}
68bool UCArrayCStrEquals(const UCArray &text, const unsigned char *cStr);
69inline bool UCArrayCStrEquals(const UCArray &text, const char *cStr) { return UCArrayCStrEquals(text, (const unsigned char *)cStr); }
70
71// stream operator to print UCArray
72ostream &operator<<(ostream &s, const UCArray &a);
73
74// used for reading and writing unsigned characters
75inline bool ReadUC (FILE *f, unsigned char &c) {
76 return (fread (&c, sizeof (unsigned char), 1, f) == 1);
77}
78inline bool WriteUC (FILE *f, unsigned char c) {
79 return (fwrite (&c, sizeof (unsigned char), 1, f) == 1);
80}
81
82// used for reading and writing variable length unsigned longs
83bool ReadVarLenUL (FILE *f, unsigned long &n);
84bool WriteVarLenUL (FILE *f, unsigned long n);
85
86// used for reading and writing unsigned longs
87bool ReadUL (FILE *f, unsigned long &n);
88bool WriteUL (FILE *f, unsigned long n);
89
90// used for reading and writing floats
91bool ReadF (FILE *f, float &n);
92bool WriteF (FILE *f, float n);
93
94// used for reading and writing doubles
95bool ReadD (FILE *f, double &n);
96bool WriteD (FILE *f, double n);
97
98// used for reading and writing arrays to files
99bool ReadUCArray (FILE *f, UCArray &a);
100bool WriteUCArray (FILE *f, const UCArray &a);
101
102
103// compares the two strings in dictionary order
104int DictCompare (const UCArray &a1, const UCArray &a2);
105
106// does the first string start with the second?
107bool StartsWith(const UCArray &a1, const UCArray &a2);
108// does the first string start with the second, ignoring case?
109bool StartsWithCasefold(const UCArray &a1, const UCArray &a2);
110
111struct LTUCArray {
112 bool operator()(const UCArray &a1, const UCArray &a2) const
113 { return (a1 < a2); }
114};
115
116struct DictLTUCArray {
117 bool operator() (const UCArray &a1, const UCArray &a2) const
118 { return (DictCompare (a1, a2) < 0); }
119};
120
121
122typedef set<UCArray, LTUCArray> UCArraySet;
123typedef vector<UCArray> UCArrayVector;
124
125unsigned long PrefixLen (const UCArray &a1, const UCArray &a2);
126
127// prev == NULL if no previous string
128bool WritePreSufStr (FILE *f, const UCArray *prev, const UCArray &a);
129bool ReadPreSufStr (FILE *f, UCArray &a); // a also used for prev
130
131
132#endif
Note: See TracBrowser for help on using the repository browser.