ofstream *file = new ofstream(resolve(name).c_str(),
ios::trunc | binary ? ios::binary : (ios::openmode)0);
if (!file->is_open())
- panic("Cannot open file %s", name);
+ fatal("Cannot open file %s", name);
return file;
}
ofstream *file = new ofstream(filename.c_str(), ios::trunc);
if (!file->is_open())
- panic("Cannot open file %s", filename);
+ fatal("Cannot open file %s", filename);
files[filename] = file;
return file;
map_t files;
std::string dir;
+ std::string resolve(const std::string &name);
+
public:
OutputDirectory();
~OutputDirectory();
void setDirectory(const std::string &dir);
const std::string &directory();
- std::string resolve(const std::string &name);
std::ostream *create(const std::string &name, bool binary = false);
std::ostream *find(const std::string &name);
using std::string;
EtherDump::EtherDump(const Params *p)
- : SimObject(p), stream(simout.resolve(p->file).c_str()),
+ : SimObject(p), stream(simout.create(p->file, true)),
maxlen(p->maxlen)
{
}
hdr.sigfigs = 0;
hdr.linktype = DLT_EN10MB;
- stream.write(reinterpret_cast<char *>(&hdr), sizeof(hdr));
+ stream->write(reinterpret_cast<char *>(&hdr), sizeof(hdr));
/*
* output an empty packet with the current time so that we know
pkthdr.microseconds = 0;
pkthdr.caplen = 0;
pkthdr.len = 0;
- stream.write(reinterpret_cast<char *>(&pkthdr), sizeof(pkthdr));
+ stream->write(reinterpret_cast<char *>(&pkthdr), sizeof(pkthdr));
- stream.flush();
+ stream->flush();
}
void
pkthdr.microseconds = (curTick / Clock::Int::us) % ULL(1000000);
pkthdr.caplen = std::min(packet->length, maxlen);
pkthdr.len = packet->length;
- stream.write(reinterpret_cast<char *>(&pkthdr), sizeof(pkthdr));
- stream.write(reinterpret_cast<char *>(packet->data), pkthdr.caplen);
- stream.flush();
+ stream->write(reinterpret_cast<char *>(&pkthdr), sizeof(pkthdr));
+ stream->write(reinterpret_cast<char *>(packet->data), pkthdr.caplen);
+ stream->flush();
}
EtherDump *
class EtherDump : public SimObject
{
private:
- std::ofstream stream;
+ std::ostream *stream;
const int maxlen;
void dumpPacket(EthPacketPtr &packet);
void init();
else if (lru_net)
lru_net->cleanupRefs();
- ofstream memPrint(simout.resolve("memory_footprint.txt").c_str(),
- ios::trunc);
+ ostream *memPrint = simout.create("memory_footprint.txt");
// this shouldn't be here but it happens at the end, which is what i want
memIter end = memHash.end();
for (memIter iter = memHash.begin(); iter != end; ++iter) {
- ccprintf(memPrint, "%8x\t%d\n", (*iter).first, (*iter).second);
+ ccprintf(*memPrint, "%8x\t%d\n", (*iter).first, (*iter).second);
}
}