A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ascii-file.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 University of Washington
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mitch Watrous (watrous@u.washington.edu)
19
*
20
* This file is based on pcap-file.cc by Craig Dowell (craigdo@ee.washington.edu)
21
*/
22
23
#include <iostream>
24
#include <string>
25
#include "ns3/assert.h"
26
#include "ns3/fatal-error.h"
27
#include "ns3/fatal-impl.h"
28
#include "
ascii-file.h
"
29
//
30
// This file is used as part of the ns-3 test framework, so please refrain from
31
// adding any ns-3 specific constructs such as Packet to this file.
32
//
33
namespace
ns3 {
34
35
AsciiFile::AsciiFile
()
36
: m_file ()
37
{
38
FatalImpl::RegisterStream
(&
m_file
);
39
}
40
41
AsciiFile::~AsciiFile
()
42
{
43
FatalImpl::UnregisterStream
(&
m_file
);
44
Close
();
45
}
46
47
bool
48
AsciiFile::Fail
(
void
)
const
49
{
50
return
m_file
.fail ();
51
}
52
bool
53
AsciiFile::Eof
(
void
)
const
54
{
55
return
m_file
.eof ();
56
}
57
58
void
59
AsciiFile::Close
(
void
)
60
{
61
m_file
.close ();
62
}
63
64
void
65
AsciiFile::Open
(std::string
const
&filename, std::ios::openmode mode)
66
{
67
NS_ASSERT
((mode & std::ios::app) == 0);
68
NS_ASSERT
(!
m_file
.fail ());
69
70
m_file
.open (filename.c_str (), mode);
71
}
72
73
void
74
AsciiFile::Read
(std::string& line)
75
{
76
NS_ASSERT
(
m_file
.good ());
77
78
// Read the next line.
79
getline (
m_file
, line);
80
}
81
82
bool
83
AsciiFile:: Diff
(std::string
const
& f1,
84
std::string
const
& f2,
85
uint64_t & lineNumber)
86
{
87
AsciiFile
ascii1, ascii2;
88
ascii1.
Open
(f1, std::ios::in);
89
ascii2.
Open
(f2, std::ios::in);
90
bool
bad = ascii1.
Fail
() || ascii2.
Fail
();
91
if
(bad)
92
{
93
return
true
;
94
}
95
96
std::string line1;
97
std::string line2;
98
lineNumber = 0;
99
bool
diff =
false
;
100
101
while
(!ascii1.
Eof
() && !ascii2.
Eof
())
102
{
103
ascii1.
Read
(line1);
104
ascii2.
Read
(line2);
105
106
lineNumber++;
107
108
bool
same = ascii1.
Fail
() == ascii2.
Fail
();
109
if
(!same)
110
{
111
diff =
true
;
112
break
;
113
}
114
if
(ascii1.
Eof
())
115
{
116
break
;
117
}
118
119
if
(line1 != line2)
120
{
121
diff =
true
;
// Lines do not match
122
break
;
123
}
124
}
125
126
return
diff;
127
}
128
129
}
// namespace ns3
src
network
utils
ascii-file.cc
Generated on Tue May 14 2013 11:08:30 for ns-3 by
1.8.1.2