Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

UnicodeMap.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // UnicodeMap.h
00004 //
00005 // Mapping from Unicode to an encoding.
00006 //
00007 // Copyright 2001-2002 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef UNICODEMAP_H
00012 #define UNICODEMAP_H
00013 
00014 #ifdef __GNUC__
00015 #pragma interface
00016 #endif
00017 
00018 #include "gtypes.h"
00019 #include "CharTypes.h"
00020 
00021 class GString;
00022 
00023 //------------------------------------------------------------------------
00024 
00025 enum UnicodeMapKind {
00026   unicodeMapUser,               // read from a file
00027   unicodeMapResident,           // static list of ranges
00028   unicodeMapFunc                // function pointer
00029 };
00030 
00031 typedef int (*UnicodeMapFunc)(Unicode u, char *buf, int bufSize);
00032 
00033 struct UnicodeMapRange {
00034   Unicode start, end;           // range of Unicode chars
00035   Guint code, nBytes;           // first output code
00036 };
00037 
00038 struct UnicodeMapExt;
00039 
00040 //------------------------------------------------------------------------
00041 
00042 class UnicodeMap {
00043 public:
00044 
00045   // Create the UnicodeMap specified by <encodingName>.  Sets the
00046   // initial reference count to 1.  Returns NULL on failure.
00047   static UnicodeMap *parse(GString *encodingNameA);
00048 
00049   // Create a resident UnicodeMap.
00050   UnicodeMap(char *encodingNameA,
00051              UnicodeMapRange *rangesA, int lenA);
00052 
00053   // Create a resident UnicodeMap that uses a function instead of a
00054   // list of ranges.
00055   UnicodeMap(char *encodingNameA, UnicodeMapFunc funcA);
00056 
00057   ~UnicodeMap();
00058 
00059   void incRefCnt();
00060   void decRefCnt();
00061 
00062   GString *getEncodingName() { return encodingName; }
00063 
00064   // Return true if this UnicodeMap matches the specified
00065   // <encodingNameA>.
00066   GBool match(GString *encodingNameA);
00067 
00068   // Map Unicode to the target encoding.  Fills in <buf> with the
00069   // output and returns the number of bytes used.  Output will be
00070   // truncated at <bufSize> bytes.  No string terminator is written.
00071   // Returns 0 if no mapping is found.
00072   int mapUnicode(Unicode u, char *buf, int bufSize);
00073 
00074 private:
00075 
00076   UnicodeMap(GString *encodingNameA);
00077 
00078   GString *encodingName;
00079   UnicodeMapKind kind;
00080   union {
00081     UnicodeMapRange *ranges;    // (user, resident)
00082     UnicodeMapFunc func;        // (func)
00083   };
00084   int len;                      // (user, resident)
00085   UnicodeMapExt *eMaps;         // (user)
00086   int eMapsLen;                 // (user)
00087   int refCnt;
00088 };
00089 
00090 //------------------------------------------------------------------------
00091 
00092 #define unicodeMapCacheSize 4
00093 
00094 class UnicodeMapCache {
00095 public:
00096 
00097   UnicodeMapCache();
00098   ~UnicodeMapCache();
00099 
00100   // Get the UnicodeMap for <encodingName>.  Increments its reference
00101   // count; there will be one reference for the cache plus one for the
00102   // caller of this function.  Returns NULL on failure.
00103   UnicodeMap *getUnicodeMap(GString *encodingName);
00104 
00105 private:
00106 
00107   UnicodeMap *cache[unicodeMapCacheSize];
00108 };
00109 
00110 #endif

Generated on Sat Nov 5 16:18:17 2005 for OPIE by  doxygen 1.4.2