InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BaseType.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: ?
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // ABSTRACT:
24 // This file defines a set of base types for use by all PageMaker applications.
25 // See the comments below for the different types.
26 //
27 //========================================================================================
28 
29 #ifndef __BASETYPE__
30 #define __BASETYPE__
31 
32 #ifndef __AnsiBasedTypes__
33 #include "AnsiBasedTypes.h"
34 #endif
35 
36 #include "K2TypeTraits.h" // For base_type
37 
38 #if defined MACINTOSH || defined WINDOWS
39 #include <limits.h>
40 #else
41 #include <climits>
42 #endif
43 
49 typedef uchar *PString; // pascal string headed with count
50 typedef const uchar *ConstPString; // pascal string headed with count
51 
56 typedef char *CString; // null terminated "C" string
57 typedef const char *ConstCString; // null terminated "C" string
58 
62 typedef uchar16 *WString; // null terminated "Unicode" string
63 typedef const uchar16 *ConstWString; // null terminated "Unicode" string
64 
65 
66 // there is a bug in the current (3.3) version of the gcc headers where __SCHAR_MAX__ is
67 // not defined.
68 #ifndef __SCHAR_MAX__
69 #define __SCHAR_MAX__ 127
70 #endif
71 
72 const int8 kMinInt8 = (int8)SCHAR_MIN; // from limits.h
73 const int8 kMaxInt8 = (int8)SCHAR_MAX;
74 const int16 kMinInt16 = (int16)SHRT_MIN;
75 const int16 kMaxInt16 = (int16)SHRT_MAX;
76 
77 const uint8 kMaxUInt8 = (uint8)UCHAR_MAX;
78 const uint16 kMaxUInt16 = (uint16)USHRT_MAX;
79 
80 #if MACINTOSH && __LP64__
81  const int32 kMinInt32 = (int32)INT_MIN;
82  const int32 kMaxInt32 = (int32)INT_MAX;
83 
84  const uint32 kMaxUInt32 = (uint32)UINT_MAX;
85 #else
86  const int32 kMinInt32 = (int32)LONG_MIN;
87  const int32 kMaxInt32 = (int32)LONG_MAX;
88 
89  const uint32 kMaxUInt32 = (uint32)ULONG_MAX;
90 #endif
91 
92 #if WINDOWS
93  const int64 kMinInt64 = (int64)_I64_MIN;
94  const int64 kMaxInt64 = (int64)_I64_MAX;
95 
96  const uint64 kMaxUInt64 = (uint64)_UI64_MAX;
97 #else
98  const int64 kMinInt64 = (int64)LONG_LONG_MIN;
99  const int64 kMaxInt64 = (int64)LONG_LONG_MAX;
100 
101  const uint64 kMaxUInt64 = (uint64)ULONG_LONG_MAX;
102 #endif
103 
104 
105 //======================================================================
106 // Other abstract types
107 //======================================================================
108 
110 typedef int32 TextIndex;
111 
113 typedef uchar16 textchar;
114 
116 typedef uchar16 UTF16TextChar;
117 
118 class IPMStream;
119 
125 {
126  public:
129 
131  inline UTF32TextChar() : fCharacterValue() {}
132 
136  inline UTF32TextChar(uint32 c32) : fCharacterValue(c32) {}
137 
142  inline UTF32TextChar(UTF16TextChar hi, UTF16TextChar low)
143  : fCharacterValue((hi - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)
144  {}
145 
149  inline UTF32TextChar(const UTF32TextChar &c) : fCharacterValue(c.fCharacterValue) {}
150 
154  inline uint32 GetValue() const { return fCharacterValue; }
155 
159  inline UTF16TextChar CalcHighSurrogate() const { return (fCharacterValue > 0xFFFF ? static_cast<UTF16TextChar>((fCharacterValue - 0x10000) / 0x400 + 0xd800) : static_cast<UTF16TextChar>(fCharacterValue)); }
160 
164  inline UTF16TextChar CalcLowSurrogate() const { return (fCharacterValue > 0xFFFF ? static_cast<UTF16TextChar>((fCharacterValue - 0x10000) % 0x400 + 0xdc00) : static_cast<UTF16TextChar>(fCharacterValue)); }
165 
170  inline void ToUTF16(UTF16TextChar * buf, int32 * len) const
171  {
172  buf[0] = CalcHighSurrogate();
173  if (fCharacterValue > 0xFFFF && *len >= 2)
174  {
175  *len = 2;
176  buf[1] = CalcLowSurrogate();
177  }
178  else
179  *len = 1;
180  }
181 
186  inline bool16 operator == (UTF32TextChar c32) const { return c32.fCharacterValue == fCharacterValue;}
187 
192  inline bool16 operator != (UTF32TextChar c32) const { return c32.fCharacterValue != fCharacterValue;}
193 
198  inline bool16 operator >= (UTF32TextChar i) const { return fCharacterValue >= i.fCharacterValue; }
199 
204  inline bool16 operator <= (UTF32TextChar i) const { return fCharacterValue <= i.fCharacterValue; }
205 
210  inline bool16 operator > (UTF32TextChar i) const { return fCharacterValue > i.fCharacterValue; }
211 
216  inline bool16 operator < (UTF32TextChar i) const { return fCharacterValue < i.fCharacterValue; }
217 
221  inline UTF32TextChar& operator = (const UTF32TextChar& c) { fCharacterValue = c.fCharacterValue; return *this; }
222 
227  inline bool16 isExtraWide() const { return GetValue() > 0xffff;}
228 
232  void ReadWriteUTF16(IPMStream *s);
233 
234  protected:
235  uint32 fCharacterValue;
236 };
237 
238 
239  template <>
241  static uint32 CONVERT(UTF32TextChar arg) {return arg.GetValue();}
242  };
243 
245 const TextIndex kInvalidTextIndex = -1;
246 
247 
249 typedef int32 ErrorCode;
250 
252 enum {
253  kSuccess = 0,
254  kFailure = 1,
255  kCancel = 2
256 };
257 
258 
268 #if 0
269  #if defined(MACINTOSH) && !defined(__POWERPC__)
270  #define RESOURCE_ENDIAN_SWAPPING 1
271  #else
272  #define RESOURCE_ENDIAN_SWAPPING 0
273 #endif
274 #else
275 #define RESOURCE_ENDIAN_SWAPPING 0
276 #endif
277 
278 template<typename T>
280 {
281  uint32 fContent;
282 
283  uint32 EE (uint32 value) const
284  {
285  #if RESOURCE_ENDIAN_SWAPPING
286  return ((value >> 24) & 0x000000ff) |
287  ((value >> 8) & 0x0000ff00) |
288  ((value << 8) & 0x00ff0000) |
289  ((value << 24) & 0xff000000);
290  #else
291  return value;
292  #endif
293  }
294 
295 public:
296 
297  void Set (T value)
298  {
299  fContent = EE ((uint32) value);
300  }
301 
302  T Get () const
303  {
304  return T (EE (fContent));
305  }
306 
307  ResourceEndianWrapper32 (T value)
308  {
309  Set (value);
310  }
311 
312  operator T () const
313  {
314  return Get ();
315  }
316 };
317 
318 template<typename T>
320 {
321  uint16 fContent;
322 
323  uint16 EE (uint16 value) const
324  {
325  #if RESOURCE_ENDIAN_SWAPPING
326  return ((value >> 8) & 0x00ff) |
327  ((value << 8) & 0xff00);
328  #else
329  return value;
330  #endif
331  }
332 
333 public:
334 
335  void Set (T value)
336  {
337  fContent = EE ((uint16) value);
338  }
339 
340  T Get () const
341  {
342  return T (EE (fContent));
343  }
344 
345  ResourceEndianWrapper16 (T value)
346  {
347  Set (value);
348  }
349 
350  operator T () const
351  {
352  return Get ();
353  }
354 };
355 
356 #if defined(MACINTOSH) && defined(__POWERPC__)
357 #define IS_BIG_ENDIAN_ARCH 1
358 #define IS_LITTLE_ENDIAN_ARCH 0
359 #else
360 #define IS_BIG_ENDIAN_ARCH 0
361 #define IS_LITTLE_ENDIAN_ARCH 1
362 #endif
363 
364 namespace K2
365 {
366  // 11/13/98 Roey
367  // Introduced this namespace to avoid possible conflicts
368  // with third party libraries.
369  // As we are adding more to this namespace it might become necessary
370  // to create a dedicated file for it.
371 
374  typedef enum {
375  kSuppressUI,
376  kMinimalUI,
377  kFullUI
378  } UIFlags;
379 }
380 
381 using namespace K2;
382 
383 #endif // __BASETYPE__