coriolis/vlsisapd/cif/CifCircuit.cpp

54 lines
1.3 KiB
C++
Raw Normal View History

#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
#include "CifCircuit.h"
#include "CifPolygon.h"
namespace IO {
CifCircuit::CifCircuit(string name) : _name(name) {}
bool CifCircuit::addPolygon(CifPolygon* polygon) {
if(polygon)
_polygons.push_back(polygon);
else {
cerr << "[CIF DRIVE ERROR]: cannot add invalid polygon." << endl;
return false;
}
return true;
}
bool CifCircuit::write(string filename) {
time_t curtime = time(0);
tm now = *localtime(&curtime);
char date[BUFSIZ]={0};
const char format[]="%d-%b-%Y %H:%M:%S";
if (!strftime(date, sizeof(date)-1, format, &now)>0)
cerr << "[CIF DRIVE ERROR]: cannot build current date." << endl;
ofstream file;
file.open(filename.c_str(), ios::out);
// Header
file << "(CIF file written on " << date << " by IO_CIF_DRIVER);" << endl
<< "DS 1 1 1;" << endl
<< "9 " << _name << ";" << endl;
// For each Polygon : write polygon.
for ( vector<CifPolygon*>::iterator it = _polygons.begin() ; it < _polygons.end() ; it++ ) {
(*it)->write(file);
}
// Footer
file << "DF;" << endl
<< "C 1;" << endl
<< "E" << endl;
file.close();
return true;
}
} // namespace