61 lines
1.1 KiB
C++
61 lines
1.1 KiB
C++
|
#include "topologyreadercsv.hh"
|
||
|
#include "posexcept.hh"
|
||
|
#include "stock.hh"
|
||
|
#include "point3d.hh"
|
||
|
#include "area.hh"
|
||
|
|
||
|
using namespace std ;
|
||
|
|
||
|
|
||
|
|
||
|
/* *** Constructors *** */
|
||
|
|
||
|
|
||
|
TopologyReaderCSV::TopologyReaderCSV(const string &filename):
|
||
|
file(filename)
|
||
|
{
|
||
|
read_topology() ;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/* *** Operations *** */
|
||
|
|
||
|
|
||
|
void TopologyReaderCSV::read_topology()
|
||
|
{
|
||
|
while (file.next_line())
|
||
|
process_line() ;
|
||
|
}
|
||
|
|
||
|
|
||
|
void TopologyReaderCSV::process_line()
|
||
|
{
|
||
|
string building_name ;
|
||
|
if (! file.read_field(building_name))
|
||
|
throw malformed_topology("Cannot read building name!") ;
|
||
|
Building &building = const_cast<Building&>(
|
||
|
Stock::find_create_building(building_name)) ;
|
||
|
|
||
|
string name ;
|
||
|
if (! file.read_field(name))
|
||
|
throw malformed_topology("Cannot read area name!") ;
|
||
|
|
||
|
Point3D p_min(read_point()) ;
|
||
|
Point3D p_max(read_point()) ;
|
||
|
|
||
|
Area *area = new Area(&building, name, p_min, p_max) ;
|
||
|
building.add_area(area) ;
|
||
|
}
|
||
|
|
||
|
|
||
|
Point3D TopologyReaderCSV::read_point()
|
||
|
{
|
||
|
float coord[3] ;
|
||
|
for (unsigned int i = 0 ; i < 3 ; ++i)
|
||
|
if (! file.read_field(coord[i]))
|
||
|
throw malformed_topology("Cannot read a whole Point3D!") ;
|
||
|
|
||
|
return Point3D(coord) ;
|
||
|
}
|