-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRamInformation.cpp
More file actions
61 lines (53 loc) · 1.25 KB
/
RamInformation.cpp
File metadata and controls
61 lines (53 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
** EPITECH PROJECT, 2019
** cpp_rush3_2018
** File description:
** RamInformation.cpp
*/
#include <sstream>
#include <fstream>
#include <iostream>
#include "RamInformation.hpp"
RamInformation::RamInformation()
: _content({ContentType::PERCENTAGE, ""})
, _title("Ram Information")
, _position({0, 0, 0})
, _file("/proc/meminfo")
{}
Content RamInformation::getContent()
{
return _content;
}
ModulePosition RamInformation::getPosititon()
{
return _position;
}
std::string RamInformation::getTitle()
{
return _title;
}
void RamInformation::UpdateContent()
{
std::string ramtotal;
std::string ramavailable;
unsigned int percent;
_content.content.clear();
std::fstream input(_file, std::ios::in);
if (!input.good())
throw std::runtime_error("Cannot open " + _file);
input >> ramtotal;
input >> ramtotal;
input >> ramavailable;
input >> ramavailable;
input >> ramavailable;
input >> ramavailable;
input >> ramavailable;
input >> ramavailable;
percent = (unsigned int) ((100 * std::stol(ramavailable)) / std::stol(ramtotal));
percent = 100 - percent;
_content.content = std::to_string(percent);
}
IMonitorModule *RamInformation::clone()
{
return new RamInformation();
}