source: main/trunk/greenstone2/common-src/indexers/mgpp/text/UCArray.h@ 26294

Last change on this file since 26294 was 25147, checked in by kjdon, 12 years ago

merged 64_bit_Greenstone branch into trunk, rev 25139

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