summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/include/graphite/GrCommon.h
blob: 8bb5728ecb36c59dda50976c5ab37853e3b3a4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001, 2003 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: GrCommon.h
Responsibility: Sharon Correll
Last reviewed:

	Common generic header file.

	This header file checks for the following compile time switches:

		USING_MFC
----------------------------------------------------------------------------------------------*/

#ifndef GRCOMMON_INCLUDED
#define GRCOMMON_INCLUDED


// Standard Headers.

#include <cstdlib>
#include <cstdio>
#include <cstdarg>
#include <climits>
//#include <exception>
#include <new>

#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

// Uncomment this to allow multiple versions of gr to coexist
// in the same program e.g. pangographite with gtk uses namespace gr
// mozilla graphite defines this to gr2moz incase the 2 libraries are 
// incompatible.
// Provided the client includes GrClient.h first this #define is
// picked up by all files.

//#define gr gr2

// Project headers
#include "GrPlatform.h"

#ifndef GrAssert
#include <cassert>
#define GrAssert(exp) assert(exp)
#endif

using std::max;
using std::min;

namespace gr
{


/***********************************************************************************************
	Simple types.
***********************************************************************************************/
typedef char	schar;

// TODO ShonK: Make generic use these where appropriate.
#ifdef UNICODE
typedef utf16 	achar;
#else // !UNICODE
typedef schar	achar;
#endif // UNICODE

typedef achar 	*Psz;
//typedef const achar * Pcsz;



// This is to make a signed isizeof operator, otherwise we get tons of warnings about
// signed / unsigned mismatches.
#define isizeof(T) (sizeof(T))

#define SizeOfArray(rgt) (isizeof(rgt) / isizeof(rgt[0]))


/***********************************************************************************************
	Tests for valid strings and pointers.
***********************************************************************************************/
inline bool ValidPsz(const data16 *pszw)
{
	// TODO ShonK: Determine if IsBadStringPtrW is implemented on Win9x.
	return pszw != 0 && !GrIsBadStringPtrW(pszw, 0x10000000);
}

inline bool ValidPsz(const schar *pszs)
{
	return pszs != 0 && !GrIsBadStringPtrA(pszs, 0x10000000);
}

template<typename T> inline bool ValidReadPtr(T *pt)
{
	return pt != 0 && !GrIsBadReadPtr(pt, isizeof(T));
}

template<typename T> inline bool ValidWritePtr(T *pt)
{
	return pt != 0 && !GrIsBadWritePtr(pt, isizeof(T));
}

inline bool ValidReadPtrSize(const void *pv, int cb)
{
	if (cb < 0)	return false;
	if (cb == 0)	return true;

	return pv != 0 && !GrIsBadReadPtr(pv, cb);
}

inline bool ValidWritePtrSize(void *pv, int cb)
{
//	if (!bstr || ::IsBadReadPtr((byte *)bstr - isizeof(int), isizeof(int) + isizeof(OLECHAR)))
//		return false;
//	int cb = ((int *)bstr)[-1];
//	if (::IsBadReadPtr((byte *)bstr - isizeof(int), isizeof(int) + isizeof(OLECHAR) + cb))
//		return false;
	if (cb < 0)	return false;
	if (cb == 0)	return true;

	return pv != 0 && !GrIsBadWritePtr(pv, cb);
}


} // namespace gr


// TODO Remove these as soon as they are no longer needed by GrCompiler:
//#include "UtilMem.h"
//#include "UtilRect.h"
//#include "UtilString.h"
//#include "UtilVector.h"

#if defined(GR_NO_NAMESPACE)
using namespace gr;
#endif

#endif // !GRCOMMON_INCLUDED