Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F119987232
source.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jul 1, 02:22
Size
1 KB
Mime Type
text/x-c
Expires
Thu, Jul 3, 02:22 (2 d)
Engine
blob
Format
Raw Data
Handle
27122032
Attached To
rSTICAZZI yearII_reports
source.cpp
View Options
#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
Log In to Comment