forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
RateSpec.h
Go to the documentation of this file.
1
9
#ifndef RATESPEC_H
10
#define RATESPEC_H
11
12
#include "
Forest.h
"
13
14
namespace
forest {
15
16
21
class
RateSpec
{
22
public
:
23
int
bitRateUp
;
24
int
bitRateDown
;
25
int
pktRateUp
;
26
int
pktRateDown
;
27
29
RateSpec
() { reset(); }
30
32
RateSpec
(
int
r) {
set
(r); }
33
35
RateSpec
(
int
bru,
int
brd,
int
pru,
int
prd) {
36
set
(bru,brd,pru,prd);
37
}
38
40
RateSpec
(
RateSpec
& rs) {
41
(*this) = rs;
42
}
43
44
void
reset() {
45
bitRateUp
= -1;
bitRateDown
=
pktRateUp
=
pktRateDown
= 0;
46
}
47
48
bool
isSet() {
return
bitRateUp
!= -1; }
49
51
void
set
(
int
r) {
52
bitRateUp
=
bitRateDown
=
pktRateUp
=
pktRateDown
= r;
53
}
54
56
void
set
(
int
bru,
int
brd,
int
pru,
int
prd) {
57
bitRateUp
= bru;
bitRateDown
= brd;
58
pktRateUp
= pru;
pktRateDown
= prd;
59
}
60
62
bool
isZero
() {
63
return
bitRateUp
== 0 &&
bitRateDown
== 0 &&
64
pktRateUp
== 0 &&
pktRateDown
== 0;
65
}
66
68
void
flip
() {
69
int
x;
70
x =
bitRateUp
;
bitRateUp
=
bitRateDown
;
bitRateDown
= x;
71
x =
pktRateUp
;
pktRateUp
=
pktRateDown
;
pktRateDown
= x;
72
}
73
75
void
add
(
const
RateSpec
& rs) {
76
bitRateUp
+= rs.
bitRateUp
;
bitRateDown
+= rs.
bitRateDown
;
77
pktRateUp
+= rs.
pktRateUp
;
pktRateDown
+= rs.
pktRateDown
;
78
}
79
81
void
subtract
(
const
RateSpec
& rs) {
82
bitRateUp
-= rs.
bitRateUp
;
bitRateDown
-= rs.
bitRateDown
;
83
pktRateUp
-= rs.
pktRateUp
;
pktRateDown
-= rs.
pktRateDown
;
84
}
85
87
void
negate
() {
88
bitRateUp
= -
bitRateUp
;
bitRateDown
= -
bitRateDown
;
89
pktRateUp
= -
pktRateUp
;
pktRateDown
= -
pktRateDown
;
90
}
91
93
void
scale
(
double
f) {
94
bitRateUp
= (int) (f*
bitRateUp
);
95
bitRateDown
= (int) (f*
bitRateDown
);
96
pktRateUp
= (int) (f*
pktRateUp
);
97
pktRateDown
= (int) (f*
pktRateDown
);
98
}
99
101
bool
equals
(
const
RateSpec
& rs) {
102
return
bitRateUp
== rs.
bitRateUp
&&
103
bitRateDown
== rs.
bitRateDown
&&
104
pktRateUp
== rs.
pktRateUp
&&
105
pktRateDown
== rs.
pktRateDown
;
106
};
107
109
bool
leq
(
const
RateSpec
& rs) {
110
return
bitRateUp
<= rs.
bitRateUp
&&
111
bitRateDown
<= rs.
bitRateDown
&&
112
pktRateUp
<= rs.
pktRateUp
&&
113
pktRateDown
<= rs.
pktRateDown
;
114
};
115
116
bool
read
(istream&);
117
string
toString
()
const
;
118
};
119
120
}
// ends namespace
121
122
123
#endif
forest-net
cpp
include
RateSpec.h
Generated on Mon Aug 4 2014 11:13:35 for forest-net by
1.8.4