Changeset 58 in projects for punch-card-project/trunk/punch-card-editor/src/text/codec.cc
- Timestamp:
- Jan 3, 2010, 3:42:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
punch-card-project/trunk/punch-card-editor/src/text/codec.cc
r52 r58 1 1 #include <QDebug> 2 2 #include <QHash> 3 #include <QMap>4 #include <QSharedPointer>5 3 6 4 #include "codec.h" … … 8 6 9 7 using namespace QPunchCard; 8 9 // initialize static members 10 QHash<QString, Codec*> CodecFactory::codec_cache; 10 11 11 12 QString Codec::toAscii(const Card* target_card) const { … … 53 54 } 54 55 55 CharArrayCodec::CharArrayCodec(const int* table, char illegal) : Codec(illegal), table(table) { 56 CharArrayCodec::CharArrayCodec(const int* table, char illegal) : Codec(illegal) { 57 d = new Data; 58 d->table = table; 59 56 60 // Inverse Tabelle (ASCII -> Column-Tabelle) erstellen 57 if(! table) {61 if(!d->table) { 58 62 // uhh... miserable failure. Sehr schlecht. 59 63 qDebug() << "CharArrayCodec: Table is NULL! This will *CRASH* application!"; … … 63 67 for(int i = 0; i < 4096; i++) { 64 68 // Illegal characters setzen 65 inverse_table[i] = illegal;69 d->inverse_table[i] = illegal; 66 70 } 67 71 68 72 for(char c = ' '; c < '`'; c++) { 69 inverse_table[ this->table[c] ] = c;73 d->inverse_table[ d->table[c] ] = c; 70 74 } 71 75 } … … 78 82 79 83 const Codec* CodecFactory::createCodec(const QString& name, char illegal) { 80 if("o29_code" == name) 81 return new CharArrayCodec(o29_code, illegal); 82 else if("o26_ftn_code" == name) 83 return new CharArrayCodec(o26_ftn_code, illegal); 84 else if("o26_comm_code" == name) 85 return new CharArrayCodec(o26_comm_code, illegal); 86 else { 87 qDebug() << QString("Codec '%s' not supported!").arg(name); 88 return NULL; 84 if(!CodecFactory::codec_cache.contains(name)) { 85 if("o29_code" == name) 86 CodecFactory::codec_cache[name] = new CharArrayCodec(o29_code, illegal); 87 else if("o26_ftn_code" == name) 88 CodecFactory::codec_cache[name] = new CharArrayCodec(o26_ftn_code, illegal); 89 else if("o26_comm_code" == name) 90 CodecFactory::codec_cache[name] = new CharArrayCodec(o26_comm_code, illegal); 91 else { 92 qDebug() << QString("Codec '%s' not supported!").arg(name); 93 return NULL; 94 } 89 95 } 96 97 return CodecFactory::codec_cache[name]; 90 98 } 91 99
Note: See TracChangeset
for help on using the changeset viewer.