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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mitch Watrous (watrous@u.washington.edu)
18 *
19 * This file is based on pcap-file.h by Craig Dowell (craigdo@ee.washington.edu)
20 */
21
22#ifndef ASCII_FILE_H
23#define ASCII_FILE_H
24
25#include <fstream>
26#include <stdint.h>
27#include <string>
28
29namespace ns3
30{
31
32/**
33 * \brief A class representing an ascii file.
34 *
35 * This class represents an ascii file
36 */
38{
39 public:
40 AsciiFile();
41 ~AsciiFile();
42
43 /**
44 * \return true if the 'fail' bit is set in the underlying iostream, false otherwise.
45 */
46 bool Fail() const;
47 /**
48 * \return true if the 'eof' bit is set in the underlying iostream, false otherwise.
49 */
50 bool Eof() const;
51
52 /**
53 * Create a new ascii file or open an existing ascii file.
54 *
55 * \param filename String containing the name of the file.
56 * \param mode the access mode for the file.
57 */
58 void Open(const std::string& filename, std::ios::openmode mode);
59
60 /**
61 * Close the underlying file.
62 */
63 void Close();
64
65 /**
66 * \brief Read next line from file
67 *
68 * \param line [out] line from file
69 *
70 */
71 void Read(std::string& line);
72
73 /**
74 * \brief Compare two ASCII files line-by-line
75 *
76 * \return true if files are different, false otherwise
77 *
78 * \param f1 First ASCII file name
79 * \param f2 Second ASCII file name
80 * \param lineNumber [out] Line number of first different line.
81 */
82 static bool Diff(const std::string& f1, const std::string& f2, uint64_t& lineNumber);
83
84 private:
85 std::string m_filename; //!< output file name
86 std::fstream m_file; //!< output file
87};
88
89} // namespace ns3
90
91#endif /* ASCII_FILE_H */
A class representing an ascii file.
Definition: ascii-file.h:38
bool Eof() const
Definition: ascii-file.cc:57
void Close()
Close the underlying file.
Definition: ascii-file.cc:63
bool Fail() const
Definition: ascii-file.cc:51
std::fstream m_file
output file
Definition: ascii-file.h:86
std::string m_filename
output file name
Definition: ascii-file.h:85
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:69
void Read(std::string &line)
Read next line from file.
Definition: ascii-file.cc:78
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:87
Every class exported by the ns3 library is enclosed in the ns3 namespace.