Beispiel #1
0
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"));
	}
}
Beispiel #2
0
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;
		}
	}
}
Beispiel #3
0
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);
	}
}
Beispiel #4
0
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;
}
Beispiel #5
0
void Format::ItemGroup::Traverse(std::basic_ifstream<Char> &from, Extension &ext) const
{
	ext.FormatTimes = 1;
	if(ext.OfFormat.length())
	{
		ext.ElemName = name;
		ext.Runtime.GenerateEvent(Extension::Trigger::Load::SubFormat);
	}
	for(unsigned i = 0, k = ext.FormatTimes; i < k; ++i)
	{
		for(items_t::const_iterator it = items.begin(); it != items.end(); ++it)
		{
			ext.FormatTimes = i;
			ext.OfFormat = name;
			ext.ElemName = (*it)->name;
			(*it)->Traverse(from, ext);
			if(!ext.Assert(from.good(), String(_T("An error occured while reading the file after: "))+(*it)->name)) return;
		}
	}
}
Beispiel #6
0
		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;
		}
Beispiel #7
0
		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;
		}
Beispiel #8
0
		Integer(std::basic_ifstream<Char> &from, const String &n) : Item(n) //Deserialize
		{
			from.read((Char*)&size, sizeof(size)/sizeof(Char));
		}
	template<typename CharType>void skip_utf8_bom(std::basic_ifstream<CharType>& fs) {
		int dst[3];
		for (auto& i : dst) i = fs.get();
		constexpr int utf8[] = { 0xEF, 0xBB, 0xBF };
		if (!std::equal(std::begin(dst), std::end(dst), utf8)) fs.seekg(0);
	}