BItem.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "BItem.h"
00025 #include "BDictionary.h"
00026 #include "BErrorItem.h"
00027 #include "BList.h"
00028 #include "BInt.h"
00029 #include "BString.h"
00030 #include "Imports.cpp"
00031
00033
00037 bool BItem::tryReadInt(BinaryReader &reader,
00038 qint64 &outValue, char terminator) const
00039 {
00040 QByteArray rawInt = reader.readString (terminator);
00041 bool ok = true;
00042 outValue = rawInt.toLongLong(&ok);
00043 return ok;
00044 }
00045
00047
00051 auto_ptr <BItem> BItem::readItem (BinaryReader &reader)
00052 {
00053 if (!reader.canRead (1))
00054 return auto_ptr <BItem> (new BErrorItem);
00055
00056 auto_ptr <BItem> item;
00057 char ch = reader.lookAhead (1);
00058
00059 switch (ch)
00060 {
00061 case 'i':
00062 item = auto_ptr <BItem> (new BInt);
00063 break;
00064 case 'l':
00065 item = auto_ptr <BItem> (new BList);
00066 break;
00067 case 'd':
00068 item = auto_ptr <BItem> (new BDictionary);
00069 break;
00070 default:
00071 if (ch > '0' && ch <= '9') {
00072 item = auto_ptr <BItem> (new BString);
00073 }
00074 break;
00075 }
00076 if (item.get() == 0 || !item->read (reader))
00077 return auto_ptr <BItem> (new BErrorItem);
00078 return item;
00079 }