]> git.stg.codes - stg.git/blob - include/stg/user_traff.h
Redundant semicolon removed
[stg.git] / include / stg / user_traff.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21 /*
22  $Revision: 1.7 $
23  $Date: 2010/10/07 19:48:52 $
24  $Author: faust $
25  */
26
27 #ifndef USER_TRAFF_H
28 #define USER_TRAFF_H
29
30 #include <iostream>
31 #include <vector>
32
33 #include "const.h"
34 #include "os_int.h"
35
36 enum TRAFF_DIRECTION {TRAFF_UPLOAD, TRAFF_DOWNLOAD};
37
38 class DIR_TRAFF
39 {
40     friend std::ostream & operator<< (std::ostream & o, const DIR_TRAFF & traff);
41
42 public:
43     //-------------------------------------------------------------------------
44     DIR_TRAFF();
45     DIR_TRAFF(const DIR_TRAFF & ts);
46     DIR_TRAFF & operator=(const DIR_TRAFF & ts);
47     ~DIR_TRAFF();
48     uint64_t operator[](int idx) const;
49     uint64_t & operator[](int idx);
50     DIR_TRAFF operator+(const DIR_TRAFF & ts);
51
52 private:
53     std::vector<uint64_t> traff;
54 };
55 //-----------------------------------------------------------------------------
56
57 //-----------------------------------------------------------------------------
58 inline DIR_TRAFF::DIR_TRAFF()
59     : traff(DIR_NUM, 0)
60 {
61 }
62 //-----------------------------------------------------------------------------
63 inline DIR_TRAFF::DIR_TRAFF(const DIR_TRAFF & ts)
64     : traff(ts.traff)
65 {
66 }
67 //-----------------------------------------------------------------------------
68 inline DIR_TRAFF::~DIR_TRAFF()
69 {
70 }
71 //-----------------------------------------------------------------------------
72 inline DIR_TRAFF & DIR_TRAFF::operator=(const DIR_TRAFF & ts)
73 {
74 traff = ts.traff;
75 return *this;
76 }
77 //-----------------------------------------------------------------------------
78 inline uint64_t & DIR_TRAFF::operator[](int idx)
79 {
80 return traff[idx];
81 }
82 //-----------------------------------------------------------------------------
83 inline uint64_t DIR_TRAFF::operator[](int idx) const
84 {
85 return traff[idx];
86 }
87 //-----------------------------------------------------------------------------
88 inline DIR_TRAFF DIR_TRAFF::operator+(const DIR_TRAFF & ts)
89 {
90 for (int i = 0; i < DIR_NUM; i++)
91     {
92     traff[i] = traff[i] + ts.traff[i];
93     }
94 return *this;
95 }
96 //-----------------------------------------------------------------------------
97 inline std::ostream & operator<<(std::ostream & o, const DIR_TRAFF & traff)
98 {
99 bool first = true;
100 for (size_t i = 0; i < DIR_NUM; ++i)
101     {
102     if (first)
103         first = false;
104     else
105         o << ",";
106     o << traff[i];
107     }
108 return o;
109 }
110 //-----------------------------------------------------------------------------
111 #endif