Page MenuHomec4science

source.cpp
No OneTemporary

File Metadata

Created
Sat, Jan 18, 05:32

source.cpp

#include "source.h"
#include "debug.hpp"
std::istream& operator>>(std::istream& is, source &s)
{
is >> std::skipws;
char delim;
// begin
is >> delim;
char type;
if (delim != '{')
throw '{';
is >> type;
is >> delim;
if (delim != ',')
throw ',';
is >> s.temperature;
is >> delim;
if (delim != ',')
throw ',';
switch(type)
{
case 'R':
is >> *dynamic_cast<rect*>(s.bounds = new rect());
break;
case 'C':
is >> *dynamic_cast<circle*>(s.bounds = new circle());
break;
default:
throw type;
}
// be sure
is >> std::skipws;
is >> delim;
if (delim != ',')
throw ',';
int fixed_buf;
// 0 or 1
is >> fixed_buf;
s.fixed = static_cast<int>(fixed_buf);
// end
is >> delim;
if (delim != '}')
throw '}';
is >> std::noskipws;
return is;
}
// allows to print a rectangle in the format {(tl[0], tl[1]), (br[0], br[1])}
std::ostream& operator<<(std::ostream& os, const source &s)
{
char type = s.bounds->chr();
os << "{" << type << ", " << s.temperature << ", ";
switch (type)
{
case 'R':
os << *dynamic_cast<rect*>(s.bounds);
break;
case 'C':
os << *dynamic_cast<circle*>(s.bounds);
break;
default:
throw "Cannot cast bounds for source";
}
os << ", " << static_cast<int>(s.fixed) << "}";
return os;
}

Event Timeline