void Format::Integer::Traverse(std::basic_ifstream<Char> &from, Extension &ext) const { if(size == 1) { from.read((Char*)&ext.ByteValue, sizeof(ext.ByteValue)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Byte); } else if(size == 2) { from.read((Char*)&ext.ShortValue, sizeof(ext.ShortValue)/sizeof(Char)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Short); } else if(size == 4) { from.read((Char*)&ext.IntValue, sizeof(ext.IntValue)/sizeof(Char)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Int); } else if(size == 8) { from.read((Char*)&ext.LongValue, sizeof(ext.LongValue)/sizeof(Char)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Long); } else { ext.GenerateError(_T("Unkown Size; not Byte, Short, Int, or Long")); } }
void Format::Float::Traverse(std::basic_ifstream<Char> &from, Extension &ext) const { if(doub) { from.read((Char*)&ext.DoubleValue, sizeof(ext.DoubleValue)/sizeof(Char)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Double); } else { from.read((Char*)&ext.FloatValue, sizeof(ext.FloatValue)/sizeof(Char)); ext.Runtime.GenerateEvent(Extension::Trigger::Load::Float); } }
Format::ItemGroup::ItemGroup(std::basic_ifstream<Char> &from, const String &nam) : Item(nam) //Deserialize { String n; int c; items_t::size_type size; from.read((Char*)&size, sizeof(size)/sizeof(Char)); for(items_t::size_type i = 0; i < size; ++i) { for(n.clear(); c = from.get(); n += char(c)); if((c = from.get()) == ItemGroup::TypeID) { items.push_back(new ItemGroup(from, n)); } else if(c == Integer::TypeID) { items.push_back(new Integer(from, n)); } else if(c == Float::TypeID) { items.push_back(new Float(from, n)); } else if(c == Str::TypeID) { items.push_back(new Str(from, n)); } else if(c == Raw::TypeID) { items.push_back(new Raw(from, n)); } else { throw this; } } }
static Script::String loadFile(std::basic_ifstream<Script::Char>& instream, const std::string& filename) { Script::String chars; Script::Char* buffer = new Script::Char[1024 * 1024]; try { while (!instream.eof()) { if (instream.bad()) throw Script::Xception(Script::String("Error reading from file: ") += Pika::escape(filename)); instream.read(buffer, 1024 * 1024); chars += Script::String(buffer, static_cast<Script::String::size_type>(instream.gcount())); } instream.close(); } catch (...) { delete [] buffer; throw; } delete [] buffer; return chars; }
Str(std::basic_ifstream<Char> &from, const String &n) : Item(n) //Deserialize { Char u; from.read(&u, sizeof(u)/sizeof(Char)); unicode = u?true:false; }
Float(std::basic_ifstream<Char> &from, const String &n) : Item(n) //Deserialize { Char d; from.read(&d, sizeof(d)/sizeof(Char)); doub = d?true:false; }
Integer(std::basic_ifstream<Char> &from, const String &n) : Item(n) //Deserialize { from.read((Char*)&size, sizeof(size)/sizeof(Char)); }