Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / filesnapshotmgr.cc @ a3be1d55

History | View | Annotate | Download (1.83 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  FILESNAPSHOTMGR.CC - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17
18
#include "simkerneldefs.h"
19
20
#include <assert.h>
21
#include <string.h>
22
#include <fstream>
23
#include "cconfigoption.h"
24
#include "fileutil.h"
25
#include "envirbase.h"
26
#include "filesnapshotmgr.h"
27
28
USING_NAMESPACE
29
30
using std::ostream;
31
using std::ofstream;
32
using std::ios;
33
34
35
Register_PerRunConfigOption(CFGID_SNAPSHOT_FILE, "snapshot-file", CFG_FILENAME, "${resultdir}/${configname}-${runnumber}.sna", "Name of the snapshot file.");
36
37
38
Register_Class(cFileSnapshotManager);
39
40
41
cFileSnapshotManager::cFileSnapshotManager()
42
{
43
}
44
45
cFileSnapshotManager::~cFileSnapshotManager()
46
{
47
}
48
49
void cFileSnapshotManager::startRun()
50
{
51
    // clean up file from previous runs
52
    fname = ev.getConfig()->getAsFilename(CFGID_SNAPSHOT_FILE).c_str();
53
    dynamic_cast<EnvirBase *>(&ev)->processFileName(fname);
54
    removeFile(fname.c_str(), "old snapshot file");
55
}
56
57
void cFileSnapshotManager::endRun()
58
{
59
}
60
61
ostream *cFileSnapshotManager::getStreamForSnapshot()
62
{
63
    mkPath(directoryOf(fname.c_str()).c_str());
64
    ostream *os = new ofstream(fname.c_str(), ios::out|ios::app);
65
    return os;
66
}
67
68
void cFileSnapshotManager::releaseStreamForSnapshot(std::ostream *os)
69
{
70
    delete os;
71
}
72
73
const char *cFileSnapshotManager::getFileName() const
74
{
75
    return fname.c_str();
76
}