A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ascii-file.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mitch Watrous (watrous@u.washington.edu)
7 *
8 * This file is based on pcap-file.h by Craig Dowell (craigdo@ee.washington.edu)
9 */
10
11#ifndef ASCII_FILE_H
12#define ASCII_FILE_H
13
14#include <fstream>
15#include <stdint.h>
16#include <string>
17
18namespace ns3
19{
20
21/**
22 * \brief A class representing an ascii file.
23 *
24 * This class represents an ascii file
25 */
27{
28 public:
29 AsciiFile();
30 ~AsciiFile();
31
32 /**
33 * \return true if the 'fail' bit is set in the underlying iostream, false otherwise.
34 */
35 bool Fail() const;
36 /**
37 * \return true if the 'eof' bit is set in the underlying iostream, false otherwise.
38 */
39 bool Eof() const;
40
41 /**
42 * Create a new ascii file or open an existing ascii file.
43 *
44 * \param filename String containing the name of the file.
45 * \param mode the access mode for the file.
46 */
47 void Open(const std::string& filename, std::ios::openmode mode);
48
49 /**
50 * Close the underlying file.
51 */
52 void Close();
53
54 /**
55 * \brief Read next line from file
56 *
57 * \param line [out] line from file
58 *
59 */
60 void Read(std::string& line);
61
62 /**
63 * \brief Compare two ASCII files line-by-line
64 *
65 * \return true if files are different, false otherwise
66 *
67 * \param f1 First ASCII file name
68 * \param f2 Second ASCII file name
69 * \param lineNumber [out] Line number of first different line.
70 */
71 static bool Diff(const std::string& f1, const std::string& f2, uint64_t& lineNumber);
72
73 private:
74 std::string m_filename; //!< output file name
75 std::fstream m_file; //!< output file
76};
77
78} // namespace ns3
79
80#endif /* ASCII_FILE_H */
A class representing an ascii file.
Definition ascii-file.h:27
bool Eof() const
Definition ascii-file.cc:46
void Close()
Close the underlying file.
Definition ascii-file.cc:52
bool Fail() const
Definition ascii-file.cc:40
std::fstream m_file
output file
Definition ascii-file.h:75
std::string m_filename
output file name
Definition ascii-file.h:74
void Open(const std::string &filename, std::ios::openmode mode)
Create a new ascii file or open an existing ascii file.
Definition ascii-file.cc:58
void Read(std::string &line)
Read next line from file.
Definition ascii-file.cc:67
static bool Diff(const std::string &f1, const std::string &f2, uint64_t &lineNumber)
Compare two ASCII files line-by-line.
Definition ascii-file.cc:76
Every class exported by the ns3 library is enclosed in the ns3 namespace.