14
14
15
15
#include " zswapobject/zswapobject.hpp"
16
16
17
- bool ZSwapObject::CheckPercent (const std::string& Value)
17
+ bool ZSwapObject::CheckPercent (const std::string& Value) const
18
18
{
19
19
if (Value.empty ()) return true ;
20
20
const int ValueInt = std::stoi (Value);
21
21
return (ValueInt < 0 ) || (ValueInt > 100 );
22
22
}
23
23
24
- bool ZSwapObject::CheckEnabled (const std::string& Value)
24
+ bool ZSwapObject::CheckEnabled (const std::string& Value) const
25
25
{
26
26
return !std::regex_match (Value, std::regex (" ^[YN]$" ));
27
27
}
28
28
29
- void ZSwapObject::WriteLogEntry (const std::string& Name, const std::string& Value)
29
+ void ZSwapObject::WriteLogEntry (const std::string& Name, const std::string& Value) const
30
30
{
31
31
std::cout << std::vformat (ZSwapMessageLog, std::make_format_args (Name, Value)) << std::endl;
32
32
}
33
33
34
- void ZSwapObject::WriteZSwapValue (const std::string& Name, const std::string& Value)
34
+ void ZSwapObject::WriteZSwapValue (const std::string& Name, const std::string& Value) const
35
35
{
36
36
const std::string FullPath = ZSwapModuleParametersPath + Name;
37
37
if (!std::filesystem::exists (FullPath)) throw std::runtime_error (std::vformat (ZSwapErrorKernel, std::make_format_args (Name)));
@@ -40,7 +40,7 @@ void ZSwapObject::WriteZSwapValue(const std::string& Name, const std::string& Va
40
40
ZSwapSysFs.close ();
41
41
}
42
42
43
- std::string ZSwapObject::ReadZSwapValue (const std::string& Name)
43
+ std::string ZSwapObject::ReadZSwapValue (const std::string& Name) const
44
44
{
45
45
const std::string FullPath = ZSwapModuleParametersPath + Name;
46
46
if (!std::filesystem::exists (FullPath)) return " N/A" ;
@@ -51,115 +51,115 @@ std::string ZSwapObject::ReadZSwapValue(const std::string& Name)
51
51
return Result;
52
52
}
53
53
54
- std::string ZSwapObject::GetZSwapEnabled ()
54
+ std::string ZSwapObject::GetZSwapEnabled () const
55
55
{
56
56
return ReadZSwapValue (ZSwapEnabledName);
57
57
}
58
58
59
- void ZSwapObject::SetZSwapEnabled (const std::string& Value)
59
+ void ZSwapObject::SetZSwapEnabled (const std::string& Value) const
60
60
{
61
61
if (CheckEnabled (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorBool, std::make_format_args (ZSwapEnabledName)));
62
62
WriteLogEntry (ZSwapEnabledName, Value);
63
63
WriteZSwapValue (ZSwapEnabledName, Value);
64
64
}
65
65
66
- std::string ZSwapObject::GetZSwapSameFilledPages ()
66
+ std::string ZSwapObject::GetZSwapSameFilledPages () const
67
67
{
68
68
return ReadZSwapValue (ZSwapSameFilledPagesName);
69
69
}
70
70
71
- void ZSwapObject::SetZSwapSameFilledPages (const std::string& Value)
71
+ void ZSwapObject::SetZSwapSameFilledPages (const std::string& Value) const
72
72
{
73
73
if (CheckEnabled (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorBool, std::make_format_args (ZSwapSameFilledPagesName)));
74
74
WriteLogEntry (ZSwapSameFilledPagesName, Value);
75
75
WriteZSwapValue (ZSwapSameFilledPagesName, Value);
76
76
}
77
77
78
- std::string ZSwapObject::GetZSwapMaxPoolPercent ()
78
+ std::string ZSwapObject::GetZSwapMaxPoolPercent () const
79
79
{
80
80
return ReadZSwapValue (ZSwapMaxPoolPercentName);
81
81
}
82
82
83
- void ZSwapObject::SetZSwapMaxPoolPercent (const std::string& Value)
83
+ void ZSwapObject::SetZSwapMaxPoolPercent (const std::string& Value) const
84
84
{
85
85
if (CheckPercent (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorRange, std::make_format_args (ZSwapMaxPoolPercentName)));
86
86
WriteLogEntry (ZSwapMaxPoolPercentName, Value);
87
87
WriteZSwapValue (ZSwapMaxPoolPercentName, Value);
88
88
}
89
89
90
- std::string ZSwapObject::GetZSwapCompressor ()
90
+ std::string ZSwapObject::GetZSwapCompressor () const
91
91
{
92
92
return ReadZSwapValue (ZSwapCompressorName);
93
93
}
94
94
95
- void ZSwapObject::SetZSwapCompressor (const std::string& Value)
95
+ void ZSwapObject::SetZSwapCompressor (const std::string& Value) const
96
96
{
97
97
if (Value.empty ()) throw std::invalid_argument (std::vformat (ZSwapErrorEmpty, std::make_format_args (ZSwapCompressorName)));
98
98
WriteLogEntry (ZSwapCompressorName, Value);
99
99
WriteZSwapValue (ZSwapCompressorName, Value);
100
100
}
101
101
102
- std::string ZSwapObject::GetZSwapZpool ()
102
+ std::string ZSwapObject::GetZSwapZpool () const
103
103
{
104
104
return ReadZSwapValue (ZSwapZpoolName);
105
105
}
106
106
107
- void ZSwapObject::SetZSwapZpool (const std::string& Value)
107
+ void ZSwapObject::SetZSwapZpool (const std::string& Value) const
108
108
{
109
109
if (Value.empty ()) throw std::invalid_argument (std::vformat (ZSwapErrorEmpty, std::make_format_args (ZSwapZpoolName)));
110
110
WriteLogEntry (ZSwapZpoolName, Value);
111
111
WriteZSwapValue (ZSwapZpoolName, Value);
112
112
}
113
113
114
- std::string ZSwapObject::GetZSwapAcceptThresholdPercent ()
114
+ std::string ZSwapObject::GetZSwapAcceptThresholdPercent () const
115
115
{
116
116
return ReadZSwapValue (ZSwapAcceptThresholdPercentName);
117
117
}
118
118
119
- void ZSwapObject::SetZSwapAcceptThresholdPercent (const std::string& Value)
119
+ void ZSwapObject::SetZSwapAcceptThresholdPercent (const std::string& Value) const
120
120
{
121
121
if (CheckPercent (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorRange, std::make_format_args (ZSwapAcceptThresholdPercentName)));
122
122
WriteLogEntry (ZSwapAcceptThresholdPercentName, Value);
123
123
WriteZSwapValue (ZSwapAcceptThresholdPercentName, Value);
124
124
}
125
125
126
- std::string ZSwapObject::GetZSwapNonSameFilledPages ()
126
+ std::string ZSwapObject::GetZSwapNonSameFilledPages () const
127
127
{
128
128
return ReadZSwapValue (ZSwapNonSameFilledPagesName);
129
129
}
130
130
131
- void ZSwapObject::SetZSwapNonSameFilledPages (const std::string& Value)
131
+ void ZSwapObject::SetZSwapNonSameFilledPages (const std::string& Value) const
132
132
{
133
133
if (CheckEnabled (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorBool, std::make_format_args (ZSwapNonSameFilledPagesName)));
134
134
WriteLogEntry (ZSwapNonSameFilledPagesName, Value);
135
135
WriteZSwapValue (ZSwapNonSameFilledPagesName, Value);
136
136
}
137
137
138
- std::string ZSwapObject::GetZSwapExclusiveLoads ()
138
+ std::string ZSwapObject::GetZSwapExclusiveLoads () const
139
139
{
140
140
return ReadZSwapValue (ZSwapExclusiveLoadsName);
141
141
}
142
142
143
- void ZSwapObject::SetZSwapExclusiveLoads (const std::string& Value)
143
+ void ZSwapObject::SetZSwapExclusiveLoads (const std::string& Value) const
144
144
{
145
145
if (CheckEnabled (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorBool, std::make_format_args (ZSwapExclusiveLoadsName)));
146
146
WriteLogEntry (ZSwapExclusiveLoadsName, Value);
147
147
WriteZSwapValue (ZSwapExclusiveLoadsName, Value);
148
148
}
149
149
150
- std::string ZSwapObject::GetZSwapShrinkerEnabled ()
150
+ std::string ZSwapObject::GetZSwapShrinkerEnabled () const
151
151
{
152
152
return ReadZSwapValue (ZSwapShrinkerEnabledName);
153
153
}
154
154
155
- void ZSwapObject::SetZSwapShrinkerEnabled (const std::string& Value)
155
+ void ZSwapObject::SetZSwapShrinkerEnabled (const std::string& Value) const
156
156
{
157
157
if (CheckEnabled (Value)) throw std::invalid_argument (std::vformat (ZSwapErrorBool, std::make_format_args (ZSwapShrinkerEnabledName)));
158
158
WriteLogEntry (ZSwapShrinkerEnabledName, Value);
159
159
WriteZSwapValue (ZSwapShrinkerEnabledName, Value);
160
160
}
161
161
162
- bool ZSwapObject::IsAvailable ()
162
+ bool ZSwapObject::IsAvailable () const
163
163
{
164
164
return std::filesystem::exists (ZSwapModuleParametersPath);
165
165
}
0 commit comments